Index: chrome/browser/signin/signin_account_id_helper.cc |
diff --git a/chrome/browser/signin/signin_account_id_helper.cc b/chrome/browser/signin/signin_account_id_helper.cc |
index 912e4fd80092553fc88c2efda387f24ddc368761..610f88f8a44b95626796a377baf336f122da5f31 100644 |
--- a/chrome/browser/signin/signin_account_id_helper.cc |
+++ b/chrome/browser/signin/signin_account_id_helper.cc |
@@ -5,10 +5,9 @@ |
#include "chrome/browser/signin/signin_account_id_helper.h" |
#include "base/prefs/pref_service.h" |
-#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
-#include "chrome/common/pref_names.h" |
#include "components/signin/core/browser/profile_oauth2_token_service.h" |
+#include "components/signin/core/browser/signin_client.h" |
+#include "components/signin/core/common/signin_pref_names.h" |
#include "google_apis/gaia/gaia_oauth_client.h" |
// TODO(guohui): this class should be moved to a more generic place for reuse. |
@@ -16,7 +15,8 @@ class SigninAccountIdHelper::GaiaIdFetcher |
: public OAuth2TokenService::Consumer, |
public gaia::GaiaOAuthClient::Delegate { |
public: |
- GaiaIdFetcher(Profile* profile, |
+ GaiaIdFetcher(SigninClient* client, |
+ ProfileOAuth2TokenService* token_service, |
SigninManagerBase* signin_manager, |
SigninAccountIdHelper* signin_account_id_helper); |
virtual ~GaiaIdFetcher(); |
@@ -36,7 +36,8 @@ class SigninAccountIdHelper::GaiaIdFetcher |
private: |
void Start(); |
- Profile* profile_; |
+ SigninClient* client_; |
+ ProfileOAuth2TokenService* token_service_; |
SigninManagerBase* signin_manager_; |
SigninAccountIdHelper* signin_account_id_helper_; |
@@ -47,11 +48,13 @@ class SigninAccountIdHelper::GaiaIdFetcher |
}; |
SigninAccountIdHelper::GaiaIdFetcher::GaiaIdFetcher( |
- Profile* profile, |
+ SigninClient* client, |
+ ProfileOAuth2TokenService* token_service, |
SigninManagerBase* signin_manager, |
SigninAccountIdHelper* signin_account_id_helper) |
: OAuth2TokenService::Consumer("gaia_id_fetcher"), |
- profile_(profile), |
+ client_(client), |
+ token_service_(token_service), |
signin_manager_(signin_manager), |
signin_account_id_helper_(signin_account_id_helper) { |
Start(); |
@@ -60,11 +63,9 @@ SigninAccountIdHelper::GaiaIdFetcher::GaiaIdFetcher( |
SigninAccountIdHelper::GaiaIdFetcher::~GaiaIdFetcher() {} |
void SigninAccountIdHelper::GaiaIdFetcher::Start() { |
- ProfileOAuth2TokenService* service = |
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
OAuth2TokenService::ScopeSet scopes; |
scopes.insert("https://www.googleapis.com/auth/userinfo.profile"); |
- login_token_request_ = service->StartRequest( |
+ login_token_request_ = token_service_->StartRequest( |
signin_manager_->GetAuthenticatedAccountId(), scopes, this); |
} |
@@ -75,7 +76,7 @@ void SigninAccountIdHelper::GaiaIdFetcher::OnGetTokenSuccess( |
DCHECK_EQ(request, login_token_request_.get()); |
gaia_oauth_client_.reset( |
- new gaia::GaiaOAuthClient(profile_->GetRequestContext())); |
+ new gaia::GaiaOAuthClient(client_->GetURLRequestContext())); |
const int kMaxGetUserIdRetries = 3; |
gaia_oauth_client_->GetUserId(access_token, kMaxGetUserIdRetries, this); |
@@ -103,39 +104,44 @@ void SigninAccountIdHelper::GaiaIdFetcher::OnNetworkError( |
VLOG(1) << "OnNetworkError " << response_code; |
} |
-SigninAccountIdHelper::SigninAccountIdHelper(Profile* profile, |
- SigninManagerBase* signin_manager) |
- : profile_(profile), signin_manager_(signin_manager) { |
+SigninAccountIdHelper::SigninAccountIdHelper( |
+ SigninClient* client, |
+ ProfileOAuth2TokenService* token_service, |
+ SigninManagerBase* signin_manager) |
+ : client_(client), |
+ token_service_(token_service), |
+ signin_manager_(signin_manager) { |
+ DCHECK(client_); |
+ DCHECK(token_service_); |
DCHECK(signin_manager_); |
signin_manager_->AddObserver(this); |
- ProfileOAuth2TokenService* token_service = |
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
std::string primary_email = signin_manager_->GetAuthenticatedAccountId(); |
if (!primary_email.empty() && |
- token_service->RefreshTokenIsAvailable(primary_email) && |
+ token_service_->RefreshTokenIsAvailable(primary_email) && |
!disable_for_test_) { |
- id_fetcher_.reset(new GaiaIdFetcher(profile_, signin_manager_, this)); |
+ id_fetcher_.reset( |
+ new GaiaIdFetcher(client_, token_service_, signin_manager_, this)); |
} |
- token_service->AddObserver(this); |
+ token_service_->AddObserver(this); |
} |
SigninAccountIdHelper::~SigninAccountIdHelper() { |
signin_manager_->RemoveObserver(this); |
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
- ->RemoveObserver(this); |
+ token_service_->RemoveObserver(this); |
} |
void SigninAccountIdHelper::GoogleSignedOut(const std::string& username) { |
- profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); |
+ client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); |
} |
void SigninAccountIdHelper::OnRefreshTokenAvailable( |
const std::string& account_id) { |
if (account_id == signin_manager_->GetAuthenticatedAccountId()) { |
std::string current_gaia_id = |
- profile_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); |
+ client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); |
if (current_gaia_id.empty() && !disable_for_test_) { |
- id_fetcher_.reset(new GaiaIdFetcher(profile_, signin_manager_, this)); |
+ id_fetcher_.reset( |
+ new GaiaIdFetcher(client_, token_service_, signin_manager_, this)); |
} |
} |
} |
@@ -143,8 +149,8 @@ void SigninAccountIdHelper::OnRefreshTokenAvailable( |
void SigninAccountIdHelper::OnPrimaryAccountIdFetched( |
const std::string& gaia_id) { |
if (!gaia_id.empty()) { |
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, |
- gaia_id); |
+ client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, |
+ gaia_id); |
} |
} |