summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 19:32:33 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 19:32:33 +0000
commit0002cb4d1545e69b44b8ff57fd3823b629a73502 (patch)
treeed3b77840b44052696212983f6a6a36f2ba5bbfd
parent082c5a81828269d44c914f30b5addae02c45cba0 (diff)
downloadchromium_src-0002cb4d1545e69b44b8ff57fd3823b629a73502.zip
chromium_src-0002cb4d1545e69b44b8ff57fd3823b629a73502.tar.gz
chromium_src-0002cb4d1545e69b44b8ff57fd3823b629a73502.tar.bz2
Move ProfileSyncService away from listening for Signin notifications.
As part of the effort to remove Signin-related notifications, move ProfileSyncService to observe the SigninManager instead. BUG=345627 R=zea@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=256213 Review URL: https://codereview.chromium.org/189163007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259293 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync/profile_sync_service.cc63
-rw-r--r--chrome/browser/sync/profile_sync_service.h21
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc45
-rw-r--r--chrome/browser/sync/test/integration/profile_sync_service_harness.cc10
4 files changed, 54 insertions, 85 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 45548e2..af96745 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -334,18 +334,14 @@ void ProfileSyncService::StartSyncingWithServer() {
void ProfileSyncService::RegisterAuthNotifications() {
oauth2_token_service_->AddObserver(this);
-
- registrar_.Add(this,
- chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_));
- registrar_.Add(this,
- chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
- content::Source<Profile>(profile_));
+ if (signin())
+ signin()->AddObserver(this);
}
void ProfileSyncService::UnregisterAuthNotifications() {
+ if (signin())
+ signin()->RemoveObserver(this);
oauth2_token_service_->RemoveObserver(this);
- registrar_.RemoveAll();
}
void ProfileSyncService::RegisterDataTypeController(
@@ -2038,42 +2034,29 @@ void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
}
}
-void ProfileSyncService::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: {
- const GoogleServiceSigninSuccessDetails* successful =
- content::Details<const GoogleServiceSigninSuccessDetails>(
- details).ptr();
- if (!sync_prefs_.IsStartSuppressed() &&
- !successful->password.empty()) {
- cached_passphrase_ = successful->password;
- // Try to consume the passphrase we just cached. If the sync backend
- // is not running yet, the passphrase will remain cached until the
- // backend starts up.
- ConsumeCachedPassphraseIfPossible();
- }
+void ProfileSyncService::GoogleSigninSucceeded(const std::string& username,
+ const std::string& password) {
+ if (!sync_prefs_.IsStartSuppressed() && !password.empty()) {
+ cached_passphrase_ = password;
+ // Try to consume the passphrase we just cached. If the sync backend
+ // is not running yet, the passphrase will remain cached until the
+ // backend starts up.
+ ConsumeCachedPassphraseIfPossible();
+ }
#if defined(OS_CHROMEOS)
- RefreshSpareBootstrapToken(successful->password);
+ RefreshSpareBootstrapToken(password);
#endif
- if (!sync_initialized() ||
- GetAuthError().state() != AuthError::NONE) {
- // Track the fact that we're still waiting for auth to complete.
- is_auth_in_progress_ = true;
- }
- break;
- }
- case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT:
- sync_disabled_by_admin_ = false;
- DisableForUser();
- break;
- default: {
- NOTREACHED();
- }
+ if (!sync_initialized() || GetAuthError().state() != AuthError::NONE) {
+ // Track the fact that we're still waiting for auth to complete.
+ is_auth_in_progress_ = true;
}
}
+void ProfileSyncService::GoogleSignedOut(const std::string& username) {
+ sync_disabled_by_admin_ = false;
+ DisableForUser();
+}
+
void ProfileSyncService::AddObserver(
ProfileSyncServiceBase::Observer* observer) {
observers_.AddObserver(observer);
@@ -2152,6 +2135,8 @@ bool ProfileSyncService::IsStartSuppressed() const {
}
SigninManagerBase* ProfileSyncService::signin() const {
+ if (!signin_)
+ return NULL;
return signin_->GetOriginal();
}
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index cdffa0b..d481dac 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -20,6 +20,7 @@
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
+#include "chrome/browser/signin/signin_manager_base.h"
#include "chrome/browser/sync/backend_unrecoverable_error_handler.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/synced_device_tracker.h"
@@ -36,9 +37,6 @@
#include "components/sync_driver/failed_data_types_handler.h"
#include "components/sync_driver/sync_frontend.h"
#include "components/sync_driver/sync_prefs.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_types.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "net/base/backoff_entry.h"
@@ -54,7 +52,6 @@ class ManagedUserSigninManagerWrapper;
class Profile;
class ProfileOAuth2TokenService;
class ProfileSyncComponentsFactory;
-class SigninManagerBase;
class SyncGlobalError;
namespace browser_sync {
@@ -173,12 +170,12 @@ class ProfileSyncService : public ProfileSyncServiceBase,
public sync_driver::SyncPrefObserver,
public browser_sync::DataTypeManagerObserver,
public syncer::UnrecoverableErrorHandler,
- public content::NotificationObserver,
public KeyedService,
public browser_sync::DataTypeEncryptionHandler,
public OAuth2TokenService::Consumer,
public OAuth2TokenService::Observer,
- public SessionsSyncManager::SyncInternalApiDelegate {
+ public SessionsSyncManager::SyncInternalApiDelegate,
+ public SigninManagerBase::Observer {
public:
typedef browser_sync::SyncBackendHost::Status Status;
@@ -400,6 +397,11 @@ class ProfileSyncService : public ProfileSyncServiceBase,
virtual bool IsPassphraseRequired() const OVERRIDE;
virtual syncer::ModelTypeSet GetEncryptedDataTypes() const OVERRIDE;
+ // SigninManagerBase::Observer implementation.
+ virtual void GoogleSigninSucceeded(const std::string& username,
+ const std::string& password) OVERRIDE;
+ virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
+
// Called when a user chooses which data types to sync as part of the sync
// setup wizard. |sync_everything| represents whether they chose the
// "keep everything synced" option; if true, |chosen_types| will be ignored
@@ -565,11 +567,6 @@ class ProfileSyncService : public ProfileSyncServiceBase,
// SyncPrefObserver implementation.
virtual void OnSyncManagedPrefChange(bool is_sync_managed) OVERRIDE;
- // content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
// Changes which data types we're going to be syncing to |preferred_types|.
// If it is running, the DataTypeManager will be instructed to reconfigure
// the sync backend so that exactly these datatypes are actively synced. See
@@ -922,8 +919,6 @@ class ProfileSyncService : public ProfileSyncServiceBase,
syncer::SyncJsController sync_js_controller_;
- content::NotificationRegistrar registrar_;
-
// This allows us to gracefully handle an ABORTED return code from the
// DataTypeManager in the event that the server informed us to cease and
// desist syncing immediately.
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index 1fef3ac..5046757 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -5,7 +5,6 @@
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
@@ -24,8 +23,6 @@
#include "components/sync_driver/data_type_manager_mock.h"
#include "components/sync_driver/pref_names.h"
#include "components/sync_driver/sync_prefs.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
@@ -116,7 +113,22 @@ class ProfileSyncServiceStartupTest : public testing::Test {
return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory());
}
+ FakeSigninManagerForTesting* fake_signin() {
+ return static_cast<FakeSigninManagerForTesting*>(sync_->signin());
+ }
+
protected:
+ void SimulateTestUserSignin() {
+ profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
+ "test_user@gmail.com");
+#if !defined(OS_CHROMEOS)
+ fake_signin()->SignIn("test_user@gmail.com", "");
+#else
+ fake_signin()->SetAuthenticatedUsername("test_user@gmail.com");
+ sync_->GoogleSigninSucceeded("test_user@gmail.com", "");
+#endif
+ }
+
DataTypeManagerMock* SetUpDataTypeManager() {
DataTypeManagerMock* data_type_manager = new DataTypeManagerMock();
EXPECT_CALL(*components_factory_mock(),
@@ -201,15 +213,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
sync_->SetSetupInProgress(true);
// Simulate successful signin as test_user.
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
- "test_user@gmail.com");
- sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
- GoogleServiceSigninSuccessDetails details("test_user@gmail.com", "");
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_.get()),
- content::Details<const GoogleServiceSigninSuccessDetails>(&details));
-
+ SimulateTestUserSignin();
// Create some tokens in the token service.
IssueTestTokens();
@@ -242,14 +246,8 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
sync_->SetSetupInProgress(true);
// Simulate successful signin as test_user.
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
- "test_user@gmail.com");
- sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
- GoogleServiceSigninSuccessDetails details("test_user@gmail.com", "");
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_.get()),
- content::Details<const GoogleServiceSigninSuccessDetails>(&details));
+ SimulateTestUserSignin();
+
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
token_service->LoadCredentials("test_user@gmail.com");
@@ -291,12 +289,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
sync_->SetSetupInProgress(true);
// Simulate successful signin.
- GoogleServiceSigninSuccessDetails details("test_user@gmail.com",
- std::string());
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_.get()),
- content::Details<const GoogleServiceSigninSuccessDetails>(&details));
+ SimulateTestUserSignin();
sync_->SetSetupInProgress(false);
diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
index 03fcb28..b791ccd 100644
--- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc
@@ -14,7 +14,8 @@
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
-#include "chrome/browser/chrome_notification_types.h"
+#include "base/timer/timer.h"
+#include "chrome/browser/invalidation/p2p_invalidation_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_base.h"
@@ -27,7 +28,6 @@
#include "chrome/common/pref_names.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/sync_driver/data_type_controller.h"
-#include "content/public/browser/notification_service.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/internal_api/public/base/progress_marker_map.h"
#include "sync/internal_api/public/util/sync_string_conversions.h"
@@ -158,11 +158,7 @@ bool ProfileSyncServiceHarness::SetupSync(
// Authenticate sync client using GAIA credentials.
service()->signin()->SetAuthenticatedUsername(username_);
- GoogleServiceSigninSuccessDetails details(username_, password_);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_),
- content::Details<const GoogleServiceSigninSuccessDetails>(&details));
+ service()->GoogleSigninSucceeded(username_, password_);
#if defined(ENABLE_MANAGED_USERS)
std::string account_id = profile_->IsManaged() ?