summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortreib <treib@chromium.org>2015-06-03 09:20:36 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-03 16:22:11 +0000
commitbaa70976bf3b485195a4b3801f2ab1d331f35ef3 (patch)
tree93ef066bb60b80e610fa85fdecb79dd7161ef52a
parenta89dd42f1bea8f3e4014dd9bddcb53a196055cf2 (diff)
downloadchromium_src-baa70976bf3b485195a4b3801f2ab1d331f35ef3.zip
chromium_src-baa70976bf3b485195a4b3801f2ab1d331f35ef3.tar.gz
chromium_src-baa70976bf3b485195a4b3801f2ab1d331f35ef3.tar.bz2
ChildAccountService: get service flags from AccountTrackerService instead of fetching them ourselves with AccountServiceFlagFetcher.
AccountServiceFlagFetcher is now unused and can be removed :) BUG=466799 Review URL: https://codereview.chromium.org/1144123003 Cr-Commit-Position: refs/heads/master@{#332624}
-rw-r--r--chrome/browser/signin/account_service_flag_fetcher_unittest.cc308
-rw-r--r--chrome/browser/supervised_user/child_accounts/child_account_service.cc125
-rw-r--r--chrome/browser/supervised_user/child_accounts/child_account_service.h31
-rw-r--r--chrome/browser/supervised_user/child_accounts/child_account_service_factory.cc8
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--components/signin.gypi2
-rw-r--r--components/signin/core/browser/BUILD.gn2
-rw-r--r--components/signin/core/browser/account_service_flag_fetcher.cc121
-rw-r--r--components/signin/core/browser/account_service_flag_fetcher.h85
9 files changed, 44 insertions, 639 deletions
diff --git a/chrome/browser/signin/account_service_flag_fetcher_unittest.cc b/chrome/browser/signin/account_service_flag_fetcher_unittest.cc
deleted file mode 100644
index 0e81008..0000000
--- a/chrome/browser/signin/account_service_flag_fetcher_unittest.cc
+++ /dev/null
@@ -1,308 +0,0 @@
-// 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 <string>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_util.h"
-#include "base/thread_task_runner_handle.h"
-#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
-#include "components/signin/core/browser/account_service_flag_fetcher.h"
-#include "google_apis/gaia/gaia_urls.h"
-#include "net/url_request/test_url_fetcher_factory.h"
-#include "net/url_request/url_request_test_util.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-const char kAccountId[] = "user@gmail.com";
-const char kDifferentAccountId[] = "some_other_user@gmail.com";
-
-const int kGaiaAuthFetcherURLFetcherID = 0;
-
-// TODO(treib): This class should really live in components/signin/ next to the
-// AccountServiceFlagFetcher, but it uses the FakePO2TS which lives in
-// chrome/browser/ (because it uses the AndroidPO2TS which depends on stuff from
-// chrome/browser/). So when the AndroidPO2TS is componentized, then this should
-// move as well.
-class AccountServiceFlagFetcherTest : public testing::Test {
- public:
- AccountServiceFlagFetcherTest()
- : request_context_(new net::TestURLRequestContextGetter(
- base::ThreadTaskRunnerHandle::Get())) {
- service_flags_.push_back("some_flag");
- service_flags_.push_back("another_flag");
- service_flags_.push_back("andonemore");
- }
-
- MOCK_METHOD2(OnFlagsFetched,
- void(AccountServiceFlagFetcher::ResultCode result,
- const std::vector<std::string>& flags));
-
- protected:
- net::TestURLFetcher* GetLoginURLFetcher() {
- net::TestURLFetcher* fetcher =
- url_fetcher_factory_.GetFetcherByID(kGaiaAuthFetcherURLFetcherID);
- EXPECT_TRUE(fetcher);
-
- EXPECT_EQ(GaiaUrls::GetInstance()->oauth1_login_url(),
- fetcher->GetOriginalURL());
-
- return fetcher;
- }
-
- net::TestURLFetcher* GetGetUserInfoURLFetcher() {
- net::TestURLFetcher* fetcher =
- url_fetcher_factory_.GetFetcherByID(kGaiaAuthFetcherURLFetcherID);
- EXPECT_TRUE(fetcher);
-
- EXPECT_EQ(GaiaUrls::GetInstance()->get_user_info_url(),
- fetcher->GetOriginalURL());
-
- return fetcher;
- }
-
- void SendValidLoginResponse() {
- net::TestURLFetcher* fetcher = GetLoginURLFetcher();
- fetcher->set_status(
- net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString(std::string("SID=sid\nLSID=lsid\nAuth=auth\n"));
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- }
-
- void SendFailedLoginResponse() {
- net::TestURLFetcher* fetcher = GetLoginURLFetcher();
- fetcher->set_status(
- net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0));
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString(std::string());
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- }
-
- void SendValidGetUserInfoResponse() {
- net::TestURLFetcher* fetcher = GetGetUserInfoURLFetcher();
- fetcher->set_status(
- net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString(BuildGetUserInfoResponse());
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- }
-
- void SendInvalidGetUserInfoResponse() {
- net::TestURLFetcher* fetcher = GetGetUserInfoURLFetcher();
- fetcher->set_status(
- net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString(std::string("allServicesIsMissing=true"));
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- }
-
- void SendFailedGetUserInfoResponse() {
- net::TestURLFetcher* fetcher = GetGetUserInfoURLFetcher();
- fetcher->set_status(
- net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0));
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString(std::string());
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- }
-
- std::string BuildGetUserInfoResponse() const {
- return "allServices=" + JoinString(service_flags_, ',');
- }
-
- base::MessageLoop message_loop_;
- FakeProfileOAuth2TokenService token_service_;
- scoped_refptr<net::TestURLRequestContextGetter> request_context_;
- net::TestURLFetcherFactory url_fetcher_factory_;
- net::ResponseCookies cookies_;
- std::vector<std::string> service_flags_;
-};
-
-TEST_F(AccountServiceFlagFetcherTest, Success) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- // Since a refresh token is already available, we should immediately get a
- // request for an access token.
- EXPECT_EQ(1U, token_service_.GetPendingRequests().size());
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- SendValidLoginResponse();
-
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::SUCCESS,
- service_flags_));
- SendValidGetUserInfoResponse();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, SuccessAfterWaitingForRefreshToken) {
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- // Since there is no refresh token yet, we should not get a request for an
- // access token at this point.
- EXPECT_EQ(0U, token_service_.GetPendingRequests().size());
-
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- // Now there is a refresh token and we should have got a request for an
- // access token.
- EXPECT_EQ(1U, token_service_.GetPendingRequests().size());
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- SendValidLoginResponse();
-
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::SUCCESS,
- service_flags_));
- SendValidGetUserInfoResponse();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, NoRefreshToken) {
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- token_service_.UpdateCredentials(kDifferentAccountId, "refresh_token");
-
- // Credentials for a different user should be ignored, i.e. not result in a
- // request for an access token.
- EXPECT_EQ(0U, token_service_.GetPendingRequests().size());
-
- // After all refresh tokens have been loaded, there is still no token for our
- // user, so we expect a token error.
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::TOKEN_ERROR,
- std::vector<std::string>()));
- token_service_.IssueAllRefreshTokensLoaded();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, GetTokenFailure) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- // On failure to get an access token we expect a token error.
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::TOKEN_ERROR,
- std::vector<std::string>()));
- token_service_.IssueErrorForAllPendingRequestsForAccount(
- kAccountId,
- GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
-}
-
-TEST_F(AccountServiceFlagFetcherTest, ClientLoginFailure) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- // Login failure should result in a service error.
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::SERVICE_ERROR,
- std::vector<std::string>()));
- SendFailedLoginResponse();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, GetUserInfoInvalidResponse) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- SendValidLoginResponse();
-
- // Invalid response data from GetUserInfo should result in a service error.
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::SERVICE_ERROR,
- std::vector<std::string>()));
- SendInvalidGetUserInfoResponse();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, GetUserInfoFailure) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- SendValidLoginResponse();
-
- // Failed GetUserInfo call should result in a service error.
- EXPECT_CALL(*this, OnFlagsFetched(AccountServiceFlagFetcher::SERVICE_ERROR,
- std::vector<std::string>()));
- SendFailedGetUserInfoResponse();
-}
-
-TEST_F(AccountServiceFlagFetcherTest, DestroyFetcher) {
- token_service_.UpdateCredentials(kAccountId, "refresh_token");
-
- // When the fetcher is destroyed before the request completes, OnFlagsFetched
- // should not be called.
- EXPECT_CALL(*this, OnFlagsFetched(testing::_, testing::_)).Times(0);
-
- AccountServiceFlagFetcher fetcher(
- kAccountId,
- &token_service_,
- request_context_.get(),
- base::Bind(&AccountServiceFlagFetcherTest::OnFlagsFetched,
- base::Unretained(this)));
-
- token_service_.IssueAllTokensForAccount(
- kAccountId,
- "access_token",
- base::Time::Now() + base::TimeDelta::FromHours(1));
-
- SendValidLoginResponse();
- // Do not send a GetUserInfo response, but make sure the request is there.
- GetGetUserInfoURLFetcher();
-}
diff --git a/chrome/browser/supervised_user/child_accounts/child_account_service.cc b/chrome/browser/supervised_user/child_accounts/child_account_service.cc
index 673849d..ce6a982 100644
--- a/chrome/browser/supervised_user/child_accounts/child_account_service.cc
+++ b/chrome/browser/supervised_user/child_accounts/child_account_service.cc
@@ -6,11 +6,11 @@
#include "base/callback.h"
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.h"
@@ -36,11 +36,11 @@ const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection";
const char kIsChildAccountServiceFlagName[] = "uca";
-// Normally, re-check the child account flag and the family info once per day.
+// Normally, re-check the family info once per day.
const int kUpdateIntervalSeconds = 60 * 60 * 24;
-// In case of an error while getting the flag or the family info, retry with
-// exponential backoff.
+// In case of an error while getting the family info, retry with exponential
+// backoff.
const net::BackoffEntry::Policy kBackoffPolicy = {
// Number of initial errors (in sequence) to ignore before applying
// exponential back-off rules.
@@ -69,7 +69,6 @@ const net::BackoffEntry::Policy kBackoffPolicy = {
ChildAccountService::ChildAccountService(Profile* profile)
: profile_(profile), active_(false),
- flag_fetch_backoff_(&kBackoffPolicy),
family_fetch_backoff_(&kBackoffPolicy),
weak_ptr_factory_(this) {}
@@ -106,6 +105,9 @@ void ChildAccountService::SetIsChildAccount(bool is_child_account) {
supervised_users::kChildAccountSUID);
} else {
profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
+
+ ClearFirstCustodianPrefs();
+ ClearSecondCustodianPrefs();
}
}
profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
@@ -116,16 +118,19 @@ void ChildAccountService::SetIsChildAccount(bool is_child_account) {
}
void ChildAccountService::Init() {
- SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
+ AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this);
PropagateChildStatusToUser(profile_->IsChild());
- // If we're already signed in, fetch the flag again just to be sure.
- // (Previously, the browser might have been closed before we got the flag.
- // This also handles the graduation use case in a basic way.)
- if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated())
- StartFetchingServiceFlags();
+ // If we're already signed in, check the account immediately just to be sure.
+ // (We might have missed an update before registering as an observer.)
+ SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
+ if (signin->IsAuthenticated()) {
+ OnAccountUpdated(
+ AccountTrackerServiceFactory::GetForProfile(profile_)->GetAccountInfo(
+ signin->GetAuthenticatedAccountId()));
+ }
}
bool ChildAccountService::IsChildAccountStatusKnown() {
@@ -134,13 +139,11 @@ bool ChildAccountService::IsChildAccountStatusKnown() {
void ChildAccountService::Shutdown() {
family_fetcher_.reset();
- CancelFetchingServiceFlags();
- SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL);
+ AccountTrackerServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
+ SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(nullptr);
DCHECK(!active_);
- SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
}
-
void ChildAccountService::AddChildStatusReceivedCallback(
const base::Closure& callback) {
if (IsChildAccountStatusKnown())
@@ -157,7 +160,7 @@ bool ChildAccountService::SetActive(bool active) {
active_ = active;
if (active_) {
- // In contrast to local SUs, child account SUs must sign in.
+ // In contrast to legacy SUs, child account SUs must sign in.
scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
SupervisedUserSettingsService* settings_service =
SupervisedUserSettingsServiceFactory::GetForProfile(profile_);
@@ -187,8 +190,7 @@ bool ChildAccountService::SetActive(bool active) {
SigninManagerFactory::GetForProfile(profile_)->ProhibitSignout(false);
#endif
- ClearFirstCustodianPrefs();
- ClearSecondCustodianPrefs();
+ CancelFetchingFamilyInfo();
}
// Trigger a sync reconfig to enable/disable the right SU data types.
@@ -201,22 +203,22 @@ bool ChildAccountService::SetActive(bool active) {
return true;
}
-void ChildAccountService::GoogleSigninSucceeded(const std::string& account_id,
- const std::string& username,
- const std::string& password) {
- DCHECK(!account_id.empty());
- DCHECK_EQ(SigninManagerFactory::GetForProfile(profile_)
- ->GetAuthenticatedAccountId(),
- account_id);
+void ChildAccountService::OnAccountUpdated(
+ const AccountTrackerService::AccountInfo& info) {
+ std::string auth_account_id = SigninManagerFactory::GetForProfile(profile_)
+ ->GetAuthenticatedAccountId();
+ if (!info.IsValid() || info.account_id != auth_account_id)
+ return;
- StartFetchingServiceFlags();
-}
+ if (!IsChildAccountDetectionEnabled()) {
+ SetIsChildAccount(false);
+ return;
+ }
-void ChildAccountService::GoogleSignedOut(const std::string& account_id,
- const std::string& username) {
- DCHECK(!profile_->IsChild());
- CancelFetchingServiceFlags();
- CancelFetchingFamilyInfo();
+ bool is_child_account =
+ std::find(info.service_flags.begin(), info.service_flags.end(),
+ kIsChildAccountServiceFlagName) != info.service_flags.end();
+ SetIsChildAccount(is_child_account);
}
void ChildAccountService::OnGetFamilyMembersSuccess(
@@ -274,65 +276,6 @@ void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) {
FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo);
}
-void ChildAccountService::StartFetchingServiceFlags() {
- if (!IsChildAccountDetectionEnabled()) {
- SetIsChildAccount(false);
- return;
- }
- account_id_ = SigninManagerFactory::GetForProfile(profile_)
- ->GetAuthenticatedAccountId();
- flag_fetcher_.reset(new AccountServiceFlagFetcher(
- account_id_,
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
- profile_->GetRequestContext(),
- base::Bind(&ChildAccountService::OnFlagsFetched,
- weak_ptr_factory_.GetWeakPtr())));
-}
-
-void ChildAccountService::CancelFetchingServiceFlags() {
- flag_fetcher_.reset();
- account_id_.clear();
- flag_fetch_timer_.Stop();
-}
-
-void ChildAccountService::OnFlagsFetched(
- AccountServiceFlagFetcher::ResultCode result,
- const std::vector<std::string>& flags) {
- // If we've been signed out again (or signed in to a different account),
- // ignore the fetched flags.
- const std::string& new_account_id =
- SigninManagerFactory::GetForProfile(profile_)
- ->GetAuthenticatedAccountId();
- if (account_id_.empty() || account_id_ != new_account_id)
- return;
-
- account_id_.clear();
-
- // In case of an error, retry with exponential backoff.
- if (result != AccountServiceFlagFetcher::SUCCESS) {
- DLOG(WARNING) << "AccountServiceFlagFetcher returned error code " << result;
- flag_fetch_backoff_.InformOfRequest(false);
- ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
- return;
- }
-
- flag_fetch_backoff_.InformOfRequest(true);
-
- bool is_child_account =
- std::find(flags.begin(), flags.end(),
- kIsChildAccountServiceFlagName) != flags.end();
-
- SetIsChildAccount(is_child_account);
-
- ScheduleNextStatusFlagUpdate(
- base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
-}
-
-void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
- flag_fetch_timer_.Start(
- FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
-}
-
void ChildAccountService::PropagateChildStatusToUser(bool is_child) {
#if defined(OS_CHROMEOS)
user_manager::User* user =
diff --git a/chrome/browser/supervised_user/child_accounts/child_account_service.h b/chrome/browser/supervised_user/child_accounts/child_account_service.h
index 454de08..ae5f342 100644
--- a/chrome/browser/supervised_user/child_accounts/child_account_service.h
+++ b/chrome/browser/supervised_user/child_accounts/child_account_service.h
@@ -8,7 +8,7 @@
#include <string>
#include <vector>
-#include "base/callback.h"
+#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
@@ -17,8 +17,7 @@
#include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "components/signin/core/browser/account_service_flag_fetcher.h"
-#include "components/signin/core/browser/signin_manager_base.h"
+#include "components/signin/core/browser/account_tracker_service.h"
#include "net/base/backoff_entry.h"
namespace base {
@@ -36,7 +35,7 @@ class Profile;
// supervised user experience, fetch information about the parent(s)).
class ChildAccountService : public KeyedService,
public FamilyInfoFetcher::Consumer,
- public SigninManagerBase::Observer,
+ public AccountTrackerService::Observer,
public SupervisedUserService::Delegate {
public:
~ChildAccountService() override;
@@ -70,12 +69,9 @@ class ChildAccountService : public KeyedService,
// SupervisedUserService::Delegate implementation.
bool SetActive(bool active) override;
- // SigninManagerBase::Observer implementation.
- void GoogleSigninSucceeded(const std::string& account_id,
- const std::string& username,
- const std::string& password) override;
- void GoogleSignedOut(const std::string& account_id,
- const std::string& username) override;
+ // AccountTrackerService::Observer implementation.
+ void OnAccountUpdated(
+ const AccountTrackerService::AccountInfo& info) override;
// FamilyInfoFetcher::Consumer implementation.
void OnGetFamilyMembersSuccess(
@@ -86,12 +82,6 @@ class ChildAccountService : public KeyedService,
void CancelFetchingFamilyInfo();
void ScheduleNextFamilyInfoUpdate(base::TimeDelta delay);
- void StartFetchingServiceFlags();
- void CancelFetchingServiceFlags();
- void OnFlagsFetched(AccountServiceFlagFetcher::ResultCode,
- const std::vector<std::string>& flags);
- void ScheduleNextStatusFlagUpdate(base::TimeDelta delay);
-
void PropagateChildStatusToUser(bool is_child);
void SetFirstCustodianPrefs(const FamilyInfoFetcher::FamilyMember& custodian);
@@ -105,15 +95,6 @@ class ChildAccountService : public KeyedService,
bool active_;
- // The user for which we are currently trying to fetch the child account flag.
- // Empty when we are not currently fetching.
- std::string account_id_;
-
- scoped_ptr<AccountServiceFlagFetcher> flag_fetcher_;
- // If fetching the account service flag fails, retry with exponential backoff.
- base::OneShotTimer<ChildAccountService> flag_fetch_timer_;
- net::BackoffEntry flag_fetch_backoff_;
-
scoped_ptr<FamilyInfoFetcher> family_fetcher_;
// If fetching the family info fails, retry with exponential backoff.
base::OneShotTimer<ChildAccountService> family_fetch_timer_;
diff --git a/chrome/browser/supervised_user/child_accounts/child_account_service_factory.cc b/chrome/browser/supervised_user/child_accounts/child_account_service_factory.cc
index 8c54377..4a48946 100644
--- a/chrome/browser/supervised_user/child_accounts/child_account_service_factory.cc
+++ b/chrome/browser/supervised_user/child_accounts/child_account_service_factory.cc
@@ -5,7 +5,8 @@
#include "chrome/browser/supervised_user/child_accounts/child_account_service_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/supervised_user/child_accounts/child_account_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
@@ -26,10 +27,9 @@ ChildAccountServiceFactory::ChildAccountServiceFactory()
: BrowserContextKeyedServiceFactory(
"ChildAccountService",
BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(AccountTrackerServiceFactory::GetInstance());
+ DependsOn(SigninManagerFactory::GetInstance());
DependsOn(SupervisedUserServiceFactory::GetInstance());
- // Indirect dependency via AccountServiceFlagFetcher.
- DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
- // TODO(treib): Do we have more dependencies here?
}
ChildAccountServiceFactory::~ChildAccountServiceFactory() {}
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index d31508fa..04d9765 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -227,7 +227,6 @@
'browser/services/gcm/gcm_account_tracker_unittest.cc',
'browser/shell_integration_win_unittest.cc',
'browser/signin/account_reconcilor_unittest.cc',
- 'browser/signin/account_service_flag_fetcher_unittest.cc',
'browser/signin/chrome_signin_client_unittest.cc',
'browser/signin/local_auth_unittest.cc',
'browser/signin/signin_global_error_unittest.cc',
diff --git a/components/signin.gypi b/components/signin.gypi
index 63bdd85..7a081c3 100644
--- a/components/signin.gypi
+++ b/components/signin.gypi
@@ -50,8 +50,6 @@
'signin/core/browser/about_signin_internals.h',
'signin/core/browser/account_reconcilor.cc',
'signin/core/browser/account_reconcilor.h',
- 'signin/core/browser/account_service_flag_fetcher.cc',
- '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/device_activity_fetcher.cc',
diff --git a/components/signin/core/browser/BUILD.gn b/components/signin/core/browser/BUILD.gn
index b57e33b..eb4353c 100644
--- a/components/signin/core/browser/BUILD.gn
+++ b/components/signin/core/browser/BUILD.gn
@@ -8,8 +8,6 @@ static_library("browser") {
"about_signin_internals.h",
"account_reconcilor.cc",
"account_reconcilor.h",
- "account_service_flag_fetcher.cc",
- "account_service_flag_fetcher.h",
"account_tracker_service.cc",
"account_tracker_service.h",
"device_activity_fetcher.cc",
diff --git a/components/signin/core/browser/account_service_flag_fetcher.cc b/components/signin/core/browser/account_service_flag_fetcher.cc
deleted file mode 100644
index 4159ee1..0000000
--- a/components/signin/core/browser/account_service_flag_fetcher.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-// 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 "components/signin/core/browser/account_service_flag_fetcher.h"
-
-#include "base/strings/string_split.h"
-#include "components/signin/core/browser/profile_oauth2_token_service.h"
-#include "google_apis/gaia/gaia_constants.h"
-
-AccountServiceFlagFetcher::AccountServiceFlagFetcher(
- const std::string& account_id,
- ProfileOAuth2TokenService* token_service,
- net::URLRequestContextGetter* request_context,
- const ResultCallback& callback)
- : OAuth2TokenService::Consumer("account_service_flag_fetcher"),
- account_id_(account_id),
- token_service_(token_service),
- gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, request_context),
- callback_(callback) {
- Start();
-}
-
-AccountServiceFlagFetcher::~AccountServiceFlagFetcher() {
- // Ensures PO2TS observation is cleared when AccountServiceFlagFetcher is
- // destructed before refresh token is available.
- token_service_->RemoveObserver(this);
-
- gaia_auth_fetcher_.CancelRequest();
-}
-
-void AccountServiceFlagFetcher::Start() {
- if (token_service_->RefreshTokenIsAvailable(account_id_)) {
- StartFetchingOAuth2AccessToken();
- } else {
- // Wait until we get a refresh token.
- token_service_->AddObserver(this);
- }
-}
-
-void AccountServiceFlagFetcher::OnRefreshTokenAvailable(
- const std::string& account_id) {
- // Wait until we get a refresh token for the requested account.
- if (account_id != account_id_)
- return;
-
- token_service_->RemoveObserver(this);
-
- StartFetchingOAuth2AccessToken();
-}
-
-void AccountServiceFlagFetcher::OnRefreshTokensLoaded() {
- token_service_->RemoveObserver(this);
-
- // The PO2TS has loaded all tokens, but we didn't get one for the account we
- // want. We probably won't get one any time soon, so report an error.
- DLOG(WARNING) << "AccountServiceFlagFetcher::OnRefreshTokensLoaded: "
- << "Did not get a refresh token for account " << account_id_;
- callback_.Run(TOKEN_ERROR, std::vector<std::string>());
-}
-
-void AccountServiceFlagFetcher::StartFetchingOAuth2AccessToken() {
- OAuth2TokenService::ScopeSet scopes;
- scopes.insert(GaiaConstants::kOAuth1LoginScope);
- oauth2_access_token_request_ = token_service_->StartRequest(
- account_id_, scopes, this);
-}
-
-void AccountServiceFlagFetcher::OnGetTokenSuccess(
- const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) {
- DCHECK_EQ(oauth2_access_token_request_.get(), request);
- oauth2_access_token_request_.reset();
-
- gaia_auth_fetcher_.StartOAuthLogin(access_token, GaiaConstants::kGaiaService);
-}
-
-void AccountServiceFlagFetcher::OnGetTokenFailure(
- const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) {
- DCHECK_EQ(oauth2_access_token_request_.get(), request);
- oauth2_access_token_request_.reset();
-
- DLOG(WARNING) << "AccountServiceFlagFetcher::OnGetTokenFailure: "
- << error.ToString();
- callback_.Run(TOKEN_ERROR, std::vector<std::string>());
-}
-
-void AccountServiceFlagFetcher::OnClientLoginSuccess(
- const ClientLoginResult& result) {
- gaia_auth_fetcher_.StartGetUserInfo(result.lsid);
-}
-
-void AccountServiceFlagFetcher::OnClientLoginFailure(
- const GoogleServiceAuthError& error) {
- DLOG(WARNING) << "AccountServiceFlagFetcher::OnClientLoginFailure: "
- << error.ToString();
- callback_.Run(SERVICE_ERROR, std::vector<std::string>());
-}
-
-void AccountServiceFlagFetcher::OnGetUserInfoSuccess(const UserInfoMap& data) {
- ResultCode result = SERVICE_ERROR;
- std::vector<std::string> services;
- UserInfoMap::const_iterator services_iter = data.find("allServices");
- if (services_iter != data.end()) {
- result = SUCCESS;
- base::SplitString(services_iter->second, ',', &services);
- } else {
- DLOG(WARNING) << "AccountServiceFlagFetcher::OnGetUserInfoSuccess: "
- << "GetUserInfo response didn't include allServices field.";
- }
- callback_.Run(result, services);
-}
-
-void AccountServiceFlagFetcher::OnGetUserInfoFailure(
- const GoogleServiceAuthError& error) {
- DLOG(WARNING) << "AccountServiceFlagFetcher::OnGetUserInfoFailure: "
- << error.ToString();
- callback_.Run(SERVICE_ERROR, std::vector<std::string>());
-}
diff --git a/components/signin/core/browser/account_service_flag_fetcher.h b/components/signin/core/browser/account_service_flag_fetcher.h
deleted file mode 100644
index 1ee6ee3..0000000
--- a/components/signin/core/browser/account_service_flag_fetcher.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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_SERVICE_FLAG_FETCHER_H_
-#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_
-
-#include <string>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
-#include "google_apis/gaia/gaia_auth_consumer.h"
-#include "google_apis/gaia/gaia_auth_fetcher.h"
-#include "google_apis/gaia/oauth2_token_service.h"
-
-class ProfileOAuth2TokenService;
-
-namespace net {
-class URLRequestContextGetter;
-}
-
-// Downloads an account's list of Gaia service flags.
-// On construction, the download starts immediately and calls the given callback
-// when either the download is successful or an error is detected. It is valid
-// to destruct the object before the callback is called; this will cancel the
-// pending request.
-class AccountServiceFlagFetcher : public GaiaAuthConsumer,
- public OAuth2TokenService::Observer,
- public OAuth2TokenService::Consumer {
- public:
- enum ResultCode {
- SUCCESS,
- TOKEN_ERROR, // Failed to get OAuth2 token.
- SERVICE_ERROR, // Service returned an error or malformed reply.
- };
-
- // If the flag download is successful, this will return the list of service
- // flags that are set for the given account.
- typedef base::Callback<void(ResultCode /* result */,
- const std::vector<std::string>& /* flags */)>
- ResultCallback;
-
- // Immediately starts fetching the flags.
- AccountServiceFlagFetcher(const std::string& account_id,
- ProfileOAuth2TokenService* token_service,
- net::URLRequestContextGetter* request_context,
- const ResultCallback& callback);
-
- // Destructing the object before the callback is called cancels the request.
- ~AccountServiceFlagFetcher() override;
-
- private:
- void Start();
- void StartFetchingOAuth2AccessToken();
-
- // Overridden from OAuth2TokenService::Observer:
- void OnRefreshTokenAvailable(const std::string& account_id) override;
- void OnRefreshTokensLoaded() override;
-
- // Overridden from OAuth2TokenService::Consumer:
- void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) override;
- void OnGetTokenFailure(const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) override;
-
- // Overridden from GaiaAuthConsumer:
- void OnClientLoginSuccess(const ClientLoginResult& result) override;
- void OnClientLoginFailure(const GoogleServiceAuthError& error) override;
- void OnGetUserInfoSuccess(const UserInfoMap& data) override;
- void OnGetUserInfoFailure(const GoogleServiceAuthError& error) override;
-
- const std::string account_id_;
- ProfileOAuth2TokenService* token_service_;
- GaiaAuthFetcher gaia_auth_fetcher_;
-
- ResultCallback callback_;
-
- scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_;
-
- DISALLOW_COPY_AND_ASSIGN(AccountServiceFlagFetcher);
-};
-
-#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_