diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 21:11:41 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 21:11:41 +0000 |
commit | e1011c9cd18af7ec751bf94d02b3b37a7f64f92f (patch) | |
tree | 6a749a53f2ed1d45cc2ef7362a0b80650b3af646 | |
parent | f22fae44c1e8dadee6cf78b7a01a6465dfe33656 (diff) | |
download | chromium_src-e1011c9cd18af7ec751bf94d02b3b37a7f64f92f.zip chromium_src-e1011c9cd18af7ec751bf94d02b3b37a7f64f92f.tar.gz chromium_src-e1011c9cd18af7ec751bf94d02b3b37a7f64f92f.tar.bz2 |
Move ownership of SigninGlobalError from SigninManager to
ProfileOAuth2TokenService.
BUG=249467
Review URL: https://chromiumcodereview.appspot.com/17007003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210618 0039d316-1c4b-4281-b951-d872f2087c98
27 files changed, 196 insertions, 146 deletions
diff --git a/chrome/browser/extensions/api/identity/identity_api.cc b/chrome/browser/extensions/api/identity/identity_api.cc index 407948f..fcfa7d4a 100644 --- a/chrome/browser/extensions/api/identity/identity_api.cc +++ b/chrome/browser/extensions/api/identity/identity_api.cc @@ -20,8 +20,8 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/signin/signin_manager.h" -#include "chrome/browser/signin/signin_manager_factory.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" +#include "chrome/browser/signin/signin_global_error.h" #include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" #include "chrome/common/chrome_notification_types.h" @@ -639,21 +639,22 @@ const base::Time& IdentityTokenCacheValue::expiration_time() const { IdentityAPI::IdentityAPI(Profile* profile) : profile_(profile), - signin_manager_(NULL), - error_(GoogleServiceAuthError::NONE) { + error_(GoogleServiceAuthError::NONE), + initialized_(false) { } IdentityAPI::~IdentityAPI() { } void IdentityAPI::Initialize() { - signin_manager_ = SigninManagerFactory::GetForProfile(profile_); - signin_manager_->signin_global_error()->AddProvider(this); + SigninGlobalError::GetForProfile(profile_)->AddProvider(this); TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); registrar_.Add(this, chrome::NOTIFICATION_TOKEN_AVAILABLE, content::Source<TokenService>(token_service)); + + initialized_ = true; } IdentityMintRequestQueue* IdentityAPI::mint_queue() { @@ -702,16 +703,18 @@ const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() { } void IdentityAPI::ReportAuthError(const GoogleServiceAuthError& error) { - if (!signin_manager_) - Initialize(); - error_ = error; - signin_manager_->signin_global_error()->AuthStatusChanged(); + SigninGlobalError::GetForProfile(profile_)->AuthStatusChanged(); } void IdentityAPI::Shutdown() { - if (signin_manager_) - signin_manager_->signin_global_error()->RemoveProvider(this); + if (!initialized_) + return; + + registrar_.RemoveAll(); + SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); + + initialized_ = false; } static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > @@ -735,15 +738,17 @@ void IdentityAPI::Observe(int type, if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken) { error_ = GoogleServiceAuthError::AuthErrorNone(); - signin_manager_->signin_global_error()->AuthStatusChanged(); + SigninGlobalError::GetForProfile(profile_)->AuthStatusChanged(); } } template <> void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies() { DependsOn(ExtensionSystemFactory::GetInstance()); + // Need dependency on ProfileOAuth2TokenServiceFactory because it owns + // the SigninGlobalError instance. + DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); DependsOn(TokenServiceFactory::GetInstance()); - DependsOn(SigninManagerFactory::GetInstance()); } IdentityAPI::TokenCacheKey::TokenCacheKey(const std::string& extension_id, diff --git a/chrome/browser/extensions/api/identity/identity_api.h b/chrome/browser/extensions/api/identity/identity_api.h index a04a01d..c1afb7e 100644 --- a/chrome/browser/extensions/api/identity/identity_api.h +++ b/chrome/browser/extensions/api/identity/identity_api.h @@ -26,7 +26,6 @@ class GoogleServiceAuthError; class MockGetAuthTokenFunction; class Profile; -class SigninManagerBase; namespace extensions { @@ -288,8 +287,8 @@ class IdentityAPI : public ProfileKeyedAPI, static const bool kServiceIsNULLWhileTesting = true; Profile* profile_; - SigninManagerBase* signin_manager_; GoogleServiceAuthError error_; + bool initialized_; // Used to listen to notifications from the TokenService. content::NotificationRegistrar registrar_; IdentityMintRequestQueue mint_queue_; diff --git a/chrome/browser/signin/profile_oauth2_token_service.cc b/chrome/browser/signin/profile_oauth2_token_service.cc index a13ac04..a0ba926 100644 --- a/chrome/browser/signin/profile_oauth2_token_service.cc +++ b/chrome/browser/signin/profile_oauth2_token_service.cc @@ -9,10 +9,13 @@ #include "base/stl_util.h" #include "base/time/time.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/signin_global_error.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/signin/token_service_factory.h" +#include "chrome/browser/ui/global_error/global_error_service.h" +#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" @@ -21,6 +24,17 @@ #include "google_apis/gaia/google_service_auth_error.h" #include "net/url_request/url_request_context_getter.h" +namespace { + +std::string GetAccountId(Profile* profile) { + SigninManagerBase* signin_manager = + SigninManagerFactory::GetForProfileIfExists(profile); + return signin_manager ? signin_manager->GetAuthenticatedUsername() : + std::string(); +} + +} // namespace + ProfileOAuth2TokenService::ProfileOAuth2TokenService( net::URLRequestContextGetter* getter) : OAuth2TokenService(getter), @@ -29,6 +43,9 @@ ProfileOAuth2TokenService::ProfileOAuth2TokenService( } ProfileOAuth2TokenService::~ProfileOAuth2TokenService() { + DCHECK(!signin_global_error_.get()) << + "ProfileOAuth2TokenService::Initialize called but not " + "ProfileOAuth2TokenService::Shutdown"; } void ProfileOAuth2TokenService::Initialize(Profile* profile) { @@ -38,6 +55,11 @@ void ProfileOAuth2TokenService::Initialize(Profile* profile) { DCHECK(!profile_); profile_ = profile; + signin_global_error_.reset(new SigninGlobalError(profile)); + GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( + signin_global_error_.get()); + signin_global_error_->AddProvider(this); + content::Source<TokenService> token_service_source( TokenServiceFactory::GetForProfile(profile)); registrar_.Add(this, @@ -52,15 +74,13 @@ void ProfileOAuth2TokenService::Initialize(Profile* profile) { registrar_.Add(this, chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, token_service_source); - SigninManagerFactory::GetForProfile(profile_)->signin_global_error()-> - AddProvider(this); } void ProfileOAuth2TokenService::Shutdown() { - if (profile_) { - SigninManagerFactory::GetForProfile(profile_)->signin_global_error()-> - RemoveProvider(this); - } + signin_global_error_->RemoveProvider(this); + GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( + signin_global_error_.get()); + signin_global_error_.reset(); } std::string ProfileOAuth2TokenService::GetRefreshToken() { @@ -81,8 +101,7 @@ void ProfileOAuth2TokenService::UpdateAuthError( if (error.state() != last_auth_error_.state()) { last_auth_error_ = error; - SigninManagerFactory::GetForProfile(profile_)->signin_global_error()-> - AuthStatusChanged(); + signin_global_error_->AuthStatusChanged(); } } @@ -98,9 +117,7 @@ void ProfileOAuth2TokenService::Observe( GaiaConstants::kGaiaOAuth2LoginRefreshToken) { ClearCache(); UpdateAuthError(GoogleServiceAuthError::AuthErrorNone()); - FireRefreshTokenAvailable( - SigninManagerFactory::GetForProfile(profile_)-> - GetAuthenticatedUsername()); + FireRefreshTokenAvailable(GetAccountId(profile_)); } break; } @@ -113,10 +130,7 @@ void ProfileOAuth2TokenService::Observe( GaiaConstants::kGaiaOAuth2LoginRefreshToken) { ClearCache(); UpdateAuthError(tok_details->error()); - FireRefreshTokenRevoked( - SigninManagerFactory::GetForProfile(profile_)-> - GetAuthenticatedUsername(), - tok_details->error()); + FireRefreshTokenRevoked(GetAccountId(profile_), tok_details->error()); } break; } diff --git a/chrome/browser/signin/profile_oauth2_token_service.h b/chrome/browser/signin/profile_oauth2_token_service.h index 762873a..8e541dc 100644 --- a/chrome/browser/signin/profile_oauth2_token_service.h +++ b/chrome/browser/signin/profile_oauth2_token_service.h @@ -21,6 +21,7 @@ class URLRequestContextGetter; class GoogleServiceAuthError; class Profile; class TokenService; +class SigninGlobalError; // ProfileOAuth2TokenService is a BrowserContextKeyedService that retrieves // OAuth2 access tokens for a given set of scopes using the OAuth2 login @@ -59,6 +60,14 @@ class ProfileOAuth2TokenService : public OAuth2TokenService, bool ShouldCacheForRefreshToken(TokenService *token_service, const std::string& refresh_token); + SigninGlobalError* signin_global_error() { + return signin_global_error_.get(); + } + + const SigninGlobalError* signin_global_error() const { + return signin_global_error_.get(); + } + protected: friend class ProfileOAuth2TokenServiceFactory; explicit ProfileOAuth2TokenService(net::URLRequestContextGetter* getter); @@ -90,6 +99,12 @@ class ProfileOAuth2TokenService : public OAuth2TokenService, // The profile with which this instance was initialized, or NULL. Profile* profile_; + // Used to show auth errors in the wrench menu. The SigninGlobalError is + // different than most GlobalErrors in that its lifetime is controlled by + // ProfileOAuth2TokenService (so we can expose a reference for use in the + // wrench menu). + scoped_ptr<SigninGlobalError> signin_global_error_; + // The auth status from the most-recently-completed request. GoogleServiceAuthError last_auth_error_; diff --git a/chrome/browser/signin/profile_oauth2_token_service_factory.cc b/chrome/browser/signin/profile_oauth2_token_service_factory.cc index 97687dc..c29881b 100644 --- a/chrome/browser/signin/profile_oauth2_token_service_factory.cc +++ b/chrome/browser/signin/profile_oauth2_token_service_factory.cc @@ -6,8 +6,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/profile_oauth2_token_service.h" -#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/token_service_factory.h" +#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" #if defined(OS_ANDROID) @@ -18,7 +18,7 @@ ProfileOAuth2TokenServiceFactory::ProfileOAuth2TokenServiceFactory() : BrowserContextKeyedServiceFactory( "ProfileOAuth2TokenService", BrowserContextDependencyManager::GetInstance()) { - DependsOn(SigninManagerFactory::GetInstance()); + DependsOn(GlobalErrorServiceFactory::GetInstance()); DependsOn(TokenServiceFactory::GetInstance()); } diff --git a/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc b/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc index 0ed2903..adcf700 100644 --- a/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc +++ b/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc @@ -159,7 +159,9 @@ scoped_ptr<OAuth2TokenService::Request> static BrowserContextKeyedService* CreateOAuth2TokenService( content::BrowserContext* profile) { - return new MockProfileOAuth2TokenService(); + MockProfileOAuth2TokenService* mock = new MockProfileOAuth2TokenService(); + mock->Initialize(static_cast<Profile*>(profile)); + return mock; } class ProfileOAuth2TokenServiceRequestTest : public testing::Test { diff --git a/chrome/browser/signin/signin_global_error.cc b/chrome/browser/signin/signin_global_error.cc index 4418ebab..4281626 100644 --- a/chrome/browser/signin/signin_global_error.cc +++ b/chrome/browser/signin/signin_global_error.cc @@ -5,24 +5,27 @@ #include "chrome/browser/signin/signin_global_error.h" #include "base/logging.h" +#include "base/prefs/pref_service.h" #include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/profile_oauth2_token_service.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager.h" +#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/browser/ui/webui/signin/login_ui_service.h" #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" +#include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -SigninGlobalError::SigninGlobalError(SigninManagerBase* manager, - Profile* profile) - : auth_error_(GoogleServiceAuthError::AuthErrorNone()), - signin_manager_(manager), - profile_(profile) { +SigninGlobalError::SigninGlobalError(Profile* profile) + : auth_error_(GoogleServiceAuthError::AuthErrorNone()), profile_(profile) { } SigninGlobalError::~SigninGlobalError() { @@ -84,7 +87,12 @@ int SigninGlobalError::MenuItemCommandID() { } string16 SigninGlobalError::MenuItemLabel() { - if (signin_manager_->GetAuthenticatedUsername().empty() || + std::string username; + SigninManagerBase* signin_manager = + SigninManagerFactory::GetForProfileIfExists(profile_); + if (signin_manager) + username = signin_manager->GetAuthenticatedUsername(); + if (username.empty() || auth_error_.state() == GoogleServiceAuthError::NONE || auth_error_.state() == GoogleServiceAuthError::CONNECTION_FAILED) { // If the user isn't signed in, or there's no auth error worth elevating to @@ -128,9 +136,14 @@ string16 SigninGlobalError::GetBubbleViewTitle() { std::vector<string16> SigninGlobalError::GetBubbleViewMessages() { std::vector<string16> messages; + // If the user isn't signed in, no need to display an error bubble. - if (signin_manager_->GetAuthenticatedUsername().empty()) { - return messages; + SigninManagerBase* signin_manager = + SigninManagerFactory::GetForProfileIfExists(profile_); + if (signin_manager) { + std::string username = signin_manager->GetAuthenticatedUsername(); + if (username.empty()) + return messages; } switch (auth_error_.state()) { @@ -190,3 +203,9 @@ void SigninGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { void SigninGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { NOTREACHED(); } + +// static +SigninGlobalError* SigninGlobalError::GetForProfile(Profile* profile) { + return ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> + signin_global_error(); +} diff --git a/chrome/browser/signin/signin_global_error.h b/chrome/browser/signin/signin_global_error.h index 8242115..1667031 100644 --- a/chrome/browser/signin/signin_global_error.h +++ b/chrome/browser/signin/signin_global_error.h @@ -12,7 +12,6 @@ #include "google_apis/gaia/google_service_auth_error.h" class Profile; -class SigninManagerBase; // Shows auth errors on the wrench menu using a bubble view and a // menu item. Services that wish to expose auth errors to the user should @@ -31,7 +30,7 @@ class SigninGlobalError : public GlobalError { virtual GoogleServiceAuthError GetAuthStatus() const = 0; }; - SigninGlobalError(SigninManagerBase* signin_manager, Profile* profile); + SigninGlobalError(Profile* profile); virtual ~SigninGlobalError(); // Adds a provider which the SigninGlobalError object will start querying for @@ -61,6 +60,9 @@ class SigninGlobalError : public GlobalError { virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; + // Returns the SigninGlobalError instance for the given profile. + static SigninGlobalError* GetForProfile(Profile* profile); + private: std::set<const AuthStatusProvider*> provider_set_; @@ -68,9 +70,6 @@ class SigninGlobalError : public GlobalError { // NONE if AuthStatusChanged() has never been invoked). GoogleServiceAuthError auth_error_; - // The SigninManager that owns this object. - SigninManagerBase* signin_manager_; - // The Profile this object belongs to. Profile* profile_; }; diff --git a/chrome/browser/signin/signin_global_error_unittest.cc b/chrome/browser/signin/signin_global_error_unittest.cc index e0aeba0..ade065e 100644 --- a/chrome/browser/signin/signin_global_error_unittest.cc +++ b/chrome/browser/signin/signin_global_error_unittest.cc @@ -10,11 +10,11 @@ #include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" -#include "chrome/browser/signin/token_service_factory.h" #include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" class SigninGlobalErrorTest : public testing::Test { @@ -27,11 +27,12 @@ class SigninGlobalErrorTest : public testing::Test { SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), FakeSigninManagerBase::Build)); profile_->GetPrefs()->SetString( - prefs::kGoogleServicesUsername, "testuser@test.com"); + prefs::kGoogleServicesUsername, "testuser@test.com"); manager->Initialize(profile_.get(), NULL); - global_error_ = manager->signin_global_error(); + global_error_ = SigninGlobalError::GetForProfile(profile_.get()); } + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<TestingProfile> profile_; SigninGlobalError* global_error_; }; diff --git a/chrome/browser/signin/signin_manager_base.cc b/chrome/browser/signin/signin_manager_base.cc index b9d2071..bdfe9e1 100644 --- a/chrome/browser/signin/signin_manager_base.cc +++ b/chrome/browser/signin/signin_manager_base.cc @@ -15,13 +15,10 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/signin/about_signin_internals.h" #include "chrome/browser/signin/about_signin_internals_factory.h" -#include "chrome/browser/signin/signin_global_error.h" #include "chrome/browser/signin/signin_manager_cookie_helper.h" #include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" #include "chrome/browser/sync/sync_prefs.h" -#include "chrome/browser/ui/global_error/global_error_service.h" -#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" @@ -39,18 +36,12 @@ SigninManagerBase::SigninManagerBase() } SigninManagerBase::~SigninManagerBase() { - DCHECK(!signin_global_error_.get()) << - "SigninManagerBase::Initialize called but not " - "SigninManagerBase::Shutdown"; } void SigninManagerBase::Initialize(Profile* profile, PrefService* local_state) { // Should never call Initialize() twice. DCHECK(!IsInitialized()); profile_ = profile; - signin_global_error_.reset(new SigninGlobalError(this, profile)); - GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( - signin_global_error_.get()); // If the user is clearing the token service from the command line, then // clear their login info also (not valid to be logged in without any @@ -118,11 +109,6 @@ bool SigninManagerBase::AuthInProgress() const { } void SigninManagerBase::Shutdown() { - if (signin_global_error_.get()) { - GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( - signin_global_error_.get()); - signin_global_error_.reset(); - } } void SigninManagerBase::AddSigninDiagnosticsObserver( diff --git a/chrome/browser/signin/signin_manager_base.h b/chrome/browser/signin/signin_manager_base.h index 87c6be9..de49af1 100644 --- a/chrome/browser/signin/signin_manager_base.h +++ b/chrome/browser/signin/signin_manager_base.h @@ -39,7 +39,6 @@ class CookieSettings; class ProfileIOData; class PrefService; -class SigninGlobalError; // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. // A listener might use this to make note of a username / password @@ -91,14 +90,6 @@ class SigninManagerBase : public BrowserContextKeyedService { // Returns true if there's a signin in progress. virtual bool AuthInProgress() const; - SigninGlobalError* signin_global_error() { - return signin_global_error_.get(); - } - - const SigninGlobalError* signin_global_error() const { - return signin_global_error_.get(); - } - // BrowserContextKeyedService implementation. virtual void Shutdown() OVERRIDE; @@ -121,11 +112,6 @@ class SigninManagerBase : public BrowserContextKeyedService { // it). Profile* profile_; - // Used to show auth errors in the wrench menu. The SigninGlobalError is - // different than most GlobalErrors in that its lifetime is controlled by - // SigninManager (so we can expose a reference for use in the wrench menu). - scoped_ptr<SigninGlobalError> signin_global_error_; - // Helper methods to notify all registered diagnostics observers with. void NotifyDiagnosticsObservers( const signin_internals_util::UntimedSigninStatusField& field, diff --git a/chrome/browser/signin/signin_manager_factory.cc b/chrome/browser/signin/signin_manager_factory.cc index 303b90b..8eb4645 100644 --- a/chrome/browser/signin/signin_manager_factory.cc +++ b/chrome/browser/signin/signin_manager_factory.cc @@ -9,7 +9,6 @@ #include "chrome/browser/signin/chrome_signin_manager_delegate.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/token_service_factory.h" -#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/common/pref_names.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" #include "components/user_prefs/pref_registry_syncable.h" @@ -19,7 +18,6 @@ SigninManagerFactory::SigninManagerFactory() "SigninManager", BrowserContextDependencyManager::GetInstance()) { DependsOn(TokenServiceFactory::GetInstance()); - DependsOn(GlobalErrorServiceFactory::GetInstance()); } SigninManagerFactory::~SigninManagerFactory() {} diff --git a/chrome/browser/signin/signin_tracker_unittest.cc b/chrome/browser/signin/signin_tracker_unittest.cc index b8fca1a..233c3c5 100644 --- a/chrome/browser/signin/signin_tracker_unittest.cc +++ b/chrome/browser/signin/signin_tracker_unittest.cc @@ -18,7 +18,7 @@ #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_service.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -59,8 +59,7 @@ class MockObserver : public SigninTracker::Observer { class SigninTrackerTest : public testing::Test { public: - SigninTrackerTest() - : ui_thread_(content::BrowserThread::UI, &ui_loop_) {} + SigninTrackerTest() {} virtual void SetUp() OVERRIDE { profile_.reset(new TestingProfile()); mock_token_service_ = static_cast<MockTokenService*>( @@ -87,13 +86,12 @@ class SigninTrackerTest : public testing::Test { content::Details<const GoogleServiceSigninSuccessDetails>(&details)); } + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<SigninTracker> tracker_; scoped_ptr<TestingProfile> profile_; FakeSigninManagerBase* mock_signin_manager_; MockTokenService* mock_token_service_; MockObserver observer_; - base::MessageLoop ui_loop_; - content::TestBrowserThread ui_thread_; }; TEST_F(SigninTrackerTest, GaiaSignInFailed) { diff --git a/chrome/browser/signin/signin_ui_util.cc b/chrome/browser/signin/signin_ui_util.cc index 95396be..1c75cc6 100644 --- a/chrome/browser/signin/signin_ui_util.cc +++ b/chrome/browser/signin/signin_ui_util.cc @@ -39,9 +39,7 @@ std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) { // Auth errors have the highest priority - after that, individual service // errors. - SigninManagerBase* signin_manager = - SigninManagerFactory::GetForProfile(profile); - SigninGlobalError* signin_error = signin_manager->signin_global_error(); + SigninGlobalError* signin_error = SigninGlobalError::GetForProfile(profile); if (signin_error && signin_error->HasMenuItem()) errors.push_back(signin_error); @@ -90,7 +88,8 @@ string16 GetSigninMenuLabel(Profile* profile) { // Given an authentication state this helper function returns various labels // that can be used to display information about the state. -void GetStatusLabelsForAuthError(const SigninManagerBase& signin_manager, +void GetStatusLabelsForAuthError(Profile* profile, + const SigninManagerBase& signin_manager, string16* status_label, string16* link_label) { string16 username = UTF8ToUTF16(signin_manager.GetAuthenticatedUsername()); @@ -98,7 +97,9 @@ void GetStatusLabelsForAuthError(const SigninManagerBase& signin_manager, if (link_label) link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); - switch (signin_manager.signin_global_error()->GetLastAuthError().state()) { + const GoogleServiceAuthError::State state = + SigninGlobalError::GetForProfile(profile)->GetLastAuthError().state(); + switch (state) { case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: case GoogleServiceAuthError::ACCOUNT_DELETED: case GoogleServiceAuthError::ACCOUNT_DISABLED: @@ -143,5 +144,4 @@ void GetStatusLabelsForAuthError(const SigninManagerBase& signin_manager, } } - } // namespace signin_ui_util diff --git a/chrome/browser/signin/signin_ui_util.h b/chrome/browser/signin/signin_ui_util.h index 3e63e1a..86034ac 100644 --- a/chrome/browser/signin/signin_ui_util.h +++ b/chrome/browser/signin/signin_ui_util.h @@ -28,7 +28,8 @@ std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile); // "Sign in to Chromium", "Signin Error...", etc). string16 GetSigninMenuLabel(Profile* profile); -void GetStatusLabelsForAuthError(const SigninManagerBase& signin_manager, +void GetStatusLabelsForAuthError(Profile* profile, + const SigninManagerBase& signin_manager, string16* status_label, string16* link_label); diff --git a/chrome/browser/sync/about_sync_util_unittest.cc b/chrome/browser/sync/about_sync_util_unittest.cc index 77c8caa..e94d6e1 100644 --- a/chrome/browser/sync/about_sync_util_unittest.cc +++ b/chrome/browser/sync/about_sync_util_unittest.cc @@ -18,7 +18,7 @@ using content::BrowserThread; namespace sync_ui_util { namespace { -TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { +TEST(SyncUIUtilTestAbout, ConstructAboutInformationWithUnrecoverableErrorTest) { base::MessageLoopForUI message_loop; content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); scoped_ptr<Profile> profile( diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 26f26d1..1d5adc1 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -196,8 +196,6 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, channel == chrome::VersionInfo::CHANNEL_BETA) { sync_service_url_ = GURL(kSyncServerUrl); } - if (signin_) - signin_->signin_global_error()->AddProvider(this); } ProfileSyncService::~ProfileSyncService() { @@ -235,6 +233,9 @@ bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { } void ProfileSyncService::Initialize() { + if (profile_) + SigninGlobalError::GetForProfile(profile_)->AddProvider(this); + InitSettings(); // We clear this here (vs Shutdown) because we want to remember that an error @@ -689,8 +690,8 @@ void ProfileSyncService::OnGetTokenFailure( } void ProfileSyncService::Shutdown() { - if (signin_) - signin_->signin_global_error()->RemoveProvider(this); + if (profile_) + SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); ShutdownImpl(false); } @@ -1034,8 +1035,9 @@ void ProfileSyncService::UpdateAuthErrorState(const AuthError& error) { // Fan the notification out to interested UI-thread components. Notify the // SigninGlobalError first so it reflects the latest auth state before we // notify observers. - if (signin()) - signin()->signin_global_error()->AuthStatusChanged(); + if (profile_) + SigninGlobalError::GetForProfile(profile_)->AuthStatusChanged(); + NotifyObservers(); } diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc index d41da39..a6fb984 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc @@ -19,6 +19,7 @@ #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" #include "chrome/browser/signin/about_signin_internals_factory.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_components_factory_impl.h" @@ -52,20 +53,21 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory() // The ProfileSyncService depends on various SyncableServices being around // when it is shut down. Specify those dependencies here to build the proper // destruction order. - DependsOn(TemplateURLServiceFactory::GetInstance()); + DependsOn(AboutSigninInternalsFactory::GetInstance()); DependsOn(autofill::PersonalDataManagerFactory::GetInstance()); + DependsOn(BookmarkModelFactory::GetInstance()); + DependsOn(extensions::ExtensionSystemFactory::GetInstance()); + DependsOn(GlobalErrorServiceFactory::GetInstance()); + DependsOn(HistoryServiceFactory::GetInstance()); + DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); + DependsOn(PasswordStoreFactory::GetInstance()); + DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); + DependsOn(SigninManagerFactory::GetInstance()); + DependsOn(TemplateURLServiceFactory::GetInstance()); #if defined(ENABLE_THEMES) DependsOn(ThemeServiceFactory::GetInstance()); #endif - DependsOn(GlobalErrorServiceFactory::GetInstance()); - DependsOn(SigninManagerFactory::GetInstance()); - DependsOn(PasswordStoreFactory::GetInstance()); - DependsOn(extensions::ExtensionSystemFactory::GetInstance()); DependsOn(WebDataServiceFactory::GetInstance()); - DependsOn(HistoryServiceFactory::GetInstance()); - DependsOn(BookmarkModelFactory::GetInstance()); - DependsOn(AboutSigninInternalsFactory::GetInstance()); - DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); // The following have not been converted to BrowserContextKeyedServices yet, // and for now they are explicitly destroyed after the diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index 6e7bbe7..4eec093 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -63,6 +63,8 @@ class ProfileSyncServiceTestHarness { profile->CreateRequestContext(); invalidation::InvalidationServiceFactory::GetInstance()-> SetBuildOnlyFakeInvalidatorsForTest(true); + ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( + profile.get(), FakeOAuth2TokenService::BuildTokenService); } void TearDown() { @@ -126,8 +128,6 @@ class ProfileSyncServiceTestHarness { } void IssueTestTokens() { - ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( - profile.get(), FakeOAuth2TokenService::BuildTokenService); TokenService* token_service = TokenServiceFactory::GetForProfile(profile.get()); token_service->IssueAuthTokenForTest( diff --git a/chrome/browser/sync/sync_startup_tracker_unittest.cc b/chrome/browser/sync/sync_startup_tracker_unittest.cc index 6511f43..a6d5de9 100644 --- a/chrome/browser/sync/sync_startup_tracker_unittest.cc +++ b/chrome/browser/sync/sync_startup_tracker_unittest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/browser/sync/sync_startup_tracker.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -37,12 +38,15 @@ class SyncStartupTrackerTest : public testing::Test { ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), ProfileSyncServiceMock::BuildMockProfileSyncService)); - mock_pss_->Initialize(); // Make gmock not spam the output with information about these uninteresting // calls. EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); + EXPECT_CALL(*mock_pss_, GetAuthError()). + WillRepeatedly(ReturnRef(no_error_)); + + mock_pss_->Initialize(); } virtual void TearDown() OVERRIDE { @@ -59,6 +63,7 @@ class SyncStartupTrackerTest : public testing::Test { .WillRepeatedly(Return(true)); } + content::TestBrowserThreadBundle thread_bundle_; GoogleServiceAuthError no_error_; scoped_ptr<TestingProfile> profile_; ProfileSyncServiceMock* mock_pss_; diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc index 645bc4c..3eea19ea 100644 --- a/chrome/browser/sync/sync_ui_util.cc +++ b/chrome/browser/sync/sync_ui_util.cc @@ -151,11 +151,13 @@ MessageType GetStatusInfo(ProfileSyncService* service, } // No auth in progress check for an auth error. - AuthError auth_error = signin.signin_global_error()->GetLastAuthError(); + AuthError auth_error = + SigninGlobalError::GetForProfile(service->profile())-> + GetLastAuthError(); if (auth_error.state() != AuthError::NONE) { if (status_label && link_label) signin_ui_util::GetStatusLabelsForAuthError( - signin, status_label, link_label); + service->profile(), signin, status_label, link_label); return SYNC_ERROR; } @@ -215,7 +217,9 @@ MessageType GetStatusInfo(ProfileSyncService* service, result_type = PRE_SYNCED; ProfileSyncService::Status status; service->QueryDetailedSyncStatus(&status); - AuthError auth_error = signin.signin_global_error()->GetLastAuthError(); + AuthError auth_error = + SigninGlobalError::GetForProfile( + service->profile())->GetLastAuthError(); if (status_label) { status_label->assign( l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); @@ -230,7 +234,7 @@ MessageType GetStatusInfo(ProfileSyncService* service, if (status_label && link_label) { status_label->clear(); signin_ui_util::GetStatusLabelsForAuthError( - signin, status_label, link_label); + service->profile(), signin, status_label, link_label); } result_type = SYNC_ERROR; } diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc index 00d0073..7246f8f 100644 --- a/chrome/browser/sync/sync_ui_util_unittest.cc +++ b/chrome/browser/sync/sync_ui_util_unittest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/browser/sync/sync_ui_util.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "grit/generated_resources.h" #include "testing/gmock/include/gmock/gmock-actions.h" #include "testing/gmock/include/gmock/gmock.h" @@ -66,11 +67,14 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, } // namespace +class SyncUIUtilTest : public testing::Test { + private: + content::TestBrowserThreadBundle thread_bundle_; +}; + // Test that GetStatusLabelsForSyncGlobalError returns an error if a // passphrase is required. -TEST(SyncUIUtilTest, PassphraseGlobalError) { - base::MessageLoopForUI message_loop; - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); +TEST_F(SyncUIUtilTest, PassphraseGlobalError) { scoped_ptr<Profile> profile( ProfileSyncServiceMock::MakeSignedInTestingProfile()); NiceMock<ProfileSyncServiceMock> service(profile.get()); @@ -88,9 +92,7 @@ TEST(SyncUIUtilTest, PassphraseGlobalError) { // Test that GetStatusLabelsForSyncGlobalError returns an error if a // passphrase is required and not for auth errors. -TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { - base::MessageLoopForUI message_loop; - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); +TEST_F(SyncUIUtilTest, AuthAndPassphraseGlobalError) { scoped_ptr<Profile> profile( ProfileSyncServiceMock::MakeSignedInTestingProfile()); NiceMock<ProfileSyncServiceMock> service(profile.get()); @@ -120,9 +122,7 @@ TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { // Test that GetStatusLabelsForSyncGlobalError does not indicate errors for // auth errors (these are reported through SigninGlobalError). -TEST(SyncUIUtilTest, AuthStateGlobalError) { - base::MessageLoopForUI message_loop; - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); +TEST_F(SyncUIUtilTest, AuthStateGlobalError) { scoped_ptr<Profile> profile( ProfileSyncServiceMock::MakeSignedInTestingProfile()); NiceMock<ProfileSyncServiceMock> service(profile.get()); @@ -319,15 +319,18 @@ void GetDistinctCase(ProfileSyncServiceMock& service, // This test ensures that a each distinctive ProfileSyncService statuses // will return a unique combination of status and link messages from // GetStatusLabels(). -TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { +TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { std::set<string16> messages; for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { scoped_ptr<Profile> profile(new TestingProfile()); ProfileSyncServiceMock service(profile.get()); + GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); + EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); FakeSigninManagerForSyncUIUtilTest signin(profile.get()); signin.SetAuthenticatedUsername("test_user@test.com"); scoped_ptr<FakeAuthStatusProvider> provider( - new FakeAuthStatusProvider(signin.signin_global_error())); + new FakeAuthStatusProvider( + SigninGlobalError::GetForProfile(profile.get()))); GetDistinctCase(service, &signin, provider.get(), idx); string16 status_label; string16 link_label; @@ -348,6 +351,7 @@ TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { messages.insert(combined_label); testing::Mock::VerifyAndClearExpectations(&service); testing::Mock::VerifyAndClearExpectations(&signin); + EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); provider.reset(); signin.Shutdown(); } @@ -355,15 +359,18 @@ TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { // This test ensures that the html_links parameter on GetStatusLabels() is // honored. -TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { +TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { scoped_ptr<Profile> profile( ProfileSyncServiceMock::MakeSignedInTestingProfile()); ProfileSyncServiceMock service(profile.get()); + GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); + EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); FakeSigninManagerForSyncUIUtilTest signin(profile.get()); signin.SetAuthenticatedUsername("test_user@test.com"); scoped_ptr<FakeAuthStatusProvider> provider( - new FakeAuthStatusProvider(signin.signin_global_error())); + new FakeAuthStatusProvider( + SigninGlobalError::GetForProfile(profile.get()))); GetDistinctCase(service, &signin, provider.get(), idx); string16 status_label; string16 link_label; @@ -381,6 +388,7 @@ TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { string16::npos); testing::Mock::VerifyAndClearExpectations(&service); testing::Mock::VerifyAndClearExpectations(&signin); + EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); provider.reset(); signin.Shutdown(); } diff --git a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm index 82032a1..d57e76f 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm @@ -707,10 +707,10 @@ TEST_F(BrowserWindowControllerTest, TestSigninMenuItemAuthError) { SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); signin->SetAuthenticatedUsername(username); ProfileSyncService* sync = - ProfileSyncServiceFactory::GetForProfile(profile()); + ProfileSyncServiceFactory::GetForProfile(profile()); sync->SetSyncSetupCompleted(); // Force an auth error. - FakeAuthStatusProvider provider(signin->signin_global_error()); + FakeAuthStatusProvider provider(SigninGlobalError::GetForProfile(profile())); GoogleServiceAuthError error( GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); provider.SetAuthError(error); diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc index 3f32a3d..d77a9ad 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc @@ -224,6 +224,7 @@ class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { protected: TestingProfile* profile_; + GoogleServiceAuthError no_error_; private: // The ID of the signin process the test will assume to be trusted. @@ -236,6 +237,7 @@ class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { OneClickSigninHelperTest::OneClickSigninHelperTest() : profile_(NULL), + no_error_(GoogleServiceAuthError::NONE), trusted_signin_process_id_(-1) { } @@ -306,13 +308,17 @@ OneClickSigninHelperTest::CreateProfileSyncServiceMock() { ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_, ProfileSyncServiceMock::BuildMockProfileSyncService)); - sync_service->Initialize(); EXPECT_CALL(*sync_service, SetSetupInProgress(true)); EXPECT_CALL(*sync_service, AddObserver(_)).Times(AtLeast(1)); EXPECT_CALL(*sync_service, FirstSetupInProgress()).WillRepeatedly( Return(false)); EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(true)); EXPECT_CALL(*sync_service, RemoveObserver(_)).Times(AtLeast(1)); + EXPECT_CALL(*sync_service, GetAuthError()). + WillRepeatedly(::testing::ReturnRef(no_error_)); + EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(false)); + sync_service->Initialize(); + EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(true)); return sync_service; } diff --git a/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc b/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc index d2bb889..d4c94a8 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/toolbar/wrench_menu_model.h" #include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/global_error/global_error.h" #include "chrome/browser/ui/global_error/global_error_service.h" @@ -159,8 +160,10 @@ TEST_F(WrenchMenuModelTest, Basics) { // Tests global error menu items in the wrench menu. TEST_F(WrenchMenuModelTest, GlobalError) { + // Make sure services required for tests are initialized. GlobalErrorService* service = GlobalErrorServiceFactory::GetForProfile(browser()->profile()); + ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); const int command1 = 1234567; // AddGlobalError takes ownership of error1. MenuError* error1 = new MenuError(command1); diff --git a/chrome/browser/ui/webui/sync_setup_handler.cc b/chrome/browser/ui/webui/sync_setup_handler.cc index a7f3410..139c0f1 100644 --- a/chrome/browser/ui/webui/sync_setup_handler.cc +++ b/chrome/browser/ui/webui/sync_setup_handler.cc @@ -984,7 +984,7 @@ void SyncSetupHandler::OpenSyncSetup() { return; } - if (signin->signin_global_error()->HasMenuItem()) { + if (SigninGlobalError::GetForProfile(GetProfile())->HasMenuItem()) { // Login has been specially requested because previously working credentials // have expired (case 3). Load the sync setup page with a spinner dialog, // and then display the gaia auth page. The user may abandon re-auth by diff --git a/chrome/browser/ui/webui/sync_setup_handler_unittest.cc b/chrome/browser/ui/webui/sync_setup_handler_unittest.cc index d863800..d0c36e7 100644 --- a/chrome/browser/ui/webui/sync_setup_handler_unittest.cc +++ b/chrome/browser/ui/webui/sync_setup_handler_unittest.cc @@ -9,12 +9,13 @@ #include "base/command_line.h" #include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" #include "base/prefs/pref_service.h" #include "base/stl_util.h" #include "base/values.h" #include "chrome/browser/signin/fake_auth_status_provider.h" #include "chrome/browser/signin/fake_signin_manager.h" +#include "chrome/browser/signin/profile_oauth2_token_service.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -28,6 +29,7 @@ #include "chrome/test/base/scoped_testing_local_state.h" #include "content/public/browser/web_ui.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -305,18 +307,21 @@ class SyncSetupHandlerTest : public testing::Test { virtual void SetUp() OVERRIDE { error_ = GoogleServiceAuthError::AuthErrorNone(); profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile()); + mock_pss_ = static_cast<ProfileSyncServiceMock*>( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), ProfileSyncServiceMock::BuildMockProfileSyncService)); - mock_pss_->Initialize(); - + EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( Return(syncer::IMPLICIT_PASSPHRASE)); ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( Return(base::Time())); ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( Return(base::Time())); + + mock_pss_->Initialize(); + #if defined(OS_CHROMEOS) mock_signin_ = static_cast<SigninManagerBase*>( SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( @@ -357,7 +362,6 @@ class SyncSetupHandlerTest : public testing::Test { .WillRepeatedly(Return(true)); EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); } @@ -405,11 +409,10 @@ class SyncSetupHandlerTest : public testing::Test { handler_->sync_startup_tracker_->OnStateChanged(); } + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<Profile> profile_; ProfileSyncServiceMock* mock_pss_; GoogleServiceAuthError error_; - // MessageLoop instance is required to work with OneShotTimer. - base::MessageLoop message_loop_; SigninManagerBase* mock_signin_; TestWebUI web_ui_; scoped_ptr<TestingSyncSetupHandler> handler_; @@ -424,8 +427,6 @@ TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { .WillRepeatedly(Return(false)); EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) .WillRepeatedly(Return(false)); - const GoogleServiceAuthError error(GoogleServiceAuthError::NONE); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(false)); handler_->HandleStartSignin(NULL); @@ -473,7 +474,6 @@ TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(false)); error_ = GoogleServiceAuthError::AuthErrorNone(); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); // We're simulating a user setting up sync, which would cause the backend to @@ -503,7 +503,6 @@ TEST_F(SyncSetupHandlerTest, EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(false)); error_ = GoogleServiceAuthError::AuthErrorNone(); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); // Sync backend is stopped initially, and will start up. EXPECT_CALL(*mock_pss_, sync_initialized()) .WillRepeatedly(Return(false)); @@ -563,7 +562,6 @@ TEST_F(SyncSetupHandlerTest, EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(false)); error_ = GoogleServiceAuthError::AuthErrorNone(); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); EXPECT_CALL(*mock_pss_, sync_initialized()) .WillOnce(Return(false)) .WillRepeatedly(Return(true)); @@ -594,7 +592,6 @@ TEST_F(SyncSetupHandlerTest, EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) .WillRepeatedly(Return(false)); error_ = GoogleServiceAuthError::AuthErrorNone(); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); handler_->OpenSyncSetup(); @@ -907,7 +904,8 @@ TEST_F(SyncSetupHandlerTest, ShowSigninOnAuthError) { SetupInitializedProfileSyncService(); mock_signin_->SetAuthenticatedUsername(kTestUser); - FakeAuthStatusProvider provider(mock_signin_->signin_global_error()); + FakeAuthStatusProvider provider( + SigninGlobalError::GetForProfile(profile_.get())); provider.SetAuthError(error_); EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) .WillRepeatedly(Return(true)); @@ -917,7 +915,6 @@ TEST_F(SyncSetupHandlerTest, ShowSigninOnAuthError) { .WillRepeatedly(Return(false)); EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); #if defined(OS_CHROMEOS) |