Chromium Code Reviews| Index: chrome/browser/extensions/updater/extension_updater.cc |
| diff --git a/chrome/browser/extensions/updater/extension_updater.cc b/chrome/browser/extensions/updater/extension_updater.cc |
| index 87f7bb569519497eabd86dd45ee4663869e94db7..048a54598bb8fef99a25c7844ba0215fd87d54f9 100644 |
| --- a/chrome/browser/extensions/updater/extension_updater.cc |
| +++ b/chrome/browser/extensions/updater/extension_updater.cc |
| @@ -50,9 +50,9 @@ typedef extensions::ExtensionDownloaderDelegate::PingResult PingResult; |
| namespace { |
| -// Wait at least 5 minutes after browser startup before we do any checks. If you |
| -// change this value, make sure to update comments where it is used. |
| -const int kStartupWaitSeconds = 60 * 5; |
| +// Wait at least 30 seconds after browser startup before we do any checks. If |
|
lazyboy
2016/08/05 00:04:19
As discussed offline, I'd be comfortable if this v
asargent_no_longer_on_chrome
2016/08/05 06:23:31
Done.
|
| +// you change this value, make sure to update comments where it is used. |
| +const int kStartupWaitSeconds = 30; |
| // For sanity checking on update frequency - enforced in release mode only. |
| #if defined(NDEBUG) |
| @@ -172,42 +172,27 @@ TimeDelta ExtensionUpdater::DetermineFirstCheckDelay() { |
| if (frequency_seconds_ < kStartupWaitSeconds) |
| return TimeDelta::FromSeconds(frequency_seconds_); |
| - // If we've never scheduled a check before, start at frequency_seconds_. |
| + // If we've never scheduled a check before, start at a random time up to |
| + // frequency_seconds_ away. |
| if (!prefs_->HasPrefPath(pref_names::kNextUpdateCheck)) |
| - return TimeDelta::FromSeconds(frequency_seconds_); |
| + return TimeDelta::FromSeconds( |
| + RandInt(kStartupWaitSeconds, frequency_seconds_)); |
| - // If it's been a long time since our last actual check, we want to do one |
| - // relatively soon. |
| - Time now = Time::Now(); |
| - Time last = Time::FromInternalValue(prefs_->GetInt64( |
| - pref_names::kLastUpdateCheck)); |
| - int days = (now - last).InDays(); |
| - if (days >= 30) { |
| - // Wait 5-10 minutes. |
| - return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds, |
| - kStartupWaitSeconds * 2)); |
| - } else if (days >= 14) { |
| - // Wait 10-20 minutes. |
| - return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds * 2, |
| - kStartupWaitSeconds * 4)); |
| - } else if (days >= 3) { |
| - // Wait 20-40 minutes. |
| - return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds * 4, |
| - kStartupWaitSeconds * 8)); |
| - } |
| - |
| - // Read the persisted next check time, and use that if it isn't too soon |
| - // or too late. Otherwise pick something random. |
| Time saved_next = Time::FromInternalValue(prefs_->GetInt64( |
| pref_names::kNextUpdateCheck)); |
| - Time earliest = now + TimeDelta::FromSeconds(kStartupWaitSeconds); |
| - Time latest = now + TimeDelta::FromSeconds(frequency_seconds_); |
| - if (saved_next >= earliest && saved_next <= latest) { |
| + |
| + Time now = Time::Now(); |
| + |
| + // Read the persisted next check time, and use that if it isn't in the past |
| + // or too far in the future (this can happen with system clock changes). |
| + if (saved_next > now && |
| + saved_next < now + TimeDelta::FromSeconds(frequency_seconds_)) |
|
lazyboy
2016/08/05 00:04:19
nit: this requires {}
asargent_no_longer_on_chrome
2016/08/05 06:23:32
Done.
|
| return saved_next - now; |
| - } else { |
| - return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds, |
| - frequency_seconds_)); |
| - } |
| + |
| + // In most cases we'll get here because the persisted next check time passed |
| + // while we weren't running, so pick something soon. |
| + return TimeDelta::FromSeconds( |
| + RandInt(kStartupWaitSeconds, kStartupWaitSeconds * 2)); |
| } |
| void ExtensionUpdater::Start() { |