Commit 30e00dad authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Migrate GAIAInfoUpdateService to use IdentityManager

Also change identity::ClearPrimaryAccount to work on a SigninManager,
so I can use it in tests that have a production SigninManager.

BUG=801971
R=blundell@chromium.org

Change-Id: I49176bd7e50a0e7c208403e276371bf93822fde6
Reviewed-on: https://chromium-review.googlesource.com/1143268
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577521}
parent 1a148103
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
...@@ -39,9 +39,9 @@ const int kMinUpdateIntervalSeconds = 5; ...@@ -39,9 +39,9 @@ const int kMinUpdateIntervalSeconds = 5;
GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile)
: profile_(profile) { : profile_(profile) {
SigninManagerBase* signin_manager = identity::IdentityManager* identity_manager =
SigninManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
signin_manager->AddObserver(this); identity_manager->AddObserver(this);
PrefService* prefs = profile_->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
last_updated_ = base::Time::FromInternalValue( last_updated_ = base::Time::FromInternalValue(
...@@ -55,9 +55,9 @@ GAIAInfoUpdateService::~GAIAInfoUpdateService() { ...@@ -55,9 +55,9 @@ GAIAInfoUpdateService::~GAIAInfoUpdateService() {
void GAIAInfoUpdateService::Update() { void GAIAInfoUpdateService::Update() {
// The user must be logged in. // The user must be logged in.
SigninManagerBase* signin_manager = identity::IdentityManager* identity_manager =
SigninManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
if (!signin_manager->IsAuthenticated()) if (!identity_manager->HasPrimaryAccount())
return; return;
if (profile_image_downloader_) if (profile_image_downloader_)
...@@ -173,9 +173,9 @@ void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { ...@@ -173,9 +173,9 @@ void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) {
void GAIAInfoUpdateService::Shutdown() { void GAIAInfoUpdateService::Shutdown() {
timer_.Stop(); timer_.Stop();
profile_image_downloader_.reset(); profile_image_downloader_.reset();
SigninManagerBase* signin_manager = identity::IdentityManager* identity_manager =
SigninManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
signin_manager->RemoveObserver(this); identity_manager->RemoveObserver(this);
// OK to reset |profile_| pointer here because GAIAInfoUpdateService will not // OK to reset |profile_| pointer here because GAIAInfoUpdateService will not
// access it again. This pointer is also used to implement the delegate for // access it again. This pointer is also used to implement the delegate for
...@@ -208,12 +208,12 @@ void GAIAInfoUpdateService::ScheduleNextUpdate() { ...@@ -208,12 +208,12 @@ void GAIAInfoUpdateService::ScheduleNextUpdate() {
timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update);
} }
void GAIAInfoUpdateService::GoogleSigninSucceeded(const std::string& account_id, void GAIAInfoUpdateService::OnPrimaryAccountSet(
const std::string& username) { const AccountInfo& primary_account_info) {
OnUsernameChanged(username); OnUsernameChanged(primary_account_info.gaia);
} }
void GAIAInfoUpdateService::GoogleSignedOut(const std::string& account_id, void GAIAInfoUpdateService::OnPrimaryAccountCleared(
const std::string& username) { const AccountInfo& previous_primary_account_info) {
OnUsernameChanged(std::string()); OnUsernameChanged(std::string());
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "chrome/browser/profiles/profile_downloader.h" #include "chrome/browser/profiles/profile_downloader.h"
#include "chrome/browser/profiles/profile_downloader_delegate.h" #include "chrome/browser/profiles/profile_downloader_delegate.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/signin_manager.h" #include "services/identity/public/cpp/identity_manager.h"
class Profile; class Profile;
class ProfileDownloader; class ProfileDownloader;
...@@ -23,7 +23,7 @@ class ProfileDownloader; ...@@ -23,7 +23,7 @@ class ProfileDownloader;
// The results are saved in the profile info cache. // The results are saved in the profile info cache.
class GAIAInfoUpdateService : public KeyedService, class GAIAInfoUpdateService : public KeyedService,
public ProfileDownloaderDelegate, public ProfileDownloaderDelegate,
public SigninManagerBase::Observer { public identity::IdentityManager::Observer {
public: public:
explicit GAIAInfoUpdateService(Profile* profile); explicit GAIAInfoUpdateService(Profile* profile);
~GAIAInfoUpdateService() override; ~GAIAInfoUpdateService() override;
...@@ -54,11 +54,10 @@ class GAIAInfoUpdateService : public KeyedService, ...@@ -54,11 +54,10 @@ class GAIAInfoUpdateService : public KeyedService,
void OnUsernameChanged(const std::string& username); void OnUsernameChanged(const std::string& username);
void ScheduleNextUpdate(); void ScheduleNextUpdate();
// Overridden from SigninManagerBase::Observer: // Overridden from identity::IdentityManager::Observer:
void GoogleSigninSucceeded(const std::string& account_id, void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override;
const std::string& username) override; void OnPrimaryAccountCleared(
void GoogleSignedOut(const std::string& account_id, const AccountInfo& previous_primary_account_info) override;
const std::string& username) override;
Profile* profile_; Profile* profile_;
std::unique_ptr<ProfileDownloader> profile_image_downloader_; std::unique_ptr<ProfileDownloader> profile_image_downloader_;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "chrome/browser/profiles/gaia_info_update_service.h" #include "chrome/browser/profiles/gaia_info_update_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
...@@ -15,7 +15,7 @@ GAIAInfoUpdateServiceFactory::GAIAInfoUpdateServiceFactory() ...@@ -15,7 +15,7 @@ GAIAInfoUpdateServiceFactory::GAIAInfoUpdateServiceFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"GAIAInfoUpdateService", "GAIAInfoUpdateService",
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(SigninManagerFactory::GetInstance()); DependsOn(IdentityManagerFactory::GetInstance());
} }
GAIAInfoUpdateServiceFactory::~GAIAInfoUpdateServiceFactory() {} GAIAInfoUpdateServiceFactory::~GAIAInfoUpdateServiceFactory() {}
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/test_signin_client_builder.h" #include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/signin_pref_names.h" #include "components/signin/core/browser/signin_pref_names.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_unittest_util.h" #include "ui/gfx/image/image_unittest_util.h"
...@@ -87,9 +89,9 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { ...@@ -87,9 +89,9 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
Profile* CreateProfile(const std::string& name) { Profile* CreateProfile(const std::string& name) {
TestingProfile::TestingFactories testing_factories; TestingProfile::TestingFactories testing_factories;
testing_factories.push_back(std::make_pair( testing_factories.push_back(
ChromeSigninClientFactory::GetInstance(), std::make_pair(ChromeSigninClientFactory::GetInstance(),
signin::BuildTestSigninClient)); signin::BuildTestSigninClient));
Profile* profile = testing_profile_manager_.CreateTestingProfile( Profile* profile = testing_profile_manager_.CreateTestingProfile(
name, std::unique_ptr<sync_preferences::PrefServiceSyncable>(), name, std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
base::UTF8ToUTF16(name), 0, std::string(), testing_factories); base::UTF8ToUTF16(name), 0, std::string(), testing_factories);
...@@ -301,9 +303,9 @@ TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { ...@@ -301,9 +303,9 @@ TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
TEST_F(GAIAInfoUpdateServiceTest, LogOut) { TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
SigninManager* signin_manager = identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
SigninManagerFactory::GetForProfile(profile()); IdentityManagerFactory::GetForProfile(profile()),
signin_manager->SetAuthenticatedAccountInfo("gaia_id", "pat@example.com"); "pat@example.com");
base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo");
ASSERT_EQ(1u, storage()->GetNumberOfProfiles()); ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
...@@ -319,8 +321,9 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) { ...@@ -319,8 +321,9 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
EXPECT_FALSE(service()->GetCachedPictureURL().empty()); EXPECT_FALSE(service()->GetCachedPictureURL().empty());
// Log out. // Log out.
signin_manager->SignOut(signin_metrics::SIGNOUT_TEST, identity::ClearPrimaryAccount(
signin_metrics::SignoutDelete::IGNORE_METRIC); SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()));
// Verify that the GAIA name and picture, and picture URL are unset. // Verify that the GAIA name and picture, and picture URL are unset.
EXPECT_TRUE(entry->GetGAIAName().empty()); EXPECT_TRUE(entry->GetGAIAName().empty());
EXPECT_EQ(nullptr, entry->GetGAIAPicture()); EXPECT_EQ(nullptr, entry->GetGAIAPicture());
...@@ -330,11 +333,9 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) { ...@@ -330,11 +333,9 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
TEST_F(GAIAInfoUpdateServiceTest, LogIn) { TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
// Log in. // Log in.
EXPECT_CALL(*service(), Update()); EXPECT_CALL(*service(), Update());
AccountTrackerServiceFactory::GetForProfile(profile()) identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
->SeedAccountInfo("gaia_id", "pat@example.com"); IdentityManagerFactory::GetForProfile(profile()),
SigninManager* signin_manager = "pat@example.com");
SigninManagerFactory::GetForProfile(profile());
signin_manager->OnExternalSigninCompleted("pat@example.com");
} }
#endif #endif
...@@ -194,7 +194,7 @@ AccountInfo MakePrimaryAccountAvailable( ...@@ -194,7 +194,7 @@ AccountInfo MakePrimaryAccountAvailable(
return account_info; return account_info;
} }
void ClearPrimaryAccount(SigninManagerForTest* signin_manager, void ClearPrimaryAccount(SigninManagerBase* signin_manager,
IdentityManager* identity_manager) { IdentityManager* identity_manager) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// TODO(blundell): If we ever need this functionality on ChromeOS (which seems // TODO(blundell): If we ever need this functionality on ChromeOS (which seems
...@@ -209,7 +209,10 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager, ...@@ -209,7 +209,10 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager,
identity_manager, run_loop.QuitClosure(), identity_manager, run_loop.QuitClosure(),
IdentityManagerEvent::PRIMARY_ACCOUNT_CLEARED); IdentityManagerEvent::PRIMARY_ACCOUNT_CLEARED);
signin_manager->ForceSignOut(); SigninManager* real_signin_manager =
SigninManager::FromSigninManagerBase(signin_manager);
real_signin_manager->SignOut(signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
run_loop.Run(); run_loop.Run();
#endif #endif
......
...@@ -79,11 +79,7 @@ AccountInfo MakePrimaryAccountAvailable( ...@@ -79,11 +79,7 @@ AccountInfo MakePrimaryAccountAvailable(
// Clears the primary account. On non-ChromeOS, results in the firing of the // Clears the primary account. On non-ChromeOS, results in the firing of the
// IdentityManager and SigninManager callbacks for signout. Blocks until the // IdentityManager and SigninManager callbacks for signout. Blocks until the
// primary account is cleared. // primary account is cleared.
// Note that this function requires FakeSigninManager, as it internally invokes void ClearPrimaryAccount(SigninManagerBase* signin_manager,
// functionality of the fake. If a use case emerges for invoking this
// functionality with a production SigninManager, contact blundell@chromium.org.
// NOTE: See disclaimer at top of file re: direct usage.
void ClearPrimaryAccount(SigninManagerForTest* signin_manager,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Makes an account available for the given email address, generating a GAIA ID // Makes an account available for the given email address, generating a GAIA ID
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment