summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 02:00:40 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 02:00:40 +0000
commit74263473b50b377b8269d2a5a93526a935dadbe8 (patch)
tree202d21dc56733752c8dae39a708ff743cf67c60f
parentff2c0c79df2e9c750cb9ae622919430d92b0f80d (diff)
downloadchromium_src-74263473b50b377b8269d2a5a93526a935dadbe8.zip
chromium_src-74263473b50b377b8269d2a5a93526a935dadbe8.tar.gz
chromium_src-74263473b50b377b8269d2a5a93526a935dadbe8.tar.bz2
Make SigninManager a ProfileKeyedService.
Added SigninManagerFactory class to handle creating and initializing SigninManager objects. Updated ProfileDependencyManager to call RegisterUserPrefs for TestingProfiles, and updated TestingProfile to allow calling SetPrefService() even if there's an existing PrefService (to accomodate having registered prefs). BUG=108017 TEST=none Review URL: http://codereview.chromium.org/9194007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117758 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc4
-rw-r--r--chrome/browser/prefs/browser_prefs.cc2
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h1
-rw-r--r--chrome/browser/profiles/profile.h4
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc9
-rw-r--r--chrome/browser/profiles/profile_impl.cc11
-rw-r--r--chrome/browser/profiles/profile_impl.h2
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.cc26
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.h7
-rw-r--r--chrome/browser/signin/signin_manager.cc23
-rw-r--r--chrome/browser/signin/signin_manager.h7
-rw-r--r--chrome/browser/signin/signin_manager_factory.cc49
-rw-r--r--chrome/browser/signin/signin_manager_factory.h41
-rw-r--r--chrome/browser/signin/signin_manager_fake.cc5
-rw-r--r--chrome/browser/signin/signin_manager_fake.h6
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_mock.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service_password_unittest.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_preference_unittest.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_session_unittest.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc10
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc14
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/test/base/testing_profile.cc14
-rw-r--r--chrome/test/base/testing_profile.h7
28 files changed, 168 insertions, 103 deletions
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index c955a06..67b3a5e 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -51,6 +51,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/browser_init.h"
@@ -893,7 +894,8 @@ void LoginUtilsImpl::StartSignedInServices(
// Fetch/Create the SigninManager - this will cause the TokenService to load
// tokens for the currently signed-in user if the SigninManager hasn't already
// been initialized.
- SigninManager* signin = user_profile->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile);
+ DCHECK(signin);
// Make sure SigninManager is connected to our current user (this should
// happen automatically because we set kGoogleServicesUsername in
// OnProfileCreated()).
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 8325ace..f2271358 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -47,7 +47,6 @@
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
-#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/tabs/pinned_tab_codec.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
@@ -189,7 +188,6 @@ void RegisterUserPrefs(PrefService* user_prefs) {
chromeos::Preferences::RegisterUserPrefs(user_prefs);
chromeos::ProxyConfigServiceImpl::RegisterPrefs(user_prefs);
#endif
- SigninManager::RegisterUserPrefs(user_prefs);
InstantController::RegisterUserPrefs(user_prefs);
NetPrefObserver::RegisterPrefs(user_prefs);
ProtocolHandlerRegistry::RegisterPrefs(user_prefs);
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index cbda251..97809b0 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -441,10 +441,6 @@ TokenService* OffTheRecordProfileImpl::GetTokenService() {
return NULL;
}
-SigninManager* OffTheRecordProfileImpl::GetSigninManager() {
- return NULL;
-}
-
ProfileSyncService* OffTheRecordProfileImpl::GetProfileSyncService() {
return NULL;
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index c242841..a647e96 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -89,7 +89,6 @@ class OffTheRecordProfileImpl : public Profile,
virtual bool DidLastSessionExitCleanly() OVERRIDE;
virtual BookmarkModel* GetBookmarkModel() OVERRIDE;
virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE;
- virtual SigninManager* GetSigninManager() OVERRIDE;
virtual TokenService* GetTokenService() OVERRIDE;
virtual ProfileSyncService* GetProfileSyncService() OVERRIDE;
virtual bool IsSameProfile(Profile* profile) OVERRIDE;
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index b79e00b..89b4c2d 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -65,7 +65,6 @@ class PrefService;
class ProfileSyncService;
class PromoCounter;
class ProtocolHandlerRegistry;
-class SigninManager;
class SpeechInputPreferences;
class SpellCheckHost;
class TemplateURLFetcher;
@@ -391,9 +390,6 @@ class Profile : public content::BrowserContext {
// Returns the ProtocolHandlerRegistry, creating if not yet created.
virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() = 0;
- // Returns the SigninManager, creating if not yet created.
- virtual SigninManager* GetSigninManager() = 0;
-
// Returns the Gaia Token Service, creating if not yet created.
virtual TokenService* GetTokenService() = 0;
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index f3c13c2..5045ddf 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -21,6 +21,7 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/speech/speech_input_extension_manager.h"
class Profile;
@@ -48,6 +49,7 @@ void AssertFactoriesBuilt() {
PluginPrefsFactory::GetInstance();
prerender::PrerenderManagerFactory::GetInstance();
SessionServiceFactory::GetInstance();
+ SigninManagerFactory::GetInstance();
SpeechInputExtensionManager::InitializeFactory();
TabRestoreServiceFactory::GetInstance();
TemplateURLServiceFactory::GetInstance();
@@ -108,10 +110,9 @@ void ProfileDependencyManager::CreateProfileServices(Profile* profile,
for (std::vector<ProfileKeyedServiceFactory*>::reverse_iterator rit =
destruction_order_.rbegin(); rit != destruction_order_.rend();
++rit) {
- if (!profile->IsOffTheRecord() && !profile->AsTestingProfile()) {
+ if (!profile->IsOffTheRecord()) {
// We only register preferences on normal profiles because the incognito
- // profile shares the pref service with the normal one and the testing
- // profile will often just insert its own PrefService.
+ // profile shares the pref service with the normal one.
(*rit)->RegisterUserPrefsOnProfile(profile);
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 5b36cc4..c73aea2 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -70,7 +70,6 @@
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
-#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/speech/chrome_speech_input_manager.h"
#include "chrome/browser/speech/chrome_speech_input_preferences.h"
@@ -163,7 +162,7 @@ namespace {
// REVIEWERS: Do not let anyone increment this. We need to drive the number of
// raw accessed services down to zero. DO NOT LET PEOPLE REGRESS THIS UNLESS
// THE PATCH ITSELF IS MAKING PROGRESS ON PKSF REFACTORING.
-COMPILE_ASSERT(sizeof(ProfileImpl) <= 664u, profile_impl_size_unexpected);
+COMPILE_ASSERT(sizeof(ProfileImpl) <= 656u, profile_impl_size_unexpected);
#endif
// Delay, in milliseconds, before we explicitly create the SessionService.
@@ -1401,14 +1400,6 @@ void ProfileImpl::EnsureSessionServiceCreated() {
SessionServiceFactory::GetForProfile(this);
}
-SigninManager* ProfileImpl::GetSigninManager() {
- if (!signin_manager_.get()) {
- signin_manager_.reset(new SigninManager());
- signin_manager_->Initialize(this);
- }
- return signin_manager_.get();
-}
-
TokenService* ProfileImpl::GetTokenService() {
if (!token_service_.get()) {
token_service_.reset(new TokenService());
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 1879aac..b5619d1 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -126,7 +126,6 @@ class ProfileImpl : public Profile,
virtual FilePath last_selected_directory() OVERRIDE;
virtual void set_last_selected_directory(const FilePath& path) OVERRIDE;
virtual ProfileSyncService* GetProfileSyncService() OVERRIDE;
- virtual SigninManager* GetSigninManager() OVERRIDE;
virtual TokenService* GetTokenService() OVERRIDE;
void InitSyncService();
virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE;
@@ -246,7 +245,6 @@ class ProfileImpl : public Profile,
scoped_refptr<PromoResourceService> promo_resource_service_;
scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
- scoped_ptr<SigninManager> signin_manager_;
scoped_ptr<TokenService> token_service_;
scoped_ptr<ProfileSyncComponentsFactory> profile_sync_factory_;
scoped_ptr<ProfileSyncService> sync_service_;
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.cc b/chrome/browser/profiles/profile_keyed_service_factory.cc
index e755ae3..886308d 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.cc
+++ b/chrome/browser/profiles/profile_keyed_service_factory.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -50,20 +50,18 @@ void ProfileKeyedServiceFactory::RegisterUserPrefsOnProfile(Profile* profile) {
// profiles, we just never register since incognito profiles share the same
// pref services with their parent profiles.
//
- // Testing profiles throw two wrenches into the mix. One: PrefService isn't
- // created at profile creation time so we have to move pref registration to
- // service creation time when using a testing factory. We can't change
- // PrefService because Two: some tests switch out the PrefService after the
- // TestingProfile has been created but before it's ever used. So we key our
- // check on Profile since there's already error checking code to prevent
- // a secondary PrefService from existing.
+ // TestingProfiles throw a wrench into the mix, in that some tests will
+ // swap out the PrefService after we've registered user prefs on the original
+ // PrefService. Test code that does this is responsible for either manually
+ // invoking RegisterUserPrefs() on the appropriate ProfileKeyedServiceFactory
+ // associated with the prefs they need, or they can use SetTestingFactory()
+ // and create a service (since service creation with a factory method causes
+ // registration to happen at service creation time).
//
- // Even worse is Three: Now that services are responsible for declaring their
- // preferences, we have to enforce a uniquenes check here because some tests
- // create one profile and multiple services of the same type attached to that
- // profile (serially, not parallel). This wasn't a problem when it was the
- // Profile that was responsible for registering the preferences, but now is
- // because of the timing issues introduced by One.
+ // Now that services are responsible for declaring their preferences, we have
+ // to enforce a uniquenes check here because some tests create one profile and
+ // multiple services of the same type attached to that profile (serially, not
+ // parallel) and we don't want to register multiple times on the same profile.
DCHECK(!profile->IsOffTheRecord());
std::set<Profile*>::iterator it = registered_preferences_.find(profile);
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.h b/chrome/browser/profiles/profile_keyed_service_factory.h
index 3cac950..ab5eceb 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.h
+++ b/chrome/browser/profiles/profile_keyed_service_factory.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -60,8 +60,9 @@ class ProfileKeyedServiceFactory {
// Common implementation that maps |profile| to some service object. Deals
// with incognito profiles per subclass instructions with
- // ServiceActiveInIncognito(). If |create| is true, the service will be
- // created using BuildServiceInstanceFor() if it doesn't already exist.
+ // ServiceRedirectedInIncognito() and ServiceHasOwnInstanceInIncognito().
+ // If |create| is true, the service will be created using
+ // BuildServiceInstanceFor() if it doesn't already exist.
ProfileKeyedService* GetServiceForProfile(Profile* profile, bool create);
// The main public interface for declaring dependencies between services
diff --git a/chrome/browser/signin/signin_manager.cc b/chrome/browser/signin/signin_manager.cc
index ae1f87b..75a4abb 100644
--- a/chrome/browser/signin/signin_manager.cc
+++ b/chrome/browser/signin/signin_manager.cc
@@ -27,18 +27,6 @@ SigninManager::SigninManager()
SigninManager::~SigninManager() {}
-// static
-void SigninManager::RegisterUserPrefs(PrefService* user_prefs) {
- user_prefs->RegisterBooleanPref(prefs::kSyncUsingOAuth, "",
- PrefService::UNSYNCABLE_PREF);
- user_prefs->RegisterStringPref(prefs::kGoogleServicesUsername, "",
- PrefService::UNSYNCABLE_PREF);
- user_prefs->RegisterBooleanPref(prefs::kAutologinEnabled, true,
- PrefService::UNSYNCABLE_PREF);
- user_prefs->RegisterBooleanPref(prefs::kReverseAutologinEnabled, true,
- PrefService::UNSYNCABLE_PREF);
-}
-
void SigninManager::Initialize(Profile* profile) {
profile_ = profile;
@@ -46,10 +34,13 @@ void SigninManager::Initialize(Profile* profile) {
prefs::kGoogleServicesUsername);
if (!user.empty())
SetAuthenticatedUsername(user);
- profile_->GetTokenService()->Initialize(
- GaiaConstants::kChromeSource, profile_);
- if (!authenticated_username_.empty()) {
- profile_->GetTokenService()->LoadTokensFromDB();
+ // TokenService can be null for unit tests.
+ TokenService* token_service = profile_->GetTokenService();
+ if (token_service) {
+ token_service->Initialize(GaiaConstants::kChromeSource, profile_);
+ if (!authenticated_username_.empty()) {
+ token_service->LoadTokensFromDB();
+ }
}
}
diff --git a/chrome/browser/signin/signin_manager.h b/chrome/browser/signin/signin_manager.h
index 8fdbd18..8f55010 100644
--- a/chrome/browser/signin/signin_manager.h
+++ b/chrome/browser/signin/signin_manager.h
@@ -24,6 +24,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/net/gaia/gaia_oauth_fetcher.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/common/net/gaia/gaia_auth_consumer.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "content/public/browser/notification_observer.h"
@@ -47,14 +48,12 @@ struct GoogleServiceSigninSuccessDetails {
class SigninManager : public GaiaAuthConsumer,
public GaiaOAuthConsumer,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public ProfileKeyedService {
public:
SigninManager();
virtual ~SigninManager();
- // Call to register our prefs.
- static void RegisterUserPrefs(PrefService* user_prefs);
-
// If user was signed in, load tokens from DB if available.
void Initialize(Profile* profile);
bool IsInitialized() const;
diff --git a/chrome/browser/signin/signin_manager_factory.cc b/chrome/browser/signin/signin_manager_factory.cc
new file mode 100644
index 0000000..c844da0
--- /dev/null
+++ b/chrome/browser/signin/signin_manager_factory.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2012 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.
+
+#include "chrome/browser/signin/signin_manager_factory.h"
+
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/common/pref_names.h"
+
+SigninManagerFactory::SigninManagerFactory()
+ : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
+ // TODO(atwilson): SigninManager depends on TokenService - when this is
+ // converted to the ProfileKeyedService framework, uncomment this dependency.
+ // DependsOn(TokenServiceFactory::GetInstance());
+}
+
+SigninManagerFactory::~SigninManagerFactory() {}
+
+// static
+SigninManager* SigninManagerFactory::GetForProfile(Profile* profile) {
+ return static_cast<SigninManager*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+// static
+SigninManagerFactory* SigninManagerFactory::GetInstance() {
+ return Singleton<SigninManagerFactory>::get();
+}
+
+void SigninManagerFactory::RegisterUserPrefs(PrefService* user_prefs) {
+ user_prefs->RegisterBooleanPref(prefs::kSyncUsingOAuth, "",
+ PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterStringPref(prefs::kGoogleServicesUsername, "",
+ PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterBooleanPref(prefs::kAutologinEnabled, true,
+ PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterBooleanPref(prefs::kReverseAutologinEnabled, true,
+ PrefService::UNSYNCABLE_PREF);
+}
+
+ProfileKeyedService* SigninManagerFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ SigninManager* service = new SigninManager();
+ service->Initialize(profile);
+ return service;
+}
+
diff --git a/chrome/browser/signin/signin_manager_factory.h b/chrome/browser/signin/signin_manager_factory.h
new file mode 100644
index 0000000..f281447
--- /dev/null
+++ b/chrome/browser/signin/signin_manager_factory.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2012 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.
+
+#ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
+#define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
+#pragma once
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class SigninManager;
+class Profile;
+
+// Singleton that owns all SigninManagers and associates them with
+// Profiles. Listens for the Profile's destruction notification and cleans up
+// the associated SigninManager.
+class SigninManagerFactory : public ProfileKeyedServiceFactory {
+ public:
+ // Returns the instance of SigninManager associated with this profile
+ // (creating one if none exists). Returns NULL if this profile cannot have a
+ // SigninManager (for example, if |profile| is incognito).
+ static SigninManager* GetForProfile(Profile* profile);
+
+ // Returns an instance of the SigninManagerFactory singleton.
+ static SigninManagerFactory* GetInstance();
+
+ // Implementation of ProfileKeyedServiceFactory (public so tests can call it).
+ virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE;
+ private:
+ friend struct DefaultSingletonTraits<SigninManagerFactory>;
+
+ SigninManagerFactory();
+ virtual ~SigninManagerFactory();
+
+ // ProfileKeyedServiceFactory:
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+};
+
+#endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
diff --git a/chrome/browser/signin/signin_manager_fake.cc b/chrome/browser/signin/signin_manager_fake.cc
index 6c70155..0eae17d 100644
--- a/chrome/browser/signin/signin_manager_fake.cc
+++ b/chrome/browser/signin/signin_manager_fake.cc
@@ -18,3 +18,8 @@ void FakeSigninManager::StartSignIn(const std::string& username,
void FakeSigninManager::SignOut() {
authenticated_username_.clear();
}
+
+// static
+ProfileKeyedService* FakeSigninManager::Build(Profile* profile) {
+ return new FakeSigninManager();
+}
diff --git a/chrome/browser/signin/signin_manager_fake.h b/chrome/browser/signin/signin_manager_fake.h
index dffe6a6..a1e1c42 100644
--- a/chrome/browser/signin/signin_manager_fake.h
+++ b/chrome/browser/signin/signin_manager_fake.h
@@ -11,6 +11,9 @@
#include "base/compiler_specific.h"
#include "chrome/browser/signin/signin_manager.h"
+class Profile;
+class ProfileKeyedService;
+
// A signin manager that bypasses actual authentication routines with servers
// and accepts the credentials provided to StartSignIn.
class FakeSigninManager : public SigninManager {
@@ -23,6 +26,9 @@ class FakeSigninManager : public SigninManager {
const std::string& login_token,
const std::string& login_captcha) OVERRIDE;
virtual void SignOut() OVERRIDE;
+
+ // Helper function to be used with ProfileKeyedService::SetTestingFactory().
+ static ProfileKeyedService* Build(Profile* profile);
};
#endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FAKE_H_
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc
index b9d4f76..dd9fd39 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.cc
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/api/syncable_service.h"
#include "chrome/browser/sync/glue/app_data_type_controller.h"
#include "chrome/browser/sync/glue/app_notification_data_type_controller.h"
@@ -94,8 +95,7 @@ ProfileSyncService*
ProfileSyncService::StartBehavior behavior =
browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START
: ProfileSyncService::MANUAL_START;
-
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
// TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync
// is set up and *not* a browser restart for a manual-start platform (where
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index 49ee5dd..efabf4a 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/engine/model_changing_syncer_command.h"
#include "chrome/browser/sync/glue/autofill_data_type_controller.h"
@@ -399,7 +400,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
bool will_fail_association,
syncable::ModelType type) {
AbstractAutofillFactory* factory = GetFactory(type);
- SigninManager* signin = profile_.GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_);
signin->SetAuthenticatedUsername("test_user");
service_.reset(
new TestProfileSyncService(&factory_,
diff --git a/chrome/browser/sync/profile_sync_service_mock.cc b/chrome/browser/sync/profile_sync_service_mock.cc
index 8770a0f..b5755bb 100644
--- a/chrome/browser/sync/profile_sync_service_mock.cc
+++ b/chrome/browser/sync/profile_sync_service_mock.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/prefs/pref_service_mock_builder.h"
#include "chrome/browser/prefs/testing_pref_store.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/common/pref_names.h"
@@ -37,7 +38,8 @@ Profile* ProfileSyncServiceMock::MakeSignedInTestingProfile() {
.WithUserPrefs(user_prefs)
.Create();
profile->SetPrefService(prefs);
- SigninManager::RegisterUserPrefs(prefs);
+ // We just blew away our prefs, so reregister them.
+ SigninManagerFactory::GetInstance()->RegisterUserPrefs(prefs);
user_prefs->SetString(prefs::kGoogleServicesUsername, "foo");
return profile;
}
diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc
index 8d3fea9..2e0cd63 100644
--- a/chrome/browser/sync/profile_sync_service_password_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/glue/password_change_processor.h"
#include "chrome/browser/sync/glue/password_data_type_controller.h"
@@ -215,7 +216,7 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
void StartSyncService(const base::Closure& root_callback,
const base::Closure& node_callback) {
if (!service_.get()) {
- SigninManager* signin = profile_.GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_);
signin->SetAuthenticatedUsername("test_user");
service_.reset(new PasswordTestProfileSyncService(
&factory_, &profile_, signin, false,
diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
index 6656abb..72e542c 100644
--- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/prefs/pref_model_associator.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/api/sync_data.h"
@@ -120,7 +121,7 @@ class ProfileSyncServicePreferenceTest
if (service_.get())
return false;
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
signin->SetAuthenticatedUsername("test");
service_.reset(new TestProfileSyncService(
&factory_,
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc
index 7c9252e..1d3a7ff 100644
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/session_service_test_helper.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/glue/session_change_processor.h"
#include "chrome/browser/sync/glue/session_data_type_controller.h"
@@ -224,7 +225,7 @@ class ProfileSyncServiceSessionTest
bool will_fail_association) {
if (sync_service_.get())
return false;
- SigninManager* signin = profile()->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile());
signin->SetAuthenticatedUsername("test_user");
sync_service_.reset(new TestProfileSyncService(
&factory_,
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index a39ff0b..b211602 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_manager_fake.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/sync/glue/data_type_manager.h"
@@ -70,9 +71,10 @@ class ProfileSyncServiceStartupTest : public testing::Test {
protected:
// Overridden below by ProfileSyncServiceStartupCrosTest.
virtual void CreateSyncService() {
- SigninManager* signin = new FakeSigninManager();
+ SigninManager* signin = static_cast<SigninManager*>(
+ SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), FakeSigninManager::Build));
signin->SetAuthenticatedUsername("test_user");
- profile_->SetSigninManager(signin);
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
signin,
@@ -101,7 +103,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
protected:
virtual void CreateSyncService() {
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
signin->SetAuthenticatedUsername("test_user");
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
@@ -120,7 +122,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
// Make sure SigninManager doesn't think we're signed in (undoes the call to
// SetAuthenticatedUsername() in CreateSyncService()).
- profile_->GetSigninManager()->SignOut();
+ SigninManagerFactory::GetForProfile(profile_.get())->SignOut();
// Should not actually start, rather just clean things up and wait
// to be enabled.
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index d4a2b38..1b2c158 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_backend_host_mock.h"
@@ -180,7 +181,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
void StartSyncService(const base::Closure& callback) {
if (!service_.get()) {
- SigninManager* signin = profile_.GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_);
signin->SetAuthenticatedUsername("test");
service_.reset(
new TestProfileSyncService(&factory_,
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index bf47f3b..10cb293 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/values.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
@@ -91,7 +92,8 @@ class ProfileSyncServiceTest : public testing::Test {
bool sync_setup_completed,
bool expect_create_dtm) {
if (!service_.get()) {
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin =
+ SigninManagerFactory::GetForProfile(profile_.get());
signin->SetAuthenticatedUsername("test");
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
@@ -142,9 +144,10 @@ class ProfileSyncServiceTest : public testing::Test {
};
TEST_F(ProfileSyncServiceTest, InitialState) {
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
- profile_->GetSigninManager(),
+ signin,
ProfileSyncService::MANUAL_START,
true,
base::Closure()));
@@ -159,9 +162,10 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicy) {
profile_->GetTestingPrefService()->SetManagedPref(
prefs::kSyncManaged,
Value::CreateBooleanValue(true));
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
- profile_->GetSigninManager(),
+ signin,
ProfileSyncService::MANUAL_START,
true,
base::Closure()));
@@ -170,7 +174,7 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicy) {
}
TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
signin->SetAuthenticatedUsername("test");
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
@@ -190,7 +194,7 @@ TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
}
TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
- SigninManager* signin = profile_->GetSigninManager();
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
signin->SetAuthenticatedUsername("test");
service_.reset(new TestProfileSyncService(&factory_,
profile_.get(),
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index cb03e7e..b264d82 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2176,6 +2176,8 @@
'browser/shell_integration_win.cc',
'browser/signin/signin_manager.cc',
'browser/signin/signin_manager.h',
+ 'browser/signin/signin_manager_factory.cc',
+ 'browser/signin/signin_manager_factory.h',
'browser/signin/token_service.cc',
'browser/signin/token_service.h',
'browser/simple_message_box.h',
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 3da1348..e3d2ebe 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -35,7 +35,6 @@
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/speech/chrome_speech_input_preferences.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
@@ -577,7 +576,6 @@ PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
}
void TestingProfile::SetPrefService(PrefService* prefs) {
- DCHECK(!prefs_.get());
prefs_.reset(prefs);
}
@@ -799,18 +797,6 @@ void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
MessageLoop::current()->Run();
}
-void TestingProfile::SetSigninManager(SigninManager* signin_manager) {
- DCHECK(!signin_manager_.get());
- signin_manager_.reset(signin_manager);
-}
-
-SigninManager* TestingProfile::GetSigninManager() {
- if (!signin_manager_.get()) {
- signin_manager_.reset(new SigninManager());
- }
- return signin_manager_.get();
-}
-
TokenService* TestingProfile::GetTokenService() {
if (!token_service_.get()) {
token_service_.reset(new TokenService());
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index ab99104..203923f 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -281,10 +281,6 @@ class TestingProfile : public Profile {
// history service processes all pending requests.
void BlockUntilHistoryProcessesPendingRequests();
- // Sets the profile's SigninManager - lets test code provide their own.
- // TestingProfile takes ownership of the passed pointer.
- void SetSigninManager(SigninManager* signin_manager);
- virtual SigninManager* GetSigninManager() OVERRIDE;
virtual TokenService* GetTokenService() OVERRIDE;
// Creates and initializes a profile sync service if the tests require one.
virtual ProfileSyncService* GetProfileSyncService() OVERRIDE;
@@ -339,9 +335,6 @@ class TestingProfile : public Profile {
// is invoked.
scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
- // The SigninManager. Created by GetSigninManager.
- scoped_ptr<SigninManager> signin_manager_;
-
// The TokenService. Created by CreateTokenService. Filled with dummy data.
scoped_ptr<TokenService> token_service_;