diff options
Diffstat (limited to 'chrome/browser/supervised_user/child_accounts')
3 files changed, 44 insertions, 120 deletions
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() {} |