diff options
81 files changed, 986 insertions, 438 deletions
diff --git a/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java b/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java index 27226bd..f1479c3 100644 --- a/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java +++ b/chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java @@ -6,6 +6,7 @@ package org.chromium.chrome.browser.sync; import android.accounts.Account; import android.app.Activity; +import android.content.Context; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -16,6 +17,7 @@ import org.chromium.base.test.util.Feature; import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory; import org.chromium.chrome.browser.identity.UuidBasedUniqueIdentificationGenerator; +import org.chromium.chrome.browser.signin.AccountIdProvider; import org.chromium.chrome.shell.ChromeShellActivity; import org.chromium.chrome.shell.ChromeShellTestBase; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; @@ -58,6 +60,22 @@ public class SyncTest extends ChromeShellTestBase { clearAppData(); + // Setup fake mapper from accountNames to Ids. + ThreadUtils.runOnUiThreadBlocking(new Runnable() { + @Override + public void run() { + if (AccountIdProvider.getInstance() != null) { + return; + } + + AccountIdProvider.setInstance(new AccountIdProvider() { + public String getAccountId(Context ctx, String accountName) { + return "gaia-id-" + accountName; + } + }); + } + }); + // Mock out the account manager on the device. mContext = new SyncTestUtil.SyncTestContext(getInstrumentation().getTargetContext()); mAccountManager = new MockAccountManager(mContext, getInstrumentation().getContext()); diff --git a/chrome/browser/app_controller_mac_unittest.mm b/chrome/browser/app_controller_mac_unittest.mm index 5994196..a0de9d4 100644 --- a/chrome/browser/app_controller_mac_unittest.mm +++ b/chrome/browser/app_controller_mac_unittest.mm @@ -124,7 +124,7 @@ TEST_F(AppControllerTest, TestSigninMenuItemNoErrors) { NSString* alreadySignedIn = l10n_util::GetNSStringFWithFixup( IDS_SYNC_MENU_SYNCED_LABEL, base::UTF8ToUTF16(username)); SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); - signin->SetAuthenticatedUsername(username); + signin->SetAuthenticatedAccountInfo(username, username); ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); sync->SetSyncSetupCompleted(); [AppController updateSigninItem:syncMenuItem @@ -144,7 +144,7 @@ TEST_F(AppControllerTest, TestSigninMenuItemAuthError) { // Now sign in. std::string username = "foo@example.com"; SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); - signin->SetAuthenticatedUsername(username); + signin->SetAuthenticatedAccountInfo(username, username); ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); sync->SetSyncSetupCompleted(); // Force an auth error. diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 68cb6f0..9723caf 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -23,6 +23,7 @@ #include "chrome/browser/autocomplete/history_url_provider.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -45,6 +46,7 @@ #include "components/search_engines/search_terms_data.h" #include "components/search_engines/template_url.h" #include "components/search_engines/template_url_service.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/pref_names.h" #include "components/variations/entropy_provider.h" @@ -3242,7 +3244,7 @@ TEST_F(SearchProviderTest, CanSendURL) { GURL("https://www.google.com/complete/search"), &google_template_url, metrics::OmniboxEventProto::OTHER, SearchTermsData(), &client)); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_); - signin->SetAuthenticatedUsername("test"); + signin->SetAuthenticatedAccountInfo("gaia_id", "test"); // All conditions should be met. EXPECT_TRUE(SearchProvider::CanSendURL( diff --git a/chrome/browser/autofill/personal_data_manager_factory.cc b/chrome/browser/autofill/personal_data_manager_factory.cc index 7550508..c68b7af 100644 --- a/chrome/browser/autofill/personal_data_manager_factory.cc +++ b/chrome/browser/autofill/personal_data_manager_factory.cc @@ -9,10 +9,12 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/webdata/web_data_service_factory.h" #include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/signin/core/browser/account_tracker_service.h" namespace autofill { @@ -32,6 +34,7 @@ PersonalDataManagerFactory::PersonalDataManagerFactory() : BrowserContextKeyedServiceFactory( "PersonalDataManager", BrowserContextDependencyManager::GetInstance()) { + DependsOn(AccountTrackerServiceFactory::GetInstance()); DependsOn(WebDataServiceFactory::GetInstance()); } @@ -46,6 +49,7 @@ KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor( service->Init(WebDataServiceFactory::GetAutofillWebDataForProfile( profile, ServiceAccessType::EXPLICIT_ACCESS), profile->GetPrefs(), + AccountTrackerServiceFactory::GetForProfile(profile), profile->IsOffTheRecord()); return service; } diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc index 0221a61..cef9f59 100644 --- a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc +++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc @@ -1224,6 +1224,7 @@ WRAPPED_INSTANTIATE_TEST_CASE_P( // Structure to describe an account info. struct TestAccountInfo { + const char* const gaia_id; const char* const email; const char* const hash; const char* const display_name; @@ -1236,10 +1237,10 @@ enum { }; static const TestAccountInfo kTestAccounts[] = { - {"__dummy__@invalid.domain", "hashdummy", "Dummy Account"}, - {"alice@invalid.domain", "hashalice", "Alice"}, - {"bob@invalid.domain", "hashbob", "Bob"}, - {"charlie@invalid.domain", "hashcharlie", "Charlie"}, + {"gaia-id-d", "__dummy__@invalid.domain", "hashdummy", "Dummy Account"}, + {"gaia-id-a", "alice@invalid.domain", "hashalice", "Alice"}, + {"gaia-id-b", "bob@invalid.domain", "hashbob", "Bob"}, + {"gaia-id-c", "charlie@invalid.domain", "hashcharlie", "Charlie"}, }; // Test fixture class for testing multi-profile features. @@ -1292,8 +1293,8 @@ class MultiProfileFileManagerBrowserTest : public FileManagerBrowserTestBase { user_manager->SaveUserDisplayName(info.email, base::UTF8ToUTF16(info.display_name)); SigninManagerFactory::GetForProfile( - chromeos::ProfileHelper::GetProfileByUserIdHash(info.hash))-> - SetAuthenticatedUsername(info.email); + chromeos::ProfileHelper::GetProfileByUserIdHash(info.hash)) + ->SetAuthenticatedAccountInfo(info.gaia_id, info.email); } private: diff --git a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc index bfc4e3b..ca519f1 100644 --- a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc +++ b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc @@ -71,6 +71,7 @@ namespace chromeos { namespace { +const char kGaiaID[] = "12345"; const char kUsername[] = "test_user@gmail.com"; const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; const char kPassword[] = "test_password"; @@ -227,6 +228,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) .Times(2); UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(kUsername); test::UserSessionManagerTestApi session_manager_test_api( @@ -277,6 +279,7 @@ void ExistingUserControllerUntrustedTest::SetUpSessionManager() { IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, ExistingUserLoginForbidden) { UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(kUsername); existing_user_controller()->Login(user_context, SigninSpecifics()); @@ -285,6 +288,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, NewUserLoginForbidden) { UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(kUsername); existing_user_controller()->CompleteLogin(user_context); @@ -569,6 +573,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, LoginStopsAutoLogin) { // Set up mocks to check login success. UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(user_context.GetUserID()); ExpectSuccessfulLogin(user_context); @@ -602,6 +607,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) .Times(2); UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); test::UserSessionManagerTestApi session_manager_test_api( UserSessionManager::GetInstance()); @@ -631,6 +637,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, CompleteLoginStopsAutoLogin) { // Set up mocks to check login success. UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(user_context.GetUserID()); ExpectSuccessfulLogin(user_context); @@ -703,6 +710,7 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, // Check that the attempt to start a public session fails with an error. ExpectLoginFailure(); UserContext user_context(kUsername); + user_context.SetGaiaID(kGaiaID); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(user_context.GetUserID()); existing_user_controller()->Login(user_context, SigninSpecifics()); diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc index 5d1cffa..fa8574b 100644 --- a/chrome/browser/chromeos/login/login_browsertest.cc +++ b/chrome/browser/chromeos/login/login_browsertest.cc @@ -42,6 +42,7 @@ using ::testing::Return; namespace { +const char kGaiaId[] = "12345"; const char kTestUser[] = "test-user@gmail.com"; const char kPassword[] = "password"; @@ -262,6 +263,7 @@ IN_PROC_BROWSER_TEST_F(LoginOfflineTest, GaiaAuthOffline) { StartGaiaAuthOffline(); chromeos::UserContext user_context(kTestUser); + user_context.SetGaiaID(kGaiaId); user_context.SetKey(chromeos::Key(kPassword)); SetExpectedCredentials(user_context); diff --git a/chrome/browser/chromeos/login/login_manager_test.cc b/chrome/browser/chromeos/login/login_manager_test.cc index bd44832..89cf712 100644 --- a/chrome/browser/chromeos/login/login_manager_test.cc +++ b/chrome/browser/chromeos/login/login_manager_test.cc @@ -136,6 +136,7 @@ bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { void LoginManagerTest::LoginUser(const std::string& user_id) { UserContext user_context(user_id); + user_context.SetGaiaID(GetGaiaIDForUserID(user_id)); user_context.SetKey(Key("password")); SetExpectedCredentials(user_context); EXPECT_TRUE(TryToLogin(user_context)); @@ -143,11 +144,17 @@ void LoginManagerTest::LoginUser(const std::string& user_id) { void LoginManagerTest::AddUser(const std::string& user_id) { UserContext user_context(user_id); + user_context.SetGaiaID(GetGaiaIDForUserID(user_id)); user_context.SetKey(Key("password")); SetExpectedCredentials(user_context); EXPECT_TRUE(AddUserToSession(user_context)); } +// static +std::string LoginManagerTest::GetGaiaIDForUserID(const std::string& user_id) { + return "gaia-id-" + user_id; +} + void LoginManagerTest::JSExpect(const std::string& expression) { js_checker_.ExpectTrue(expression); } diff --git a/chrome/browser/chromeos/login/login_manager_test.h b/chrome/browser/chromeos/login/login_manager_test.h index ff4a6dd..caa2a14 100644 --- a/chrome/browser/chromeos/login/login_manager_test.h +++ b/chrome/browser/chromeos/login/login_manager_test.h @@ -67,6 +67,8 @@ class LoginManagerTest : public MixinBasedBrowserTest { test::JSChecker& js_checker() { return js_checker_; } + static std::string GetGaiaIDForUserID(const std::string& user_id); + protected: bool use_webview() { return use_webview_; } void set_use_webview(bool use_webview) { use_webview_ = use_webview; } diff --git a/chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.cc b/chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.cc index 5a76212..b9f4083 100644 --- a/chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.cc +++ b/chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.cc @@ -26,7 +26,7 @@ void StubLoginSessionManagerDelegate::Start() { // For dev machines and stub user emulate as if sync has been initialized. SigninManagerFactory::GetForProfile(profile()) - ->SetAuthenticatedUsername(login_user_id()); + ->SetAuthenticatedAccountInfo(login_user_id(), login_user_id()); RestoreAfterCrashSessionManagerDelegate::Start(); } diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc index 50f75fb..01d04f1 100644 --- a/chrome/browser/chromeos/login/session/user_session_manager.cc +++ b/chrome/browser/chromeos/login/session/user_session_manager.cc @@ -929,15 +929,18 @@ void UserSessionManager::InitProfilePreferences( supervised_user_sync_id); } else if (user_manager::UserManager::Get()-> IsLoggedInAsUserWithGaiaAccount()) { - // Prime the account tracker with this combination of gaia id/display email. - // Don't do this unless both email and gaia_id are valid. They may not - // be when simply unlocking the profile. - if (!user_context.GetGaiaID().empty() && - !user_context.GetUserID().empty()) { + // Get the Gaia ID from the user context. If it's not available, this may + // not be available when unlocking a previously opened profile, or when + // creating a supervised users. However, in these cases the gaia_id should + // be already available in the account tracker. + std::string gaia_id = user_context.GetGaiaID(); + if (gaia_id.empty()) { AccountTrackerService* account_tracker = AccountTrackerServiceFactory::GetForProfile(profile); - account_tracker->SeedAccountInfo(user_context.GetGaiaID(), - user_context.GetUserID()); + AccountTrackerService::AccountInfo info = + account_tracker->FindAccountInfoByEmail(user_context.GetUserID()); + gaia_id = info.gaia; + DCHECK(!gaia_id.empty()); } // Make sure that the google service username is properly set (we do this @@ -945,7 +948,8 @@ void UserSessionManager::InitProfilePreferences( // profiles that might not have it set yet). SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(profile); - signin_manager->SetAuthenticatedUsername(user_context.GetUserID()); + signin_manager->SetAuthenticatedAccountInfo(gaia_id, + user_context.GetUserID()); } } diff --git a/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc b/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc index c09e3a7..dc10ab14 100644 --- a/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc +++ b/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc @@ -29,6 +29,7 @@ #include "chromeos/login/auth/user_context.h" #include "components/app_modal/javascript_app_modal_dialog.h" #include "components/app_modal/native_app_modal_dialog.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/user_manager/user.h" #include "components/user_manager/user_manager.h" @@ -58,8 +59,9 @@ namespace chromeos { namespace { // Email of owner account for test. -const char kTestAccountId[] = "username@gmail.com"; -const char kTestRawAccountId[] = "User.Name"; +const char kTestGaiaId[] = "12345"; +const char kTestEmail[] = "username@gmail.com"; +const char kTestRawEmail[] = "User.Name@gmail.com"; const char kTestAccountPassword[] = "fake-password"; const char kTestAuthCode[] = "fake-auth-code"; const char kTestGaiaUberToken[] = "fake-uber-token"; @@ -76,6 +78,13 @@ const char kTestLoginToken[] = "fake-login-token"; const char kTestSyncToken[] = "fake-sync-token"; const char kTestAuthLoginToken[] = "fake-oauthlogin-token"; +std::string PickAccountId(Profile* profile, + const std::string& gaia_id, + const std::string& email) { + return AccountTrackerService::PickAccountIdForAccount(profile->GetPrefs(), + gaia_id, email); +} + class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer { public: explicit OAuth2LoginManagerStateWaiter(Profile* profile) @@ -162,7 +171,7 @@ class OAuth2Test : public OobeBaseTest, void SetupGaiaServerForUnexpiredAccount() { FakeGaia::MergeSessionParams params; - params.email = kTestAccountId; + params.email = kTestEmail; fake_gaia_->SetMergeSessionParams(params); SetupGaiaServerWithAccessTokens(); } @@ -184,10 +193,14 @@ class OAuth2Test : public OobeBaseTest, JsExpect("!!document.querySelector('#account-picker')"); JsExpect("!!document.querySelector('#pod-row')"); - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), + std::string account_id = PickAccountId( + ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail); + + EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); - EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); + // Try login. Primary profile has changed. + EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); Profile* profile = ProfileManager::GetPrimaryUserProfile(); // Wait for the session merge to finish. @@ -196,15 +209,16 @@ class OAuth2Test : public OobeBaseTest, // Check for existance of refresh token. ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); - EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); + EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), + EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); } - bool TryToLogin(const std::string& username, + bool TryToLogin(const std::string& gaia_id, + const std::string& username, const std::string& password) { - if (!AddUserToSession(username, password)) + if (!AddUserToSession(gaia_id, username, password)) return false; if (const user_manager::User* active_user = @@ -216,14 +230,14 @@ class OAuth2Test : public OobeBaseTest, } user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( - const std::string& user_id) const { + const std::string& account_id) const { PrefService* local_state = g_browser_process->local_state(); const base::DictionaryValue* prefs_oauth_status = local_state->GetDictionary("OAuthTokenStatus"); int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; if (prefs_oauth_status && prefs_oauth_status->GetIntegerWithoutPathExpansion( - user_id, &oauth_token_status)) { + account_id, &oauth_token_status)) { user_manager::User::OAuthTokenStatus result = static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); return result; @@ -240,7 +254,8 @@ class OAuth2Test : public OobeBaseTest, return OobeBaseTest::profile(); } - bool AddUserToSession(const std::string& username, + bool AddUserToSession(const std::string& gaia_id, + const std::string& username, const std::string& password) { ExistingUserController* controller = ExistingUserController::current_controller(); @@ -250,6 +265,7 @@ class OAuth2Test : public OobeBaseTest, } UserContext user_context(username); + user_context.SetGaiaID(gaia_id); user_context.SetKey(Key(password)); controller->Login(user_context, SigninSpecifics()); content::WindowedNotificationObserver( @@ -267,6 +283,8 @@ class OAuth2Test : public OobeBaseTest, } void SetupGaiaServerWithAccessTokens() { + fake_gaia_->MapEmailToGaiaId(kTestEmail, kTestGaiaId); + // Configure OAuth authentication. GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); @@ -277,7 +295,7 @@ class OAuth2Test : public OobeBaseTest, userinfo_token_info.scopes.insert( "https://www.googleapis.com/auth/userinfo.email"); userinfo_token_info.audience = gaia_urls->oauth2_chrome_client_id(); - userinfo_token_info.email = kTestAccountId; + userinfo_token_info.email = kTestEmail; fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_token_info); FakeGaia::AccessTokenInfo userinfo_profile_token_info; @@ -285,7 +303,7 @@ class OAuth2Test : public OobeBaseTest, userinfo_profile_token_info.scopes.insert( "https://www.googleapis.com/auth/userinfo.profile"); userinfo_profile_token_info.audience = gaia_urls->oauth2_chrome_client_id(); - userinfo_profile_token_info.email = kTestAccountId; + userinfo_profile_token_info.email = kTestEmail; fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_profile_token_info); // The any-api access token for accessing the token minting endpoint. @@ -339,7 +357,7 @@ class OAuth2Test : public OobeBaseTest, // Use capitalized and dotted user name on purpose to make sure // our email normalization kicks in. - GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawAccountId, + GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawEmail, kTestAccountPassword); session_start_waiter.Wait(); @@ -415,12 +433,13 @@ class CookieReader : public base::RefCountedThreadSafe<CookieReader> { IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_PRE_MergeSession) { StartNewUserSession(true); // Check for existance of refresh token. + std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail); ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile( profile()); - EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); + EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), + EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); scoped_refptr<CookieReader> cookie_reader(new CookieReader()); cookie_reader->ReadCookies(profile()); @@ -472,15 +491,16 @@ IN_PROC_BROWSER_TEST_P(OAuth2Test, MergeSession) { JsExpect("!!document.querySelector('#account-picker')"); JsExpect("!!document.querySelector('#pod-row')"); - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), + std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail); + EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); - EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); + EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); // Wait for the session merge to finish. WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), + EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); } diff --git a/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc b/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc index 64bec8af0..f8e1a67 100644 --- a/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc +++ b/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc @@ -295,6 +295,7 @@ void SupervisedUserTestBase::StartFlowLoginAsManager() { // Next button is now enabled. JSExpect("!$('supervised-user-creation-next-button').disabled"); UserContext user_context(kTestManager); + user_context.SetGaiaID(GetGaiaIDForUserID(kTestManager)); user_context.SetKey(Key(kTestManagerPassword)); SetExpectedCredentials(user_context); content::WindowedNotificationObserver login_observer( diff --git a/chrome/browser/chromeos/policy/consumer_enrollment_handler_unittest.cc b/chrome/browser/chromeos/policy/consumer_enrollment_handler_unittest.cc index 15ecd7e..70d20d2 100644 --- a/chrome/browser/chromeos/policy/consumer_enrollment_handler_unittest.cc +++ b/chrome/browser/chromeos/policy/consumer_enrollment_handler_unittest.cc @@ -4,8 +4,11 @@ #include "chrome/browser/chromeos/policy/consumer_enrollment_handler.h" +#include <utility> + #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" +#include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" @@ -16,6 +19,7 @@ #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" +#include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" @@ -65,17 +69,21 @@ class ConsumerEnrollmentHandlerTest : public testing::Test { void SetUp() override { ASSERT_TRUE(testing_profile_manager_->SetUp()); - profile_ = testing_profile_manager_->CreateTestingProfile(kTestUser); - - // Set up FakeProfileOAuth2TokenService and issue a fake refresh token. - ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( - profile_, &BuildAutoIssuingFakeProfileOAuth2TokenService); - GetFakeProfileOAuth2TokenService()-> - IssueRefreshTokenForUser(kTestOwner, "fake_token"); + TestingProfile::TestingFactories factories; + factories.push_back( + std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), + BuildAutoIssuingFakeProfileOAuth2TokenService)); + profile_ = testing_profile_manager_->CreateTestingProfile( + kTestUser, scoped_ptr<PrefServiceSyncable>(), + base::UTF8ToUTF16(kTestUser), 0, std::string(), factories); // Set up the authenticated user name and ID. - SigninManagerFactory::GetForProfile(profile_)-> - SetAuthenticatedUsername(kTestOwner); + SigninManagerFactory::GetForProfile(profile_) + ->SetAuthenticatedAccountInfo(kTestOwner, kTestOwner); + + // Issue a fake refresh token. + GetFakeProfileOAuth2TokenService()->IssueRefreshTokenForUser(kTestOwner, + "fake_token"); } FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { diff --git a/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.cc b/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.cc index f0cbfd2..9791ecd 100644 --- a/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.cc +++ b/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.cc @@ -6,11 +6,20 @@ #include "chrome/browser/devtools/device/webrtc/devtools_bridge_client.h" #include "chrome/browser/local_discovery/gcd_api_flow.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/ui/browser.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "content/public/browser/web_ui_message_handler.h" +namespace { + +const char kGaiaId[] = "stub-user@example.com"; +const char kUsername[] = "stub-user@example.com"; + +} // namespace + class DevToolsBridgeClientBrowserTest::GCDApiFlowMock : public local_discovery::GCDApiFlow { public: @@ -79,10 +88,14 @@ class DevToolsBridgeClientBrowserTest::DevToolsBridgeClientMock void GoogleSigninSucceeded() { // This username is checked on Chrome OS. - const std::string username = "stub-user@example.com"; - test_->fake_signin_manager_->SetAuthenticatedUsername(username); - identity_provider().GoogleSigninSucceeded("test_account", username, - "testing"); + const std::string account_id = + AccountTrackerServiceFactory::GetForProfile( + test_->browser()->profile()) + ->PickAccountIdForAccount(kGaiaId, kUsername); + test_->fake_signin_manager_->SetAuthenticatedAccountInfo(kGaiaId, + kUsername); + identity_provider().GoogleSigninSucceeded(account_id, kUsername, + "password"); } private: @@ -109,8 +122,11 @@ class DevToolsBridgeClientBrowserTest::MessageHandler void SignIn(const base::ListValue*) { if (test_->client_mock_.get()) test_->client_mock_->GoogleSigninSucceeded(); - test_->fake_token_service_->UpdateCredentials("test_user@gmail.com", - "token"); + const std::string account_id = + AccountTrackerServiceFactory::GetForProfile( + test_->browser()->profile())->PickAccountIdForAccount(kGaiaId, + kUsername); + test_->fake_token_service_->UpdateCredentials(account_id, "token"); } void GCDApiResponse(const base::ListValue* params) { diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc index 7c31488..d85b6ad 100644 --- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc +++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc @@ -200,7 +200,7 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { // user in the SigninManager class. virtual void SetAuthenticatedUser() { SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedUsername("test@google.com"); + SetAuthenticatedAccountInfo("12345", "test@google.com"); } NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; @@ -517,7 +517,7 @@ class EPKPChallengeMachineKeyUnmanagedUserTest protected: void SetAuthenticatedUser() override { SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedUsername("test@chromium.com"); + SetAuthenticatedAccountInfo("12345", "test@chromium.com"); } }; @@ -530,7 +530,7 @@ class EPKPChallengeUserKeyUnmanagedUserTest : public EPKPChallengeUserKeyTest { protected: void SetAuthenticatedUser() override { SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedUsername("test@chromium.com"); + SetAuthenticatedAccountInfo("12345", "test@chromium.com"); } }; diff --git a/chrome/browser/extensions/api/identity/identity_apitest.cc b/chrome/browser/extensions/api/identity/identity_apitest.cc index 5ff783d..1d4ba1e 100644 --- a/chrome/browser/extensions/api/identity/identity_apitest.cc +++ b/chrome/browser/extensions/api/identity/identity_apitest.cc @@ -573,20 +573,22 @@ class IdentityTestWithSignin : public AsyncExtensionBrowserTest { } protected: - void SignIn(const std::string account_key) { -#if defined(OS_CHROMEOS) - signin_manager_->SetAuthenticatedUsername(account_key); -#else - signin_manager_->SignIn(account_key, "password"); -#endif - token_service_->IssueRefreshTokenForUser(account_key, "refresh_token"); + void SignIn(const std::string& account_key) { + SignIn(account_key, account_key); } - void SignIn(const std::string& account_key, const std::string& gaia) { + void SignIn(const std::string& email, const std::string& gaia) { AccountTrackerService* account_tracker = AccountTrackerServiceFactory::GetForProfile(profile()); - account_tracker->SeedAccountInfo(gaia, account_key); - SignIn(account_key); + std::string account_id = + account_tracker->SeedAccountInfo(gaia, email); + +#if defined(OS_CHROMEOS) + signin_manager_->SetAuthenticatedAccountInfo(gaia, email); +#else + signin_manager_->SignIn(gaia, email, "password"); +#endif + token_service_->IssueRefreshTokenForUser(account_id, "refresh_token"); } FakeSigninManagerForTesting* signin_manager_; diff --git a/chrome/browser/extensions/api/screenlock_private/screenlock_private_apitest.cc b/chrome/browser/extensions/api/screenlock_private/screenlock_private_apitest.cc index 9c1b39c..5c79260 100644 --- a/chrome/browser/extensions/api/screenlock_private/screenlock_private_apitest.cc +++ b/chrome/browser/extensions/api/screenlock_private/screenlock_private_apitest.cc @@ -22,6 +22,7 @@ namespace extensions { namespace { +const char kTestGaiaId[] = "gaia-id-testuser@gmail.com"; const char kAttemptClickAuthMessage[] = "attemptClickAuth"; const char kTestExtensionId[] = "lkegkdgachcnekllcdfkijonogckdnjo"; const char kTestUser[] = "testuser@gmail.com"; @@ -49,7 +50,7 @@ class ScreenlockPrivateApiTest : public ExtensionApiTest, void SetUpOnMainThread() override { SigninManagerFactory::GetForProfile(profile()) - ->SetAuthenticatedUsername(kTestUser); + ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); ProfileInfoCache& info_cache = g_browser_process->profile_manager()->GetProfileInfoCache(); size_t index = info_cache.GetIndexOfProfileWithPath(profile()->GetPath()); diff --git a/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager_unittest.cc b/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager_unittest.cc index 992a817..708bb4a 100644 --- a/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager_unittest.cc +++ b/chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager_unittest.cc @@ -28,7 +28,7 @@ KeyedService* CreateProfileSyncServiceMock(content::BrowserContext* profile) { TEST(SignedInDevicesManager, UpdateListener) { scoped_ptr<TestingProfile> profile(new TestingProfile()); SigninManagerFactory::GetForProfile(profile.get())-> - SetAuthenticatedUsername("foo"); + SetAuthenticatedAccountInfo("gaia_id", "foo"); ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( profile.get(), CreateProfileSyncServiceMock); SignedInDevicesManager manager(profile.get()); diff --git a/chrome/browser/extensions/api/sync_file_system/sync_file_system_browsertest.cc b/chrome/browser/extensions/api/sync_file_system/sync_file_system_browsertest.cc index bafa06b..d3e3c42 100644 --- a/chrome/browser/extensions/api/sync_file_system/sync_file_system_browsertest.cc +++ b/chrome/browser/extensions/api/sync_file_system/sync_file_system_browsertest.cc @@ -135,8 +135,8 @@ class SyncFileSystemTest : public extensions::PlatformAppBrowserTest, } void SignIn() { - fake_signin_manager_->SetAuthenticatedUsername("tester"); - sync_engine()->GoogleSigninSucceeded("test_account", "tester", "testing"); + fake_signin_manager_->SetAuthenticatedAccountInfo("12345", "tester"); + sync_engine()->GoogleSigninSucceeded("12345", "tester", "password"); } void SetSyncEnabled(bool enabled) { diff --git a/chrome/browser/extensions/external_provider_impl_chromeos_unittest.cc b/chrome/browser/extensions/external_provider_impl_chromeos_unittest.cc index d399b10..809e2e9 100644 --- a/chrome/browser/extensions/external_provider_impl_chromeos_unittest.cc +++ b/chrome/browser/extensions/external_provider_impl_chromeos_unittest.cc @@ -157,7 +157,8 @@ TEST_F(ExternalProviderImplChromeOSTest, PolicyDisabled) { new ProfileManagerWithoutInit(temp_dir().path())); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_.get()); - signin->SetAuthenticatedUsername("test_user@gmail.com"); + signin->SetAuthenticatedAccountInfo("gaia-id-test_user@gmail.com", + "test_user@gmail.com"); ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()) ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token"); @@ -184,7 +185,8 @@ TEST_F(ExternalProviderImplChromeOSTest, PriorityCompleted) { // User is logged in. SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_.get()); - signin->SetAuthenticatedUsername("test_user@gmail.com"); + signin->SetAuthenticatedAccountInfo("gaia-id-test_user@gmail.com", + "test_user@gmail.com"); // App sync will wait for priority sync to complete. service_->CheckForExternalUpdates(); diff --git a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc index 96d9e07..ebce294 100644 --- a/chrome/browser/policy/cloud/cloud_policy_browsertest.cc +++ b/chrome/browser/policy/cloud/cloud_policy_browsertest.cc @@ -84,6 +84,12 @@ KeyedService* BuildFakeProfileInvalidationProvider( new invalidation::FakeInvalidationService)); } +#if !defined(OS_CHROMEOS) +const char* GetTestGaiaId() { + return "gaia-id-user@example.com"; +} +#endif + const char* GetTestUser() { #if defined(OS_CHROMEOS) return chromeos::login::kStubUser; @@ -246,7 +252,7 @@ class CloudPolicyTest : public InProcessBrowserTest, SigninManager* signin_manager = SigninManagerFactory::GetForProfile(browser()->profile()); ASSERT_TRUE(signin_manager); - signin_manager->SetAuthenticatedUsername(GetTestUser()); + signin_manager->SetAuthenticatedAccountInfo(GetTestGaiaId(), GetTestUser()); UserCloudPolicyManager* policy_manager = UserCloudPolicyManagerFactory::GetForBrowserContext( diff --git a/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc b/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc index d8699bf..9c63d1a 100644 --- a/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc +++ b/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc @@ -73,7 +73,7 @@ class CloudPolicyManagerTest : public InProcessBrowserTest { SigninManager* signin_manager = SigninManagerFactory::GetForProfile(browser()->profile()); ASSERT_TRUE(signin_manager); - signin_manager->SetAuthenticatedUsername("user@example.com"); + signin_manager->SetAuthenticatedAccountInfo("12345", "user@example.com"); ASSERT_TRUE(policy_manager()); policy_manager()->Connect( diff --git a/chrome/browser/policy/cloud/component_cloud_policy_browsertest.cc b/chrome/browser/policy/cloud/component_cloud_policy_browsertest.cc index c909b22..d1adf4e 100644 --- a/chrome/browser/policy/cloud/component_cloud_policy_browsertest.cc +++ b/chrome/browser/policy/cloud/component_cloud_policy_browsertest.cc @@ -182,7 +182,7 @@ class ComponentCloudPolicyTest : public ExtensionBrowserTest { SigninManager* signin_manager = SigninManagerFactory::GetForProfile(browser()->profile()); ASSERT_TRUE(signin_manager); - signin_manager->SetAuthenticatedUsername("user@example.com"); + signin_manager->SetAuthenticatedAccountInfo("12345", "user@example.com"); UserCloudPolicyManager* policy_manager = UserCloudPolicyManagerFactory::GetForBrowserContext( diff --git a/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc b/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc index 9bd3908..4cc4e8e 100644 --- a/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc +++ b/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc @@ -33,6 +33,7 @@ #include "components/policy/core/common/cloud/mock_user_cloud_policy_store.h" #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" #include "components/policy/core/common/schema_registry.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/notification_details.h" @@ -65,6 +66,7 @@ namespace policy { namespace { +const char kTestGaiaId[] = "gaia-id-testuser@test.com"; const char kTestUser[] = "testuser@test.com"; #if !defined(OS_ANDROID) @@ -134,8 +136,10 @@ class UserPolicySigninServiceTest : public testing::Test { // a valid login token, while on other platforms, the login refresh token // is specified directly. #if defined(OS_ANDROID) - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth2_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + AccountTrackerService::PickAccountIdForAccount( + profile_.get()->GetPrefs(), kTestGaiaId, kTestUser), + "oauth2_login_refresh_token"); #endif service->RegisterForPolicy( kTestUser, @@ -390,7 +394,7 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { // Set the user as signed in. SigninManagerFactory::GetForProfile(profile_.get())-> - SetAuthenticatedUsername(kTestUser); + SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); // Let the SigninService know that the profile has been created. content::NotificationService::current()->Notify( @@ -425,8 +429,10 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedIn) { ASSERT_FALSE(IsRequestActive()); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // Client registration should be in progress since we now have an oauth token. EXPECT_EQ(mock_store_->signin_username_, kTestUser); @@ -444,8 +450,10 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { ASSERT_FALSE(IsRequestActive()); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // Client registration should be in progress since we now have an oauth token. ASSERT_TRUE(IsRequestActive()); @@ -463,15 +471,17 @@ TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { ASSERT_FALSE(manager_->core()->service()); // Now sign in the user. - SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( - kTestUser); + SigninManagerFactory::GetForProfile(profile_.get()) + ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); // Complete initialization of the store. mock_store_->NotifyStoreLoaded(); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // UserCloudPolicyManager should be initialized. EXPECT_EQ(mock_store_->signin_username_, kTestUser); @@ -487,15 +497,18 @@ TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { ASSERT_FALSE(manager_->core()->service()); // Now sign in a non-enterprise user (blacklisted gmail.com domain). - SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( - "non_enterprise_user@gmail.com"); + SigninManagerFactory::GetForProfile(profile_.get()) + ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com", + "non_enterprise_user@gmail.com"); // Complete initialization of the store. mock_store_->NotifyStoreLoaded(); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // UserCloudPolicyManager should not be initialized and there should be no // DMToken request active. @@ -509,12 +522,14 @@ TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { ASSERT_FALSE(manager_->core()->service()); // Now sign in the user. - SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( - kTestUser); + SigninManagerFactory::GetForProfile(profile_.get()) + ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // UserCloudPolicyManager should be initialized. EXPECT_EQ(mock_store_->signin_username_, kTestUser); @@ -537,12 +552,14 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) { ASSERT_FALSE(manager_->core()->service()); // Now sign in the user. - SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( - kTestUser); + SigninManagerFactory::GetForProfile(profile_.get()) + ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); // Make oauth token available. - GetTokenService()->IssueRefreshTokenForUser(kTestUser, - "oauth_login_refresh_token"); + GetTokenService()->IssueRefreshTokenForUser( + SigninManagerFactory::GetForProfile(profile_.get()) + ->GetAuthenticatedAccountId(), + "oauth_login_refresh_token"); // UserCloudPolicyManager should be initialized. EXPECT_EQ(mock_store_->signin_username_, kTestUser); diff --git a/chrome/browser/prefs/chrome_pref_service_factory.cc b/chrome/browser/prefs/chrome_pref_service_factory.cc index 3581fe1..a22f002 100644 --- a/chrome/browser/prefs/chrome_pref_service_factory.cc +++ b/chrome/browser/prefs/chrome_pref_service_factory.cc @@ -221,6 +221,8 @@ const PrefHashFilter::TrackedPreferenceMetadata kTrackedPrefs[] = { PrefHashFilter::VALUE_IMPERSONAL }, #endif + // This pref is deprecated and will be removed a few releases after M43. + // kGoogleServicesAccountId replaces it. { 21, prefs::kGoogleServicesUsername, PrefHashFilter::ENFORCE_ON_LOAD, @@ -235,6 +237,12 @@ const PrefHashFilter::TrackedPreferenceMetadata kTrackedPrefs[] = { PrefHashFilter::VALUE_IMPERSONAL }, #endif + { + 23, prefs::kGoogleServicesAccountId, + PrefHashFilter::ENFORCE_ON_LOAD, + PrefHashFilter::TRACKING_STRATEGY_ATOMIC, + PrefHashFilter::VALUE_PERSONAL + }, // See note at top, new items added here also need to be added to // histograms.xml's TrackedPreference enum. }; diff --git a/chrome/browser/profiles/gaia_info_update_service_unittest.cc b/chrome/browser/profiles/gaia_info_update_service_unittest.cc index 4a89e37..64c1a85 100644 --- a/chrome/browser/profiles/gaia_info_update_service_unittest.cc +++ b/chrome/browser/profiles/gaia_info_update_service_unittest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache_unittest.h" #include "chrome/browser/profiles/profiles_state.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/test_signin_client_builder.h" @@ -19,6 +20,7 @@ #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_unittest_util.h" @@ -280,7 +282,7 @@ TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { TEST_F(GAIAInfoUpdateServiceTest, LogOut) { SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile()); - signin_manager->SetAuthenticatedUsername("pat@example.com"); + signin_manager->SetAuthenticatedAccountInfo("gaia_id", "pat@example.com"); base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); gfx::Image gaia_picture = gfx::test::CreateImage(256,256); @@ -303,9 +305,12 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) { TEST_F(GAIAInfoUpdateServiceTest, LogIn) { // Log in. EXPECT_CALL(*service(), Update()); + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(profile()) + ->SeedAccountInfo("gaia_id", "pat@example.com"); SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile()); - signin_manager->OnExternalSigninCompleted("pat@example.com"); + signin_manager->OnExternalSigninCompleted(account_id); } #endif diff --git a/chrome/browser/services/gcm/fake_signin_manager.cc b/chrome/browser/services/gcm/fake_signin_manager.cc index 64f7ccc..563ee4f 100644 --- a/chrome/browser/services/gcm/fake_signin_manager.cc +++ b/chrome/browser/services/gcm/fake_signin_manager.cc @@ -11,6 +11,7 @@ #include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" #include "components/keyed_service/core/keyed_service.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/common/signin_pref_names.h" #include "content/public/browser/browser_context.h" @@ -23,7 +24,8 @@ namespace gcm { FakeSigninManager::FakeSigninManager(Profile* profile) #if defined(OS_CHROMEOS) : SigninManagerBase( - ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)), + ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), + AccountTrackerServiceFactory::GetForProfile(profile)), #else : SigninManager( ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), @@ -38,19 +40,20 @@ FakeSigninManager::FakeSigninManager(Profile* profile) FakeSigninManager::~FakeSigninManager() { } -void FakeSigninManager::SignIn(const std::string& username) { - SetAuthenticatedUsername(username); +void FakeSigninManager::SignIn(const std::string& account_id) { + SetAuthenticatedAccountId(account_id); FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, - GoogleSigninSucceeded(username, username, std::string())); + GoogleSigninSucceeded(account_id, account_id, + std::string())); } void FakeSigninManager::SignOut( signin_metrics::ProfileSignout signout_source_metric) { const std::string account_id = GetAuthenticatedAccountId(); const std::string username = GetAuthenticatedUsername(); - ClearAuthenticatedUsername(); - profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); + clear_authenticated_user(); + profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId); FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, GoogleSignedOut(account_id, username)); diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc index 43f97c4..7d6e9c5 100644 --- a/chrome/browser/signin/account_reconcilor_unittest.cc +++ b/chrome/browser/signin/account_reconcilor_unittest.cc @@ -11,6 +11,7 @@ #include "build/build_config.h" #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/signin/account_reconcilor_factory.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" @@ -23,6 +24,7 @@ #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "components/signin/core/browser/account_reconcilor.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_metrics.h" @@ -38,8 +40,6 @@ namespace { -const char kTestEmail[] = "user@gmail.com"; - class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { public: static KeyedService* Build(content::BrowserContext* context); @@ -87,6 +87,7 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> { FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } FakeProfileOAuth2TokenService* token_service() { return token_service_; } TestSigninClient* test_signin_client() { return test_signin_client_; } + AccountTrackerService* account_tracker() { return account_tracker_; } base::HistogramTester* histogram_tester() { return &histogram_tester_; } void SetFakeResponse(const std::string& url, @@ -98,6 +99,12 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> { MockAccountReconcilor* GetMockReconcilor(); + std::string ConnectProfileToAccount(const std::string& gaia_id, + const std::string& username); + + std::string PickAccountIdForAccount(const std::string& gaia_id, + const std::string& username); + void SimulateAddAccountToCookieCompleted( GaiaCookieManagerService::Observer* observer, const std::string& account_id, @@ -118,6 +125,7 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> { FakeSigninManagerForTesting* signin_manager_; FakeProfileOAuth2TokenService* token_service_; TestSigninClient* test_signin_client_; + AccountTrackerService* account_tracker_; MockAccountReconcilor* mock_reconcilor_; net::FakeURLFetcherFactory url_fetcher_factory_; scoped_ptr<TestingProfileManager> testing_profile_manager_; @@ -173,17 +181,20 @@ void AccountReconcilorTest::SetUp() { base::UTF8ToUTF16("name"), 0, std::string(), factories); - signin_manager_ = - static_cast<FakeSigninManagerForTesting*>( - SigninManagerFactory::GetForProfile(profile())); + test_signin_client_ = + static_cast<TestSigninClient*>( + ChromeSigninClientFactory::GetForProfile(profile())); token_service_ = static_cast<FakeProfileOAuth2TokenService*>( ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); - test_signin_client_ = - static_cast<TestSigninClient*>( - ChromeSigninClientFactory::GetForProfile(profile())); + account_tracker_ = + AccountTrackerServiceFactory::GetForProfile(profile()); + + signin_manager_ = + static_cast<FakeSigninManagerForTesting*>( + SigninManagerFactory::GetForProfile(profile())); } MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { @@ -196,6 +207,24 @@ MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { return mock_reconcilor_; } +std::string AccountReconcilorTest::ConnectProfileToAccount( + const std::string& gaia_id, + const std::string& username) { + const std::string account_id = PickAccountIdForAccount(gaia_id, username); +#if !defined(OS_CHROMEOS) + signin_manager()->set_password("password"); +#endif + signin_manager()->SetAuthenticatedAccountInfo(gaia_id, username); + token_service()->UpdateCredentials(account_id, "refresh_token"); + return account_id; +} + +std::string AccountReconcilorTest::PickAccountIdForAccount( + const std::string& gaia_id, + const std::string& username) { + return account_tracker()->PickAccountIdForAccount(gaia_id, username); +} + void AccountReconcilorTest::SimulateAddAccountToCookieCompleted( GaiaCookieManagerService::Observer* observer, const std::string& account_id, @@ -231,8 +260,8 @@ TEST_F(AccountReconcilorTest, SigninManagerRegistration) { ASSERT_TRUE(reconcilor); ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); - signin_manager()->set_password("password"); - signin_manager()->OnExternalSigninCompleted(kTestEmail); + account_tracker()->SeedAccountInfo("12345", "user@gmail.com"); + signin_manager()->SignIn("12345", "user@gmail.com", "password"); ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); @@ -246,8 +275,9 @@ TEST_F(AccountReconcilorTest, SigninManagerRegistration) { // method with an empty implementation. On MacOS, the normal implementation // causes the try_bots to time out. TEST_F(AccountReconcilorTest, Reauth) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - signin_manager()->set_password("password"); + const std::string email = "user@gmail.com"; + const std::string account_id = + ConnectProfileToAccount("12345", email); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -255,14 +285,14 @@ TEST_F(AccountReconcilorTest, Reauth) { ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); // Simulate reauth. The state of the reconcilor should not change. - signin_manager()->OnExternalSigninCompleted(kTestEmail); + signin_manager()->OnExternalSigninCompleted(email); ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); } #endif // !defined(OS_CHROMEOS) TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); + ConnectProfileToAccount("12345", "user@gmail.com"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -271,9 +301,10 @@ TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) { } TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail)); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); + AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); ASSERT_TRUE(reconcilor); @@ -290,12 +321,11 @@ TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { const std::vector<std::pair<std::string, bool> >& accounts = reconcilor->GetGaiaAccountsForTesting(); ASSERT_EQ(1u, accounts.size()); - ASSERT_EQ("user@gmail.com", accounts[0].first); + ASSERT_EQ(account_id, accounts[0].first); } TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + ConnectProfileToAccount("12345", "user@gmail.com"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); ASSERT_TRUE(reconcilor); @@ -311,8 +341,8 @@ TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { } TEST_P(AccountReconcilorTest, StartReconcileNoop) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -338,8 +368,9 @@ TEST_P(AccountReconcilorTest, StartReconcileNoop) { } TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); test_signin_client()->set_are_signin_cookies_allowed(false); AccountReconcilor* reconcilor = @@ -355,8 +386,9 @@ TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) { } TEST_P(AccountReconcilorTest, StartReconcileContentSettings) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -374,8 +406,9 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettings) { } TEST_P(AccountReconcilorTest, StartReconcileContentSettingsGaiaUrl) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -388,8 +421,9 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettingsGaiaUrl) { } TEST_P(AccountReconcilorTest, StartReconcileContentSettingsNonGaiaUrl) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -402,8 +436,9 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettingsNonGaiaUrl) { } TEST_P(AccountReconcilorTest, StartReconcileContentSettingsInvalidPattern) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -417,7 +452,7 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettingsInvalidPattern) { ASSERT_TRUE(reconcilor->is_reconcile_started_); } -// This is test is needed until chrome changes to use gaia obfuscated id. +// This test is needed until chrome changes to use gaia obfuscated id. // The signin manager and token service use the gaia "email" property, which // preserves dots in usernames and preserves case. gaia::ParseListAccountsData() // however uses gaia "displayEmail" which does not preserve case, and then @@ -426,9 +461,13 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettingsInvalidPattern) { // token service, will be considered the same as "dots@gmail.com" as returned // by gaia::ParseListAccountsData(). TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { - signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com"); - token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token"); + if (account_tracker()->GetMigrationState() != + AccountTrackerService::MIGRATION_NOT_STARTED) { + return; + } + const std::string account_id = + ConnectProfileToAccount("12345", "Dot.S@gmail.com"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); ASSERT_TRUE(reconcilor); @@ -450,9 +489,11 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) { } TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); - token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + const std::string account_id2 = + PickAccountIdForAccount("67890", "other@gmail.com"); + token_service()->UpdateCredentials(account_id2, "refresh_token"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -477,11 +518,15 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) { } TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); - token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); + + const std::string account_id2 = + PickAccountIdForAccount("67890", "other@gmail.com"); + token_service()->UpdateCredentials(account_id2, "refresh_token"); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); SetFakeResponse(list_accounts_url().spec(), "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", @@ -492,7 +537,7 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { base::RunLoop().RunUntilIdle(); ASSERT_TRUE(reconcilor->is_reconcile_started_); - SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, account_id2, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); @@ -507,11 +552,12 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) { } TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + token_service()->UpdateCredentials(account_id, "refresh_token"); EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); SetFakeResponse(list_accounts_url().spec(), "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], " @@ -538,12 +584,17 @@ TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) { } TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); - token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + const std::string account_id2 = + PickAccountIdForAccount("67890", "other@gmail.com"); + const std::string account_id3 = + PickAccountIdForAccount("34567", "third@gmail.com"); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com")); + token_service()->UpdateCredentials(account_id2, "refresh_token"); + + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id3)); SetFakeResponse( list_accounts_url().spec(), @@ -557,7 +608,7 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { base::RunLoop().RunUntilIdle(); ASSERT_TRUE(reconcilor->is_reconcile_started_); SimulateAddAccountToCookieCompleted( - reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone()); + reconcilor, account_id2, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); histogram_tester()->ExpectUniqueSample( @@ -578,13 +629,12 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { net::HTTP_OK, net::URLRequestStatus::SUCCESS); // This will cause the reconcilor to fire. - token_service()->UpdateCredentials("third@gmail.com", "refresh_token"); - + token_service()->UpdateCredentials(account_id3, "refresh_token"); base::RunLoop().RunUntilIdle(); ASSERT_TRUE(reconcilor->is_reconcile_started_); SimulateAddAccountToCookieCompleted( - reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone()); + reconcilor, account_id3, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); histogram_tester()->ExpectUniqueSample( @@ -606,13 +656,16 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) { } TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); - token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + const std::string account_id2 = + PickAccountIdForAccount("67890", "other@gmail.com"); + + token_service()->UpdateCredentials(account_id2, "refresh_token"); EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2)); SetFakeResponse(list_accounts_url().spec(), "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], " @@ -624,10 +677,10 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { base::RunLoop().RunUntilIdle(); ASSERT_TRUE(reconcilor->is_reconcile_started_); - SimulateAddAccountToCookieCompleted(reconcilor, "other@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, account_id2, GoogleServiceAuthError::AuthErrorNone()); ASSERT_TRUE(reconcilor->is_reconcile_started_); - SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, account_id, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); @@ -642,8 +695,8 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) { } TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); @@ -662,11 +715,13 @@ TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) { } TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); - token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); + const std::string account_id2 = + PickAccountIdForAccount("67890", "other@gmail.com"); + token_service()->UpdateCredentials(account_id2, "refresh_token"); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); SetFakeResponse(list_accounts_url().spec(), "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]," @@ -682,16 +737,16 @@ TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) { ASSERT_TRUE(reconcilor->is_reconcile_started_); base::RunLoop().RunUntilIdle(); - SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, account_id, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); } TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) { - signin_manager()->SetAuthenticatedUsername("user@gmail.com"); - token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); + const std::string account_id = + ConnectProfileToAccount("12345", "user@gmail.com"); - EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com")); + EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id)); SetFakeResponse(list_accounts_url().spec(), "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]", @@ -708,11 +763,11 @@ TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) { base::RunLoop().RunUntilIdle(); // If an unknown account id is sent, it should not upset the state. - SimulateAddAccountToCookieCompleted(reconcilor, "bogus@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, "bogus_account_id", GoogleServiceAuthError::AuthErrorNone()); ASSERT_TRUE(reconcilor->is_reconcile_started_); - SimulateAddAccountToCookieCompleted(reconcilor, "user@gmail.com", + SimulateAddAccountToCookieCompleted(reconcilor, account_id, GoogleServiceAuthError::AuthErrorNone()); ASSERT_FALSE(reconcilor->is_reconcile_started_); } diff --git a/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc b/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc index 6651564..c5b3418 100644 --- a/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc +++ b/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc @@ -280,7 +280,7 @@ class EasyUnlockServiceTest : public testing::Test { SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(profile->get()); - signin_manager->SetAuthenticatedUsername(user_id); + signin_manager->SetAuthenticatedAccountInfo(user_id, user_id); } protected: diff --git a/chrome/browser/signin/fake_signin_manager.cc b/chrome/browser/signin/fake_signin_manager.cc index 8314079..6cc2902 100644 --- a/chrome/browser/signin/fake_signin_manager.cc +++ b/chrome/browser/signin/fake_signin_manager.cc @@ -14,10 +14,13 @@ #include "chrome/browser/signin/signin_manager_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 "components/signin/core/browser/account_tracker_service.h" FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) : SigninManagerBase( - ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)) {} + ChromeSigninClientFactory::GetForProfile(profile), + AccountTrackerServiceFactory::GetForProfile(profile)) {} FakeSigninManagerBase::~FakeSigninManagerBase() { } @@ -41,7 +44,7 @@ KeyedService* FakeSigninManagerBase::Build(content::BrowserContext* context) { FakeSigninManager::FakeSigninManager(Profile* profile) : SigninManager( - ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), + ChromeSigninClientFactory::GetForProfile(profile), ProfileOAuth2TokenServiceFactory::GetForProfile(profile), AccountTrackerServiceFactory::GetForProfile(profile), GaiaCookieManagerServiceFactory::GetForProfile(profile)) {} @@ -51,30 +54,36 @@ FakeSigninManager::~FakeSigninManager() { void FakeSigninManager::StartSignInWithRefreshToken( const std::string& refresh_token, + const std::string& gaia_id, const std::string& username, const std::string& password, const OAuthTokenFetchedCallback& oauth_fetched_callback) { - set_auth_in_progress(username); + set_auth_in_progress( + account_tracker_service()->SeedAccountInfo(gaia_id, username)); set_password(password); + username_ = username; + if (!oauth_fetched_callback.is_null()) oauth_fetched_callback.Run(refresh_token); } void FakeSigninManager::CompletePendingSignin() { - SetAuthenticatedUsername(GetUsernameForAuthInProgress()); + SetAuthenticatedAccountId(GetAccountIdForAuthInProgress()); set_auth_in_progress(std::string()); FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, - GoogleSigninSucceeded(authenticated_username_, - authenticated_username_, + GoogleSigninSucceeded(authenticated_account_id_, + username_, password_)); } -void FakeSigninManager::SignIn(const std::string& username, +void FakeSigninManager::SignIn(const std::string& gaia_id, + const std::string& username, const std::string& password) { StartSignInWithRefreshToken( - std::string(), username, password, OAuthTokenFetchedCallback()); + std::string(), gaia_id, username, password, + OAuthTokenFetchedCallback()); CompletePendingSignin(); } @@ -92,7 +101,7 @@ void FakeSigninManager::SignOut( set_password(std::string()); const std::string account_id = GetAuthenticatedAccountId(); const std::string username = GetAuthenticatedUsername(); - ClearAuthenticatedUsername(); + authenticated_account_id_.clear(); FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, GoogleSignedOut(account_id, username)); diff --git a/chrome/browser/signin/fake_signin_manager.h b/chrome/browser/signin/fake_signin_manager.h index 8e91531..24e59c4 100644 --- a/chrome/browser/signin/fake_signin_manager.h +++ b/chrome/browser/signin/fake_signin_manager.h @@ -44,18 +44,21 @@ class FakeSigninManager : public SigninManager { explicit FakeSigninManager(Profile* profile); ~FakeSigninManager() override; - void set_auth_in_progress(const std::string& username) { - possibly_invalid_username_ = username; + void set_auth_in_progress(const std::string& account_id) { + possibly_invalid_account_id_ = account_id; } void set_password(const std::string& password) { password_ = password; } - void SignIn(const std::string& username, const std::string& password); + void SignIn(const std::string& account_id, + const std::string& username, + const std::string& password); void FailSignin(const GoogleServiceAuthError& error); void StartSignInWithRefreshToken( const std::string& refresh_token, + const std::string& gaia_id, const std::string& username, const std::string& password, const OAuthTokenFetchedCallback& oauth_fetched_callback) override; @@ -63,6 +66,9 @@ class FakeSigninManager : public SigninManager { void SignOut(signin_metrics::ProfileSignout signout_source_metric) override; void CompletePendingSignin() override; + + // Username specified in StartSignInWithRefreshToken() call. + std::string username_; }; #endif // !defined (OS_CHROMEOS) diff --git a/chrome/browser/signin/signin_global_error_unittest.cc b/chrome/browser/signin/signin_global_error_unittest.cc index 0b16dcf8..c9416dc 100644 --- a/chrome/browser/signin/signin_global_error_unittest.cc +++ b/chrome/browser/signin/signin_global_error_unittest.cc @@ -30,7 +30,7 @@ #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" -static const char kTestAccountId[] = "testuser@test.com"; +static const char kTestAccountId[] = "id-testuser@test.com"; static const char kTestUsername[] = "testuser@test.com"; class SigninGlobalErrorTest : public testing::Test { @@ -54,12 +54,12 @@ class SigninGlobalErrorTest : public testing::Test { base::UTF8ToUTF16("Person 1"), 0, std::string(), testing_factories); SigninManagerFactory::GetForProfile(profile()) - ->SetAuthenticatedUsername(kTestAccountId); + ->SetAuthenticatedAccountInfo(kTestAccountId, kTestUsername); ProfileInfoCache& cache = profile_manager_.profile_manager()->GetProfileInfoCache(); cache.SetUserNameOfProfileAtIndex( cache.GetIndexOfProfileWithPath(profile()->GetPath()), - base::UTF8ToUTF16(kTestAccountId)); + base::UTF8ToUTF16(kTestUsername)); global_error_ = SigninGlobalErrorFactory::GetForProfile(profile()); error_controller_ = SigninErrorControllerFactory::GetForProfile(profile()); diff --git a/chrome/browser/signin/signin_manager_factory.cc b/chrome/browser/signin/signin_manager_factory.cc index f7f828e..9222645 100644 --- a/chrome/browser/signin/signin_manager_factory.cc +++ b/chrome/browser/signin/signin_manager_factory.cc @@ -98,11 +98,11 @@ void SigninManagerFactory::RegisterProfilePrefs( std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( - prefs::kGoogleServicesUserAccountId, + prefs::kGoogleServicesAccountId, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( - prefs::kGoogleServicesUsername, + prefs::kGoogleServicesUserAccountId, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterBooleanPref( @@ -120,7 +120,14 @@ void SigninManagerFactory::RegisterProfilePrefs( prefs::kSignedInTime, base::Time().ToInternalValue(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + LocalAuth::RegisterLocalAuthPrefs(registry); + + // Deprecated prefs: will be removed in a future release. + registry->RegisterStringPref( + prefs::kGoogleServicesUsername, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); } // static @@ -149,7 +156,9 @@ KeyedService* SigninManagerFactory::BuildServiceInstanceFor( SigninClient* client = ChromeSigninClientFactory::GetInstance()->GetForProfile(profile); #if defined(OS_CHROMEOS) - service = new SigninManagerBase(client); + service = new SigninManagerBase( + client, + AccountTrackerServiceFactory::GetForProfile(profile)); #else service = new SigninManager( client, diff --git a/chrome/browser/signin/signin_manager_unittest.cc b/chrome/browser/signin/signin_manager_unittest.cc index 44d2f11..750333e 100644 --- a/chrome/browser/signin/signin_manager_unittest.cc +++ b/chrome/browser/signin/signin_manager_unittest.cc @@ -29,6 +29,7 @@ #include "chrome/common/url_constants.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/test_signin_client.h" #include "content/public/browser/child_process_security_policy.h" @@ -115,7 +116,10 @@ class SigninManagerTest : public testing::Test { FakeAccountTrackerService::Build); profile_ = builder.Build(); - signin_client()->SetURLRequestContext(profile_->GetRequestContext()); + TestSigninClient* client = + static_cast<TestSigninClient*>( + ChromeSigninClientFactory::GetForProfile(profile())); + client->SetURLRequestContext(profile_->GetRequestContext()); } void TearDown() override { @@ -144,6 +148,17 @@ class SigninManagerTest : public testing::Test { ChromeSigninClientFactory::GetInstance()->GetForProfile(profile())); } + // Seed the account tracker with information from logged in user. Normally + // this is done by UI code before calling SigninManager. Returns the string + // to use as the account_id. + std::string AddToAccountTracker(const std::string& gaia_id, + const std::string& email) { + AccountTrackerService* service = + AccountTrackerServiceFactory::GetForProfile(profile()); + service->SeedAccountInfo(gaia_id, email); + return service->PickAccountIdForAccount(gaia_id, email); + } + // Sets up the signin manager as a service if other code will try to get it as // a PKS. void SetUpSigninManagerAsService() { @@ -179,11 +194,13 @@ class SigninManagerTest : public testing::Test { void ExpectSignInWithRefreshTokenSuccess() { EXPECT_TRUE(manager_->IsAuthenticated()); + EXPECT_FALSE(manager_->GetAuthenticatedAccountId().empty()); + EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); EXPECT_TRUE(token_service->RefreshTokenIsAvailable( - manager_->GetAuthenticatedUsername())); + manager_->GetAuthenticatedAccountId())); // Should go into token service and stop. EXPECT_EQ(1, test_observer_.num_successful_signins_); @@ -210,8 +227,10 @@ TEST_F(SigninManagerTest, SignInWithRefreshToken) { SetUpSigninManagerAsService(); EXPECT_FALSE(manager_->IsAuthenticated()); + std::string account_id = AddToAccountTracker("gaia_id", "user@gmail.com"); manager_->StartSignInWithRefreshToken( - "rt1", + "rt", + "gaia_id", "user@gmail.com", "password", SigninManager::OAuthTokenFetchedCallback()); @@ -222,7 +241,7 @@ TEST_F(SigninManagerTest, SignInWithRefreshToken) { ShutDownManager(); CreateNakedSigninManager(); manager_->Initialize(NULL); - EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); + EXPECT_EQ(account_id, manager_->GetAuthenticatedAccountId()); } TEST_F(SigninManagerTest, SignInWithRefreshTokenCallbackComplete) { @@ -234,14 +253,15 @@ TEST_F(SigninManagerTest, SignInWithRefreshTokenCallbackComplete) { base::Bind(&SigninManagerTest::CompleteSigninCallback, base::Unretained(this)); manager_->StartSignInWithRefreshToken( - "rt1", + "rt", + "gaia_id", "user@gmail.com", "password", callback); ExpectSignInWithRefreshTokenSuccess(); ASSERT_EQ(1U, oauth_tokens_fetched_.size()); - EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); + EXPECT_EQ(oauth_tokens_fetched_[0], "rt"); } TEST_F(SigninManagerTest, SignInWithRefreshTokenCallsPostSignout) { @@ -263,6 +283,7 @@ TEST_F(SigninManagerTest, SignInWithRefreshTokenCallsPostSignout) { manager_->StartSignInWithRefreshToken( "rt1", + gaia_id, email, "password", SigninManager::OAuthTokenFetchedCallback()); @@ -283,24 +304,31 @@ TEST_F(SigninManagerTest, SignInWithRefreshTokenCallsPostSignout) { TEST_F(SigninManagerTest, SignOut) { SetUpSigninManagerAsService(); manager_->StartSignInWithRefreshToken( - "rt1", + "rt", + "gaia_id", "user@gmail.com", "password", SigninManager::OAuthTokenFetchedCallback()); manager_->SignOut(signin_metrics::SIGNOUT_TEST); EXPECT_FALSE(manager_->IsAuthenticated()); + EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); + EXPECT_TRUE(manager_->GetAuthenticatedAccountId().empty()); // Should not be persisted anymore ShutDownManager(); CreateNakedSigninManager(); manager_->Initialize(NULL); EXPECT_FALSE(manager_->IsAuthenticated()); + EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); + EXPECT_TRUE(manager_->GetAuthenticatedAccountId().empty()); } TEST_F(SigninManagerTest, SignOutWhileProhibited) { SetUpSigninManagerAsService(); EXPECT_FALSE(manager_->IsAuthenticated()); + EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); + EXPECT_TRUE(manager_->GetAuthenticatedAccountId().empty()); - manager_->SetAuthenticatedUsername("user@gmail.com"); + manager_->SetAuthenticatedAccountInfo("gaia_id", "user@gmail.com"); manager_->ProhibitSignout(true); manager_->SignOut(signin_metrics::SIGNOUT_TEST); EXPECT_TRUE(manager_->IsAuthenticated()); @@ -336,47 +364,80 @@ TEST_F(SigninManagerTest, TestAlternateWildcard) { } TEST_F(SigninManagerTest, ProhibitedAtStartup) { - profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "monkey@invalid.com"); + std::string account_id = AddToAccountTracker("gaia_id", "user@gmail.com"); + profile()->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); g_browser_process->local_state()->SetString( prefs::kGoogleServicesUsernamePattern, ".*@google.com"); CreateNakedSigninManager(); manager_->Initialize(g_browser_process->local_state()); // Currently signed in user is prohibited by policy, so should be signed out. EXPECT_EQ("", manager_->GetAuthenticatedUsername()); + EXPECT_EQ("", manager_->GetAuthenticatedAccountId()); } TEST_F(SigninManagerTest, ProhibitedAfterStartup) { - std::string user("monkey@invalid.com"); - profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); + std::string account_id = AddToAccountTracker("gaia_id", "user@gmail.com"); + profile()->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); CreateNakedSigninManager(); manager_->Initialize(g_browser_process->local_state()); - EXPECT_EQ(user, manager_->GetAuthenticatedUsername()); + EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); + EXPECT_EQ(account_id, manager_->GetAuthenticatedAccountId()); // Update the profile - user should be signed out. g_browser_process->local_state()->SetString( prefs::kGoogleServicesUsernamePattern, ".*@google.com"); EXPECT_EQ("", manager_->GetAuthenticatedUsername()); + EXPECT_EQ("", manager_->GetAuthenticatedAccountId()); } TEST_F(SigninManagerTest, ExternalSignIn) { CreateNakedSigninManager(); manager_->Initialize(g_browser_process->local_state()); - EXPECT_EQ("", - profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); EXPECT_EQ("", manager_->GetAuthenticatedUsername()); + EXPECT_EQ("", manager_->GetAuthenticatedAccountId()); EXPECT_EQ(0, test_observer_.num_successful_signins_); - manager_->OnExternalSigninCompleted("external@example.com"); + std::string account_id = AddToAccountTracker("gaia_id", "user@gmail.com"); + manager_->OnExternalSigninCompleted(account_id); EXPECT_EQ(1, test_observer_.num_successful_signins_); EXPECT_EQ(0, test_observer_.num_failed_signins_); - EXPECT_EQ("external@example.com", - profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); - EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); + EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); + EXPECT_EQ(account_id, manager_->GetAuthenticatedAccountId()); } TEST_F(SigninManagerTest, SigninNotAllowed) { std::string user("user@google.com"); - profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); + profile()->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, user); profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); - SetUpSigninManagerAsService(); + CreateNakedSigninManager(); + AddToAccountTracker("gaia_id", user); + manager_->Initialize(g_browser_process->local_state()); + // Currently signing in is prohibited by policy, so should be signed out. + EXPECT_EQ("", manager_->GetAuthenticatedUsername()); + EXPECT_EQ("", manager_->GetAuthenticatedAccountId()); +} + +TEST_F(SigninManagerTest, UpgradeToNewPrefs) { + profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "user@gmail.com"); + profile()->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, + "account_id"); + CreateNakedSigninManager(); + manager_->Initialize(g_browser_process->local_state()); + EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); + + // TODO(rogerta): until the migration to gaia id, the account id will remain + // the old username. + EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedAccountId()); + EXPECT_EQ("user@gmail.com", + profile()->GetPrefs()->GetString(prefs::kGoogleServicesAccountId)); + EXPECT_EQ("", + profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); + + // Make sure account tracker was updated. + AccountTrackerService* service = + AccountTrackerServiceFactory::GetForProfile(profile()); + AccountTrackerService::AccountInfo info = service->GetAccountInfo( + manager_->GetAuthenticatedAccountId()); + EXPECT_EQ("user@gmail.com", info.email); + EXPECT_EQ("account_id", info.gaia); } diff --git a/chrome/browser/signin/signin_names_io_thread_unittest.cc b/chrome/browser/signin/signin_names_io_thread_unittest.cc index d79013e..607f8e1 100644 --- a/chrome/browser/signin/signin_names_io_thread_unittest.cc +++ b/chrome/browser/signin/signin_names_io_thread_unittest.cc @@ -8,11 +8,13 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile_info_cache.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/signin/signin_names_io_thread.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_browser_thread.h" @@ -59,7 +61,12 @@ void SigninNamesOnIOThreadTest::TearDown() { } void SigninNamesOnIOThreadTest::SimulateSignin(const base::string16& email) { - signin_manager_->SignIn(base::UTF16ToUTF8(email), "password"); + const std::string gaia_id = "gaia_id"; + const std::string email_str = base::UTF16ToUTF8(email); + AccountTrackerService* service = + AccountTrackerServiceFactory::GetForProfile(profile_.get()); + service->SeedAccountInfo(gaia_id, email_str); + signin_manager_->SignIn(gaia_id, email_str, "password"); } void SigninNamesOnIOThreadTest::AddNewProfile(const base::string16& name, diff --git a/chrome/browser/signin/signin_tracker_unittest.cc b/chrome/browser/signin/signin_tracker_unittest.cc index e982549..34483b7 100644 --- a/chrome/browser/signin/signin_tracker_unittest.cc +++ b/chrome/browser/signin/signin_tracker_unittest.cc @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/fake_signin_manager.h" @@ -18,6 +19,7 @@ #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/test/base/testing_profile.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/fake_auth_status_provider.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/signin_manager.h" @@ -69,11 +71,22 @@ class SigninTrackerTest : public testing::Test { tracker_ = SigninTrackerFactory::CreateForProfile(profile_.get(), &observer_); } + void TearDown() override { tracker_.reset(); profile_.reset(); } + // Seed the account tracker with information from logged in user. Normally + // this is done by UI code before calling SigninManager. Returns the string + // to use as the account_id. + std::string AddToAccountTracker(const std::string& gaia_id, + const std::string& email) { + AccountTrackerService* service = + AccountTrackerServiceFactory::GetForProfile(profile_.get()); + return service->SeedAccountInfo(gaia_id, email); + } + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<SigninTracker> tracker_; scoped_ptr<TestingProfile> profile_; @@ -99,7 +112,13 @@ TEST_F(SigninTrackerTest, SignInSucceeds) { EXPECT_CALL(observer_, SigninSuccess()); EXPECT_CALL(observer_, SigninFailed(_)).Times(0); - mock_signin_manager_->SetAuthenticatedUsername("user@gmail.com"); - fake_oauth2_token_service_->IssueRefreshTokenForUser( - "user@gmail.com", "refresh_token"); + AccountTrackerService* service = + AccountTrackerServiceFactory::GetForProfile(profile_.get()); + std::string gaia_id = "gaia_id"; + std::string email = "user@gmail.com"; + std::string account_id = service->SeedAccountInfo(gaia_id, email); + + mock_signin_manager_->SetAuthenticatedAccountInfo(gaia_id, email); + fake_oauth2_token_service_->IssueRefreshTokenForUser(account_id, + "refresh_token"); } diff --git a/chrome/browser/supervised_user/supervised_user_service_unittest.cc b/chrome/browser/supervised_user/supervised_user_service_unittest.cc index 83778b3..eb01a78 100644 --- a/chrome/browser/supervised_user/supervised_user_service_unittest.cc +++ b/chrome/browser/supervised_user/supervised_user_service_unittest.cc @@ -219,7 +219,7 @@ TEST_F(SupervisedUserServiceTest, ShutDownCustodianProfileDownloader) { // Emulate being logged in, then start to download a profile so a // ProfileDownloader gets created. SigninManagerFactory::GetForProfile(profile_.get())-> - SetAuthenticatedUsername("Logged In"); + SetAuthenticatedAccountInfo("12345", "Logged In"); downloader_service->DownloadProfile(base::Bind(&OnProfileDownloadedFail)); } diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 758db1b..25082eb 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -23,6 +23,7 @@ #include "base/time/time.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/prefs/pref_service_syncable.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" @@ -47,6 +48,7 @@ #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_controller.h" #include "components/webdata/common/web_database.h" @@ -497,6 +499,7 @@ class ProfileSyncServiceAutofillTest WebDataServiceFactory::GetAutofillWebDataForProfile( profile_, ServiceAccessType::EXPLICIT_ACCESS), profile_->GetPrefs(), + AccountTrackerServiceFactory::GetForProfile(profile_), profile_->IsOffTheRecord()); web_data_service_->StartSyncableService(); @@ -534,7 +537,7 @@ class ProfileSyncServiceAutofillTest syncer::ModelType type) { AbstractAutofillFactory* factory = GetFactory(type); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); - signin->SetAuthenticatedUsername("test_user@gmail.com"); + signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com"); sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_, callback); @@ -556,7 +559,8 @@ class ProfileSyncServiceAutofillTest // We need tokens to get the tests going ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) - ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token"); + ->UpdateCredentials(signin->GetAuthenticatedAccountId(), + "oauth2_login_token"); sync_service_->RegisterDataTypeController(data_type_controller); sync_service_->Initialize(); diff --git a/chrome/browser/sync/profile_sync_service_mock.cc b/chrome/browser/sync/profile_sync_service_mock.cc index 1bdcc4d..343c793 100644 --- a/chrome/browser/sync/profile_sync_service_mock.cc +++ b/chrome/browser/sync/profile_sync_service_mock.cc @@ -47,7 +47,7 @@ ProfileSyncServiceMock::~ProfileSyncServiceMock() { TestingProfile* ProfileSyncServiceMock::MakeSignedInTestingProfile() { TestingProfile* profile = new TestingProfile(); SigninManagerFactory::GetForProfile(profile)-> - SetAuthenticatedUsername("foo"); + SetAuthenticatedAccountInfo("12345", "foo"); return profile; } diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc index 4db61d7..55563b9 100644 --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc @@ -7,6 +7,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/prefs/pref_service_syncable.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/fake_signin_manager.h" @@ -21,6 +22,7 @@ #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_manager.h" @@ -47,6 +49,14 @@ using testing::Mock; using testing::Return; using testing::SaveArg; +namespace { + +const char kGaiaId[] = "12345"; +const char kEmail[] = "test_user@gmail.com"; +const char kDummyPassword[] = ""; + +} // namespace + ACTION_P(InvokeOnConfigureStart, pss) { ProfileSyncService* service = static_cast<ProfileSyncService*>(pss); @@ -129,9 +139,9 @@ class ProfileSyncServiceStartupTest : public testing::Test { sync_->AddObserver(&observer_); } - void IssueTestTokens() { + void IssueTestTokens(const std::string& account_id) { ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) - ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token"); + ->UpdateCredentials(account_id, "oauth2_login_token"); } ProfileSyncComponentsFactoryMock* components_factory_mock() { @@ -153,15 +163,23 @@ class ProfileSyncServiceStartupTest : public testing::Test { } protected: - void SimulateTestUserSignin() { + static std::string SimulateTestUserSignin( + Profile* profile, + FakeSigninManagerForTesting* fake_signin, + ProfileSyncService* sync) { + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(profile) + ->SeedAccountInfo(kGaiaId, kEmail); + profile->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, + account_id); #if !defined(OS_CHROMEOS) - fake_signin()->SignIn("test_user@gmail.com", ""); + fake_signin->SignIn(kGaiaId, kEmail, kDummyPassword); #else - fake_signin()->SetAuthenticatedUsername("test_user@gmail.com"); - sync_->GoogleSigninSucceeded("test_user@gmail.com", - "test_user@gmail.com", - ""); + fake_signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); + if (sync) + sync->GoogleSigninSucceeded(account_id, kEmail, kDummyPassword); #endif + return account_id; } DataTypeManagerMock* SetUpDataTypeManager() { @@ -201,9 +219,10 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { static KeyedService* BuildCrosService(content::BrowserContext* context) { Profile* profile = static_cast<Profile*>(context); - SigninManagerBase* signin = - SigninManagerFactory::GetForProfile(profile); - signin->SetAuthenticatedUsername("test_user@gmail.com"); + FakeSigninManagerForTesting* signin = + static_cast<FakeSigninManagerForTesting*>( + SigninManagerFactory::GetForProfile(profile)); + SimulateTestUserSignin(profile, signin, nullptr); ProfileOAuth2TokenService* oauth2_token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); EXPECT_TRUE(signin->IsAuthenticated()); @@ -250,9 +269,10 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { sync_->SetSetupInProgress(true); // Simulate successful signin as test_user. - SimulateTestUserSignin(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); // Create some tokens in the token service. - IssueTestTokens(); + IssueTestTokens(account_id); // Simulate the UI telling sync it has finished setting up. sync_->SetSetupInProgress(false); @@ -283,11 +303,12 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { sync_->SetSetupInProgress(true); // Simulate successful signin as test_user. - SimulateTestUserSignin(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); - token_service->LoadCredentials("test_user@gmail.com"); + token_service->LoadCredentials(account_id); sync_->SetSetupInProgress(false); // ProfileSyncService should try to start by requesting access token. @@ -299,8 +320,9 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { // TODO(pavely): Reenable test once android is switched to oauth2. TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { - sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); // Tell the backend to stall while downloading control types (simulating an @@ -324,7 +346,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { sync_->SetSetupInProgress(true); // Simulate successful signin. - SimulateTestUserSignin(); + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSetupInProgress(false); @@ -365,7 +387,9 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { EXPECT_CALL(*data_type_manager, Stop()).Times(1); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens( + AccountTrackerServiceFactory::GetForProfile(profile_) + ->PickAccountIdForAccount("12345", kEmail)); sync_->Initialize(); EXPECT_TRUE(sync_->SyncActive()); } @@ -378,9 +402,9 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { #endif TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) { // Pre load the tokens - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSyncSetupCompleted(); SetUpSyncBackendHost(); DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); @@ -390,7 +414,7 @@ TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) { EXPECT_CALL(*data_type_manager, Stop()).Times(1); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->Initialize(); } @@ -410,9 +434,9 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { } // Pre load the tokens - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSyncSetupCompleted(); SetUpSyncBackendHost(); DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); @@ -422,7 +446,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { EXPECT_CALL(*data_type_manager, Stop()).Times(1); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->Initialize(); EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( @@ -444,9 +468,9 @@ TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartDontRecoverDatatypePrefs) { sync_driver::prefs::kSyncKeepEverythingSynced, false); // Pre load the tokens - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSyncSetupCompleted(); SetUpSyncBackendHost(); DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); @@ -455,7 +479,7 @@ TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartDontRecoverDatatypePrefs) { WillRepeatedly(Return(DataTypeManager::CONFIGURED)); EXPECT_CALL(*data_type_manager, Stop()).Times(1); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->Initialize(); EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( @@ -470,8 +494,8 @@ TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartDontRecoverDatatypePrefs) { #endif TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) { // Service should not be started by Initialize() since it's managed. - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "test_user@gmail.com"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, + kEmail); CreateSyncService(); // Disable sync through policy. @@ -484,15 +508,15 @@ TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) { } TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSyncSetupCompleted(); SetUpSyncBackendHost(); DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); EXPECT_CALL(*data_type_manager, Configure(_, _)); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->Initialize(); // The service should stop when switching to managed mode. @@ -513,9 +537,9 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { } TEST_F(ProfileSyncServiceStartupTest, StartFailure) { - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); sync_->SetSyncSetupCompleted(); SetUpSyncBackendHost(); DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); @@ -533,16 +557,16 @@ TEST_F(ProfileSyncServiceStartupTest, StartFailure) { EXPECT_CALL(*data_type_manager, state()). WillOnce(Return(DataTypeManager::STOPPED)); EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->Initialize(); EXPECT_TRUE(sync_->HasUnrecoverableError()); } TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { // Pre load the tokens - SigninManagerFactory::GetForProfile(profile_) - ->SetAuthenticatedUsername("test_user@gmail.com"); CreateSyncService(); + std::string account_id = + SimulateTestUserSignin(profile_, fake_signin(), sync_); SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); mock_sbh->set_fail_initial_download(true); @@ -552,7 +576,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { sync_->Initialize(); sync_->SetSetupInProgress(true); - IssueTestTokens(); + IssueTestTokens(account_id); sync_->SetSetupInProgress(false); EXPECT_FALSE(sync_->SyncActive()); } 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 262bfc9..2a7bc23 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/invalidation/fake_invalidation_service.h" #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" #include "chrome/browser/prefs/pref_service_syncable.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" @@ -47,6 +48,7 @@ #include "components/invalidation/invalidation_service.h" #include "components/invalidation/profile_invalidation_provider.h" #include "components/keyed_service/core/refcounted_keyed_service.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_error_handler_mock.h" #include "content/public/browser/notification_service.h" @@ -258,8 +260,11 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { TypedUrlModelAssociator* StartSyncService(const base::Closure& callback) { TypedUrlModelAssociator* model_associator = NULL; if (!sync_service_) { + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(profile_) + ->SeedAccountInfo("gaia_id", "test"); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); - signin->SetAuthenticatedUsername("test"); + signin->SetAuthenticatedAccountInfo("gaia_id", "test"); sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_, callback); ProfileSyncComponentsFactoryMock* components = @@ -279,7 +284,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { ProfileOAuth2TokenService* oauth2_token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); - oauth2_token_service->UpdateCredentials("test", "oauth2_login_token"); + oauth2_token_service->UpdateCredentials(account_id, "oauth2_login_token"); sync_service_->RegisterDataTypeController(data_type_controller); diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index 2d08b39..cba1633 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -12,6 +12,7 @@ #include "base/values.h" #include "chrome/browser/invalidation/fake_invalidation_service.h" #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" @@ -28,6 +29,8 @@ #include "chrome/test/base/testing_profile_manager.h" #include "components/invalidation/invalidation_service.h" #include "components/invalidation/profile_invalidation_provider.h" +#include "components/signin/core/browser/account_tracker_service.h" +#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_manager.h" #include "components/sync_driver/pref_names.h" @@ -46,6 +49,9 @@ namespace browser_sync { namespace { +const char kGaiaId[] = "12345"; +const char kEmail[] = "test_user@gmail.com"; + class FakeDataTypeManager : public sync_driver::DataTypeManager { public: explicit FakeDataTypeManager(sync_driver::DataTypeManagerObserver* observer) @@ -205,14 +211,17 @@ class ProfileSyncServiceTest : public ::testing::Test { } void IssueTestTokens() { + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(profile_) + ->SeedAccountInfo(kGaiaId, kEmail); ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) - ->UpdateCredentials("test", "oauth2_login_token"); + ->UpdateCredentials(account_id, "oauth2_login_token"); } void CreateService(ProfileSyncServiceStartBehavior behavior) { SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); - signin->SetAuthenticatedUsername("test"); + signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); ProfileOAuth2TokenService* oauth2_token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); components_factory_ = new ProfileSyncComponentsFactoryMock(); @@ -526,7 +535,7 @@ TEST_F(ProfileSyncServiceTest, BackupBeforeFirstSync) { InitializeForFirstSync(); SigninManagerFactory::GetForProfile(profile()) - ->SetAuthenticatedUsername("test"); + ->SetAuthenticatedAccountInfo(kGaiaId, kEmail); IssueTestTokens(); PumpLoop(); diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc index f84856a..157abc6 100644 --- a/chrome/browser/sync/sync_ui_util_unittest.cc +++ b/chrome/browser/sync/sync_ui_util_unittest.cc @@ -44,6 +44,7 @@ enum DistinctState { namespace { +const char kTestGaiaId[] = "gaia-id-test_user@test.com"; const char kTestUser[] = "test_user@test.com"; #if !defined(OS_CHROMEOS) @@ -252,7 +253,7 @@ void GetDistinctCase(ProfileSyncServiceMock& service, .WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false))); provider->SetAuthError( - kTestUser, + signin->GetAuthenticatedAccountId(), kTestUser, GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); EXPECT_CALL(service, HasUnrecoverableError()) @@ -339,7 +340,7 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); FakeSigninManagerForSyncUIUtilTest signin(profile.get()); - signin.SetAuthenticatedUsername(kTestUser); + signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( SigninErrorControllerFactory::GetForProfile(profile.get()))); GetDistinctCase(service, &signin, provider.get(), idx); @@ -378,7 +379,7 @@ TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); FakeSigninManagerForSyncUIUtilTest signin(profile.get()); - signin.SetAuthenticatedUsername(kTestUser); + signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( SigninErrorControllerFactory::GetForProfile(profile.get()))); GetDistinctCase(service, &signin, provider.get(), idx); 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 2f4450b..e739a36a 100644 --- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc +++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc @@ -37,6 +37,10 @@ using syncer::sessions::SyncSessionSnapshot; namespace { +std::string GetGaiaIdForUsername(const std::string& username) { + return "gaia-id-" + username; +} + bool HasAuthError(ProfileSyncService* service) { return service->GetAuthError().state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || @@ -155,6 +159,12 @@ bool ProfileSyncServiceHarness::SetupSync( // until we've finished configuration. service()->SetSetupInProgress(true); + // Authenticate sync client using GAIA credentials. + std::string gaia_id = GetGaiaIdForUsername(username_); + service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); + std::string account_id = service()->signin()->GetAuthenticatedAccountId(); + service()->GoogleSigninSucceeded(account_id, username_, password_); + DCHECK(!username_.empty()); if (signin_type_ == SigninType::UI_SIGNIN) { Browser* browser = @@ -166,10 +176,10 @@ bool ProfileSyncServiceHarness::SetupSync( } } else if (signin_type_ == SigninType::FAKE_SIGNIN) { // Authenticate sync client using GAIA credentials. - service()->signin()->SetAuthenticatedUsername(username_); - service()->GoogleSigninSucceeded(username_, username_, password_); + service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); + service()->GoogleSigninSucceeded(account_id, username_, password_); ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> - UpdateCredentials(username_, GenerateFakeOAuth2RefreshTokenString()); + UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); } else { LOG(ERROR) << "Unsupported profile signin type."; } diff --git a/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc b/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc index 7302af1..902f9b5 100644 --- a/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc +++ b/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc @@ -25,6 +25,7 @@ namespace app_list { +static const char* kTestGaiaId = "gaia_id"; static const char* kTestUser = "test.user@chromium.org.test"; static const char* kScope = "https://www.googleapis.com/auth/webhistory"; static const char* kAccessToken = "fake_access_token"; @@ -53,8 +54,8 @@ class SpeechAuthHelperTest : public testing::Test { factories); // Set up the authenticated user name and ID. - SigninManagerFactory::GetForProfile(profile_)->SetAuthenticatedUsername( - kTestUser); + SigninManagerFactory::GetForProfile(profile_)->SetAuthenticatedAccountInfo( + kTestGaiaId, kTestUser); } protected: diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index aa5e119..e1e566e 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -14,6 +14,7 @@ #include "base/time/time.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/ui/autofill/account_chooser_model.h" #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" @@ -43,6 +44,7 @@ #include "components/autofill/core/common/autofill_switches.h" #include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_field_data.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/interstitial_page.h" #include "content/public/browser/navigation_details.h" @@ -104,9 +106,12 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { use_validation_(false), sign_in_user_index_(0U), weak_ptr_factory_(this) { + Profile* profile = + Profile::FromBrowserContext(contents->GetBrowserContext()); test_manager_.Init( NULL, - Profile::FromBrowserContext(contents->GetBrowserContext())->GetPrefs(), + profile->GetPrefs(), + AccountTrackerServiceFactory::GetForProfile(profile), false); } diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 55b9a39..4b7e267 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -18,6 +18,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" #include "chrome/browser/ui/autofill/autofill_dialog_view.h" @@ -48,6 +49,7 @@ #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/common/autofill_switches.h" #include "components/autofill/core/common/form_data.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/user_prefs/user_prefs.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" @@ -267,10 +269,12 @@ class TestAutofillDialogController } void Init(content::BrowserContext* browser_context) { + Profile* profile = Profile::FromBrowserContext(browser_context); test_manager_.Init(WebDataServiceFactory::GetAutofillWebDataForProfile( - Profile::FromBrowserContext(browser_context), + profile, ServiceAccessType::EXPLICIT_ACCESS), user_prefs::UserPrefs::Get(browser_context), + AccountTrackerServiceFactory::GetForProfile(profile), browser_context->IsOffTheRecord()); } diff --git a/chrome/browser/ui/autofill/country_combobox_model_unittest.cc b/chrome/browser/ui/autofill/country_combobox_model_unittest.cc index c243d8e..1952c14 100644 --- a/chrome/browser/ui/autofill/country_combobox_model_unittest.cc +++ b/chrome/browser/ui/autofill/country_combobox_model_unittest.cc @@ -6,9 +6,11 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/test/base/testing_profile.h" #include "components/autofill/core/browser/autofill_country.h" #include "components/autofill/core/browser/test_personal_data_manager.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui_component.h" @@ -19,7 +21,9 @@ namespace autofill { class CountryComboboxModelTest : public testing::Test { public: CountryComboboxModelTest() { - manager_.Init(NULL, profile_.GetPrefs(), false); + manager_.Init( + NULL, profile_.GetPrefs(), + AccountTrackerServiceFactory::GetForProfile(&profile_), false); manager_.set_timezone_country_code("KR"); model_.reset(new CountryComboboxModel()); model_->SetCountries(manager_, base::Callback<bool(const std::string&)>()); diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm index d93356f..d979bbe 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm @@ -468,7 +468,7 @@ TEST_F(BookmarkBubbleControllerTest, SyncPromoNotSignedIn) { // Confirm that the sync promo is not displayed when the user is signed in. TEST_F(BookmarkBubbleControllerTest, SyncPromoSignedIn) { SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); - signin->SetAuthenticatedUsername("fake_username"); + signin->SetAuthenticatedAccountInfo("fake_username", "fake_username"); const BookmarkNode* node = CreateTestBookmark(); BookmarkBubbleController* controller = ControllerForNode(node); diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm index 2a4958e..2b1afd9 100644 --- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm @@ -370,7 +370,7 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { // Set up the signin manager and the OAuth2Tokens. Profile* profile = browser()->profile(); SigninManagerFactory::GetForProfile(profile)-> - SetAuthenticatedUsername(kEmail); + SetAuthenticatedAccountInfo(kEmail, kEmail); ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> UpdateCredentials(kEmail, kLoginToken); ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc index 9855cc4..850a574 100644 --- a/chrome/browser/ui/search/search_tab_helper_unittest.cc +++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc @@ -99,7 +99,7 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { if (!username.empty()) { ASSERT_TRUE(signin_manager); - signin_manager->SetAuthenticatedUsername(username); + signin_manager->SetAuthenticatedAccountInfo(username, username); } } diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc index ad9d1f2..9c347ba 100644 --- a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc +++ b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc @@ -73,6 +73,7 @@ void SetUserChoiceHistogram(SigninChoice choice) { OneClickSigninSyncStarter::OneClickSigninSyncStarter( Profile* profile, Browser* browser, + const std::string& gaia_id, const std::string& email, const std::string& password, const std::string& refresh_token, @@ -98,7 +99,7 @@ OneClickSigninSyncStarter::OneClickSigninSyncStarter( // before signin completes. SigninManagerFactory::GetForProfile(profile_)-> StartSignInWithRefreshToken( - refresh_token, email, password, + refresh_token, gaia_id, email, password, base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, weak_pointer_factory_.GetWeakPtr())); } @@ -149,7 +150,7 @@ void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { DCHECK(!oauth_token.empty()); SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); - // If this is a new signin (no authenticated username yet) try loading + // If this is a new signin (no account authenticated yet) try loading // policy for this user now, before any signed in services are initialized. if (!signin->IsAuthenticated()) { #if defined(ENABLE_CONFIGURATION_POLICY) diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter.h b/chrome/browser/ui/sync/one_click_signin_sync_starter.h index b66f918..f5b6466 100644 --- a/chrome/browser/ui/sync/one_click_signin_sync_starter.h +++ b/chrome/browser/ui/sync/one_click_signin_sync_starter.h @@ -94,6 +94,7 @@ class OneClickSigninSyncStarter : public SigninTracker::Observer, // It can be empty. OneClickSigninSyncStarter(Profile* profile, Browser* browser, + const std::string& gaia_id, const std::string& email, const std::string& password, const std::string& refresh_token, diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc b/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc index 10b5228..571f624 100644 --- a/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc @@ -8,18 +8,23 @@ #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" namespace { + +const char* kTestingGaiaId = "gaia_id"; const char* kTestingUsername = "fake_username"; + } // namespace class OneClickSigninSyncStarterTest : public ChromeRenderViewHostTestHarness { @@ -41,7 +46,8 @@ class OneClickSigninSyncStarterTest : public ChromeRenderViewHostTestHarness { SigninManagerFactory::GetForProfile(profile())); signin_manager->Initialize(NULL); - signin_manager->SetAuthenticatedUsername(kTestingUsername); + signin_manager->SetAuthenticatedAccountInfo(kTestingGaiaId, + kTestingUsername); } void Callback(OneClickSigninSyncStarter::SyncSetupResult result) { @@ -67,6 +73,7 @@ class OneClickSigninSyncStarterTest : public ChromeRenderViewHostTestHarness { sync_starter_ = new OneClickSigninSyncStarter( profile(), NULL, + kTestingGaiaId, kTestingUsername, std::string(), "refresh_token", diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view_unittest.cc index 25dae71..14fe038 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view_unittest.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view_unittest.cc @@ -69,10 +69,11 @@ class BookmarkBubbleViewTest : public BrowserWithTestWindowTest { void SetUpSigninManager(const std::string& username) { if (username.empty()) return; + SigninManagerBase* signin_manager = static_cast<SigninManagerBase*>( SigninManagerFactory::GetForProfile(profile())); ASSERT_TRUE(signin_manager); - signin_manager->SetAuthenticatedUsername(username); + signin_manager->SetAuthenticatedAccountInfo(username, username); } scoped_ptr<BookmarkBubbleView> bubble_; diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc index fb99545..45d41c8 100644 --- a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc +++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc @@ -275,6 +275,7 @@ const char kURLRegisterComplete[] = const char kURLGaiaToken[] = "https://accounts.google.com/o/oauth2/token"; +const char kSampleGaiaId[] = "12345"; const char kSampleUser[] = "user@host.com"; class TestMessageLoopCondition { @@ -364,7 +365,7 @@ class LocalDiscoveryUITest : public WebUIBrowserTest { SigninManagerFactory::GetForProfile(browser()->profile()); DCHECK(signin_manager); - signin_manager->SetAuthenticatedUsername(kSampleUser); + signin_manager->SetAuthenticatedAccountInfo(kSampleGaiaId, kSampleUser); fake_fetcher_factory().SetFakeResponse( GURL(kURLInfo), diff --git a/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc index d51fd41..ba10be6 100644 --- a/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc +++ b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc @@ -139,7 +139,8 @@ class SharedOptionsTest : public LoginManagerTest { Browser* CreateBrowserForUser(const user_manager::User* user) { Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); SigninManagerFactory::GetForProfile(profile)-> - SetAuthenticatedUsername(user->email()); + SetAuthenticatedAccountInfo(GetGaiaIDForUserID(user->email()), + user->email()); ui_test_utils::BrowserAddedObserver observer; Browser* browser = CreateBrowser(profile); diff --git a/chrome/browser/ui/webui/options/options_ui_browsertest.cc b/chrome/browser/ui/webui/options/options_ui_browsertest.cc index 091f4c3..284c38a 100644 --- a/chrome/browser/ui/webui/options/options_ui_browsertest.cc +++ b/chrome/browser/ui/webui/options/options_ui_browsertest.cc @@ -9,6 +9,7 @@ #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chrome_notification_types.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/chrome_pages.h" @@ -18,6 +19,7 @@ #include "chrome/common/url_constants.h" #include "chrome/grit/generated_resources.h" #include "chrome/test/base/ui_test_utils.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/signin_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_frame_host.h" @@ -248,10 +250,13 @@ IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, MAYBE_VerifyManagedSignout) { } IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, VerifyUnmanagedSignout) { + const std::string user = "test@example.com"; + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(browser()->profile()) + ->SeedAccountInfo("12345", user); SigninManager* signin = SigninManagerFactory::GetForProfile(browser()->profile()); - const std::string user = "test@example.com"; - signin->OnExternalSigninCompleted(user); + signin->OnExternalSigninCompleted(account_id); NavigateToSettingsFrame(); diff --git a/chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc b/chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc index 92fd14d..db05b3c 100644 --- a/chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc +++ b/chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc @@ -276,7 +276,7 @@ class SyncSetupHandlerTest : public testing::Test { SigninManagerFactory::GetForProfile(profile_.get())); std::string username = GetTestUser(); if (!username.empty()) - mock_signin_->SetAuthenticatedUsername(username); + mock_signin_->SetAuthenticatedAccountInfo(username, username); mock_pss_ = static_cast<ProfileSyncServiceMock*>( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( @@ -865,7 +865,7 @@ TEST_F(SyncSetupHandlerTest, ShowSigninOnAuthError) { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); SetupInitializedProfileSyncService(); - mock_signin_->SetAuthenticatedUsername(kTestUser); + mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); FakeAuthStatusProvider provider( SigninErrorControllerFactory::GetForProfile(profile_.get())); provider.SetAuthError(kTestUser, kTestUser, error_); diff --git a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc index a76a764..697d92f 100644 --- a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc +++ b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc @@ -306,13 +306,10 @@ void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { AboutSigninInternalsFactory::GetForProfile(profile_); about_signin_internals->OnRefreshTokenReceived("Successful"); - AccountTrackerService* account_tracker = - AccountTrackerServiceFactory::GetForProfile(profile_); - std::string account_id = - account_tracker->PickAccountIdForAccount(gaia_id_, email_); - // Prime the account tracker with this combination of gaia id/display email. - account_tracker->SeedAccountInfo(gaia_id_, email_); + std::string account_id = + AccountTrackerServiceFactory::GetForProfile(profile_) + ->SeedAccountInfo(gaia_id_, email_); signin_metrics::Source source = signin::GetSourceForPromoURL(current_url_); @@ -387,7 +384,7 @@ void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { // OneClickSigninSyncStarter will delete itself once the job is done. new OneClickSigninSyncStarter( profile_, browser, - email_, password_, result.refresh_token, + gaia_id_, email_, password_, result.refresh_token, start_mode, contents, confirmation_required, @@ -448,7 +445,7 @@ void InlineSigninHelper::ConfirmEmailAction( break; case ConfirmEmailDialogDelegate::START_SYNC: new OneClickSigninSyncStarter( - profile_, browser, email_, password_, refresh_token, + profile_, browser, gaia_id_, email_, password_, refresh_token, start_mode, web_contents, confirmation_required, GURL(), base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); break; diff --git a/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc b/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc index 1f822e6..f34482f 100644 --- a/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc +++ b/chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc @@ -137,7 +137,7 @@ void InlineLoginUIBrowserTest::SetUpSigninManager(const std::string& username) { SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(browser()->profile()); - signin_manager->SetAuthenticatedUsername(username); + signin_manager->SetAuthenticatedAccountInfo(username, username); } void InlineLoginUIBrowserTest::EnableSigninAllowed(bool enable) { diff --git a/chrome/test/base/chrome_render_view_host_test_harness.cc b/chrome/test/base/chrome_render_view_host_test_harness.cc index 8a76f35..ca3dce9 100644 --- a/chrome/test/base/chrome_render_view_host_test_harness.cc +++ b/chrome/test/base/chrome_render_view_host_test_harness.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "chrome/test/base/chrome_render_view_host_test_harness.h" - #include "chrome/browser/browser_process.h" +#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" @@ -36,7 +36,8 @@ static KeyedService* BuildSigninManagerFake(content::BrowserContext* context) { Profile* profile = static_cast<Profile*>(context); #if defined (OS_CHROMEOS) SigninManagerBase* signin = new SigninManagerBase( - ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)); + ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), + AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile)); signin->Initialize(NULL); return signin; #else diff --git a/chrome/test/data/webui/ntp4_browsertest.cc b/chrome/test/data/webui/ntp4_browsertest.cc index 7c292ab..75f8854 100644 --- a/chrome/test/data/webui/ntp4_browsertest.cc +++ b/chrome/test/data/webui/ntp4_browsertest.cc @@ -17,5 +17,5 @@ NTP4LoggedInWebUITest::~NTP4LoggedInWebUITest() {} void NTP4LoggedInWebUITest::SetLoginName(const std::string& name) { SigninManagerFactory::GetForProfile(browser()->profile())-> - SetAuthenticatedUsername(name); + SetAuthenticatedAccountInfo(name, name); } diff --git a/chromeos/login/auth/stub_authenticator.cc b/chromeos/login/auth/stub_authenticator.cc index 8a3e30f..6613ea2 100644 --- a/chromeos/login/auth/stub_authenticator.cc +++ b/chromeos/login/auth/stub_authenticator.cc @@ -35,7 +35,10 @@ void StubAuthenticator::CompleteLogin(content::BrowserContext* context, void StubAuthenticator::AuthenticateToLogin(content::BrowserContext* context, const UserContext& user_context) { authentication_context_ = context; - if (user_context == expected_user_context_) { + // Don't compare the entire |expected_user_context_| to |user_context| because + // during non-online re-auth |user_context| does not have a gaia id. + if (expected_user_context_.GetUserID() == user_context.GetUserID() && + *expected_user_context_.GetKey() == *user_context.GetKey()) { message_loop_->PostTask( FROM_HERE, base::Bind(&StubAuthenticator::OnAuthSuccess, this)); return; diff --git a/components/autofill.gypi b/components/autofill.gypi index fd5ceaf..a9ae29c 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -105,6 +105,7 @@ 'os_crypt', 'pref_registry', 'rappor', + 'signin_core_browser', 'signin_core_common', 'webdata_common', ], @@ -254,6 +255,7 @@ 'os_crypt', 'pref_registry', 'rappor', + 'signin_core_browser_test_support', ], 'sources': [ 'autofill/core/browser/autofill_test_utils.cc', diff --git a/components/autofill/core/browser/BUILD.gn b/components/autofill/core/browser/BUILD.gn index 4a6b2f4..72a5dba 100644 --- a/components/autofill/core/browser/BUILD.gn +++ b/components/autofill/core/browser/BUILD.gn @@ -262,6 +262,7 @@ source_set("unit_tests") { "//components/os_crypt", "//components/rappor:test_support", "//components/resources", + "//components/signin/core/browser:test_support", "//components/strings", "//components/webdata/common", "//net:test_support", diff --git a/components/autofill/core/browser/DEPS b/components/autofill/core/browser/DEPS index 84e1441..41b846a 100644 --- a/components/autofill/core/browser/DEPS +++ b/components/autofill/core/browser/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+components/infobars/core", "+components/keyed_service/core", + "+components/signin/core/browser", "+components/signin/core/common", "+components/webdata/common", "+components/webdata_services", diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc index 0b1d5bb..3764d3f 100644 --- a/components/autofill/core/browser/autofill_metrics_unittest.cc +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc @@ -25,6 +25,8 @@ #include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_field_data.h" #include "components/rappor/test_rappor_service.h" +#include "components/signin/core/browser/account_tracker_service.h" +#include "components/signin/core/browser/test_signin_client.h" #include "components/signin/core/common/signin_pref_names.h" #include "components/webdata/common/web_data_results.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,6 +47,7 @@ class TestPersonalDataManager : public PersonalDataManager { CreateTestAutofillProfiles(&web_profiles_); } + using PersonalDataManager::set_account_tracker; using PersonalDataManager::set_database; using PersonalDataManager::SetPrefService; @@ -284,6 +287,8 @@ class AutofillMetricsTest : public testing::Test { base::MessageLoop message_loop_; TestAutofillClient autofill_client_; + scoped_ptr<AccountTrackerService> account_tracker_; + scoped_ptr<TestSigninClient> signin_client_; scoped_ptr<TestAutofillDriver> autofill_driver_; scoped_ptr<TestAutofillManager> autofill_manager_; scoped_ptr<TestPersonalDataManager> personal_data_; @@ -302,9 +307,17 @@ void AutofillMetricsTest::SetUp() { // Ensure Mac OS X does not pop up a modal dialog for the Address Book. test::DisableSystemServices(autofill_client_.GetPrefs()); + // Setup account tracker. + signin_client_.reset(new TestSigninClient(autofill_client_.GetPrefs())); + account_tracker_.reset(new AccountTrackerService()); + account_tracker_->Initialize( + autofill_client_.GetIdentityProvider()->GetTokenService(), + signin_client_.get()); + personal_data_.reset(new TestPersonalDataManager()); personal_data_->set_database(autofill_client_.GetDatabase()); personal_data_->SetPrefService(autofill_client_.GetPrefs()); + personal_data_->set_account_tracker(account_tracker_.get()); autofill_driver_.reset(new TestAutofillDriver()); autofill_manager_.reset(new TestAutofillManager( autofill_driver_.get(), &autofill_client_, personal_data_.get())); @@ -321,13 +334,18 @@ void AutofillMetricsTest::TearDown() { autofill_manager_.reset(); autofill_driver_.reset(); personal_data_.reset(); + account_tracker_->Shutdown(); + account_tracker_.reset(); + signin_client_.reset(); } void AutofillMetricsTest::EnableWalletSync() { autofill_client_.GetPrefs()->SetBoolean( prefs::kAutofillWalletSyncExperimentEnabled, true); + std::string account_id = + account_tracker_->SeedAccountInfo("12345", "syncuser@example.com"); autofill_client_.GetPrefs()->SetString( - ::prefs::kGoogleServicesUsername, "syncuser@example.com"); + ::prefs::kGoogleServicesAccountId, account_id); } // Test that we log quality metrics appropriately. @@ -1051,7 +1069,8 @@ TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { base::HistogramTester histogram_tester; personal_data_->set_autofill_enabled(true); personal_data_->Init( - autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); + autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), + account_tracker_.get(), false); histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1); } @@ -1060,7 +1079,8 @@ TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { base::HistogramTester histogram_tester; personal_data_->set_autofill_enabled(false); personal_data_->Init( - autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); + autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), + account_tracker_.get(), false); histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1); } diff --git a/components/autofill/core/browser/autofill_test_utils.cc b/components/autofill/core/browser/autofill_test_utils.cc index 922eff7..c69611a 100644 --- a/components/autofill/core/browser/autofill_test_utils.cc +++ b/components/autofill/core/browser/autofill_test_utils.cc @@ -19,6 +19,7 @@ #include "components/autofill/core/common/form_field_data.h" #include "components/os_crypt/os_crypt.h" #include "components/pref_registry/pref_registry_syncable.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/common/signin_pref_names.h" using base::ASCIIToUTF16; @@ -40,8 +41,19 @@ scoped_ptr<PrefService> PrefServiceForTesting() { // PDM depends on this pref, which is normally registered in // SigninManagerFactory. registry->RegisterStringPref( - ::prefs::kGoogleServicesUsername, std::string(), + ::prefs::kGoogleServicesAccountId, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + + // PDM depends on these prefs, which are normally registered in + // AccountTrackerServiceFactory. + registry->RegisterListPref( + AccountTrackerService::kAccountInfoPref, + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterIntegerPref( + ::prefs::kAccountIdMigrationState, + AccountTrackerService::MIGRATION_NOT_STARTED, + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + base::PrefServiceFactory factory; factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore())); return factory.Create(registry.get()); diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc index b7a0a46..15edaac 100644 --- a/components/autofill/core/browser/personal_data_manager.cc +++ b/components/autofill/core/browser/personal_data_manager.cc @@ -30,6 +30,7 @@ #include "components/autofill/core/browser/validation.h" #include "components/autofill/core/common/autofill_pref_names.h" #include "components/autofill/core/common/autofill_switches.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/common/signin_pref_names.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h" @@ -241,14 +242,17 @@ PersonalDataManager::PersonalDataManager(const std::string& app_locale) pending_server_creditcards_query_(0), app_locale_(app_locale), pref_service_(NULL), + account_tracker_(NULL), is_off_the_record_(false), has_logged_profile_count_(false) {} void PersonalDataManager::Init(scoped_refptr<AutofillWebDataService> database, PrefService* pref_service, + AccountTrackerService* account_tracker, bool is_off_the_record) { database_ = database; SetPrefService(pref_service); + account_tracker_ = account_tracker; is_off_the_record_ = is_off_the_record; if (!is_off_the_record_) @@ -306,8 +310,11 @@ void PersonalDataManager::OnWebDataServiceRequestDone( &server_profiles_); if (!server_profiles_.empty()) { - base::string16 email = base::UTF8ToUTF16( - pref_service_->GetString(::prefs::kGoogleServicesUsername)); + std::string account_id = + pref_service_->GetString(::prefs::kGoogleServicesAccountId); + base::string16 email = + base::UTF8ToUTF16( + account_tracker_->GetAccountInfo(account_id).email); DCHECK(!email.empty()); for (AutofillProfile* profile : server_profiles_) profile->SetRawInfo(EMAIL_ADDRESS, email); diff --git a/components/autofill/core/browser/personal_data_manager.h b/components/autofill/core/browser/personal_data_manager.h index 4d2f712..91f9276 100644 --- a/components/autofill/core/browser/personal_data_manager.h +++ b/components/autofill/core/browser/personal_data_manager.h @@ -26,6 +26,7 @@ class Browser; class PrefService; class RemoveAutofillTester; +class AccountTrackerService; namespace autofill { class AutofillInteractiveTest; @@ -58,6 +59,7 @@ class PersonalDataManager : public KeyedService, // context. void Init(scoped_refptr<AutofillWebDataService> database, PrefService* pref_service, + AccountTrackerService* account_tracker, bool is_off_the_record); // WebDataServiceConsumer: @@ -309,6 +311,10 @@ class PersonalDataManager : public KeyedService, database_ = database; } + void set_account_tracker(AccountTrackerService* account_tracker) { + account_tracker_ = account_tracker; + } + // The backing database that this PersonalDataManager uses. scoped_refptr<AutofillWebDataService> database_; @@ -372,6 +378,10 @@ class PersonalDataManager : public KeyedService, // The PrefService that this instance uses. Must outlive this instance. PrefService* pref_service_; + // The AccountTrackerService that this instance uses. Must outlive this + // instance. + AccountTrackerService* account_tracker_; + // Whether the user is currently operating in an off-the-record context. // Default value is false. bool is_off_the_record_; diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc index ae63c86..9082808 100644 --- a/components/autofill/core/browser/personal_data_manager_unittest.cc +++ b/components/autofill/core/browser/personal_data_manager_unittest.cc @@ -25,9 +25,12 @@ #include "components/autofill/core/common/autofill_pref_names.h" #include "components/autofill/core/common/autofill_switches.h" #include "components/autofill/core/common/form_data.h" +#include "components/signin/core/browser/account_tracker_service.h" +#include "components/signin/core/browser/test_signin_client.h" #include "components/signin/core/common/signin_pref_names.h" #include "components/webdata/common/web_data_service_base.h" #include "components/webdata/common/web_database_service.h" +#include "google_apis/gaia/fake_oauth2_token_service.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -94,6 +97,14 @@ class PersonalDataManagerTest : public testing::Test { web_database_ = new WebDatabaseService(path, base::MessageLoopProxy::current(), base::MessageLoopProxy::current()); + + // Setup account tracker. + signin_client_.reset(new TestSigninClient(prefs_.get())); + fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); + account_tracker_.reset(new AccountTrackerService()); + account_tracker_->Initialize(fake_oauth2_token_service_.get(), + signin_client_.get()); + // Hacky: hold onto a pointer but pass ownership. autofill_table_ = new AutofillTable("en-US"); web_database_->AddTable(scoped_ptr<WebDatabaseTable>(autofill_table_)); @@ -109,12 +120,22 @@ class PersonalDataManagerTest : public testing::Test { ResetPersonalDataManager(USER_MODE_NORMAL); } + void TearDown() override { + // Order of destruction is important as AutofillManager relies on + // PersonalDataManager to be around when it gets destroyed. + account_tracker_->Shutdown(); + fake_oauth2_token_service_.reset(); + account_tracker_.reset(); + signin_client_.reset(); + } + void ResetPersonalDataManager(UserMode user_mode) { bool is_incognito = (user_mode == USER_MODE_INCOGNITO); personal_data_.reset(new PersonalDataManager("en")); personal_data_->Init( scoped_refptr<AutofillWebDataService>(autofill_database_service_), prefs_.get(), + account_tracker_.get(), is_incognito); personal_data_->AddObserver(&personal_data_observer_); @@ -126,7 +147,9 @@ class PersonalDataManagerTest : public testing::Test { void EnableWalletCardImport() { prefs_->SetBoolean(prefs::kAutofillWalletSyncExperimentEnabled, true); - prefs_->SetString(::prefs::kGoogleServicesUsername, "syncuser@example.com"); + std::string account_id = + account_tracker_->SeedAccountInfo("12345", "syncuser@example.com"); + prefs_->SetString(::prefs::kGoogleServicesAccountId, account_id); } // The temporary directory should be deleted at the end to ensure that @@ -134,6 +157,9 @@ class PersonalDataManagerTest : public testing::Test { base::ScopedTempDir temp_dir_; base::MessageLoopForUI message_loop_; scoped_ptr<PrefService> prefs_; + scoped_ptr<FakeOAuth2TokenService> fake_oauth2_token_service_; + scoped_ptr<AccountTrackerService> account_tracker_; + scoped_ptr<TestSigninClient> signin_client_; scoped_refptr<AutofillWebDataService> autofill_database_service_; scoped_refptr<WebDatabaseService> web_database_; AutofillTable* autofill_table_; // weak ref diff --git a/components/signin/core/browser/account_tracker_service.cc b/components/signin/core/browser/account_tracker_service.cc index 1191a96..78d942a 100644 --- a/components/signin/core/browser/account_tracker_service.cc +++ b/components/signin/core/browser/account_tracker_service.cc @@ -601,12 +601,8 @@ std::string AccountTrackerService::PickAccountIdForAccount( } } -void AccountTrackerService::SeedAccountInfo(const std::string& gaia, - const std::string& email) { - DVLOG(1) << "AccountTrackerService::SeedAccountInfo" - << " gaia_id=" << gaia - << " email=" << email; - +std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, + const std::string& email) { DCHECK(!gaia.empty()); DCHECK(!email.empty()); const std::string account_id = PickAccountIdForAccount(gaia, email); @@ -617,4 +613,11 @@ void AccountTrackerService::SeedAccountInfo(const std::string& gaia, state.info.gaia = gaia; state.info.email = email; SaveToPrefs(state); + + DVLOG(1) << "AccountTrackerService::SeedAccountInfo" + << " account_id=" << account_id + << " gaia_id=" << gaia + << " email=" << email; + + return account_id; } diff --git a/components/signin/core/browser/account_tracker_service.h b/components/signin/core/browser/account_tracker_service.h index 20249dd..a32b766 100644 --- a/components/signin/core/browser/account_tracker_service.h +++ b/components/signin/core/browser/account_tracker_service.h @@ -115,8 +115,10 @@ class AccountTrackerService : public KeyedService, const std::string& email); // Seeds the account whose account_id is given by PickAccountIdForAccount() - // with its corresponding gaia id and email address. - void SeedAccountInfo(const std::string& gaia, const std::string& email); + // with its corresponding gaia id and email address. Returns the same + // value PickAccountIdForAccount() when given the same arguments. + std::string SeedAccountInfo(const std::string& gaia, + const std::string& email); AccountIdMigrationState GetMigrationState(); static AccountIdMigrationState GetMigrationState(PrefService* pref_service); diff --git a/components/signin/core/browser/signin_manager.cc b/components/signin/core/browser/signin_manager.cc index 3910305..a6548a0 100644 --- a/components/signin/core/browser/signin_manager.cc +++ b/components/signin/core/browser/signin_manager.cc @@ -13,9 +13,9 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" +#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/gaia_cookie_manager_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" -#include "components/signin/core/browser/signin_account_id_helper.h" #include "components/signin/core/browser/signin_client.h" #include "components/signin/core/browser/signin_internals_util.h" #include "components/signin/core/browser/signin_manager_cookie_helper.h" @@ -33,12 +33,11 @@ SigninManager::SigninManager(SigninClient* client, ProfileOAuth2TokenService* token_service, AccountTrackerService* account_tracker_service, GaiaCookieManagerService* cookie_manager_service) - : SigninManagerBase(client), + : SigninManagerBase(client, account_tracker_service), prohibit_signout_(false), type_(SIGNIN_TYPE_NONE), client_(client), token_service_(token_service), - account_tracker_service_(account_tracker_service), cookie_manager_service_(cookie_manager_service), signin_manager_signed_in_(false), user_info_fetched_by_account_tracker_(false), @@ -64,11 +63,14 @@ std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) { } bool SigninManager::PrepareForSignin(SigninType type, + const std::string& gaia_id, const std::string& username, const std::string& password) { - DCHECK(possibly_invalid_username_.empty() || - possibly_invalid_username_ == username); - DCHECK(!username.empty()); + std::string account_id = + account_tracker_service()->PickAccountIdForAccount(gaia_id, username); + DCHECK(possibly_invalid_account_id_.empty() || + possibly_invalid_account_id_ == account_id); + DCHECK(!account_id.empty()); if (!IsAllowedUsername(username)) { // Account is not allowed by admin policy. @@ -84,7 +86,9 @@ bool SigninManager::PrepareForSignin(SigninType type, // restart we don't think sync setup has never completed. ClearTransientSigninData(); type_ = type; - possibly_invalid_username_.assign(username); + possibly_invalid_account_id_.assign(account_id); + possibly_invalid_gaia_id_.assign(gaia_id); + possibly_invalid_email_.assign(username); password_.assign(password); signin_manager_signed_in_ = false; user_info_fetched_by_account_tracker_ = false; @@ -94,18 +98,19 @@ bool SigninManager::PrepareForSignin(SigninType type, void SigninManager::StartSignInWithRefreshToken( const std::string& refresh_token, + const std::string& gaia_id, const std::string& username, const std::string& password, const OAuthTokenFetchedCallback& callback) { - DCHECK(!IsAuthenticated() || - gaia::AreEmailsSame(username, GetAuthenticatedUsername())); + DCHECK(!IsAuthenticated()); - if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password)) + if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, gaia_id, username, + password)) { return; + } - // Store our callback and token. + // Store our token. temp_refresh_token_ = refresh_token; - possibly_invalid_username_ = username; if (!callback.is_null() && !temp_refresh_token_.empty()) { callback.Run(temp_refresh_token_); @@ -117,7 +122,9 @@ void SigninManager::StartSignInWithRefreshToken( void SigninManager::CopyCredentialsFrom(const SigninManager& source) { DCHECK_NE(this, &source); - possibly_invalid_username_ = source.possibly_invalid_username_; + possibly_invalid_account_id_ = source.possibly_invalid_account_id_; + possibly_invalid_gaia_id_ = source.possibly_invalid_gaia_id_; + possibly_invalid_email_ = source.possibly_invalid_email_; temp_refresh_token_ = source.temp_refresh_token_; password_ = source.password_; } @@ -125,7 +132,9 @@ void SigninManager::CopyCredentialsFrom(const SigninManager& source) { void SigninManager::ClearTransientSigninData() { DCHECK(IsInitialized()); - possibly_invalid_username_.clear(); + possibly_invalid_account_id_.clear(); + possibly_invalid_gaia_id_.clear(); + possibly_invalid_email_.clear(); password_.clear(); type_ = SIGNIN_TYPE_NONE; temp_refresh_token_.clear(); @@ -172,9 +181,10 @@ void SigninManager::SignOut( const base::Time signin_time = base::Time::FromInternalValue( client_->GetPrefs()->GetInt64(prefs::kSignedInTime)); - ClearAuthenticatedUsername(); + clear_authenticated_user(); client_->GetPrefs()->ClearPref(prefs::kGoogleServicesHostedDomain); - client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId); + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); client_->GetPrefs()->ClearPref(prefs::kSignedInTime); client_->OnSignedOut(); @@ -213,31 +223,28 @@ void SigninManager::Initialize(PrefService* local_state) { base::Bind(&SigninManager::OnSigninAllowedPrefChanged, base::Unretained(this))); - std::string user = - client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); - if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) { + std::string account_id = + client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); + std::string user = account_id.empty() ? std::string() : + account_tracker_service()->GetAccountInfo(account_id).email; + if ((!account_id.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) { // User is signed in, but the username is invalid - the administrator must // have changed the policy since the last signin, so sign out the user. SignOut(signin_metrics::SIGNIN_PREF_CHANGED_DURING_SIGNIN); } InitTokenService(); - account_id_helper_.reset( - new SigninAccountIdHelper(client_, token_service_, this)); - - account_tracker_service_->AddObserver(this); + account_tracker_service()->AddObserver(this); } void SigninManager::Shutdown() { - account_tracker_service_->RemoveObserver(this); + account_tracker_service()->RemoveObserver(this); local_state_pref_registrar_.RemoveAll(); - account_id_helper_.reset(); SigninManagerBase::Shutdown(); } void SigninManager::OnGoogleServicesUsernamePatternChanged() { - if (IsAuthenticated() && - !IsAllowedUsername(GetAuthenticatedUsername())) { + if (IsAuthenticated() && !IsAllowedUsername(GetAuthenticatedUsername())) { // Signed in user is invalid according to the current policy so sign // the user out. SignOut(signin_metrics::GOOGLE_SERVICE_NAME_PATTERN_CHANGED); @@ -297,11 +304,15 @@ bool SigninManager::IsAllowedUsername(const std::string& username) const { } bool SigninManager::AuthInProgress() const { - return !possibly_invalid_username_.empty(); + return !possibly_invalid_account_id_.empty(); +} + +const std::string& SigninManager::GetAccountIdForAuthInProgress() const { + return possibly_invalid_account_id_; } const std::string& SigninManager::GetUsernameForAuthInProgress() const { - return possibly_invalid_username_; + return possibly_invalid_email_; } void SigninManager::DisableOneClickSignIn(PrefService* prefs) { @@ -320,28 +331,38 @@ void SigninManager::MergeSigninCredentialIntoCookieJar() { void SigninManager::CompletePendingSignin() { NotifyDiagnosticsObservers(SIGNIN_COMPLETED, "Successful"); - - DCHECK(!possibly_invalid_username_.empty()); - OnSignedIn(possibly_invalid_username_); + DCHECK(!possibly_invalid_account_id_.empty()); + OnSignedIn(); DCHECK(!temp_refresh_token_.empty()); DCHECK(IsAuthenticated()); - token_service_->UpdateCredentials(GetAuthenticatedAccountId(), - temp_refresh_token_); + + std::string account_id = GetAuthenticatedAccountId(); + token_service_->UpdateCredentials(account_id, temp_refresh_token_); temp_refresh_token_.clear(); MergeSigninCredentialIntoCookieJar(); } void SigninManager::OnExternalSigninCompleted(const std::string& username) { - OnSignedIn(username); + AccountTrackerService::AccountInfo info = + account_tracker_service()->FindAccountInfoByEmail(username); + DCHECK(!info.gaia.empty()); + DCHECK(!info.email.empty()); + possibly_invalid_account_id_ = info.account_id; + possibly_invalid_gaia_id_ = info.gaia; + possibly_invalid_email_ = info.email; + OnSignedIn(); } -void SigninManager::OnSignedIn(const std::string& username) { +void SigninManager::OnSignedIn() { client_->GetPrefs()->SetInt64(prefs::kSignedInTime, base::Time::Now().ToInternalValue()); - SetAuthenticatedUsername(username); - possibly_invalid_username_.clear(); + SetAuthenticatedAccountInfo(possibly_invalid_gaia_id_, + possibly_invalid_email_); + possibly_invalid_account_id_.clear(); + possibly_invalid_gaia_id_.clear(); + possibly_invalid_email_.clear(); signin_manager_signed_in_ = true; FOR_EACH_OBSERVER( diff --git a/components/signin/core/browser/signin_manager.h b/components/signin/core/browser/signin_manager.h index fe9605c..a24a0e9 100644 --- a/components/signin/core/browser/signin_manager.h +++ b/components/signin/core/browser/signin_manager.h @@ -42,7 +42,6 @@ class GaiaCookieManagerService; class GoogleServiceAuthError; class PrefService; class ProfileOAuth2TokenService; -class SigninAccountIdHelper; class SigninClient; class SigninManager : public SigninManagerBase, @@ -78,6 +77,7 @@ class SigninManager : public SigninManagerBase, // continue or cancel the in-process signin. virtual void StartSignInWithRefreshToken( const std::string& refresh_token, + const std::string& gaia_id, const std::string& username, const std::string& password, const OAuthTokenFetchedCallback& oauth_fetched_callback); @@ -104,7 +104,9 @@ class SigninManager : public SigninManagerBase, virtual void CompletePendingSignin(); // Invoked from SigninManagerAndroid to indicate that the sign-in process - // has completed for |username|. + // has completed for the email |username|. SigninManager assumes that + // |username| can be used to look up the corresponding account_id and gaia_id + // for this email. void OnExternalSigninCompleted(const std::string& username); // Returns true if there's a signin in progress. @@ -116,6 +118,10 @@ class SigninManager : public SigninManagerBase, // mocking in tests. virtual bool IsAllowedUsername(const std::string& username) const; + // If an authentication is in progress, return the account id being + // authenticated. Returns an empty string if no auth is in progress. + const std::string& GetAccountIdForAuthInProgress() const; + // If an authentication is in progress, return the username being // authenticated. Returns an empty string if no auth is in progress. const std::string& GetUsernameForAuthInProgress() const; @@ -153,14 +159,16 @@ class SigninManager : public SigninManagerBase, // StartSigninXXX methods. |type| indicates which of the methods is being // used to perform the signin while |username| and |password| identify the // account to be signed in. Returns false and generates an auth error if the - // passed |username| is not allowed by policy. + // passed |username| is not allowed by policy. |gaia_id| is the obfuscated + // gaia id corresponding to |username|. bool PrepareForSignin(SigninType type, + const std::string& gaia_id, const std::string& username, const std::string& password); - // Persists |username| as the currently signed-in account, and triggers + // Persists |account_id| as the currently signed-in account, and triggers // a sign-in success notification. - void OnSignedIn(const std::string& username); + void OnSignedIn(); // Waits for the AccountTrackerService, then sends GoogleSigninSucceeded to // the client and clears the local password. @@ -184,13 +192,11 @@ class SigninManager : public SigninManagerBase, void OnSigninAllowedPrefChanged(); void OnGoogleServicesUsernamePatternChanged(); - // ClientLogin identity. - std::string possibly_invalid_username_; + std::string possibly_invalid_account_id_; + std::string possibly_invalid_gaia_id_; + std::string possibly_invalid_email_; std::string password_; // This is kept empty whenever possible. - // Fetcher for the obfuscated user id. - scoped_ptr<SigninAccountIdHelper> account_id_helper_; - // The type of sign being performed. This value is valid only between a call // to one of the StartSigninXXX methods and when the sign in is either // successful or not. @@ -208,10 +214,6 @@ class SigninManager : public SigninManagerBase, // outlive this object. ProfileOAuth2TokenService* token_service_; - // The AccountTrackerService instance associated with this object. Must - // outlive this object. - AccountTrackerService* account_tracker_service_; - // Object used to use the token to push a GAIA cookie into the cookie jar. GaiaCookieManagerService* cookie_manager_service_; diff --git a/components/signin/core/browser/signin_manager_base.cc b/components/signin/core/browser/signin_manager_base.cc index 08cdc6b..a3986b6 100644 --- a/components/signin/core/browser/signin_manager_base.cc +++ b/components/signin/core/browser/signin_manager_base.cc @@ -23,8 +23,16 @@ using namespace signin_internals_util; -SigninManagerBase::SigninManagerBase(SigninClient* client) - : client_(client), initialized_(false), weak_pointer_factory_(this) {} +SigninManagerBase::SigninManagerBase( + SigninClient* client, + AccountTrackerService* account_tracker_service) + : client_(client), + account_tracker_service_(account_tracker_service), + initialized_(false), + weak_pointer_factory_(this) { + DCHECK(client_); + DCHECK(account_tracker_service_); +} SigninManagerBase::~SigninManagerBase() {} @@ -37,13 +45,41 @@ void SigninManagerBase::Initialize(PrefService* local_state) { // clear their login info also (not valid to be logged in without any // tokens). base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); - if (cmd_line->HasSwitch(switches::kClearTokenService)) + if (cmd_line->HasSwitch(switches::kClearTokenService)) { + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId); client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); + } - std::string user = - client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); - if (!user.empty()) - SetAuthenticatedUsername(user); + std::string account_id = + client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); + + // Handle backward compatibility: if kGoogleServicesAccountId is empty, but + // kGoogleServicesUsername is not, then this is an old profile that needs to + // be updated. kGoogleServicesUserAccountId should not be empty, and contains + // the gaia_id. Use both properties to prime the account tracker before + // proceeding. + if (account_id.empty()) { + std::string pref_account_username = + client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); + std::string pref_gaia_id = + client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); + DCHECK(pref_account_username.empty() || !pref_gaia_id.empty()); + if (!pref_account_username.empty() && !pref_gaia_id.empty()) { + account_id = account_tracker_service_->SeedAccountInfo( + pref_gaia_id, pref_account_username); + + // Now remove obsolete preferences. + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); + + // TODO(rogerta): once migration to gaia id is complete, remove + // kGoogleServicesUserAccountId and change all uses of that pref to + // kGoogleServicesAccountId. + } + } + + if (!account_id.empty()) + SetAuthenticatedAccountId(account_id); } bool SigninManagerBase::IsInitialized() const { return initialized_; } @@ -52,58 +88,54 @@ bool SigninManagerBase::IsSigninAllowed() const { return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); } -const std::string& SigninManagerBase::GetAuthenticatedUsername() const { - return authenticated_username_; +std::string SigninManagerBase::GetAuthenticatedUsername() const { + return account_tracker_service_->GetAccountInfo( + GetAuthenticatedAccountId()).email; } const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { return authenticated_account_id_; } -void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { - DCHECK(!username.empty()); - if (!authenticated_username_.empty()) { - DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) - << "Tried to change the authenticated username to something different: " - << "Current: " << authenticated_username_ << ", New: " << username; - -#if defined(OS_IOS) - // Prior to M26, chrome on iOS did not normalize the email before setting - // it in SigninManager. If the emails are the same as given by - // gaia::AreEmailsSame() but not the same as given by std::string::op==(), - // make sure to set the authenticated name below. - if (!gaia::AreEmailsSame(username, authenticated_username_) || - username == authenticated_username_) { - return; - } -#else +void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id, + const std::string& email) { + std::string account_id = + account_tracker_service_->SeedAccountInfo(gaia_id, email); + SetAuthenticatedAccountId(account_id); +} + +void SigninManagerBase::SetAuthenticatedAccountId( + const std::string& account_id) { + DCHECK(!account_id.empty()); + if (!authenticated_account_id_.empty()) { + DLOG_IF(ERROR, account_id != authenticated_account_id_) + << "Tried to change the authenticated id to something different: " + << "Current: " << authenticated_account_id_ << ", New: " << account_id; return; -#endif } - std::string pref_username = - client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); - DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) - << "username: " << username << "; pref_username: " << pref_username; - authenticated_username_ = username; - - // TODO(rogerta): remove this DCHECK when migration work is started. - DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, - AccountTrackerService::GetMigrationState(client_->GetPrefs())); - authenticated_account_id_ = - AccountTrackerService::PickAccountIdForAccount(client_->GetPrefs(), - username, - username); - client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); - - // Go ahead and update the last signed in username here as well. Once a + + std::string pref_account_id = + client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); + + DCHECK(pref_account_id.empty() || pref_account_id == account_id) + << "account_id=" << account_id + << " pref_account_id=" << pref_account_id; + authenticated_account_id_ = account_id; + client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); + + // This preference is set so that code on I/O thread has access to the + // Gaia id of the signed in user. + AccountTrackerService::AccountInfo info = + account_tracker_service_->GetAccountInfo(account_id); + DCHECK(!info.gaia.empty()); + client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, + info.gaia); + + // Go ahead and update the last signed in account info here as well. Once a // user is signed in the two preferences should match. Doing it here as // opposed to on signin allows us to catch the upgrade scenario. - client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); -} - -void SigninManagerBase::ClearAuthenticatedUsername() { - authenticated_username_.clear(); - authenticated_account_id_.clear(); + client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, + info.email); } bool SigninManagerBase::IsAuthenticated() const { diff --git a/components/signin/core/browser/signin_manager_base.h b/components/signin/core/browser/signin_manager_base.h index 1bbd5f1..b064734 100644 --- a/components/signin/core/browser/signin_manager_base.h +++ b/components/signin/core/browser/signin_manager_base.h @@ -36,8 +36,8 @@ #include "components/signin/core/browser/signin_internals_util.h" #include "google_apis/gaia/google_service_auth_error.h" +class AccountTrackerService; class PrefService; - class SigninClient; class SigninManagerBase : public KeyedService { @@ -60,7 +60,8 @@ class SigninManagerBase : public KeyedService { virtual ~Observer() {} }; - SigninManagerBase(SigninClient* client); + SigninManagerBase(SigninClient* client, + AccountTrackerService* account_tracker_service); ~SigninManagerBase() override; // If user was signed in, load tokens from DB if available. @@ -78,7 +79,7 @@ class SigninManagerBase : public KeyedService { // If a user has previously signed in (and has not signed out), this returns // the normalized email address of the account. Otherwise, it returns an empty // string. - const std::string& GetAuthenticatedUsername() const; + std::string GetAuthenticatedUsername() const; // If a user has previously signed in (and has not signed out), this returns // the account id. Otherwise, it returns an empty string. This id can be used @@ -96,11 +97,11 @@ class SigninManagerBase : public KeyedService { // in the hotdog menu. const std::string& GetAuthenticatedAccountId() const; - // Sets the user name. Note: |username| should be already authenticated as - // this is a sticky operation (in contrast to StartSignIn). - // TODO(tim): Remove this in favor of passing username on construction by - // (by platform / depending on StartBehavior). Bug 88109. - void SetAuthenticatedUsername(const std::string& username); + // Sets the authenticated user's Gaia ID and display email. Internally, + // this will seed the account information in AccountTrackerService and pick + // the right account_id for this account. + void SetAuthenticatedAccountInfo(const std::string& gaia_id, + const std::string& email); // Returns true if there is an authenticated user. bool IsAuthenticated() const; @@ -122,10 +123,19 @@ class SigninManagerBase : public KeyedService { signin_internals_util::SigninDiagnosticsObserver* observer); protected: - // Used by subclass to clear authenticated_username_ instead of using - // SetAuthenticatedUsername, which enforces special preconditions due + AccountTrackerService* account_tracker_service() const { + return account_tracker_service_; + } + + SigninClient* signin_client() const { return client_; } + + // Sets the authenticated user's account id. + void SetAuthenticatedAccountId(const std::string& account_id); + + // Used by subclass to clear the authenticated user instead of using + // SetAuthenticatedAccountId, which enforces special preconditions due // to the fact that it is part of the public API and called by clients. - void ClearAuthenticatedUsername(); + void clear_authenticated_user() { authenticated_account_id_.clear(); } // List of observers to notify on signin events. // Makes sure list is empty on destruction. @@ -141,10 +151,10 @@ class SigninManagerBase : public KeyedService { friend class FakeSigninManager; SigninClient* client_; + AccountTrackerService* account_tracker_service_; bool initialized_; - // Actual username and account_id after successful authentication. - std::string authenticated_username_; + // Account id after successful authentication. std::string authenticated_account_id_; // The list of SigninDiagnosticObservers. diff --git a/components/signin/core/common/signin_pref_names.cc b/components/signin/core/common/signin_pref_names.cc index 4e4b87e..38496dc 100644 --- a/components/signin/core/common/signin_pref_names.cc +++ b/components/signin/core/common/signin_pref_names.cc @@ -14,14 +14,23 @@ const char kAccountIdMigrationState[] = "account_id_migration_state"; // Boolean identifying whether reverse auto-login is enabled. const char kAutologinEnabled[] = "autologin.enabled"; + // The profile's hosted domain; empty if unset; // AccountTrackerService::kNoHostedDomainFound if there is none. + +const char kGoogleServicesAccountId[] = "google.services.account_id"; + +// The profile's hosted domain; empty if unset; Profile::kNoHostedDomainFound +// if there is none. const char kGoogleServicesHostedDomain[] = "google.services.hosted_domain"; // String the identifies the last user that logged into sync and other // google services. As opposed to kGoogleServicesUsername, this value is not // cleared on signout, but while the user is signed in the two values will -// be the same. +// be the same. This pref remains in order to pre-fill the sign in page when +// reconnecting a profile, but programmatic checks to see if a given account +// is the same as the last account should use kGoogleServicesLastAccountId +// instead. const char kGoogleServicesLastUsername[] = "google.services.last_username"; // Int64 as time from epoch of when next RefreshTokenAnnotationRequest should be @@ -41,6 +50,7 @@ const char kGoogleServicesUserAccountId[] = "google.services.user_account_id"; // String that identifies the current user logged into sync and other google // services. +// DEPRECATED. const char kGoogleServicesUsername[] = "google.services.username"; // Local state pref containing a string regex that restricts which accounts diff --git a/components/signin/core/common/signin_pref_names.h b/components/signin/core/common/signin_pref_names.h index 5e66471..412a3d6 100644 --- a/components/signin/core/common/signin_pref_names.h +++ b/components/signin/core/common/signin_pref_names.h @@ -9,6 +9,7 @@ namespace prefs { extern const char kAccountIdMigrationState[]; extern const char kAutologinEnabled[]; +extern const char kGoogleServicesAccountId[]; extern const char kGoogleServicesHostedDomain[]; extern const char kGoogleServicesLastUsername[]; extern const char kGoogleServicesRefreshTokenAnnotateScheduledTime[]; |