Index: chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc |
diff --git a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc |
index 0631673f5b6d94f45c17a2a535cd87ee094a2c94..224d660dccc13225012c899ae77d594597cfb279 100644 |
--- a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc |
+++ b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc |
@@ -35,11 +35,13 @@ const int64 CloudPolicyRefreshScheduler::kRefreshDelayMinMs = |
30 * 60 * 1000; // 30 minutes. |
const int64 CloudPolicyRefreshScheduler::kRefreshDelayMaxMs = |
24 * 60 * 60 * 1000; // 1 day. |
+const int64 CloudPolicyRefreshScheduler::kFirstRefreshDelayMs = 4000; |
CloudPolicyRefreshScheduler::CloudPolicyRefreshScheduler( |
CloudPolicyClient* client, |
CloudPolicyStore* store, |
- const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
+ bool invalidations_enabled) |
: client_(client), |
store_(store), |
task_runner_(task_runner), |
@@ -50,11 +52,16 @@ CloudPolicyRefreshScheduler::CloudPolicyRefreshScheduler( |
base::Bind(&CloudPolicyRefreshScheduler::RefreshNow, |
base::Unretained(this)), |
task_runner_, |
- scoped_ptr<base::TickClock>(new base::DefaultTickClock())) { |
+ scoped_ptr<base::TickClock>(new base::DefaultTickClock())), |
+ first_refresh_(base::Time::NowFromSystemTime() + |
+ base::TimeDelta::FromMilliseconds(kFirstRefreshDelayMs)) { |
client_->AddObserver(this); |
store_->AddObserver(this); |
net::NetworkChangeNotifier::AddIPAddressObserver(this); |
+ // Disable first refresh delay if invalidations are not enabled. |
+ if (!invalidations_enabled) |
+ first_refresh_ = base::Time(); |
UpdateLastRefreshFromPolicy(); |
ScheduleRefresh(); |
} |
@@ -75,6 +82,13 @@ void CloudPolicyRefreshScheduler::RefreshSoon() { |
rate_limiter_.PostRequest(); |
} |
+void CloudPolicyRefreshScheduler::RefreshForInvalidation() { |
+ // Remove the first refresh time restriction, as the intent is to prevent |
+ // refreshes on login from occurring before invalidations can be processed. |
+ first_refresh_ = base::Time(); |
+ RefreshNow(); |
+} |
+ |
void CloudPolicyRefreshScheduler::OnPolicyFetched(CloudPolicyClient* client) { |
error_retry_delay_ms_ = kInitialErrorRetryDelayMs; |
@@ -219,10 +233,14 @@ void CloudPolicyRefreshScheduler::RefreshAfter(int delta_ms) { |
base::TimeDelta delta(base::TimeDelta::FromMilliseconds(delta_ms)); |
refresh_callback_.Cancel(); |
+ // Make sure the refresh does not occur before the first refresh time. |
rlarocque
2013/07/23 17:43:08
Did cloud policy refresh within minutes of restart
Joao da Silva
2013/07/23 20:44:47
On the desktop, yes (on Android we will delay it d
Steve Condie
2013/07/24 01:42:04
As we discussed I reverted all my changes to Cloud
|
+ base::Time now = base::Time::NowFromSystemTime(); |
+ base::TimeDelta min_delay; |
+ if (now < first_refresh_) |
+ min_delay = first_refresh_ - now; |
+ |
// Schedule the callback. |
- base::TimeDelta delay = |
- std::max((last_refresh_ + delta) - base::Time::NowFromSystemTime(), |
- base::TimeDelta()); |
+ base::TimeDelta delay = std::max((last_refresh_ + delta) - now, min_delay); |
refresh_callback_.Reset( |
base::Bind(&CloudPolicyRefreshScheduler::PerformRefresh, |
base::Unretained(this))); |