Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java |
| index 83b9cd31d506b571b46f489948e4aa3ef28d9f6e..969462cd749095aa264bfe25ba02bcbdc0364cb9 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java |
| @@ -13,10 +13,8 @@ import android.content.Context; |
| import android.content.SyncResult; |
| import android.os.Bundle; |
| import android.os.Handler; |
| -import android.util.Log; |
| - |
| -import com.google.protos.ipc.invalidation.Types; |
| +import org.chromium.base.Log; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.SuppressFBWarnings; |
| @@ -24,6 +22,7 @@ import org.chromium.base.library_loader.LibraryProcessType; |
| import org.chromium.base.library_loader.ProcessInitException; |
| import org.chromium.chrome.browser.invalidation.InvalidationServiceFactory; |
| import org.chromium.chrome.browser.profiles.Profile; |
| +import org.chromium.components.invalidation.PendingInvalidation; |
| import org.chromium.content.app.ContentApplication; |
| import org.chromium.content.browser.BrowserStartupController; |
| import org.chromium.sync.signin.ChromeSigninController; |
| @@ -32,21 +31,11 @@ import java.util.concurrent.Semaphore; |
| import java.util.concurrent.TimeUnit; |
| /** |
| - * A sync adapter for Chromium. |
| + * A Sync adapter that receives invalidations from {@link InvalidationClientService} and dispatches |
| + * it to the native side with a caching layer in {@link DelayedSyncController}. |
| */ |
| public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| - private static final String TAG = "ChromiumSyncAdapter"; |
| - |
| - // TODO(nyquist) Make these fields package protected once downstream sync adapter tests are |
| - // removed. |
| - @VisibleForTesting |
| - public static final String INVALIDATION_OBJECT_SOURCE_KEY = "objectSource"; |
| - @VisibleForTesting |
| - public static final String INVALIDATION_OBJECT_ID_KEY = "objectId"; |
| - @VisibleForTesting |
| - public static final String INVALIDATION_VERSION_KEY = "version"; |
| - @VisibleForTesting |
| - public static final String INVALIDATION_PAYLOAD_KEY = "payload"; |
| + private static final String TAG = Log.makeTag("invalidation"); |
|
nyquist
2015/05/22 20:21:07
Nit: "cr.invalidation"? static initializers hurt s
knn
2015/06/04 18:23:29
Done.
|
| private final Application mApplication; |
| private final boolean mAsyncStartup; |
| @@ -71,8 +60,11 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| } |
| return; |
| } |
| + PendingInvalidation invalidation = new PendingInvalidation(extras); |
| - if (!DelayedSyncController.getInstance().shouldPerformSync(getContext(), extras, account)) { |
| + DelayedSyncController controller = DelayedSyncController.getInstance(); |
| + if (!controller.shouldNotifyInvalidation(extras)) { |
| + controller.addPendingInvalidation(getContext(), account.name, invalidation); |
| return; |
| } |
| @@ -81,7 +73,7 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| // Configure the callback with all the data it needs. |
| BrowserStartupController.StartupCallback callback = |
| - getStartupCallback(mApplication, account, extras, syncResult, semaphore); |
| + getStartupCallback(mApplication, account.name, invalidation, syncResult, semaphore); |
| startBrowserProcess(callback, syncResult, semaphore); |
| try { |
| @@ -92,7 +84,7 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| syncResult.stats.numIoExceptions++; |
| } |
| } catch (InterruptedException e) { |
| - Log.w(TAG, "Got InterruptedException when trying to request a sync.", e); |
| + Log.w(TAG, "Got InterruptedException when trying to request an invalidation.", e); |
| // Using numIoExceptions so Android will treat this as a soft error. |
| syncResult.stats.numIoExceptions++; |
| } |
| @@ -123,7 +115,7 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| }); |
| } catch (RuntimeException e) { |
| // It is still unknown why we ever experience this. See http://crbug.com/180044. |
| - Log.w(TAG, "Got exception when trying to request a sync. Informing Android system.", e); |
| + Log.w(TAG, "Got exception when trying to notify the invalidation.", e); |
| // Using numIoExceptions so Android will treat this as a soft error. |
| syncResult.stats.numIoExceptions++; |
| semaphore.release(); |
| @@ -148,40 +140,29 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| }); |
| } |
| - private BrowserStartupController.StartupCallback getStartupCallback( |
| - final Context context, final Account acct, Bundle extras, |
| + private BrowserStartupController.StartupCallback getStartupCallback(final Context context, |
| + final String account, final PendingInvalidation invalidation, |
| final SyncResult syncResult, final Semaphore semaphore) { |
| - final boolean syncAllTypes = extras.getString(INVALIDATION_OBJECT_ID_KEY) == null; |
| - final int objectSource = syncAllTypes ? 0 : extras.getInt(INVALIDATION_OBJECT_SOURCE_KEY); |
| - final String objectId = syncAllTypes ? "" : extras.getString(INVALIDATION_OBJECT_ID_KEY); |
| - final long version = syncAllTypes ? 0 : extras.getLong(INVALIDATION_VERSION_KEY); |
| - final String payload = syncAllTypes ? "" : extras.getString(INVALIDATION_PAYLOAD_KEY); |
| - |
| return new BrowserStartupController.StartupCallback() { |
| @Override |
| public void onSuccess(boolean alreadyStarted) { |
| - // Startup succeeded, so we can tickle the sync engine. |
| - if (syncAllTypes) { |
| - Log.v(TAG, "Received sync tickle for all types."); |
| - requestSyncForAllTypes(); |
| + // Startup succeeded, so we can notify the invalidation. |
| + if (invalidation.isInvalidateAll()) { |
| + Log.v(TAG, "Received invalidation for all types."); |
| } else { |
| - // Invalidations persisted before objectSource was added should be assumed to be |
| - // for Sync objects. TODO(stepco): Remove this check once all persisted |
| - // invalidations can be expected to have the objectSource. |
| - int resolvedSource = objectSource; |
| - if (resolvedSource == 0) { |
| - resolvedSource = Types.ObjectSource.CHROME_SYNC; |
| - } |
| - Log.v(TAG, "Received sync tickle for " + resolvedSource + " " + objectId + "."); |
| - requestSync(resolvedSource, objectId, version, payload); |
| + Log.v(TAG, "Received invalidation for " + invalidation.mObjectSource + " " |
| + + invalidation.mObjectId + "."); |
| } |
| + notifyInvalidation(invalidation.mObjectSource, invalidation.mObjectId, |
| + invalidation.mVersion, invalidation.mPayload); |
| semaphore.release(); |
| } |
| @Override |
| public void onFailure() { |
| - // The startup failed, so we reset the delayed sync state. |
| - DelayedSyncController.getInstance().setDelayedSync(context, acct.name); |
| + // The startup failed, so we defer the invalidation. |
| + DelayedSyncController.getInstance().addPendingInvalidation( |
| + context, account, invalidation); |
| // Using numIoExceptions so Android will treat this as a soft error. |
| syncResult.stats.numIoExceptions++; |
| semaphore.release(); |
| @@ -190,14 +171,9 @@ public abstract class ChromiumSyncAdapter extends AbstractThreadedSyncAdapter { |
| } |
| @VisibleForTesting |
| - public void requestSync(int objectSource, String objectId, long version, String payload) { |
| - InvalidationServiceFactory.getForProfile(Profile.getLastUsedProfile()) |
| - .requestSyncFromNativeChrome(objectSource, objectId, version, payload); |
| - } |
| - |
| - @VisibleForTesting |
| - public void requestSyncForAllTypes() { |
| + public void notifyInvalidation( |
| + int objectSource, String objectId, long version, String payload) { |
| InvalidationServiceFactory.getForProfile(Profile.getLastUsedProfile()) |
| - .requestSyncFromNativeChromeForAllTypes(); |
| + .notifyInvalidationToNativeChrome(objectSource, objectId, version, payload); |
| } |
| } |