Commit c5f96267 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Remove GmsCoreSyncListener

This CL removes GmsCoreSyncListener class and some harness around it.
This class was implemented for https://crbug.com/552106, but that
feature was never finished. This CL also removes
ProfileSyncService::GetCustomPassphraseKey that became unused.

Bug: 903284
Change-Id: I096b2ab74915d2ed93b4c4077902a1de9abb4cee
Reviewed-on: https://chromium-review.googlesource.com/c/1326502Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606809}
parent 9f547d17
...@@ -47,7 +47,6 @@ import org.chromium.chrome.browser.rlz.RevenueStats; ...@@ -47,7 +47,6 @@ import org.chromium.chrome.browser.rlz.RevenueStats;
import org.chromium.chrome.browser.services.AndroidEduOwnerCheckCallback; import org.chromium.chrome.browser.services.AndroidEduOwnerCheckCallback;
import org.chromium.chrome.browser.signin.GoogleActivityController; import org.chromium.chrome.browser.signin.GoogleActivityController;
import org.chromium.chrome.browser.survey.SurveyController; import org.chromium.chrome.browser.survey.SurveyController;
import org.chromium.chrome.browser.sync.GmsCoreSyncListener;
import org.chromium.chrome.browser.tab.AuthenticatorNavigationInterceptor; import org.chromium.chrome.browser.tab.AuthenticatorNavigationInterceptor;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.GooglePlayWebApkInstallDelegate; import org.chromium.chrome.browser.webapps.GooglePlayWebApkInstallDelegate;
...@@ -152,14 +151,6 @@ public abstract class AppHooks { ...@@ -152,14 +151,6 @@ public abstract class AppHooks {
return new FeedbackReporter() {}; return new FeedbackReporter() {};
} }
/**
* @return An instance of GmsCoreSyncListener to notify GmsCore of sync encryption key changes.
* Will be null if one is unavailable.
*/
public GmsCoreSyncListener createGmsCoreSyncListener() {
return null;
}
/** /**
* @return An instance of GoogleActivityController. * @return An instance of GoogleActivityController.
*/ */
......
// 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.isEngineInitialized()
&& 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;
}
}
}
...@@ -220,11 +220,6 @@ public class ProfileSyncService { ...@@ -220,11 +220,6 @@ public class ProfileSyncService {
return nativeIsUsingSecondaryPassphrase(mNativeProfileSyncServiceAndroid); return nativeIsUsingSecondaryPassphrase(mNativeProfileSyncServiceAndroid);
} }
public byte[] getCustomPassphraseKey() {
assert isUsingSecondaryPassphrase();
return nativeGetCustomPassphraseKey(mNativeProfileSyncServiceAndroid);
}
/** /**
* Checks if we need a passphrase to decrypt a currently-enabled data type. This returns false * Checks if we need a passphrase to decrypt a currently-enabled data type. This returns false
* if a passphrase is needed for a type that is not currently enabled. * if a passphrase is needed for a type that is not currently enabled.
...@@ -563,7 +558,7 @@ public class ProfileSyncService { ...@@ -563,7 +558,7 @@ public class ProfileSyncService {
private native boolean nativeIsPassphraseRequiredForDecryption( private native boolean nativeIsPassphraseRequiredForDecryption(
long nativeProfileSyncServiceAndroid); long nativeProfileSyncServiceAndroid);
private native boolean nativeIsUsingSecondaryPassphrase(long nativeProfileSyncServiceAndroid); private native boolean nativeIsUsingSecondaryPassphrase(long nativeProfileSyncServiceAndroid);
private native byte[] nativeGetCustomPassphraseKey(long nativeProfileSyncServiceAndroid);
private native boolean nativeSetDecryptionPassphrase( private native boolean nativeSetDecryptionPassphrase(
long nativeProfileSyncServiceAndroid, String passphrase); long nativeProfileSyncServiceAndroid, String passphrase);
private native void nativeSetEncryptionPassphrase( private native void nativeSetEncryptionPassphrase(
......
...@@ -15,7 +15,6 @@ import org.chromium.base.Log; ...@@ -15,7 +15,6 @@ import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory; import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory;
import org.chromium.chrome.browser.invalidation.InvalidationController; import org.chromium.chrome.browser.invalidation.InvalidationController;
...@@ -99,11 +98,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen ...@@ -99,11 +98,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
} }
}); });
GmsCoreSyncListener gmsCoreSyncListener = AppHooks.get().createGmsCoreSyncListener();
if (gmsCoreSyncListener != null) {
mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
}
SigninManager.get().addSignInStateObserver(new SigninManager.SignInStateObserver() { SigninManager.get().addSignInStateObserver(new SigninManager.SignInStateObserver() {
@Override @Override
public void onSignedIn() { public void onSignedIn() {
......
...@@ -1474,7 +1474,6 @@ chrome_java_sources = [ ...@@ -1474,7 +1474,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/suggestions/SuggestionsSheetVisibilityChangeObserver.java", "java/src/org/chromium/chrome/browser/suggestions/SuggestionsSheetVisibilityChangeObserver.java",
"java/src/org/chromium/chrome/browser/survey/ChromeSurveyController.java", "java/src/org/chromium/chrome/browser/survey/ChromeSurveyController.java",
"java/src/org/chromium/chrome/browser/survey/SurveyController.java", "java/src/org/chromium/chrome/browser/survey/SurveyController.java",
"java/src/org/chromium/chrome/browser/sync/GmsCoreSyncListener.java",
"java/src/org/chromium/chrome/browser/sync/GoogleServiceAuthError.java", "java/src/org/chromium/chrome/browser/sync/GoogleServiceAuthError.java",
"java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java", "java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java",
"java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java", "java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java",
...@@ -2179,7 +2178,6 @@ chrome_test_java_sources = [ ...@@ -2179,7 +2178,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/sync/BookmarksTest.java", "javatests/src/org/chromium/chrome/browser/sync/BookmarksTest.java",
"javatests/src/org/chromium/chrome/browser/sync/FakeProfileSyncService.java", "javatests/src/org/chromium/chrome/browser/sync/FakeProfileSyncService.java",
"javatests/src/org/chromium/chrome/browser/sync/FirstRunTest.java", "javatests/src/org/chromium/chrome/browser/sync/FirstRunTest.java",
"javatests/src/org/chromium/chrome/browser/sync/GmsCoreSyncListenerTest.java",
"javatests/src/org/chromium/chrome/browser/sync/OpenTabsTest.java", "javatests/src/org/chromium/chrome/browser/sync/OpenTabsTest.java",
"javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java", "javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/sync/SyncTest.java", "javatests/src/org/chromium/chrome/browser/sync/SyncTest.java",
......
// 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 android.accounts.Account;
import android.support.test.filters.MediumTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import java.util.concurrent.Callable;
/**
* Test suite for the GmsCoreSyncListener.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@DisabledTest // crbug.com/789947
public class GmsCoreSyncListenerTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String PASSPHRASE = "passphrase";
static class CountingGmsCoreSyncListener extends GmsCoreSyncListener {
private int mCallCount;
@Override
public void updateEncryptionKey(byte[] key) {
mCallCount++;
}
public int callCount() {
return mCallCount;
}
}
private CountingGmsCoreSyncListener mListener;
@Before
public void setUp() throws Exception {
mListener = new CountingGmsCoreSyncListener();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
ProfileSyncService.get().addSyncStateChangedListener(mListener);
}
});
}
@After
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
ProfileSyncService.get().removeSyncStateChangedListener(mListener);
}
});
}
@Test
@MediumTest
@Feature({"Sync"})
public void testGetsKey() throws Throwable {
Account account = mSyncTestRule.setUpTestAccountAndSignIn();
Assert.assertEquals(0, mListener.callCount());
SyncTestUtil.encryptWithPassphrase(PASSPHRASE);
waitForCallCount(1);
mSyncTestRule.signOut();
mSyncTestRule.signIn(account);
Assert.assertEquals(1, mListener.callCount());
SyncTestUtil.decryptWithPassphrase(PASSPHRASE);
waitForCallCount(2);
}
@Test
@MediumTest
@Feature({"Sync"})
public void testClearData() throws Throwable {
Account account = mSyncTestRule.setUpTestAccountAndSignIn();
Assert.assertEquals(0, mListener.callCount());
SyncTestUtil.encryptWithPassphrase(PASSPHRASE);
waitForCallCount(1);
mSyncTestRule.clearServerData();
mSyncTestRule.signIn(account);
SyncTestUtil.encryptWithPassphrase(PASSPHRASE);
waitForCallCount(2);
}
private void waitForCallCount(int count) {
CriteriaHelper.pollUiThread(Criteria.equals(count, new Callable<Integer>() {
@Override
public Integer call() {
return mListener.callCount();
}
}));
}
}
...@@ -278,15 +278,6 @@ jboolean ProfileSyncServiceAndroid::IsUsingSecondaryPassphrase( ...@@ -278,15 +278,6 @@ jboolean ProfileSyncServiceAndroid::IsUsingSecondaryPassphrase(
return sync_service_->IsUsingSecondaryPassphrase(); return sync_service_->IsUsingSecondaryPassphrase();
} }
ScopedJavaLocalRef<jbyteArray>
ProfileSyncServiceAndroid::GetCustomPassphraseKey(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
std::string key = sync_service_->GetCustomPassphraseKey();
return base::android::ToJavaByteArray(
env, reinterpret_cast<const uint8_t*>(key.data()), key.size());
}
jint ProfileSyncServiceAndroid::GetPassphraseType( jint ProfileSyncServiceAndroid::GetPassphraseType(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>&) { const JavaParamRef<jobject>&) {
......
...@@ -95,9 +95,6 @@ class ProfileSyncServiceAndroid : public syncer::SyncServiceObserver { ...@@ -95,9 +95,6 @@ class ProfileSyncServiceAndroid : public syncer::SyncServiceObserver {
jboolean IsUsingSecondaryPassphrase( jboolean IsUsingSecondaryPassphrase(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
base::android::ScopedJavaLocalRef<jbyteArray> GetCustomPassphraseKey(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
jint GetPassphraseType(JNIEnv* env, jint GetPassphraseType(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
void SetEncryptionPassphrase( void SetEncryptionPassphrase(
......
...@@ -1457,14 +1457,6 @@ bool ProfileSyncService::IsUsingSecondaryPassphrase() const { ...@@ -1457,14 +1457,6 @@ bool ProfileSyncService::IsUsingSecondaryPassphrase() const {
return crypto_.IsUsingSecondaryPassphrase(); return crypto_.IsUsingSecondaryPassphrase();
} }
std::string ProfileSyncService::GetCustomPassphraseKey() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
syncer::SystemEncryptor encryptor;
syncer::Cryptographer cryptographer(&encryptor);
cryptographer.Bootstrap(sync_prefs_.GetEncryptionBootstrapToken());
return cryptographer.GetDefaultNigoriKeyData();
}
syncer::PassphraseType ProfileSyncService::GetPassphraseType() const { syncer::PassphraseType ProfileSyncService::GetPassphraseType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return crypto_.GetPassphraseType(); return crypto_.GetPassphraseType();
......
...@@ -447,10 +447,6 @@ class ProfileSyncService : public syncer::SyncService, ...@@ -447,10 +447,6 @@ class ProfileSyncService : public syncer::SyncService,
// to OpenTabsUIDelegate by introducing a similar observer mechanism. // to OpenTabsUIDelegate by introducing a similar observer mechanism.
virtual void NotifyForeignSessionUpdated(); virtual void NotifyForeignSessionUpdated();
// Returns a serialized NigoriKey proto generated from the bootstrap token in
// SyncPrefs. Will return the empty string if no bootstrap token exists.
std::string GetCustomPassphraseKey() const;
// Set whether sync is currently allowed by the platform. // Set whether sync is currently allowed by the platform.
void SetSyncAllowedByPlatform(bool allowed); void SetSyncAllowedByPlatform(bool allowed);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment