| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" | 5 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
| 10 #include "chrome/browser/policy/cloud_policy_constants.h" | 10 #include "chrome/browser/policy/cloud_policy_constants.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 ScheduleRefresh(); | 110 ScheduleRefresh(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void CloudPolicyRefreshScheduler::OnIPAddressChanged() { | 113 void CloudPolicyRefreshScheduler::OnIPAddressChanged() { |
| 114 if (client_->status() == DM_STATUS_REQUEST_FAILED) | 114 if (client_->status() == DM_STATUS_REQUEST_FAILED) |
| 115 RefreshAfter(0); | 115 RefreshAfter(0); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void CloudPolicyRefreshScheduler::UpdateLastRefreshFromPolicy() { | 118 void CloudPolicyRefreshScheduler::UpdateLastRefreshFromPolicy() { |
| 119 if (store_->has_policy() && !store_->is_managed() && | 119 if (!last_refresh_.is_null()) |
| 120 last_refresh_.is_null()) { | 120 return; |
| 121 |
| 122 // If the client has already fetched policy, assume that happened recently. If |
| 123 // that assumption ever breaks, the proper thing to do probably is to move the |
| 124 // |last_refresh_| bookkeeping to CloudPolicyClient. |
| 125 if (client_->policy()) { |
| 126 last_refresh_ = base::Time::NowFromSystemTime(); |
| 127 return; |
| 128 } |
| 129 |
| 130 // If there is a cached non-managed response, make sure to only re-query the |
| 131 // server after kUnmanagedRefreshDelayMs. NB: For existing policy, an |
| 132 // immediate refresh is intentional. |
| 133 if (store_->has_policy() && !store_->is_managed()) { |
| 121 last_refresh_ = | 134 last_refresh_ = |
| 122 base::Time::UnixEpoch() + | 135 base::Time::UnixEpoch() + |
| 123 base::TimeDelta::FromMilliseconds(store_->policy()->timestamp()); | 136 base::TimeDelta::FromMilliseconds(store_->policy()->timestamp()); |
| 124 } | 137 } |
| 125 } | 138 } |
| 126 | 139 |
| 127 void CloudPolicyRefreshScheduler::ScheduleRefresh() { | 140 void CloudPolicyRefreshScheduler::ScheduleRefresh() { |
| 128 // If the client isn't registered, there is nothing to do. | 141 // If the client isn't registered, there is nothing to do. |
| 129 if (!client_->is_registered()) { | 142 if (!client_->is_registered()) { |
| 130 refresh_callback_.Cancel(); | 143 refresh_callback_.Cancel(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 task_runner_->PostDelayedTask(FROM_HERE, refresh_callback_.callback(), delay); | 210 task_runner_->PostDelayedTask(FROM_HERE, refresh_callback_.callback(), delay); |
| 198 } | 211 } |
| 199 | 212 |
| 200 int64 CloudPolicyRefreshScheduler::GetRefreshDelay() { | 213 int64 CloudPolicyRefreshScheduler::GetRefreshDelay() { |
| 201 return std::min(std::max<int64>(refresh_delay_.GetValue(), | 214 return std::min(std::max<int64>(refresh_delay_.GetValue(), |
| 202 kRefreshDelayMinMs), | 215 kRefreshDelayMinMs), |
| 203 kRefreshDelayMaxMs); | 216 kRefreshDelayMaxMs); |
| 204 } | 217 } |
| 205 | 218 |
| 206 } // namespace policy | 219 } // namespace policy |
| OLD | NEW |