summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc8
-rw-r--r--chrome/browser/signin/account_reconcilor.cc143
-rw-r--r--chrome/browser/signin/account_reconcilor.h49
-rw-r--r--chrome/browser/signin/account_reconcilor_unittest.cc183
-rw-r--r--chrome/browser/signin/fake_profile_oauth2_token_service.cc52
-rw-r--r--chrome/browser/signin/fake_profile_oauth2_token_service.h18
-rw-r--r--chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc9
7 files changed, 51 insertions, 411 deletions
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
index 8a442c7..393a05c 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
@@ -58,6 +58,7 @@ namespace policy {
namespace {
const char kOAuthTokenCookie[] = "oauth_token=1234";
+const char kTestAccountId[] = "user@gmail.com";
const char kOAuth2TokenPairData[] =
"{"
@@ -532,10 +533,9 @@ TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) {
static_cast<FakeProfileOAuth2TokenService*>(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_));
ASSERT_TRUE(token_service);
- const std::string account_id = token_service->GetPrimaryAccountId();
- EXPECT_FALSE(token_service->RefreshTokenIsAvailable(account_id));
- token_service->UpdateCredentials(account_id, "refresh_token");
- EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
+ EXPECT_FALSE(token_service->RefreshTokenIsAvailable(kTestAccountId));
+ token_service->IssueRefreshToken(kTestAccountId);
+ EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId));
// That should have notified the manager, which now issues the request for the
// policy oauth token.
diff --git a/chrome/browser/signin/account_reconcilor.cc b/chrome/browser/signin/account_reconcilor.cc
index ed10cbe..0d83f81 100644
--- a/chrome/browser/signin/account_reconcilor.cc
+++ b/chrome/browser/signin/account_reconcilor.cc
@@ -2,14 +2,12 @@
// 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 "base/json/json_reader.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/account_reconcilor.h"
#include "chrome/browser/signin/google_auto_login_helper.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
@@ -21,64 +19,9 @@
#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"
-
-class AccountReconcilor::UserIdFetcher
- : public gaia::GaiaOAuthClient::Delegate {
- public:
- UserIdFetcher(AccountReconcilor* reconcilor,
- const std::string& access_token,
- const std::string& account_id);
-
- private:
- // Overriden from gaia::GaiaOAuthClient::Delegate.
- virtual void OnGetUserIdResponse(const std::string& user_id) OVERRIDE;
- virtual void OnOAuthError() OVERRIDE;
- virtual void OnNetworkError(int response_code) OVERRIDE;
-
- AccountReconcilor* const reconcilor_;
- const std::string account_id_;
- gaia::GaiaOAuthClient gaia_auth_client_;
-
- DISALLOW_COPY_AND_ASSIGN(UserIdFetcher);
-};
-
-AccountReconcilor::UserIdFetcher::UserIdFetcher(AccountReconcilor* reconcilor,
- const std::string& access_token,
- const std::string& account_id)
- : reconcilor_(reconcilor),
- account_id_(account_id),
- gaia_auth_client_(reconcilor_->profile()->GetRequestContext()) {
- DCHECK(reconcilor_);
- DCHECK(!account_id_.empty());
-
- const int kMaxRetries = 5;
- gaia_auth_client_.GetUserId(access_token, kMaxRetries, this);
-}
-
-void AccountReconcilor::UserIdFetcher::OnGetUserIdResponse(
- const std::string& user_id) {
- DVLOG(1) << "AccountReconcilor::OnGetUserIdResponse: " << account_id_;
- reconcilor_->HandleSuccessfulAccountIdCheck(account_id_);
-}
-
-void AccountReconcilor::UserIdFetcher::OnOAuthError() {
- DVLOG(1) << "AccountReconcilor::OnOAuthError: " << account_id_;
- reconcilor_->HandleFailedAccountIdCheck(account_id_);
-}
-
-void AccountReconcilor::UserIdFetcher::OnNetworkError(int response_code) {
- DVLOG(1) << "AccountReconcilor::OnNetworkError: " << account_id_
- << " response_code=" << response_code;
-
- // TODO(rogerta): some response error should not be treated like
- // permanent errors. Figure out appropriate ones.
- reconcilor_->HandleFailedAccountIdCheck(account_id_);
-}
AccountReconcilor::AccountReconcilor(Profile* profile)
: profile_(profile),
- registered_with_token_service_(false),
are_gaia_accounts_set_(false),
requests_(NULL) {
DVLOG(1) << "AccountReconcilor::AccountReconcilor";
@@ -95,32 +38,23 @@ AccountReconcilor::AccountReconcilor(Profile* profile)
AccountReconcilor::~AccountReconcilor() {
// Make sure shutdown was called first.
- DCHECK(!registered_with_token_service_);
DCHECK(registrar_.IsEmpty());
DCHECK(!reconciliation_timer_.IsRunning());
DCHECK(!requests_);
- DCHECK_EQ(0u, user_id_fetchers_.size());
}
void AccountReconcilor::Shutdown() {
DVLOG(1) << "AccountReconcilor::Shutdown";
- DeleteAccessTokenRequestsAndUserIdFetchers();
+ DeleteAccessTokenRequests();
UnregisterWithSigninManager();
UnregisterWithTokenService();
UnregisterWithCookieMonster();
StopPeriodicReconciliation();
}
-void AccountReconcilor::DeleteAccessTokenRequestsAndUserIdFetchers() {
+void AccountReconcilor::DeleteAccessTokenRequests() {
delete[] requests_;
requests_ = NULL;
-
- user_id_fetchers_.clear();
-}
-
-bool AccountReconcilor::AreAllRefreshTokensChecked() const {
- return chrome_accounts_.size() ==
- (valid_chrome_accounts_.size() + invalid_chrome_accounts_.size());
}
void AccountReconcilor::RegisterWithCookieMonster() {
@@ -148,26 +82,15 @@ void AccountReconcilor::UnregisterWithSigninManager() {
void AccountReconcilor::RegisterWithTokenService() {
DVLOG(1) << "AccountReconcilor::RegisterWithTokenService";
- // During re-auth, the reconcilor will get a GOOGLE_SIGNIN_SUCCESSFUL
- // even when the profile is already connected. Avoid re-registering
- // with the token service since this will DCHECK.
- if (registered_with_token_service_)
- return;
-
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
token_service->AddObserver(this);
- registered_with_token_service_ = true;
}
void AccountReconcilor::UnregisterWithTokenService() {
- if (!registered_with_token_service_)
- return;
-
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
token_service->RemoveObserver(this);
- registered_with_token_service_ = false;
}
bool AccountReconcilor::IsProfileConnected() {
@@ -257,7 +180,7 @@ void AccountReconcilor::StartReconcileAction() {
// Reset state for validating oauth2 tokens.
primary_account_.clear();
chrome_accounts_.clear();
- DeleteAccessTokenRequestsAndUserIdFetchers();
+ DeleteAccessTokenRequests();
valid_chrome_accounts_.clear();
invalid_chrome_accounts_.clear();
ValidateAccountsFromTokenService();
@@ -317,49 +240,38 @@ void AccountReconcilor::ValidateAccountsFromTokenService() {
OAuth2TokenService::ScopeSet(),
this);
}
-
- DCHECK_EQ(0u, user_id_fetchers_.size());
- user_id_fetchers_.resize(chrome_accounts_.size());
}
void AccountReconcilor::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) {
- size_t index;
- for (index = 0; index < chrome_accounts_.size(); ++index) {
- if (request == requests_[index].get())
- break;
- }
- DCHECK(index < chrome_accounts_.size());
-
- const std::string& account_id = chrome_accounts_[index];
-
- DVLOG(1) << "AccountReconcilor::OnGetTokenSuccess: valid " << account_id;
-
- DCHECK(!user_id_fetchers_[index]);
- user_id_fetchers_[index] =
- new UserIdFetcher(this, access_token, account_id);
+ DVLOG(1) << "AccountReconcilor::OnGetTokenSuccess: valid "
+ << request->GetAccountId();
+ valid_chrome_accounts_.insert(request->GetAccountId());
+ FinishReconcileAction();
}
void AccountReconcilor::OnGetTokenFailure(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) {
- DVLOG(1) << "AccountReconcilor::OnGetTokenFailure: invalid "
+ DVLOG(1) << "AccountReconcilor::OnGetTokenSuccess: invalid "
<< request->GetAccountId();
- HandleFailedAccountIdCheck(request->GetAccountId());
+ invalid_chrome_accounts_.insert(request->GetAccountId());
+ FinishReconcileAction();
}
void AccountReconcilor::FinishReconcileAction() {
// Make sure that the process of validating the gaia cookie and the oauth2
// tokens individually is done before proceeding with reconciliation.
- if (!are_gaia_accounts_set_ || !AreAllRefreshTokensChecked())
+ if (!are_gaia_accounts_set_ ||
+ (chrome_accounts_.size() != (valid_chrome_accounts_.size() +
+ invalid_chrome_accounts_.size()))) {
return;
+ }
DVLOG(1) << "AccountReconcilor::FinishReconcileAction";
- DeleteAccessTokenRequestsAndUserIdFetchers();
-
bool are_primaries_equal =
gaia_accounts_.size() > 0 && primary_account_ == gaia_accounts_[0];
bool have_same_accounts = chrome_accounts_.size() == gaia_accounts_.size();
@@ -373,28 +285,7 @@ void AccountReconcilor::FinishReconcileAction() {
}
}
- if (!are_primaries_equal) {
- // TODO(rogerta): really messed up state. Blow away the gaia cookie
- // completely and rebuild it, making sure the primary account as specified
- // by the SigninManager is the first session in the gaia cookie.
- } else if (!have_same_accounts) {
- // TODO(rogerta): for each account known to chrome but not in the gaia
- // cookie, PerformMergeAction().
-
- // TODO(rogerta): for each account in the gaia cookie not known to chrome,
- // warn the user by showing a signin global error. I don't think we want
- // automatically add the account to chrome.
+ if (!are_primaries_equal || !have_same_accounts) {
+ // TODO(rogerta): fix things up.
}
}
-
-void AccountReconcilor::HandleSuccessfulAccountIdCheck(
- const std::string& account_id) {
- valid_chrome_accounts_.insert(account_id);
- FinishReconcileAction();
-}
-
-void AccountReconcilor::HandleFailedAccountIdCheck(
- const std::string& account_id) {
- invalid_chrome_accounts_.insert(account_id);
- FinishReconcileAction();
-}
diff --git a/chrome/browser/signin/account_reconcilor.h b/chrome/browser/signin/account_reconcilor.h
index db8f0b7..4ac7e2a 100644
--- a/chrome/browser/signin/account_reconcilor.h
+++ b/chrome/browser/signin/account_reconcilor.h
@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -32,42 +31,12 @@ class AccountReconcilor : public BrowserContextKeyedService,
Profile* profile() { return profile_; }
- bool IsPeriodicReconciliationRunning() const {
+ bool IsPeriodicReconciliationRunning() {
return reconciliation_timer_.IsRunning();
}
- bool IsRegisteredWithTokenService() const {
- return registered_with_token_service_;
- }
-
- bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; }
-
- bool AreAllRefreshTokensChecked() const;
-
- const std::vector<std::string>& GetGaiaAccountsForTesting() const {
- return gaia_accounts_;
- }
-
- const std::set<std::string>& GetValidChromeAccountsForTesting() const {
- return valid_chrome_accounts_;
- }
-
- const std::set<std::string>& GetInvalidChromeAccountsForTesting() const {
- return invalid_chrome_accounts_;
- }
-
private:
class AccountReconcilorTest;
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
- ValidateAccountsFromTokensFailedUserInfo);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
- ValidateAccountsFromTokensFailedTokenRequest);
- FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAction);
-
- class UserIdFetcher;
// Register and unregister with dependent services.
void RegisterWithCookieMonster();
@@ -79,7 +48,7 @@ class AccountReconcilor : public BrowserContextKeyedService,
bool IsProfileConnected();
- void DeleteAccessTokenRequestsAndUserIdFetchers();
+ void DeleteAccessTokenRequests();
// Start and stop the periodic reconciliation.
void StartPeriodicReconciliation();
@@ -88,36 +57,32 @@ class AccountReconcilor : public BrowserContextKeyedService,
void PerformMergeAction(const std::string& account_id);
void PerformRemoveAction(const std::string& account_id);
-
- // Used during period reconciliation.
void StartReconcileAction();
void FinishReconcileAction();
- void HandleSuccessfulAccountIdCheck(const std::string& account_id);
- void HandleFailedAccountIdCheck(const std::string& account_id);
void GetAccountsFromCookie();
void ValidateAccountsFromTokenService();
void OnCookieChanged(ChromeCookieDetails* details);
- // Overriden from content::NotificationObserver.
+ // Overriden from content::NotificationObserver
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // Overriden from OAuth2TokenService::Consumer.
+ // Overriden from OAuth2TokenService::Consumer
virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) OVERRIDE;
virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) OVERRIDE;
- // Overriden from OAuth2TokenService::Observer.
+ // Overriden from OAuth2TokenService::Observer
virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
virtual void OnRefreshTokensLoaded() OVERRIDE;
- // Overriden from GaiaAuthConsumer.
+ // Overriden from GaiaAuthConsumer
virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
virtual void OnListAccountsFailure(
const GoogleServiceAuthError& error) OVERRIDE;
@@ -126,7 +91,6 @@ class AccountReconcilor : public BrowserContextKeyedService,
Profile* profile_;
content::NotificationRegistrar registrar_;
base::RepeatingTimer<AccountReconcilor> reconciliation_timer_;
- bool registered_with_token_service_;
// Used during reconcile action.
// These members are used used to validate the gaia cookie.
@@ -139,7 +103,6 @@ class AccountReconcilor : public BrowserContextKeyedService,
std::string primary_account_;
std::vector<std::string> chrome_accounts_;
scoped_ptr<OAuth2TokenService::Request>* requests_;
- ScopedVector<UserIdFetcher> user_id_fetchers_;
std::set<std::string> valid_chrome_accounts_;
std::set<std::string> invalid_chrome_accounts_;
diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc
index 320b050..ca5a8d2 100644
--- a/chrome/browser/signin/account_reconcilor_unittest.cc
+++ b/chrome/browser/signin/account_reconcilor_unittest.cc
@@ -3,8 +3,6 @@
// found in the LICENSE file.
#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/fake_profile_oauth2_token_service.h"
@@ -15,7 +13,6 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
-#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -39,25 +36,15 @@ class AccountReconcilorTest : public testing::Test {
FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
FakeProfileOAuth2TokenService* token_service() { return token_service_; }
- void SetFakeResponse(const std::string& url,
- const std::string& data,
- net::HttpStatusCode code,
- net::URLRequestStatus::Status status) {
- url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
- }
-
private:
content::TestBrowserThreadBundle bundle_;
scoped_ptr<TestingProfile> profile_;
FakeSigninManagerForTesting* signin_manager_;
FakeProfileOAuth2TokenService* token_service_;
- net::FakeURLFetcherFactory url_fetcher_factory_;
};
AccountReconcilorTest::AccountReconcilorTest()
- : signin_manager_(NULL),
- token_service_(NULL),
- url_fetcher_factory_(NULL) {}
+ : signin_manager_(NULL), token_service_(NULL) {}
void AccountReconcilorTest::SetUp() {
TestingProfile::Builder builder;
@@ -87,191 +74,31 @@ void AccountReconcilorTest::TearDown() {
TEST_F(AccountReconcilorTest, Basic) {
AccountReconcilor* reconcilor =
AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
+ ASSERT_TRUE(NULL != reconcilor);
ASSERT_EQ(profile(), reconcilor->profile());
}
#if !defined(OS_CHROMEOS)
-
TEST_F(AccountReconcilorTest, SigninManagerRegistration) {
AccountReconcilor* reconcilor =
AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
+ ASSERT_TRUE(NULL != reconcilor);
ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
signin_manager()->OnExternalSigninCompleted(kTestEmail);
ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
signin_manager()->SignOut();
ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
-}
-
-TEST_F(AccountReconcilorTest, Reauth) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
-
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
- ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
-
- // Simulate reauth. The state of the reconcilor should not change.
- signin_manager()->OnExternalSigninCompleted(kTestEmail);
- ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
}
-
-#endif // !defined(OS_CHROMEOS)
+#endif
TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) {
signin_manager()->SetAuthenticatedUsername(kTestEmail);
AccountReconcilor* reconcilor =
AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
+ ASSERT_TRUE(NULL != reconcilor);
ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning());
- ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
-}
-
-TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- SetFakeResponse("https://accounts.google.com/ListAccounts",
- "[\"foo\", [[\"bar\", 0, \"name\", \"email\", \"photo\", 0, 0, 0]]]",
- net::HTTP_OK, net::URLRequestStatus::SUCCESS);
-
- reconcilor->GetAccountsFromCookie();
- ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
- const std::vector<std::string>& accounts =
- reconcilor->GetGaiaAccountsForTesting();
- ASSERT_EQ(1u, accounts.size());
- ASSERT_EQ("email", accounts[0]);
-}
-
-TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- SetFakeResponse("https://accounts.google.com/ListAccounts", "",
- net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
-
- reconcilor->GetAccountsFromCookie();
- ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
- ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size());
-}
-
-TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- token_service()->UpdateCredentials(kTestEmail, "refresh_token");
-
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- reconcilor->ValidateAccountsFromTokenService();
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
-
- SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
- "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS);
- token_service()->IssueTokenForAllPendingRequests("access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
- ASSERT_EQ(1u, reconcilor->GetValidChromeAccountsForTesting().size());
- ASSERT_EQ(0u, reconcilor->GetInvalidChromeAccountsForTesting().size());
-}
-
-TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedUserInfo) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- token_service()->UpdateCredentials(kTestEmail, "refresh_token");
-
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- reconcilor->ValidateAccountsFromTokenService();
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
-
- SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
- "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
- token_service()->IssueTokenForAllPendingRequests("access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
- ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
- ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
-}
-
-TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- token_service()->UpdateCredentials(kTestEmail, "refresh_token");
-
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- reconcilor->ValidateAccountsFromTokenService();
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
-
- token_service()->IssueErrorForAllPendingRequests(
- GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
- ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size());
- ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size());
-}
-
-TEST_F(AccountReconcilorTest, StartReconcileAction) {
- signin_manager()->SetAuthenticatedUsername(kTestEmail);
- token_service()->UpdateCredentials(kTestEmail, "refresh_token");
-
- AccountReconcilor* reconcilor =
- AccountReconcilorFactory::GetForProfile(profile());
- ASSERT_TRUE(reconcilor);
-
- SetFakeResponse("https://accounts.google.com/ListAccounts",
- "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0], "
- "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0]]]",
- net::HTTP_OK, net::URLRequestStatus::SUCCESS);
-
- reconcilor->StartReconcileAction();
- ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
- ASSERT_EQ(2u, reconcilor->GetGaiaAccountsForTesting().size());
-
- SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo",
- "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
- token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- base::RunLoop().RunUntilIdle();
- ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
-
- token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
}
diff --git a/chrome/browser/signin/fake_profile_oauth2_token_service.cc b/chrome/browser/signin/fake_profile_oauth2_token_service.cc
index 8c7d3f3..c991fe0 100644
--- a/chrome/browser/signin/fake_profile_oauth2_token_service.cc
+++ b/chrome/browser/signin/fake_profile_oauth2_token_service.cc
@@ -32,15 +32,6 @@ bool FakeProfileOAuth2TokenService::RefreshTokenIsAvailable(
return !GetRefreshToken(account_id).empty();
}
-std::vector<std::string> FakeProfileOAuth2TokenService::GetAccounts() {
- std::vector<std::string> account_ids;
- for (std::map<std::string, std::string>::const_iterator iter =
- refresh_tokens_.begin(); iter != refresh_tokens_.end(); ++iter) {
- account_ids.push_back(iter->first);
- }
- return account_ids;
-}
-
void FakeProfileOAuth2TokenService::UpdateCredentials(
const std::string& account_id,
const std::string& refresh_token) {
@@ -55,34 +46,19 @@ void FakeProfileOAuth2TokenService::IssueRefreshToken(
void FakeProfileOAuth2TokenService::IssueRefreshTokenForUser(
const std::string& account_id,
const std::string& token) {
- if (token.empty()) {
- refresh_tokens_.erase(account_id);
+ refresh_token_ = token;
+ if (refresh_token_.empty())
FireRefreshTokenRevoked(account_id);
- } else {
- refresh_tokens_[account_id] = token;
+ else
FireRefreshTokenAvailable(account_id);
- // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
- }
-}
-
-void FakeProfileOAuth2TokenService::IssueAllTokensForAccount(
- const std::string& account_id,
- const std::string& access_token,
- const base::Time& expiration) {
- CompleteRequests(account_id,
- true,
- ScopeSet(),
- GoogleServiceAuthError::AuthErrorNone(),
- access_token,
- expiration);
+ // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
}
void FakeProfileOAuth2TokenService::IssueTokenForScope(
const ScopeSet& scope,
const std::string& access_token,
const base::Time& expiration) {
- CompleteRequests("",
- false,
+ CompleteRequests(false,
scope,
GoogleServiceAuthError::AuthErrorNone(),
access_token,
@@ -92,19 +68,18 @@ void FakeProfileOAuth2TokenService::IssueTokenForScope(
void FakeProfileOAuth2TokenService::IssueErrorForScope(
const ScopeSet& scope,
const GoogleServiceAuthError& error) {
- CompleteRequests("", false, scope, error, std::string(), base::Time());
+ CompleteRequests(false, scope, error, std::string(), base::Time());
}
void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests(
const GoogleServiceAuthError& error) {
- CompleteRequests("", true, ScopeSet(), error, std::string(), base::Time());
+ CompleteRequests(true, ScopeSet(), error, std::string(), base::Time());
}
void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests(
const std::string& access_token,
const base::Time& expiration) {
- CompleteRequests("",
- true,
+ CompleteRequests(true,
ScopeSet(),
GoogleServiceAuthError::AuthErrorNone(),
access_token,
@@ -112,7 +87,6 @@ void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests(
}
void FakeProfileOAuth2TokenService::CompleteRequests(
- const std::string& account_id,
bool all_scopes,
const ScopeSet& scope,
const GoogleServiceAuthError& error,
@@ -124,20 +98,14 @@ void FakeProfileOAuth2TokenService::CompleteRequests(
// Walk the requests and notify the callbacks.
for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
it != pending_requests_.end(); ++it) {
- if (!it->request)
- continue;
-
- bool scope_matches = all_scopes || it->scopes == scope;
- bool account_matches = account_id.empty() || account_id == it->account_id;
- if (account_matches && scope_matches)
+ if (it->request && (all_scopes || it->scopes == scope))
it->request->InformConsumer(error, access_token, expiration);
}
}
std::string FakeProfileOAuth2TokenService::GetRefreshToken(
const std::string& account_id) {
- return refresh_tokens_.count(account_id) > 0 ? refresh_tokens_[account_id] :
- std::string();
+ return refresh_token_;
}
std::vector<FakeProfileOAuth2TokenService::PendingRequest>
diff --git a/chrome/browser/signin/fake_profile_oauth2_token_service.h b/chrome/browser/signin/fake_profile_oauth2_token_service.h
index 0acc172..f1bd623 100644
--- a/chrome/browser/signin/fake_profile_oauth2_token_service.h
+++ b/chrome/browser/signin/fake_profile_oauth2_token_service.h
@@ -66,8 +66,6 @@ class FakeProfileOAuth2TokenService
virtual bool RefreshTokenIsAvailable(
const std::string& account_id) OVERRIDE;
- virtual std::vector<std::string> GetAccounts() OVERRIDE;
-
// Overriden to make sure it works on Android. Simply calls
// IssueRefreshToken().
virtual void UpdateCredentials(const std::string& account_id,
@@ -88,10 +86,7 @@ class FakeProfileOAuth2TokenService
std::vector<PendingRequest> GetPendingRequests();
// Helper routines to issue tokens for pending requests.
- void IssueAllTokensForAccount(const std::string& account_id,
- const std::string& access_token,
- const base::Time& expiration);
-
+ // TODO(fgorski): Add account IDs as parameters.
void IssueTokenForScope(const ScopeSet& scopes,
const std::string& access_token,
const base::Time& expiration);
@@ -127,20 +122,15 @@ class FakeProfileOAuth2TokenService
private:
// Helper function to complete pending requests - if |all_scopes| is true,
// then all pending requests are completed, otherwise, only those requests
- // matching |scopes| are completed. If |account_id| is empty, then pending
- // requests for all accounts are completed, otherwise only requests for the
- // given account.
- void CompleteRequests(const std::string& account_id,
- bool all_scopes,
+ // matching |scopes| are completed.
+ void CompleteRequests(bool all_scopes,
const ScopeSet& scopes,
const GoogleServiceAuthError& error,
const std::string& access_token,
const base::Time& expiration);
std::vector<PendingRequest> pending_requests_;
-
- // Maps account ids to their refresh token strings.
- std::map<std::string, std::string> refresh_tokens_;
+ std::string refresh_token_;
DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService);
};
diff --git a/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc b/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc
index 2412fa8..6ef1036 100644
--- a/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc
+++ b/chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc
@@ -104,8 +104,9 @@ TEST_F(ProfileOAuth2TokenServiceRequestTest,
EXPECT_EQ(1, consumer_.number_of_errors_);
}
-TEST_F(ProfileOAuth2TokenServiceRequestTest, Success) {
- oauth2_service_->UpdateCredentials(kAccountId, kRefreshToken);
+TEST_F(ProfileOAuth2TokenServiceRequestTest,
+ Success) {
+ oauth2_service_->IssueRefreshToken(kRefreshToken);
scoped_ptr<ProfileOAuth2TokenServiceRequest> request(
ProfileOAuth2TokenServiceRequest::CreateAndStart(
profile_.get(),
@@ -122,7 +123,7 @@ TEST_F(ProfileOAuth2TokenServiceRequestTest, Success) {
TEST_F(ProfileOAuth2TokenServiceRequestTest,
RequestDeletionBeforeServiceComplete) {
- oauth2_service_->UpdateCredentials(kAccountId, kRefreshToken);
+ oauth2_service_->IssueRefreshToken(kRefreshToken);
scoped_ptr<ProfileOAuth2TokenServiceRequest> request(
ProfileOAuth2TokenServiceRequest::CreateAndStart(
profile_.get(),
@@ -139,7 +140,7 @@ TEST_F(ProfileOAuth2TokenServiceRequestTest,
TEST_F(ProfileOAuth2TokenServiceRequestTest,
RequestDeletionAfterServiceComplete) {
- oauth2_service_->UpdateCredentials(kAccountId, kRefreshToken);
+ oauth2_service_->IssueRefreshToken(kRefreshToken);
scoped_ptr<ProfileOAuth2TokenServiceRequest> request(
ProfileOAuth2TokenServiceRequest::CreateAndStart(
profile_.get(),