summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 15:48:10 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 15:48:10 +0000
commitb47dbc3e7ef0bd0145d83ca4ac8bb7bc76a4d5a9 (patch)
treedad4f1d03572895e81bfecf151437a51f331a595
parentf48405e6b24e0e737be3aa2df1f13b6d9334e979 (diff)
downloadchromium_src-b47dbc3e7ef0bd0145d83ca4ac8bb7bc76a4d5a9.zip
chromium_src-b47dbc3e7ef0bd0145d83ca4ac8bb7bc76a4d5a9.tar.gz
chromium_src-b47dbc3e7ef0bd0145d83ca4ac8bb7bc76a4d5a9.tar.bz2
Componentize AccountReconcilor.
This CL does the following: - Componentize SigninOAuthHelper - Replaces AccountReconcilor's calls to Profile with calls to SigninClient - Passes AccountReconcilor's dependencies in directly rather than having AccountReconcilor obtain them from factories via the Profile - Componentizes AccountReconcilor BUG=334196,333999 Review URL: https://codereview.chromium.org/219933002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261422 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/signin/account_reconcilor_factory.cc4
-rw-r--r--chrome/browser/signin/account_reconcilor_factory.h2
-rw-r--r--chrome/browser/signin/account_reconcilor_unittest.cc22
-rw-r--r--chrome/browser/signin/signin_tracker.cc2
-rw-r--r--chrome/browser/ui/sync/one_click_signin_helper.h2
-rw-r--r--chrome/browser/ui/webui/signin/inline_login_handler_impl.cc2
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--components/signin.gypi4
-rw-r--r--components/signin/core/browser/account_reconcilor.cc (renamed from chrome/browser/signin/account_reconcilor.cc)181
-rw-r--r--components/signin/core/browser/account_reconcilor.h (renamed from chrome/browser/signin/account_reconcilor.h)46
-rw-r--r--components/signin/core/browser/signin_oauth_helper.cc (renamed from chrome/browser/signin/signin_oauth_helper.cc)11
-rw-r--r--components/signin/core/browser/signin_oauth_helper.h (renamed from chrome/browser/signin/signin_oauth_helper.h)20
12 files changed, 146 insertions, 154 deletions
diff --git a/chrome/browser/signin/account_reconcilor_factory.cc b/chrome/browser/signin/account_reconcilor_factory.cc
index 7270665..a70a9b3 100644
--- a/chrome/browser/signin/account_reconcilor_factory.cc
+++ b/chrome/browser/signin/account_reconcilor_factory.cc
@@ -37,7 +37,9 @@ KeyedService* AccountReconcilorFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
AccountReconcilor* reconcilor = new AccountReconcilor(
- profile, ChromeSigninClientFactory::GetForProfile(profile));
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
+ SigninManagerFactory::GetForProfile(profile),
+ ChromeSigninClientFactory::GetForProfile(profile));
reconcilor->Initialize(true /* start_reconcile_if_tokens_available */);
return reconcilor;
}
diff --git a/chrome/browser/signin/account_reconcilor_factory.h b/chrome/browser/signin/account_reconcilor_factory.h
index e27c4c2..48025c6 100644
--- a/chrome/browser/signin/account_reconcilor_factory.h
+++ b/chrome/browser/signin/account_reconcilor_factory.h
@@ -6,8 +6,8 @@
#define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_FACTORY_H_
#include "base/memory/singleton.h"
-#include "chrome/browser/signin/account_reconcilor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+#include "components/signin/core/browser/account_reconcilor.h"
class AccountReconcilor;
class Profile;
diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc
index 3fd7345d..ca312d5 100644
--- a/chrome/browser/signin/account_reconcilor_unittest.cc
+++ b/chrome/browser/signin/account_reconcilor_unittest.cc
@@ -5,7 +5,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/time/time.h"
-#include "chrome/browser/signin/account_reconcilor.h"
#include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
@@ -14,6 +13,7 @@
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
@@ -30,7 +30,9 @@ class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
public:
static KeyedService* Build(content::BrowserContext* context);
- explicit MockAccountReconcilor(Profile* profile, SigninClient* client);
+ MockAccountReconcilor(ProfileOAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ SigninClient* client);
virtual ~MockAccountReconcilor() {}
MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id));
@@ -49,14 +51,20 @@ class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
AccountReconcilor* reconcilor = new MockAccountReconcilor(
- profile, ChromeSigninClientFactory::GetForProfile(profile));
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
+ SigninManagerFactory::GetForProfile(profile),
+ ChromeSigninClientFactory::GetForProfile(profile));
reconcilor->Initialize(false /* start_reconcile_if_tokens_available */);
return reconcilor;
}
-MockAccountReconcilor::MockAccountReconcilor(Profile* profile,
- SigninClient* client)
- : testing::StrictMock<AccountReconcilor>(profile, client) {}
+MockAccountReconcilor::MockAccountReconcilor(
+ ProfileOAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ SigninClient* client)
+ : testing::StrictMock<AccountReconcilor>(token_service,
+ signin_manager,
+ client) {}
} // namespace
@@ -156,7 +164,7 @@ TEST_F(AccountReconcilorTest, Basic) {
AccountReconcilor* reconcilor =
AccountReconcilorFactory::GetForProfile(profile());
ASSERT_TRUE(reconcilor);
- ASSERT_EQ(profile(), reconcilor->profile());
+ ASSERT_EQ(token_service(), reconcilor->token_service());
}
#if !defined(OS_CHROMEOS)
diff --git a/chrome/browser/signin/signin_tracker.cc b/chrome/browser/signin/signin_tracker.cc
index 281bc6c..a8e3026 100644
--- a/chrome/browser/signin/signin_tracker.cc
+++ b/chrome/browser/signin/signin_tracker.cc
@@ -4,7 +4,7 @@
#include "chrome/browser/signin/signin_tracker.h"
-#include "chrome/browser/signin/account_reconcilor.h"
+#include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_client.h"
#include "google_apis/gaia/gaia_constants.h"
diff --git a/chrome/browser/ui/sync/one_click_signin_helper.h b/chrome/browser/ui/sync/one_click_signin_helper.h
index e566edb..f966c6e 100644
--- a/chrome/browser/ui/sync/one_click_signin_helper.h
+++ b/chrome/browser/ui/sync/one_click_signin_helper.h
@@ -9,10 +9,10 @@
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/signin/signin_oauth_helper.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
+#include "components/signin/core/browser/signin_oauth_helper.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
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 db7cddc..5ab044a 100644
--- a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc
+++ b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc
@@ -14,7 +14,6 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
-#include "chrome/browser/signin/signin_oauth_helper.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -26,6 +25,7 @@
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
+#include "components/signin/core/browser/signin_oauth_helper.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 329c646..998285d 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2093,8 +2093,6 @@
'browser/shell_integration_win.cc',
'browser/signin/about_signin_internals_factory.cc',
'browser/signin/about_signin_internals_factory.h',
- 'browser/signin/account_reconcilor.cc',
- 'browser/signin/account_reconcilor.h',
'browser/signin/account_reconcilor_factory.cc',
'browser/signin/account_reconcilor_factory.h',
'browser/signin/chrome_signin_client.cc',
@@ -2123,8 +2121,6 @@
'browser/signin/signin_manager_factory.h',
'browser/signin/signin_names_io_thread.cc',
'browser/signin/signin_names_io_thread.h',
- 'browser/signin/signin_oauth_helper.cc',
- 'browser/signin/signin_oauth_helper.h',
'browser/signin/signin_header_helper.cc',
'browser/signin/signin_header_helper.h',
'browser/signin/signin_tracker.cc',
diff --git a/components/signin.gypi b/components/signin.gypi
index 2e809ce..0d197b1 100644
--- a/components/signin.gypi
+++ b/components/signin.gypi
@@ -39,6 +39,8 @@
'sources': [
'signin/core/browser/about_signin_internals.cc',
'signin/core/browser/about_signin_internals.h',
+ 'signin/core/browser/account_reconcilor.cc',
+ 'signin/core/browser/account_reconcilor.h',
'signin/core/browser/mutable_profile_oauth2_token_service.cc',
'signin/core/browser/mutable_profile_oauth2_token_service.h',
'signin/core/browser/profile_oauth2_token_service.cc',
@@ -56,6 +58,8 @@
'signin/core/browser/signin_manager.h',
'signin/core/browser/signin_manager_cookie_helper.cc',
'signin/core/browser/signin_manager_cookie_helper.h',
+ 'signin/core/browser/signin_oauth_helper.cc',
+ 'signin/core/browser/signin_oauth_helper.h',
'signin/core/browser/webdata/token_service_table.cc',
'signin/core/browser/webdata/token_service_table.h',
'signin/core/browser/webdata/token_web_data.cc',
diff --git a/chrome/browser/signin/account_reconcilor.cc b/components/signin/core/browser/account_reconcilor.cc
index 7c1afba..9725b0b 100644
--- a/chrome/browser/signin/account_reconcilor.cc
+++ b/components/signin/core/browser/account_reconcilor.cc
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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.
-#include "chrome/browser/signin/account_reconcilor.h"
+#include "components/signin/core/browser/account_reconcilor.h"
#include <algorithm>
@@ -13,17 +13,15 @@
#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
-#include "chrome/browser/signin/signin_manager_factory.h"
-#include "chrome/browser/signin/signin_oauth_helper.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_client.h"
+#include "components/signin/core/browser/signin_oauth_helper.h"
#include "google_apis/gaia/gaia_auth_fetcher.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/gaia_urls.h"
+#include "net/cookies/canonical_cookie.h"
// Fetches a refresh token from the given session in the GAIA cookie. This is
// a best effort only. If it should fail, another reconcile action will occur
@@ -59,8 +57,9 @@ AccountReconcilor::RefreshTokenFetcher::RefreshTokenFetcher(
AccountReconcilor* reconcilor,
const std::string& account_id,
int session_index)
- : SigninOAuthHelper(reconcilor->profile()->GetRequestContext(),
- base::IntToString(session_index), this),
+ : SigninOAuthHelper(reconcilor->client()->GetURLRequestContext(),
+ base::IntToString(session_index),
+ this),
reconcilor_(reconcilor),
account_id_(account_id),
session_index_(session_index) {
@@ -69,12 +68,11 @@ AccountReconcilor::RefreshTokenFetcher::RefreshTokenFetcher(
}
void AccountReconcilor::RefreshTokenFetcher::OnSigninOAuthInformationAvailable(
- const std::string& email,
- const std::string& display_email,
- const std::string& refresh_token) {
+ const std::string& email,
+ const std::string& display_email,
+ const std::string& refresh_token) {
VLOG(1) << "RefreshTokenFetcher::OnSigninOAuthInformationAvailable:"
- << " account=" << account_id_
- << " email=" << email
+ << " account=" << account_id_ << " email=" << email
<< " displayEmail=" << display_email;
// TODO(rogerta): because of the problem with email vs displayEmail and
@@ -87,12 +85,10 @@ void AccountReconcilor::RefreshTokenFetcher::OnSigninOAuthInformationAvailable(
void AccountReconcilor::RefreshTokenFetcher::OnSigninOAuthInformationFailure(
const GoogleServiceAuthError& error) {
VLOG(1) << "RefreshTokenFetcher::OnSigninOAuthInformationFailure:"
- << " account=" << account_id_
- << " session_index=" << session_index_;
+ << " account=" << account_id_ << " session_index=" << session_index_;
reconcilor_->HandleRefreshTokenFetched(account_id_, std::string());
}
-
bool AccountReconcilor::EmailLessFunc::operator()(const std::string& s1,
const std::string& s2) const {
return gaia::CanonicalizeEmail(s1) < gaia::CanonicalizeEmail(s2);
@@ -128,7 +124,7 @@ AccountReconcilor::UserIdFetcher::UserIdFetcher(AccountReconcilor* reconcilor,
: reconcilor_(reconcilor),
account_id_(account_id),
access_token_(access_token),
- gaia_auth_client_(reconcilor_->profile()->GetRequestContext()) {
+ gaia_auth_client_(reconcilor_->client()->GetURLRequestContext()) {
DCHECK(reconcilor_);
DCHECK(!account_id_.empty());
@@ -155,9 +151,8 @@ void AccountReconcilor::UserIdFetcher::OnOAuthError() {
VLOG(1) << "AccountReconcilor::OnOAuthError: " << account_id_;
// Invalidate the access token to force a refetch next time.
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(reconcilor_->profile());
- token_service->InvalidateToken(account_id_, GetScopes(), access_token_);
+ reconcilor_->token_service()->InvalidateToken(
+ account_id_, GetScopes(), access_token_);
// HandleFailedAccountIdCheck() may delete |this|, so call it last.
reconcilor_->HandleFailedAccountIdCheck(account_id_);
@@ -173,14 +168,16 @@ void AccountReconcilor::UserIdFetcher::OnNetworkError(int response_code) {
reconcilor_->HandleFailedAccountIdCheck(account_id_);
}
-AccountReconcilor::AccountReconcilor(Profile* profile, SigninClient* client)
+AccountReconcilor::AccountReconcilor(ProfileOAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ SigninClient* client)
: OAuth2TokenService::Consumer("account_reconcilor"),
- profile_(profile),
+ token_service_(token_service),
+ signin_manager_(signin_manager),
client_(client),
- merge_session_helper_(
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
- profile->GetRequestContext(),
- this),
+ merge_session_helper_(token_service_,
+ client->GetURLRequestContext(),
+ this),
registered_with_token_service_(false),
is_reconcile_started_(false),
are_gaia_accounts_set_(false),
@@ -202,18 +199,16 @@ void AccountReconcilor::Initialize(bool start_reconcile_if_tokens_available) {
VLOG(1) << "AccountReconcilor::Initialize";
RegisterWithSigninManager();
- // If this profile is not connected, the reconcilor should do nothing but
- // wait for the connection.
+ // If this user is not signed in, the reconcilor should do nothing but
+ // wait for signin.
if (IsProfileConnected()) {
RegisterForCookieChanges();
RegisterWithTokenService();
StartPeriodicReconciliation();
// Start a reconcile if the tokens are already loaded.
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
if (start_reconcile_if_tokens_available &&
- token_service->GetAccounts().size() > 0) {
+ token_service_->GetAccounts().size() > 0) {
StartReconcile();
}
}
@@ -251,7 +246,7 @@ void AccountReconcilor::DeleteFetchers() {
bool AccountReconcilor::AreAllRefreshTokensChecked() const {
return chrome_accounts_.size() ==
- (valid_chrome_accounts_.size() + invalid_chrome_accounts_.size());
+ (valid_chrome_accounts_.size() + invalid_chrome_accounts_.size());
}
void AccountReconcilor::RegisterForCookieChanges() {
@@ -267,15 +262,11 @@ void AccountReconcilor::UnregisterForCookieChanges() {
}
void AccountReconcilor::RegisterWithSigninManager() {
- SigninManagerBase* signin_manager =
- SigninManagerFactory::GetForProfile(profile_);
- signin_manager->AddObserver(this);
+ signin_manager_->AddObserver(this);
}
void AccountReconcilor::UnregisterWithSigninManager() {
- SigninManagerBase* signin_manager =
- SigninManagerFactory::GetForProfile(profile_);
- signin_manager->RemoveObserver(this);
+ signin_manager_->RemoveObserver(this);
}
void AccountReconcilor::RegisterWithTokenService() {
@@ -286,9 +277,7 @@ void AccountReconcilor::RegisterWithTokenService() {
if (registered_with_token_service_)
return;
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
- token_service->AddObserver(this);
+ token_service_->AddObserver(this);
registered_with_token_service_ = true;
}
@@ -296,25 +285,21 @@ void AccountReconcilor::UnregisterWithTokenService() {
if (!registered_with_token_service_)
return;
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
- token_service->RemoveObserver(this);
+ token_service_->RemoveObserver(this);
registered_with_token_service_ = false;
}
bool AccountReconcilor::IsProfileConnected() {
- return !SigninManagerFactory::GetForProfile(profile_)->
- GetAuthenticatedUsername().empty();
+ return !signin_manager_->GetAuthenticatedUsername().empty();
}
void AccountReconcilor::StartPeriodicReconciliation() {
VLOG(1) << "AccountReconcilor::StartPeriodicReconciliation";
// TODO(rogerta): pick appropriate thread and timeout value.
- reconciliation_timer_.Start(
- FROM_HERE,
- base::TimeDelta::FromSeconds(300),
- this,
- &AccountReconcilor::PeriodicReconciliation);
+ reconciliation_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(300),
+ this,
+ &AccountReconcilor::PeriodicReconciliation);
}
void AccountReconcilor::StopPeriodicReconciliation() {
@@ -335,9 +320,7 @@ void AccountReconcilor::OnCookieChanged(const net::CanonicalCookie* cookie) {
#ifdef OS_CHROMEOS
// On Chrome OS it is possible that O2RT is not available at this moment
// because profile data transfer is still in progress.
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
- if (!token_service->GetAccounts().size()) {
+ if (!token_service_->GetAccounts().size()) {
VLOG(1) << "AccountReconcilor::OnCookieChanged: cookie change is ingored"
"because profile data transfer is in progress.";
return;
@@ -359,8 +342,8 @@ void AccountReconcilor::OnRefreshTokenRevoked(const std::string& account_id) {
void AccountReconcilor::OnRefreshTokensLoaded() {}
-void AccountReconcilor::GoogleSigninSucceeded(
- const std::string& username, const std::string& password) {
+void AccountReconcilor::GoogleSigninSucceeded(const std::string& username,
+ const std::string& password) {
VLOG(1) << "AccountReconcilor::GoogleSigninSucceeded: signed in";
RegisterForCookieChanges();
RegisterWithTokenService();
@@ -381,10 +364,9 @@ void AccountReconcilor::PerformMergeAction(const std::string& account_id) {
void AccountReconcilor::StartRemoveAction(const std::string& account_id) {
VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id;
- GetAccountsFromCookie(
- base::Bind(&AccountReconcilor::FinishRemoveAction,
- base::Unretained(this),
- account_id));
+ GetAccountsFromCookie(base::Bind(&AccountReconcilor::FinishRemoveAction,
+ base::Unretained(this),
+ account_id));
}
void AccountReconcilor::FinishRemoveAction(
@@ -392,13 +374,14 @@ void AccountReconcilor::FinishRemoveAction(
const GoogleServiceAuthError& error,
const std::vector<std::pair<std::string, bool> >& accounts) {
VLOG(1) << "AccountReconcilor::FinishRemoveAction:"
- << " account=" << account_id
- << " error=" << error.ToString();
+ << " account=" << account_id << " error=" << error.ToString();
if (error.state() == GoogleServiceAuthError::NONE) {
AbortReconcile();
std::vector<std::string> accounts_only;
for (std::vector<std::pair<std::string, bool> >::const_iterator i =
- accounts.begin(); i != accounts.end(); ++i) {
+ accounts.begin();
+ i != accounts.end();
+ ++i) {
accounts_only.push_back(i->first);
}
merge_session_helper_.LogOut(account_id, accounts_only);
@@ -406,12 +389,10 @@ void AccountReconcilor::FinishRemoveAction(
// Wait for the next ReconcileAction if there is an error.
}
-void AccountReconcilor::PerformAddToChromeAction(
- const std::string& account_id,
- int session_index) {
+void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id,
+ int session_index) {
VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:"
- << " account=" << account_id
- << " session_index=" << session_index;
+ << " account=" << account_id << " session_index=" << session_index;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
refresh_token_fetchers_.push_back(
@@ -435,7 +416,7 @@ void AccountReconcilor::StartReconcile() {
gaia_accounts_.clear();
GetAccountsFromCookie(base::Bind(
&AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts,
- base::Unretained(this)));
+ base::Unretained(this)));
// Reset state for validating oauth2 tokens.
primary_account_.clear();
@@ -453,8 +434,8 @@ void AccountReconcilor::GetAccountsFromCookie(
get_gaia_accounts_callbacks_.push_back(callback);
if (!gaia_fetcher_) {
// There is no list account request in flight.
- gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
- profile_->GetRequestContext()));
+ gaia_fetcher_.reset(new GaiaAuthFetcher(
+ this, GaiaConstants::kChromeSource, client_->GetURLRequestContext()));
gaia_fetcher_->StartListAccounts();
}
}
@@ -478,10 +459,10 @@ void AccountReconcilor::OnListAccountsSuccess(const std::string& data) {
// There must be at least one callback waiting for result.
DCHECK(!get_gaia_accounts_callbacks_.empty());
- GoogleServiceAuthError error = !valid_json
- ? GoogleServiceAuthError(
- GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)
- : GoogleServiceAuthError::AuthErrorNone();
+ GoogleServiceAuthError error =
+ !valid_json ? GoogleServiceAuthError(
+ GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)
+ : GoogleServiceAuthError::AuthErrorNone();
get_gaia_accounts_callbacks_.front().Run(error, gaia_accounts);
get_gaia_accounts_callbacks_.pop_front();
@@ -505,8 +486,8 @@ void AccountReconcilor::OnListAccountsFailure(
void AccountReconcilor::MayBeDoNextListAccounts() {
if (!get_gaia_accounts_callbacks_.empty()) {
- gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
- profile_->GetRequestContext()));
+ gaia_fetcher_.reset(new GaiaAuthFetcher(
+ this, GaiaConstants::kChromeSource, client_->GetURLRequestContext()));
gaia_fetcher_->StartListAccounts();
}
}
@@ -524,13 +505,10 @@ void AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts(
}
void AccountReconcilor::ValidateAccountsFromTokenService() {
- primary_account_ =
- SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername();
+ primary_account_ = signin_manager_->GetAuthenticatedUsername();
DCHECK(!primary_account_.empty());
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
- chrome_accounts_ = token_service->GetAccounts();
+ chrome_accounts_ = token_service_->GetAccounts();
DCHECK_GT(chrome_accounts_.size(), 0u);
VLOG(1) << "AccountReconcilor::ValidateAccountsFromTokenService: "
@@ -543,9 +521,8 @@ void AccountReconcilor::ValidateAccountsFromTokenService() {
const OAuth2TokenService::ScopeSet scopes =
AccountReconcilor::UserIdFetcher::GetScopes();
for (size_t i = 0; i < chrome_accounts_.size(); ++i) {
- requests_[i] = token_service->StartRequest(chrome_accounts_[i],
- scopes,
- this);
+ requests_[i] =
+ token_service_->StartRequest(chrome_accounts_[i], scopes, this);
}
DCHECK_EQ(0u, user_id_fetchers_.size());
@@ -568,8 +545,7 @@ void AccountReconcilor::OnGetTokenSuccess(
VLOG(1) << "AccountReconcilor::OnGetTokenSuccess: valid " << account_id;
DCHECK(!user_id_fetchers_[index]);
- user_id_fetchers_[index] =
- new UserIdFetcher(this, access_token, account_id);
+ user_id_fetchers_[index] = new UserIdFetcher(this, access_token, account_id);
}
void AccountReconcilor::OnGetTokenFailure(
@@ -584,8 +560,7 @@ void AccountReconcilor::OnGetTokenFailure(
const std::string& account_id = chrome_accounts_[index];
- VLOG(1) << "AccountReconcilor::OnGetTokenFailure: invalid "
- << account_id;
+ VLOG(1) << "AccountReconcilor::OnGetTokenFailure: invalid " << account_id;
HandleFailedAccountIdCheck(account_id);
}
@@ -610,15 +585,16 @@ void AccountReconcilor::FinishReconcile() {
for (size_t i = 0; i < gaia_accounts_.size(); ++i) {
const std::string& gaia_account = gaia_accounts_[i].first;
if (gaia_accounts_[i].second &&
- valid_chrome_accounts_.find(gaia_account) ==
- valid_chrome_accounts_.end()) {
+ valid_chrome_accounts_.find(gaia_account) ==
+ valid_chrome_accounts_.end()) {
add_to_chrome_.push_back(std::make_pair(gaia_account, i));
}
}
// Determine if we need to merge accounts from chrome into gaia cookie.
for (EmailSet::const_iterator i = valid_chrome_accounts_.begin();
- i != valid_chrome_accounts_.end(); ++i) {
+ i != valid_chrome_accounts_.end();
+ ++i) {
bool add_to_cookie = true;
for (size_t j = 0; j < gaia_accounts_.size(); ++j) {
if (gaia::AreEmailsSame(gaia_accounts_[j].first, *i)) {
@@ -637,7 +613,8 @@ void AccountReconcilor::FinishReconcile() {
PerformLogoutAllAccountsAction();
add_to_cookie_.push_back(primary_account_);
for (EmailSet::const_iterator i = valid_chrome_accounts_.begin();
- i != valid_chrome_accounts_.end(); ++i) {
+ i != valid_chrome_accounts_.end();
+ ++i) {
if (*i != primary_account_)
add_to_cookie_.push_back(*i);
}
@@ -651,8 +628,9 @@ void AccountReconcilor::FinishReconcile() {
// For each account in the gaia cookie not known to chrome,
// PerformAddToChromeAction.
for (std::vector<std::pair<std::string, int> >::const_iterator i =
- add_to_chrome_.begin();
- i != add_to_chrome_.end(); ++i) {
+ add_to_chrome_.begin();
+ i != add_to_chrome_.end();
+ ++i) {
PerformAddToChromeAction(i->first, i->second);
}
@@ -681,8 +659,7 @@ void AccountReconcilor::ScheduleStartReconcileIfChromeAccountsChanged() {
// Start a reconcile as the token accounts have changed.
VLOG(1) << "AccountReconcilor::StartReconcileIfChromeAccountsChanged";
std::vector<std::string> reconciled_accounts(chrome_accounts_);
- std::vector<std::string> new_chrome_accounts(
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts());
+ std::vector<std::string> new_chrome_accounts(token_service_->GetAccounts());
std::sort(reconciled_accounts.begin(), reconciled_accounts.end());
std::sort(new_chrome_accounts.begin(), new_chrome_accounts.end());
if (reconciled_accounts != new_chrome_accounts) {
@@ -700,7 +677,8 @@ void AccountReconcilor::MergeSessionCompleted(
// Remove the account from the list that is being merged.
for (std::vector<std::string>::iterator i = add_to_cookie_.begin();
- i != add_to_cookie_.end(); ++i) {
+ i != add_to_cookie_.end();
+ ++i) {
if (account_id == *i) {
add_to_cookie_.erase(i);
break;
@@ -727,15 +705,14 @@ void AccountReconcilor::HandleRefreshTokenFetched(
const std::string& account_id,
const std::string& refresh_token) {
if (!refresh_token.empty()) {
- ProfileOAuth2TokenService* token_service =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
- token_service->UpdateCredentials(account_id, refresh_token);
+ token_service_->UpdateCredentials(account_id, refresh_token);
}
// Remove the account from the list that is being updated.
for (std::vector<std::pair<std::string, int> >::iterator i =
add_to_chrome_.begin();
- i != add_to_chrome_.end(); ++i) {
+ i != add_to_chrome_.end();
+ ++i) {
if (gaia::AreEmailsSame(account_id, i->first)) {
add_to_chrome_.erase(i);
break;
diff --git a/chrome/browser/signin/account_reconcilor.h b/components/signin/core/browser/account_reconcilor.h
index f05721c..018dfd2 100644
--- a/chrome/browser/signin/account_reconcilor.h
+++ b/components/signin/core/browser/account_reconcilor.h
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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_RECONCILOR_H_
-#define CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_
+#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
+#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
#include <deque>
#include <functional>
@@ -24,7 +24,7 @@
#include "google_apis/gaia/oauth2_token_service.h"
class GaiaAuthFetcher;
-class Profile;
+class ProfileOAuth2TokenService;
class SigninClient;
class SigninOAuthHelper;
@@ -39,7 +39,9 @@ class AccountReconcilor : public KeyedService,
public OAuth2TokenService::Observer,
public SigninManagerBase::Observer {
public:
- explicit AccountReconcilor(Profile* profile, SigninClient* client);
+ AccountReconcilor(ProfileOAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ SigninClient* client);
virtual ~AccountReconcilor();
void Initialize(bool start_reconcile_if_tokens_available);
@@ -51,7 +53,8 @@ class AccountReconcilor : public KeyedService,
void AddMergeSessionObserver(MergeSessionHelper::Observer* observer);
void RemoveMergeSessionObserver(MergeSessionHelper::Observer* observer);
- Profile* profile() { return profile_; }
+ ProfileOAuth2TokenService* token_service() { return token_service_; }
+ SigninClient* client() { return client_; }
private:
// An std::set<> for use with email addresses that uses
@@ -82,8 +85,8 @@ class AccountReconcilor : public KeyedService,
bool AreAllRefreshTokensChecked() const;
- const std::vector<std::pair<std::string, bool> >&
- GetGaiaAccountsForTesting() const {
+ const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting()
+ const {
return gaia_accounts_;
}
@@ -97,10 +100,10 @@ class AccountReconcilor : public KeyedService,
// Used during GetAccountsFromCookie.
// Stores a callback for the next action to perform.
- typedef base::Callback<void(
- const GoogleServiceAuthError& error,
- const std::vector<std::pair<std::string, bool> >&)>
- GetAccountsFromCookieCallback;
+ typedef base::Callback<
+ void(const GoogleServiceAuthError& error,
+ const std::vector<std::pair<std::string, bool> >&)>
+ GetAccountsFromCookieCallback;
friend class AccountReconcilorTest;
FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration);
@@ -175,13 +178,13 @@ class AccountReconcilor : public KeyedService,
// Overriden from GaiaAuthConsumer.
virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
- virtual void OnListAccountsFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
+ virtual void OnListAccountsFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
// Overriden from MergeSessionHelper::Observer.
- virtual void MergeSessionCompleted(
- const std::string& account_id,
- const GoogleServiceAuthError& error) OVERRIDE;
+ virtual void MergeSessionCompleted(const std::string& account_id,
+ const GoogleServiceAuthError& error)
+ OVERRIDE;
// Overriden from OAuth2TokenService::Consumer.
virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
@@ -202,8 +205,11 @@ class AccountReconcilor : public KeyedService,
void MayBeDoNextListAccounts();
- // The profile that this reconcilor belongs to.
- Profile* profile_;
+ // The ProfileOAuth2TokenService associated with this reconcilor.
+ ProfileOAuth2TokenService* token_service_;
+
+ // The SigninManager associated with this reconcilor.
+ SigninManagerBase* signin_manager_;
// The SigninClient associated with this reconcilor.
SigninClient* client_;
@@ -243,4 +249,4 @@ class AccountReconcilor : public KeyedService,
DISALLOW_COPY_AND_ASSIGN(AccountReconcilor);
};
-#endif // CHROME_BROWSER_SIGNIN_ACCOUNT_RECONCILOR_H_
+#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
diff --git a/chrome/browser/signin/signin_oauth_helper.cc b/components/signin/core/browser/signin_oauth_helper.cc
index 2c8790b..db51a59 100644
--- a/chrome/browser/signin/signin_oauth_helper.cc
+++ b/components/signin/core/browser/signin_oauth_helper.cc
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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.
-#include "chrome/browser/signin/signin_oauth_helper.h"
+#include "components/signin/core/browser/signin_oauth_helper.h"
#include "base/message_loop/message_loop.h"
#include "google_apis/gaia/gaia_auth_fetcher.h"
@@ -28,7 +28,7 @@ void SigninOAuthHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) {
}
void SigninOAuthHelper::OnClientOAuthFailure(
- const GoogleServiceAuthError& error) {
+ const GoogleServiceAuthError& error) {
VLOG(1) << "SigninOAuthHelper::OnClientOAuthFailure: " << error.ToString();
consumer_->OnSigninOAuthInformationFailure(error);
}
@@ -56,9 +56,8 @@ void SigninOAuthHelper::OnGetUserInfoSuccess(const UserInfoMap& data) {
VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess:"
<< " email=" << email_iter->second
<< " displayEmail=" << display_email_iter->second;
- consumer_->OnSigninOAuthInformationAvailable(email_iter->second,
- display_email_iter->second,
- refresh_token_);
+ consumer_->OnSigninOAuthInformationAvailable(
+ email_iter->second, display_email_iter->second, refresh_token_);
}
}
diff --git a/chrome/browser/signin/signin_oauth_helper.h b/components/signin/core/browser/signin_oauth_helper.h
index f372d27..d5c046c 100644
--- a/chrome/browser/signin/signin_oauth_helper.h
+++ b/components/signin/core/browser/signin_oauth_helper.h
@@ -1,9 +1,9 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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_SIGNIN_OAUTH_HELPER_H_
-#define CHROME_BROWSER_SIGNIN_SIGNIN_OAUTH_HELPER_H_
+#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_
+#define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_
#include <string>
@@ -42,14 +42,14 @@ class SigninOAuthHelper : public GaiaAuthConsumer {
private:
// Overridden from GaiaAuthConsumer.
virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE;
- virtual void OnClientOAuthFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
+ virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
- virtual void OnClientLoginFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
+ virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE;
- virtual void OnGetUserInfoFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
+ virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
GaiaAuthFetcher gaia_auth_fetcher_;
std::string refresh_token_;
@@ -58,4 +58,4 @@ class SigninOAuthHelper : public GaiaAuthConsumer {
DISALLOW_COPY_AND_ASSIGN(SigninOAuthHelper);
};
-#endif // CHROME_BROWSER_SIGNIN_SIGNIN_OAUTH_HELPER_H_
+#endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_