Commit 1f295e36 authored by rogerta's avatar rogerta Committed by Commit bot

Create a new AccountTrackerService PKS based on the existing AccountTracker.

This CL is one part of the effort to change chrome to use gaiaid instead of
email address as the unique id for an account.

BUG=341408

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=291263

Review URL: https://codereview.chromium.org/425823002

Cr-Commit-Position: refs/heads/master@{#291686}
parent 9c7cf784
...@@ -32,9 +32,9 @@ public class OAuth2TokenServiceIntegrationTest extends ChromeShellTestBase { ...@@ -32,9 +32,9 @@ public class OAuth2TokenServiceIntegrationTest extends ChromeShellTestBase {
private static final Account TEST_ACCOUNT2 = private static final Account TEST_ACCOUNT2 =
AccountManagerHelper.createAccountFromName("bar@gmail.com"); AccountManagerHelper.createAccountFromName("bar@gmail.com");
private static final AccountHolder TEST_ACCOUNT_HOLDER_1 = private static final AccountHolder TEST_ACCOUNT_HOLDER_1 =
AccountHolder.create().account(TEST_ACCOUNT1).build(); AccountHolder.create().account(TEST_ACCOUNT1).alwaysAccept(true).build();
private static final AccountHolder TEST_ACCOUNT_HOLDER_2 = private static final AccountHolder TEST_ACCOUNT_HOLDER_2 =
AccountHolder.create().account(TEST_ACCOUNT2).build(); AccountHolder.create().account(TEST_ACCOUNT2).alwaysAccept(true).build();
private AdvancedMockContext mContext; private AdvancedMockContext mContext;
private OAuth2TokenService mOAuth2TokenService; private OAuth2TokenService mOAuth2TokenService;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h" #include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/signin/about_signin_internals_factory.h" #include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
...@@ -149,6 +150,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -149,6 +150,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#endif #endif
AboutSigninInternalsFactory::GetInstance(); AboutSigninInternalsFactory::GetInstance();
AccountTrackerServiceFactory::GetInstance();
autofill::PersonalDataManagerFactory::GetInstance(); autofill::PersonalDataManagerFactory::GetInstance();
#if defined(ENABLE_BACKGROUND) #if defined(ENABLE_BACKGROUND)
BackgroundContentsServiceFactory::GetInstance(); BackgroundContentsServiceFactory::GetInstance();
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/browser/profiles/startup_task_runner_service.h" #include "chrome/browser/profiles/startup_task_runner_service.h"
#include "chrome/browser/profiles/startup_task_runner_service_factory.h" #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
#include "chrome/browser/signin/account_reconcilor_factory.h" #include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -1013,6 +1014,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile, ...@@ -1013,6 +1014,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
StartupTaskRunnerServiceFactory::GetForProfile(profile)-> StartupTaskRunnerServiceFactory::GetForProfile(profile)->
StartDeferredTaskRunners(); StartDeferredTaskRunners();
AccountTrackerServiceFactory::GetForProfile(profile);
AccountReconcilorFactory::GetForProfile(profile); AccountReconcilorFactory::GetForProfile(profile);
} }
......
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
AccountTrackerServiceFactory::AccountTrackerServiceFactory()
: BrowserContextKeyedServiceFactory(
"AccountTrackerServiceFactory",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
}
AccountTrackerServiceFactory::~AccountTrackerServiceFactory() {
}
// static
AccountTrackerService*
AccountTrackerServiceFactory::GetForProfile(Profile* profile) {
return static_cast<AccountTrackerService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
AccountTrackerServiceFactory* AccountTrackerServiceFactory::GetInstance() {
return Singleton<AccountTrackerServiceFactory>::get();
}
void AccountTrackerServiceFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterListPref(
AccountTrackerService::kAccountInfoPref,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
KeyedService* AccountTrackerServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
AccountTrackerService* service = new AccountTrackerService();
service->Initialize(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
profile->GetPrefs(),
profile->GetRequestContext());
return service;
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_ACCOUNT_TRACKER_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SIGNIN_ACCOUNT_TRACKER_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class AccountTrackerService;
class Profile;
// Singleton that owns all AccountTrackerServices and associates them with
// Profiles. Listens for the Profile's destruction notification and cleans up
// the associated AccountTrackerService.
class AccountTrackerServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
// Returns the instance of AccountTrackerService associated with this
// profile (creating one if none exists). Returns NULL if this profile
// cannot have a AccountTrackerService (for example, if |profile| is
// incognito).
static AccountTrackerService* GetForProfile(Profile* profile);
// Returns an instance of the AccountTrackerServiceFactory singleton.
static AccountTrackerServiceFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<AccountTrackerServiceFactory>;
AccountTrackerServiceFactory();
virtual ~AccountTrackerServiceFactory();
// BrowserContextKeyedServiceFactory implementation.
virtual void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(AccountTrackerServiceFactory);
};
#endif // CHROME_BROWSER_SIGNIN_ACCOUNT_TRACKER_SERVICE_FACTORY_H_
...@@ -1176,6 +1176,8 @@ ...@@ -1176,6 +1176,8 @@
'browser/signin/about_signin_internals_factory.h', 'browser/signin/about_signin_internals_factory.h',
'browser/signin/account_reconcilor_factory.cc', 'browser/signin/account_reconcilor_factory.cc',
'browser/signin/account_reconcilor_factory.h', 'browser/signin/account_reconcilor_factory.h',
'browser/signin/account_tracker_service_factory.cc',
'browser/signin/account_tracker_service_factory.h',
'browser/signin/chrome_signin_client.cc', 'browser/signin/chrome_signin_client.cc',
'browser/signin/chrome_signin_client.h', 'browser/signin/chrome_signin_client.h',
'browser/signin/chrome_signin_client_factory.cc', 'browser/signin/chrome_signin_client_factory.cc',
......
...@@ -180,6 +180,7 @@ ...@@ -180,6 +180,7 @@
'search_provider_logos/logo_cache_unittest.cc', 'search_provider_logos/logo_cache_unittest.cc',
'search_provider_logos/logo_tracker_unittest.cc', 'search_provider_logos/logo_tracker_unittest.cc',
'sessions/serialized_navigation_entry_unittest.cc', 'sessions/serialized_navigation_entry_unittest.cc',
'signin/core/browser/account_tracker_service_unittest.cc',
'signin/core/browser/mutable_profile_oauth2_token_service_unittest.cc', 'signin/core/browser/mutable_profile_oauth2_token_service_unittest.cc',
'signin/core/browser/signin_error_controller_unittest.cc', 'signin/core/browser/signin_error_controller_unittest.cc',
'signin/core/browser/webdata/token_service_table_unittest.cc', 'signin/core/browser/webdata/token_service_table_unittest.cc',
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
'signin/core/browser/account_reconcilor.h', 'signin/core/browser/account_reconcilor.h',
'signin/core/browser/account_service_flag_fetcher.cc', 'signin/core/browser/account_service_flag_fetcher.cc',
'signin/core/browser/account_service_flag_fetcher.h', 'signin/core/browser/account_service_flag_fetcher.h',
'signin/core/browser/account_tracker_service.cc',
'signin/core/browser/account_tracker_service.h',
'signin/core/browser/mutable_profile_oauth2_token_service.cc', 'signin/core/browser/mutable_profile_oauth2_token_service.cc',
'signin/core/browser/mutable_profile_oauth2_token_service.h', 'signin/core/browser/mutable_profile_oauth2_token_service.h',
'signin/core/browser/profile_oauth2_token_service.cc', 'signin/core/browser/profile_oauth2_token_service.cc',
......
This diff is collapsed.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_TRACKER_SERVICE_H_
#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_TRACKER_SERVICE_H_
#include <map>
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "components/keyed_service/core/keyed_service.h"
#include "google_apis/gaia/oauth2_token_service.h"
class AccountInfoFetcher;
class OAuth2TokenService;
class PrefService;
namespace base {
class DictionaryValue;
}
// AccountTrackerService is a KeyedService that retrieves and caches GAIA
// information about Google Accounts.
class AccountTrackerService : public KeyedService,
public OAuth2TokenService::Observer {
public:
// Name of the preference property that persists the account information
// tracked by this service.
static const char kAccountInfoPref[];
// Information about a specific account.
struct AccountInfo {
std::string account_id; // The account ID used by OAuth2TokenService.
std::string gaia;
std::string email;
// TODO(rogerta): eventually this structure will include other information
// about the account, like full name, profile picture URL, etc.
};
// Clients of AccountTrackerService can implement this interface and register
// with AddObserver() to learn about account information changes.
class Observer {
public:
virtual ~Observer() {}
virtual void OnAccountUpdated(const AccountInfo& info) = 0;
virtual void OnAccountRemoved(const AccountInfo& info) = 0;
};
AccountTrackerService();
virtual ~AccountTrackerService();
// KeyedService implementation.
virtual void Shutdown() OVERRIDE;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void Initialize(OAuth2TokenService* token_service,
PrefService* pref_service,
net::URLRequestContextGetter* request_context_getter);
// Returns the list of known accounts and for which gaia IDs
// have been fetched.
std::vector<AccountInfo> GetAccounts() const;
AccountInfo GetAccountInfo(const std::string& account_id);
AccountInfo FindAccountInfoByGaiaId(const std::string& gaia_id);
AccountInfo FindAccountInfoByEmail(const std::string& email);
// Indicates if all user information has been fetched. If the result is false,
// there are still unfininshed fetchers.
virtual bool IsAllUserInfoFetched() const;
private:
friend class AccountInfoFetcher;
// These methods are called by fetchers.
void OnUserInfoFetchSuccess(AccountInfoFetcher* fetcher,
const base::DictionaryValue* user_info);
void OnUserInfoFetchFailure(AccountInfoFetcher* fetcher);
// OAuth2TokenService::Observer implementation.
virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
struct AccountState {
AccountInfo info;
};
void NotifyAccountUpdated(const AccountState& state);
void NotifyAccountRemoved(const AccountState& state);
void StartTrackingAccount(const std::string& account_id);
void StopTrackingAccount(const std::string& account_id);
void StartFetchingUserInfo(const std::string& account_id);
void DeleteFetcher(AccountInfoFetcher* fetcher);
// Load the current state of the account info from the preferences file.
void LoadFromPrefs();
void SaveToPrefs(const AccountState& account);
void RemoveFromPrefs(const AccountState& account);
void LoadFromTokenService();
OAuth2TokenService* token_service_; // Not owned.
PrefService* pref_service_; // Not owned.
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
std::map<std::string, AccountInfoFetcher*> user_info_requests_;
std::map<std::string, AccountState> accounts_;
ObserverList<Observer> observer_list_;
bool shutdown_called_;
DISALLOW_COPY_AND_ASSIGN(AccountTrackerService);
};
#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_TRACKER_SERVICE_H_
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