summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrogerta <rogerta@chromium.org>2014-08-27 14:51:43 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-27 21:54:13 +0000
commitf15548e894657da4ec5eca5680e45d2253d34852 (patch)
tree88d5573cf8680233b9b9824b6390ffa8750385ff
parent47106fe835d8d8aca61704d5d5a07bc8ea88fdf5 (diff)
downloadchromium_src-f15548e894657da4ec5eca5680e45d2253d34852.zip
chromium_src-f15548e894657da4ec5eca5680e45d2253d34852.tar.gz
chromium_src-f15548e894657da4ec5eca5680e45d2253d34852.tar.bz2
Add IsAuthenticated() method to SigninManager to check for connected profile.
Make sure callers are using GetAuthenticatedUsername and GetAuthenticatedAccountId correctly. BUG=341408 TBR=bauerb@chromium.org, benwells@chromium.org, gene@chromium.org, asvitkine@chromium.org, noms@chromium.org, tim@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/479353003 Cr-Commit-Position: refs/heads/master@{#292235}
-rw-r--r--chrome/browser/android/bookmarks/bookmarks_bridge.cc2
-rw-r--r--chrome/browser/extensions/external_component_loader.cc2
-rw-r--r--chrome/browser/local_discovery/privet_notifications.cc2
-rw-r--r--chrome/browser/metrics/signin_status_metrics_provider.cc6
-rw-r--r--chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc6
-rw-r--r--chrome/browser/profiles/gaia_info_update_service.cc2
-rw-r--r--chrome/browser/signin/signin_global_error.cc5
-rw-r--r--chrome/browser/signin/signin_manager_unittest.cc16
-rw-r--r--chrome/browser/signin/signin_promo.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc2
-rw-r--r--chrome/browser/sync/supervised_user_signin_manager_wrapper.cc8
-rw-r--r--chrome/browser/sync/sync_ui_util.cc4
-rw-r--r--chrome/browser/sync_file_system/drive_backend/sync_engine.cc6
-rw-r--r--chrome/browser/ui/app_list/search/people/people_result.cc2
-rw-r--r--chrome/browser/ui/chrome_pages.cc2
-rw-r--r--chrome/browser/ui/sync/one_click_signin_sync_starter.cc6
-rw-r--r--chrome/browser/ui/views/profiles/profile_chooser_view.cc7
-rw-r--r--chrome/browser/ui/webui/options/browser_options_handler.cc3
-rw-r--r--chrome/browser/ui/webui/options/options_ui_browsertest.cc2
-rw-r--r--chrome/browser/ui/webui/options/supervised_user_import_handler.cc2
-rw-r--r--chrome/browser/ui/webui/sync_setup_handler.cc20
-rw-r--r--components/signin/core/browser/about_signin_internals.cc2
-rw-r--r--components/signin/core/browser/account_reconcilor.cc4
-rw-r--r--components/signin/core/browser/signin_manager.cc8
-rw-r--r--components/signin/core/browser/signin_manager_base.cc4
-rw-r--r--components/signin/core/browser/signin_manager_base.h3
27 files changed, 63 insertions, 70 deletions
diff --git a/chrome/browser/android/bookmarks/bookmarks_bridge.cc b/chrome/browser/android/bookmarks/bookmarks_bridge.cc
index 7cd704a..f03c38f 100644
--- a/chrome/browser/android/bookmarks/bookmarks_bridge.cc
+++ b/chrome/browser/android/bookmarks/bookmarks_bridge.cc
@@ -491,7 +491,7 @@ bool BookmarksBridge::IsFolderAvailable(
profile_->GetOriginalProfile());
return (folder->type() != BookmarkNode::BOOKMARK_BAR &&
folder->type() != BookmarkNode::OTHER_NODE) ||
- (signin && !signin->GetAuthenticatedUsername().empty());
+ (signin && signin->IsAuthenticated());
}
void BookmarksBridge::NotifyIfDoneLoading() {
diff --git a/chrome/browser/extensions/external_component_loader.cc b/chrome/browser/extensions/external_component_loader.cc
index a80f441..88d9260 100644
--- a/chrome/browser/extensions/external_component_loader.cc
+++ b/chrome/browser/extensions/external_component_loader.cc
@@ -19,7 +19,7 @@ namespace {
bool IsUserSignedin(Profile* profile) {
SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
- return signin && !signin->GetAuthenticatedUsername().empty();
+ return signin && signin->IsAuthenticated();
}
} // namespace
diff --git a/chrome/browser/local_discovery/privet_notifications.cc b/chrome/browser/local_discovery/privet_notifications.cc
index f87e0a9..9d3c5f8 100644
--- a/chrome/browser/local_discovery/privet_notifications.cc
+++ b/chrome/browser/local_discovery/privet_notifications.cc
@@ -297,7 +297,7 @@ void PrivetNotificationService::Start() {
SigninManagerFactory::GetForProfileIfExists(
Profile::FromBrowserContext(profile_));
- if (!signin_manager || signin_manager->GetAuthenticatedUsername().empty())
+ if (!signin_manager || !signin_manager->IsAuthenticated())
return;
#endif
diff --git a/chrome/browser/metrics/signin_status_metrics_provider.cc b/chrome/browser/metrics/signin_status_metrics_provider.cc
index d58dcee..d334df1 100644
--- a/chrome/browser/metrics/signin_status_metrics_provider.cc
+++ b/chrome/browser/metrics/signin_status_metrics_provider.cc
@@ -92,7 +92,7 @@ void SigninStatusMetricsProvider::OnBrowserAdded(Browser* browser) {
if (!manager)
return;
- const bool signed_in = !manager->GetAuthenticatedUsername().empty();
+ const bool signed_in = manager->IsAuthenticated();
UpdateStatusWhenBrowserAdded(signed_in);
}
@@ -108,7 +108,7 @@ void SigninStatusMetricsProvider::SigninManagerCreated(
// profile.
if (signin_status_ == UNKNOWN_SIGNIN_STATUS) {
size_t signed_in_count =
- manager->GetAuthenticatedUsername().empty() ? 0 : 1;
+ manager->IsAuthenticated() ? 1 : 0;
UpdateInitialSigninStatus(1, signed_in_count);
}
}
@@ -210,7 +210,7 @@ void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() {
opened_profiles_count++;
SigninManager* manager = SigninManagerFactory::GetForProfile(
profile_list[i]->GetOriginalProfile());
- if (manager && !manager->GetAuthenticatedUsername().empty())
+ if (manager && manager->IsAuthenticated())
signed_in_profiles_count++;
}
UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count);
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 51db158..602b1d4 100644
--- a/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc
+++ b/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc
@@ -212,7 +212,7 @@ class UserPolicySigninServiceTest : public testing::Test {
virtual void AddProfile() {
// For this test, the user should not be signed in yet.
- DCHECK(signin_manager_->GetAuthenticatedUsername().empty());
+ DCHECK(!signin_manager_->IsAuthenticated());
// Initializing UserPolicySigninService while the user is not signed in
// should result in the store being cleared to remove any lingering policy.
@@ -394,8 +394,8 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest {
TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) {
// Make sure user is not signed in.
- ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile_.get())->
- GetAuthenticatedUsername().empty());
+ ASSERT_FALSE(SigninManagerFactory::GetForProfile(profile_.get())->
+ IsAuthenticated());
// UserCloudPolicyManager should not be initialized.
ASSERT_FALSE(manager_->core()->service());
diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc
index 010756c..777589e 100644
--- a/chrome/browser/profiles/gaia_info_update_service.cc
+++ b/chrome/browser/profiles/gaia_info_update_service.cc
@@ -49,7 +49,7 @@ void GAIAInfoUpdateService::Update() {
// The user must be logged in.
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
- if (signin_manager->GetAuthenticatedAccountId().empty())
+ if (!signin_manager->IsAuthenticated())
return;
if (profile_image_downloader_)
diff --git a/chrome/browser/signin/signin_global_error.cc b/chrome/browser/signin/signin_global_error.cc
index 5131e09..8fabe93 100644
--- a/chrome/browser/signin/signin_global_error.cc
+++ b/chrome/browser/signin/signin_global_error.cc
@@ -124,11 +124,8 @@ std::vector<base::string16> SigninGlobalError::GetBubbleViewMessages() {
// If the user isn't signed in, no need to display an error bubble.
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile_);
- if (signin_manager) {
- std::string username = signin_manager->GetAuthenticatedUsername();
- if (username.empty())
+ if (signin_manager && !signin_manager->IsAuthenticated())
return messages;
- }
if (!error_controller_->HasError())
return messages;
diff --git a/chrome/browser/signin/signin_manager_unittest.cc b/chrome/browser/signin/signin_manager_unittest.cc
index 378fe7b..997a130 100644
--- a/chrome/browser/signin/signin_manager_unittest.cc
+++ b/chrome/browser/signin/signin_manager_unittest.cc
@@ -165,7 +165,7 @@ class SigninManagerTest : public testing::Test {
}
void ExpectSignInWithRefreshTokenSuccess() {
- EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_TRUE(manager_->IsAuthenticated());
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
@@ -195,7 +195,7 @@ class SigninManagerTest : public testing::Test {
TEST_F(SigninManagerTest, SignInWithRefreshToken) {
SetUpSigninManagerAsService();
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
manager_->StartSignInWithRefreshToken(
"rt1",
@@ -214,7 +214,7 @@ TEST_F(SigninManagerTest, SignInWithRefreshToken) {
TEST_F(SigninManagerTest, SignInWithRefreshTokenCallbackComplete) {
SetUpSigninManagerAsService();
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
// Since the password is empty, must verify the gaia cookies first.
SigninManager::OAuthTokenFetchedCallback callback =
@@ -239,25 +239,25 @@ TEST_F(SigninManagerTest, SignOut) {
"password",
SigninManager::OAuthTokenFetchedCallback());
manager_->SignOut(signin_metrics::SIGNOUT_TEST);
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
// Should not be persisted anymore
ShutDownManager();
CreateNakedSigninManager();
manager_->Initialize(NULL);
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
}
TEST_F(SigninManagerTest, SignOutWhileProhibited) {
SetUpSigninManagerAsService();
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
manager_->SetAuthenticatedUsername("user@gmail.com");
manager_->ProhibitSignout(true);
manager_->SignOut(signin_metrics::SIGNOUT_TEST);
- EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_TRUE(manager_->IsAuthenticated());
manager_->ProhibitSignout(false);
manager_->SignOut(signin_metrics::SIGNOUT_TEST);
- EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(manager_->IsAuthenticated());
}
TEST_F(SigninManagerTest, TestIsWebBasedSigninFlowURL) {
diff --git a/chrome/browser/signin/signin_promo.cc b/chrome/browser/signin/signin_promo.cc
index 86c4585..6680566 100644
--- a/chrome/browser/signin/signin_promo.cc
+++ b/chrome/browser/signin/signin_promo.cc
@@ -99,7 +99,7 @@ bool ShouldShowPromo(Profile* profile) {
SigninManager* signin = SigninManagerFactory::GetForProfile(
profile->GetOriginalProfile());
return !signin->AuthInProgress() && signin->IsSigninAllowed() &&
- signin->GetAuthenticatedUsername().empty();
+ !signin->IsAuthenticated();
#endif
}
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 52aa05f..6bbf381 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -2541,10 +2541,7 @@ SigninManagerBase* ProfileSyncService::signin() const {
void ProfileSyncService::UnsuppressAndStart() {
DCHECK(profile_);
sync_prefs_.SetStartSuppressed(false);
- // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
- // is never called for some clients.
- if (signin_.get() &&
- signin_->GetOriginal()->GetAuthenticatedUsername().empty()) {
+ if (signin_.get() && !signin_->GetOriginal()->IsAuthenticated()) {
signin_->GetOriginal()->SetAuthenticatedUsername(
profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
}
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index 260e44d..90434a2 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -215,7 +215,7 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
signin->SetAuthenticatedUsername("test_user@gmail.com");
ProfileOAuth2TokenService* oauth2_token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
- EXPECT_FALSE(signin->GetAuthenticatedUsername().empty());
+ EXPECT_TRUE(signin->IsAuthenticated());
return new TestProfileSyncServiceNoBackup(
scoped_ptr<ProfileSyncComponentsFactory>(
new ProfileSyncComponentsFactoryMock()),
diff --git a/chrome/browser/sync/supervised_user_signin_manager_wrapper.cc b/chrome/browser/sync/supervised_user_signin_manager_wrapper.cc
index 9abdc9a..21b045e 100644
--- a/chrome/browser/sync/supervised_user_signin_manager_wrapper.cc
+++ b/chrome/browser/sync/supervised_user_signin_manager_wrapper.cc
@@ -34,18 +34,16 @@ std::string SupervisedUserSigninManagerWrapper::GetEffectiveUsername() const {
}
std::string SupervisedUserSigninManagerWrapper::GetAccountIdToUse() const {
- const std::string& auth_account = original_->GetAuthenticatedAccountId();
#if defined(ENABLE_MANAGED_USERS)
- if (auth_account.empty() && profile_->IsSupervised())
+ if (!original_->IsAuthenticated() && profile_->IsSupervised())
return supervised_users::kSupervisedUserPseudoEmail;
#endif
- return auth_account;
+ return original_->GetAuthenticatedAccountId();
}
std::string SupervisedUserSigninManagerWrapper::GetSyncScopeToUse() const {
#if defined(ENABLE_MANAGED_USERS)
- const std::string& auth_account = original_->GetAuthenticatedAccountId();
- if (auth_account.empty() && profile_->IsSupervised())
+ if (!original_->IsAuthenticated() && profile_->IsSupervised())
return GaiaConstants::kChromeSyncSupervisedOAuth2Scope;
#endif
return GaiaConstants::kChromeSyncOAuth2Scope;
diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc
index d67b68d..3cc6189 100644
--- a/chrome/browser/sync/sync_ui_util.cc
+++ b/chrome/browser/sync/sync_ui_util.cc
@@ -140,7 +140,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
MessageType result_type(SYNCED);
- if (signin.GetAuthenticatedUsername().empty())
+ if (!signin.IsAuthenticated())
return PRE_SYNCED;
if (!service || service->IsManaged() || service->HasSyncSetupCompleted() ||
@@ -265,7 +265,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
} else if (status_label) {
status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR));
}
- } else if (!signin.GetAuthenticatedUsername().empty()) {
+ } else if (signin.IsAuthenticated()) {
// The user is signed in, but sync has been stopped.
if (status_label) {
base::string16 label = l10n_util::GetStringFUTF16(
diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine.cc b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc
index 3e1b39c..84a2ed54 100644
--- a/chrome/browser/sync_file_system/drive_backend/sync_engine.cc
+++ b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc
@@ -274,8 +274,7 @@ void SyncEngine::Reset() {
void SyncEngine::Initialize() {
Reset();
- if (!signin_manager_ ||
- signin_manager_->GetAuthenticatedAccountId().empty())
+ if (!signin_manager_ || !signin_manager_->IsAuthenticated())
return;
DCHECK(drive_service_factory_);
@@ -380,8 +379,7 @@ void SyncEngine::RegisterOrigin(const GURL& origin,
if (!sync_worker_) {
// TODO(tzik): Record |origin| and retry the registration after late
// sign-in. Then, return SYNC_STATUS_OK.
- if (!signin_manager_ ||
- signin_manager_->GetAuthenticatedAccountId().empty())
+ if (!signin_manager_ || !signin_manager_->IsAuthenticated())
callback.Run(SYNC_STATUS_AUTHENTICATION_FAILED);
else
callback.Run(SYNC_STATUS_ABORT);
diff --git a/chrome/browser/ui/app_list/search/people/people_result.cc b/chrome/browser/ui/app_list/search/people/people_result.cc
index 152bc80..3531f64 100644
--- a/chrome/browser/ui/app_list/search/people/people_result.cc
+++ b/chrome/browser/ui/app_list/search/people/people_result.cc
@@ -152,7 +152,7 @@ void PeopleResult::OpenChat() {
SigninManagerBase* signin_manager =
SigninManagerFactory::GetInstance()->GetForProfile(profile_);
DCHECK(signin_manager);
- request.from = signin_manager->GetAuthenticatedAccountId();
+ request.from = signin_manager->GetAuthenticatedUsername();
// to: list of users with whom to start this hangout is with.
linked_ptr<User> target(new User());
diff --git a/chrome/browser/ui/chrome_pages.cc b/chrome/browser/ui/chrome_pages.cc
index 4cc02c0..7b7243b 100644
--- a/chrome/browser/ui/chrome_pages.cc
+++ b/chrome/browser/ui/chrome_pages.cc
@@ -311,7 +311,7 @@ void ShowBrowserSignin(Browser* browser, signin::Source source) {
SigninManagerFactory::GetForProfile(original_profile);
DCHECK(manager->IsSigninAllowed());
// If we're signed in, just show settings.
- if (!manager->GetAuthenticatedUsername().empty()) {
+ if (manager->IsAuthenticated()) {
ShowSettings(browser);
} else {
// If the browser's profile is an incognito profile, make sure to use
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 3a6d7f1..5952be3 100644
--- a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc
+++ b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc
@@ -153,7 +153,7 @@ void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) {
SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
// If this is a new signin (no authenticated username yet) try loading
// policy for this user now, before any signed in services are initialized.
- if (signin->GetAuthenticatedUsername().empty()) {
+ if (!signin->IsAuthenticated()) {
#if defined(ENABLE_CONFIGURATION_POLICY)
policy::UserPolicySigninService* policy_service =
policy::UserPolicySigninServiceFactory::GetForProfile(profile_);
@@ -302,8 +302,8 @@ void OneClickSigninSyncStarter::CompleteInitForNewProfile(
SigninManager* new_signin_manager =
SigninManagerFactory::GetForProfile(new_profile);
DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty());
- DCHECK(old_signin_manager->GetAuthenticatedUsername().empty());
- DCHECK(new_signin_manager->GetAuthenticatedUsername().empty());
+ DCHECK(!old_signin_manager->IsAuthenticated());
+ DCHECK(!new_signin_manager->IsAuthenticated());
DCHECK(!dm_token_.empty());
DCHECK(!client_id_.empty());
diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.cc b/chrome/browser/ui/views/profiles/profile_chooser_view.cc
index d61b483..aee21c8 100644
--- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc
+++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc
@@ -744,12 +744,11 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
account_id_to_remove_.clear();
ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
} else if (sender == gaia_signin_cancel_button_) {
- std::string primary_account =
- SigninManagerFactory::GetForProfile(browser_->profile())->
- GetAuthenticatedAccountId();
// The account management view is only available with the
// --enable-account-consistency flag.
- bool account_management_available = !primary_account.empty() &&
+ bool account_management_available =
+ SigninManagerFactory::GetForProfile(browser_->profile())->
+ IsAuthenticated() &&
switches::IsEnableAccountConsistency();
ShowView(account_management_available ?
profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc
index 1d41103..ff649cd 100644
--- a/chrome/browser/ui/webui/options/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options/browser_options_handler.cc
@@ -1389,8 +1389,7 @@ BrowserOptionsHandler::GetSyncStateDictionary() {
sync_status->SetBoolean("hasError", status_has_error);
sync_status->SetBoolean("managed", service && service->IsManaged());
- sync_status->SetBoolean("signedIn",
- !signin->GetAuthenticatedUsername().empty());
+ sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
sync_status->SetBoolean("hasUnrecoverableError",
service && service->HasUnrecoverableError());
diff --git a/chrome/browser/ui/webui/options/options_ui_browsertest.cc b/chrome/browser/ui/webui/options/options_ui_browsertest.cc
index 9227db6..c8ff39a 100644
--- a/chrome/browser/ui/webui/options/options_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/options/options_ui_browsertest.cc
@@ -285,7 +285,7 @@ IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, VerifyUnmanagedSignout) {
sign_out_waiter.Wait();
EXPECT_TRUE(browser()->profile()->GetProfileName() != user);
- EXPECT_TRUE(signin->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(signin->IsAuthenticated());
}
// Regression test for http://crbug.com/301436, excluded on Chrome OS because
diff --git a/chrome/browser/ui/webui/options/supervised_user_import_handler.cc b/chrome/browser/ui/webui/options/supervised_user_import_handler.cc
index 93039f8..f3cbf11 100644
--- a/chrome/browser/ui/webui/options/supervised_user_import_handler.cc
+++ b/chrome/browser/ui/webui/options/supervised_user_import_handler.cc
@@ -220,7 +220,7 @@ bool SupervisedUserImportHandler::IsAccountConnected() const {
Profile* profile = Profile::FromWebUI(web_ui());
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
- return signin_manager && !signin_manager->GetAuthenticatedUsername().empty();
+ return signin_manager && signin_manager->IsAuthenticated();
}
bool SupervisedUserImportHandler::HasAuthError() const {
diff --git a/chrome/browser/ui/webui/sync_setup_handler.cc b/chrome/browser/ui/webui/sync_setup_handler.cc
index c588e41..60104ec 100644
--- a/chrome/browser/ui/webui/sync_setup_handler.cc
+++ b/chrome/browser/ui/webui/sync_setup_handler.cc
@@ -310,8 +310,8 @@ void SyncSetupHandler::GetStaticLocalizedValues(
void SyncSetupHandler::DisplayConfigureSync(bool show_advanced,
bool passphrase_failed) {
// Should never call this when we are not signed in.
- DCHECK(!SigninManagerFactory::GetForProfile(
- GetProfile())->GetAuthenticatedUsername().empty());
+ DCHECK(SigninManagerFactory::GetForProfile(
+ GetProfile())->IsAuthenticated());
ProfileSyncService* service = GetSyncService();
DCHECK(service);
if (!service->sync_initialized()) {
@@ -520,9 +520,8 @@ void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() {
// re-auth scenario, and we need to ensure that the user signs in with the
// same email address.
GURL url;
- std::string email = SigninManagerFactory::GetForProfile(
- browser->profile())->GetAuthenticatedUsername();
- if (!email.empty()) {
+ if (SigninManagerFactory::GetForProfile(
+ browser->profile())->IsAuthenticated()) {
UMA_HISTOGRAM_ENUMERATION("Signin.Reauth",
signin::HISTOGRAM_SHOWN,
signin::HISTOGRAM_MAX);
@@ -768,7 +767,7 @@ void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(GetProfile());
- if (signin->GetAuthenticatedUsername().empty()) {
+ if (!signin->IsAuthenticated()) {
// For web-based signin, the signin page is not displayed in an overlay
// on the settings page. So if we get here, it must be due to the user
// cancelling signin (by reloading the sync settings page during initial
@@ -806,8 +805,8 @@ void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
#if !defined(OS_CHROMEOS)
void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) {
// Should only be called if the user is not already signed in.
- DCHECK(SigninManagerFactory::GetForProfile(GetProfile())->
- GetAuthenticatedUsername().empty());
+ DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())->
+ IsAuthenticated());
OpenSyncSetup();
}
@@ -886,8 +885,7 @@ void SyncSetupHandler::OpenSyncSetup() {
// There are several different UI flows that can bring the user here:
// 1) Signin promo.
- // 2) Normal signin through settings page (GetAuthenticatedUsername() is
- // empty).
+ // 2) Normal signin through settings page (IsAuthenticated() is false).
// 3) Previously working credentials have expired.
// 4) User is signed in, but has stopped sync via the google dashboard, and
// signout is prohibited by policy so we need to force a re-auth.
@@ -900,7 +898,7 @@ void SyncSetupHandler::OpenSyncSetup() {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(GetProfile());
- if (signin->GetAuthenticatedUsername().empty() ||
+ if (!signin->IsAuthenticated() ||
ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile())->
signin_error_controller()->HasError()) {
// User is not logged in (cases 1-2), or login has been specially requested
diff --git a/components/signin/core/browser/about_signin_internals.cc b/components/signin/core/browser/about_signin_internals.cc
index 01f5782..86db713 100644
--- a/components/signin/core/browser/about_signin_internals.cc
+++ b/components/signin/core/browser/about_signin_internals.cc
@@ -165,7 +165,7 @@ void AboutSigninInternals::RefreshSigninPrefs() {
// (as seen in the AboutSigninInternalsFactory) the SigninManager can have
// the AuthenticatedUsername set before AboutSigninInternals can observe it.
// For that scenario, read the AuthenticatedUsername if it exists.
- if (!signin_manager_->GetAuthenticatedUsername().empty()) {
+ if (signin_manager_->IsAuthenticated()) {
signin_status_.untimed_signin_fields[USERNAME] =
signin_manager_->GetAuthenticatedUsername();
}
diff --git a/components/signin/core/browser/account_reconcilor.cc b/components/signin/core/browser/account_reconcilor.cc
index 8b2932a..d60482e 100644
--- a/components/signin/core/browser/account_reconcilor.cc
+++ b/components/signin/core/browser/account_reconcilor.cc
@@ -312,7 +312,7 @@ void AccountReconcilor::UnregisterWithTokenService() {
}
bool AccountReconcilor::IsProfileConnected() {
- return !signin_manager_->GetAuthenticatedUsername().empty();
+ return signin_manager_->IsAuthenticated();
}
void AccountReconcilor::OnCookieChanged(const net::CanonicalCookie* cookie) {
@@ -531,7 +531,7 @@ void AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts(
}
void AccountReconcilor::ValidateAccountsFromTokenService() {
- primary_account_ = signin_manager_->GetAuthenticatedUsername();
+ primary_account_ = signin_manager_->GetAuthenticatedAccountId();
DCHECK(!primary_account_.empty());
chrome_accounts_ = token_service_->GetAccounts();
diff --git a/components/signin/core/browser/signin_manager.cc b/components/signin/core/browser/signin_manager.cc
index 7358cbb..710c21f 100644
--- a/components/signin/core/browser/signin_manager.cc
+++ b/components/signin/core/browser/signin_manager.cc
@@ -131,7 +131,7 @@ void SigninManager::StartSignInWithRefreshToken(
const std::string& username,
const std::string& password,
const OAuthTokenFetchedCallback& callback) {
- DCHECK(GetAuthenticatedUsername().empty() ||
+ DCHECK(!IsAuthenticated() ||
gaia::AreEmailsSame(username, GetAuthenticatedUsername()));
if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password))
@@ -178,7 +178,7 @@ void SigninManager::SignOut(
DCHECK(IsInitialized());
signin_metrics::LogSignout(signout_source_metric);
- if (GetAuthenticatedUsername().empty()) {
+ if (!IsAuthenticated()) {
if (AuthInProgress()) {
// If the user is in the process of signing in, then treat a call to
// SignOut as a cancellation request.
@@ -269,7 +269,7 @@ void SigninManager::Shutdown() {
}
void SigninManager::OnGoogleServicesUsernamePatternChanged() {
- if (!GetAuthenticatedUsername().empty() &&
+ if (IsAuthenticated() &&
!IsAllowedUsername(GetAuthenticatedUsername())) {
// Signed in user is invalid according to the current policy so sign
// the user out.
@@ -351,7 +351,7 @@ void SigninManager::CompletePendingSignin() {
}
DCHECK(!temp_refresh_token_.empty());
- DCHECK(!GetAuthenticatedUsername().empty());
+ DCHECK(IsAuthenticated());
token_service_->UpdateCredentials(GetAuthenticatedUsername(),
temp_refresh_token_);
temp_refresh_token_.clear();
diff --git a/components/signin/core/browser/signin_manager_base.cc b/components/signin/core/browser/signin_manager_base.cc
index 52172e8f..770cf7a 100644
--- a/components/signin/core/browser/signin_manager_base.cc
+++ b/components/signin/core/browser/signin_manager_base.cc
@@ -96,6 +96,10 @@ void SigninManagerBase::clear_authenticated_username() {
authenticated_username_.clear();
}
+bool SigninManagerBase::IsAuthenticated() const {
+ return !GetAuthenticatedAccountId().empty();
+}
+
bool SigninManagerBase::AuthInProgress() const {
// SigninManagerBase never kicks off auth processes itself.
return false;
diff --git a/components/signin/core/browser/signin_manager_base.h b/components/signin/core/browser/signin_manager_base.h
index dc7b672..2d3ca43 100644
--- a/components/signin/core/browser/signin_manager_base.h
+++ b/components/signin/core/browser/signin_manager_base.h
@@ -100,6 +100,9 @@ class SigninManagerBase : public KeyedService {
// (by platform / depending on StartBehavior). Bug 88109.
void SetAuthenticatedUsername(const std::string& username);
+ // Returns true if there is an authenticated user.
+ bool IsAuthenticated() const;
+
// Returns true if there's a signin in progress.
virtual bool AuthInProgress() const;