Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3372)

Unified Diff: chrome/browser/supervised_user/child_accounts/child_account_service.cc

Issue 880483002: ChildAccountService: periodically re-fetch parent info; retry on failure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/supervised_user/child_accounts/child_account_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/supervised_user/child_accounts/child_account_service.cc
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 a0c30ac724bbc2bcd38903d869b973eca26d8fb8..6af9dec3208716c71f35a812d8eca19218b69e68 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
Marc Treib 2015/01/26 13:19:31 WDYT?
Bernhard Bauer 2015/01/26 13:41:23 That seems like a good idea. We could check at eve
+ // 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) {
« no previous file with comments | « chrome/browser/supervised_user/child_accounts/child_account_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698