diff options
author | treib <treib@chromium.org> | 2015-01-26 06:45:43 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-26 14:46:47 +0000 |
commit | f528e43789eb29153e5cd242b71fc4db46b32dd3 (patch) | |
tree | 32dac9f104b161c4ac781cfa37d18ffac03cfcd5 | |
parent | 78924e45a48629664deeee14e3c84638ae13ff66 (diff) | |
download | chromium_src-f528e43789eb29153e5cd242b71fc4db46b32dd3.zip chromium_src-f528e43789eb29153e5cd242b71fc4db46b32dd3.tar.gz chromium_src-f528e43789eb29153e5cd242b71fc4db46b32dd3.tar.bz2 |
ChildAccountService: periodically re-fetch parent info; retry on failure
with exponential backoff!
BUG=372381,450828
Review URL: https://codereview.chromium.org/880483002
Cr-Commit-Position: refs/heads/master@{#313065}
-rw-r--r-- | chrome/browser/supervised_user/child_accounts/child_account_service.cc | 57 | ||||
-rw-r--r-- | chrome/browser/supervised_user/child_accounts/child_account_service.h | 7 |
2 files changed, 46 insertions, 18 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 a0c30ac..6af9dec 100644 --- a/chrome/browser/supervised_user/child_accounts/child_account_service.cc +++ b/chrome/browser/supervised_user/child_accounts/child_account_service.cc @@ -36,11 +36,12 @@ const char kIsChildAccountServiceFlagName[] = "uca"; -// Normally, re-check the child account flag once per day. -const int kStatusFlagUpdateIntervalSeconds = 60 * 60 * 24; +// Normally, re-check the child account flag and the family info once per day. +const int kUpdateIntervalSeconds = 60 * 60 * 24; -// In case of an error while getting the flag, retry with exponential backoff. -const net::BackoffEntry::Policy kFlagFetchBackoffPolicy = { +// In case of an error while getting the flag or 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. 0, @@ -68,7 +69,8 @@ const net::BackoffEntry::Policy kFlagFetchBackoffPolicy = { ChildAccountService::ChildAccountService(Profile* profile) : profile_(profile), active_(false), - flag_fetch_backoff_(&kFlagFetchBackoffPolicy), + flag_fetch_backoff_(&kBackoffPolicy), + family_fetch_backoff_(&kBackoffPolicy), weak_ptr_factory_(this) {} ChildAccountService::~ChildAccountService() {} @@ -128,16 +130,9 @@ bool ChildAccountService::SetActive(bool active) { SigninManagerFactory::GetForProfile(profile_)->ProhibitSignout(true); #endif - // TODO(treib): Maybe only fetch the parents on the first start, and then - // refresh occasionally (like once every 24h)? That's what - // GAIAInfoUpdateService does. - family_fetcher_.reset(new FamilyInfoFetcher( - this, - SigninManagerFactory::GetForProfile(profile_) - ->GetAuthenticatedAccountId(), - ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), - profile_->GetRequestContext())); - family_fetcher_->StartGetFamilyMembers(); + // TODO(treib): Maybe store the last update time in a pref, so we don't + // have to re-fetch on every start. + StartFetchingFamilyInfo(); SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile(profile_); @@ -205,6 +200,7 @@ void ChildAccountService::GoogleSignedOut(const std::string& account_id, const std::string& username) { DCHECK(!profile_->IsChild()); CancelFetchingServiceFlags(); + CancelFetchingFamilyInfo(); } void ChildAccountService::OnGetFamilyMembersSuccess( @@ -229,12 +225,37 @@ void ChildAccountService::OnGetFamilyMembersSuccess( if (!parent_found) ClearSecondCustodianPrefs(); family_fetcher_.reset(); + + family_fetch_backoff_.InformOfRequest(true); + + ScheduleNextFamilyInfoUpdate( + base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); } void ChildAccountService::OnFailure(FamilyInfoFetcher::ErrorCode error) { DLOG(WARNING) << "GetFamilyMembers failed with code " << error; + family_fetch_backoff_.InformOfRequest(false); + ScheduleNextFamilyInfoUpdate(family_fetch_backoff_.GetTimeUntilRelease()); +} + +void ChildAccountService::StartFetchingFamilyInfo() { + family_fetcher_.reset(new FamilyInfoFetcher( + this, + SigninManagerFactory::GetForProfile(profile_) + ->GetAuthenticatedAccountId(), + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), + profile_->GetRequestContext())); + family_fetcher_->StartGetFamilyMembers(); +} + +void ChildAccountService::CancelFetchingFamilyInfo() { family_fetcher_.reset(); - // TODO(treib): Retry after a while? + family_fetch_timer_.Stop(); +} + +void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { + family_fetch_timer_.Start( + FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); } void ChildAccountService::StartFetchingServiceFlags() { @@ -282,8 +303,8 @@ void ChildAccountService::OnFlagsFetched( kIsChildAccountServiceFlagName) != flags.end(); SetIsChildAccount(is_child_account); - ScheduleNextStatusFlagUpdate(base::TimeDelta::FromSeconds( - kStatusFlagUpdateIntervalSeconds)); + ScheduleNextStatusFlagUpdate( + base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); } void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 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 0c2fb1c..4a15196 100644 --- a/chrome/browser/supervised_user/child_accounts/child_account_service.h +++ b/chrome/browser/supervised_user/child_accounts/child_account_service.h @@ -70,6 +70,10 @@ class ChildAccountService : public KeyedService, const std::vector<FamilyInfoFetcher::FamilyMember>& members) override; void OnFailure(FamilyInfoFetcher::ErrorCode error) override; + void StartFetchingFamilyInfo(); + void CancelFetchingFamilyInfo(); + void ScheduleNextFamilyInfoUpdate(base::TimeDelta delay); + void StartFetchingServiceFlags(); void CancelFetchingServiceFlags(); void OnFlagsFetched(AccountServiceFlagFetcher::ResultCode, @@ -101,6 +105,9 @@ class ChildAccountService : public KeyedService, 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_; + net::BackoffEntry family_fetch_backoff_; base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_; |