mobile/android/base/sync/synchronizer/ServerLocalSynchronizerSession.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.sync.synchronizer;
     7 import org.mozilla.gecko.background.common.log.Logger;
     8 import org.mozilla.gecko.sync.repositories.FetchFailedException;
     9 import org.mozilla.gecko.sync.repositories.StoreFailedException;
    11 /**
    12  * A <code>SynchronizerSession</code> designed to be used between a remote
    13  * server and a local repository.
    14  * <p>
    15  * Handles failure cases as follows (in the order they will occur during a sync):
    16  * <ul>
    17  * <li>Remote fetch failures abort.</li>
    18  * <li>Local store failures are ignored.</li>
    19  * <li>Local fetch failures abort.</li>
    20  * <li>Remote store failures abort.</li>
    21  * </ul>
    22  */
    23 public class ServerLocalSynchronizerSession extends SynchronizerSession {
    24   protected static final String LOG_TAG = "ServLocSynchronizerSess";
    26   public ServerLocalSynchronizerSession(Synchronizer synchronizer, SynchronizerSessionDelegate delegate) {
    27     super(synchronizer, delegate);
    28   }
    30   public void onFirstFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) {
    31     // Fetch failures always abort.
    32     int numRemoteFetchFailed = recordsChannel.getFetchFailureCount();
    33     if (numRemoteFetchFailed > 0) {
    34       final String message = "Got " + numRemoteFetchFailed + " failures fetching remote records!";
    35       Logger.warn(LOG_TAG, message + " Aborting session.");
    36       delegate.onSynchronizeFailed(this, new FetchFailedException(), message);
    37       return;
    38     }
    39     Logger.trace(LOG_TAG, "No failures fetching remote records.");
    41     // Local store failures are ignored.
    42     int numLocalStoreFailed = recordsChannel.getStoreFailureCount();
    43     if (numLocalStoreFailed > 0) {
    44       final String message = "Got " + numLocalStoreFailed + " failures storing local records!";
    45       Logger.warn(LOG_TAG, message + " Ignoring local store failures and continuing synchronizer session.");
    46     } else {
    47       Logger.trace(LOG_TAG, "No failures storing local records.");
    48     }
    50     super.onFirstFlowCompleted(recordsChannel, fetchEnd, storeEnd);
    51   }
    53   public void onSecondFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) {
    54     // Fetch failures always abort.
    55     int numLocalFetchFailed = recordsChannel.getFetchFailureCount();
    56     if (numLocalFetchFailed > 0) {
    57       final String message = "Got " + numLocalFetchFailed + " failures fetching local records!";
    58       Logger.warn(LOG_TAG, message + " Aborting session.");
    59       delegate.onSynchronizeFailed(this, new FetchFailedException(), message);
    60       return;
    61     }
    62     Logger.trace(LOG_TAG, "No failures fetching local records.");
    64     // Remote store failures abort!
    65     int numRemoteStoreFailed = recordsChannel.getStoreFailureCount();
    66     if (numRemoteStoreFailed > 0) {
    67       final String message = "Got " + numRemoteStoreFailed + " failures storing remote records!";
    68       Logger.warn(LOG_TAG, message + " Aborting session.");
    69       delegate.onSynchronizeFailed(this, new StoreFailedException(), message);
    70       return;
    71     }
    72     Logger.trace(LOG_TAG, "No failures storing remote records.");
    74     super.onSecondFlowCompleted(recordsChannel, fetchEnd, storeEnd);
    75   }
    76 }

mercurial