Index: chrome/android/java/src/org/chromium/chrome/browser/sync/GmsCoreSyncListener.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/GmsCoreSyncListener.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/GmsCoreSyncListener.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4d3642acf33c7a43c7547bed75b169389299e189 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/GmsCoreSyncListener.java |
@@ -0,0 +1,42 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.sync; |
+ |
+import org.chromium.base.VisibleForTesting; |
+ |
+/** |
+ * A listener that will share sync's custom passphrase encryption key with GmsCore. |
+ * |
+ * This is to prevent users from seeing the custom passphrase dialog pop up in GmsCore after they |
+ * have already entered it in Chrome. |
+ */ |
+public abstract class GmsCoreSyncListener implements ProfileSyncService.SyncStateChangedListener { |
+ private boolean mGmsCoreInformed; |
+ |
+ /** |
+ * Inform GMSCore of a new custom passphrase encryption key. |
+ * |
+ * @param key The serialized NigoriKey proto. |
+ */ |
+ public abstract void updateEncryptionKey(byte[] key); |
+ |
+ @Override |
+ @VisibleForTesting |
+ public void syncStateChanged() { |
+ ProfileSyncService syncService = ProfileSyncService.get(); |
+ boolean passphraseSet = syncService.isBackendInitialized() |
+ && syncService.isUsingSecondaryPassphrase() && syncService.isCryptographerReady(); |
+ if (passphraseSet && !mGmsCoreInformed) { |
+ byte[] key = syncService.getCustomPassphraseKey(); |
+ if (key.length > 0) { |
+ updateEncryptionKey(key); |
+ mGmsCoreInformed = true; |
+ } |
+ } else if (!passphraseSet && mGmsCoreInformed) { |
+ // Prepare to inform GmsCore if a passphrase is set again. |
+ mGmsCoreInformed = false; |
+ } |
+ } |
+} |