| 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 "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 5 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // If there is an old policy cache then a fetch will be performed "soon"; if | 232 // If there is an old policy cache then a fetch will be performed "soon"; if |
| 233 // that fetch fails then a retry is attempted after a delay, with exponential | 233 // that fetch fails then a retry is attempted after a delay, with exponential |
| 234 // backoff. If those fetches keep failing then the cached timestamp is *not* | 234 // backoff. If those fetches keep failing then the cached timestamp is *not* |
| 235 // updated, and another fetch (and subsequent retries) will be attempted | 235 // updated, and another fetch (and subsequent retries) will be attempted |
| 236 // again on the next startup. | 236 // again on the next startup. |
| 237 // | 237 // |
| 238 // But if the cached policy is considered fresh enough then we try to avoid | 238 // But if the cached policy is considered fresh enough then we try to avoid |
| 239 // fetching again on startup; the Android logic differs from the desktop in | 239 // fetching again on startup; the Android logic differs from the desktop in |
| 240 // this aspect. | 240 // this aspect. |
| 241 if (store_->has_policy() && store_->policy()->has_timestamp()) { | 241 if (store_->has_policy() && store_->policy()->has_timestamp()) { |
| 242 last_refresh_ = | 242 last_refresh_ = base::Time::FromJavaTime(store_->policy()->timestamp()); |
| 243 base::Time::UnixEpoch() + | |
| 244 base::TimeDelta::FromMilliseconds(store_->policy()->timestamp()); | |
| 245 last_refresh_ticks_ = base::TimeTicks::Now() + | 243 last_refresh_ticks_ = base::TimeTicks::Now() + |
| 246 (last_refresh_ - base::Time::NowFromSystemTime()); | 244 (last_refresh_ - base::Time::NowFromSystemTime()); |
| 247 } | 245 } |
| 248 #else | 246 #else |
| 249 // If there is a cached non-managed response, make sure to only re-query the | 247 // If there is a cached non-managed response, make sure to only re-query the |
| 250 // server after kUnmanagedRefreshDelayMs. NB: For existing policy, an | 248 // server after kUnmanagedRefreshDelayMs. NB: For existing policy, an |
| 251 // immediate refresh is intentional. | 249 // immediate refresh is intentional. |
| 252 if (store_->has_policy() && store_->policy()->has_timestamp() && | 250 if (store_->has_policy() && store_->policy()->has_timestamp() && |
| 253 !store_->is_managed()) { | 251 !store_->is_managed()) { |
| 254 last_refresh_ = | 252 last_refresh_ = base::Time::FromJavaTime(store_->policy()->timestamp()); |
| 255 base::Time::UnixEpoch() + | |
| 256 base::TimeDelta::FromMilliseconds(store_->policy()->timestamp()); | |
| 257 last_refresh_ticks_ = base::TimeTicks::Now() + | 253 last_refresh_ticks_ = base::TimeTicks::Now() + |
| 258 (last_refresh_ - base::Time::NowFromSystemTime()); | 254 (last_refresh_ - base::Time::NowFromSystemTime()); |
| 259 } | 255 } |
| 260 #endif | 256 #endif |
| 261 } | 257 } |
| 262 | 258 |
| 263 void CloudPolicyRefreshScheduler::ScheduleRefresh() { | 259 void CloudPolicyRefreshScheduler::ScheduleRefresh() { |
| 264 // If the client isn't registered, there is nothing to do. | 260 // If the client isn't registered, there is nothing to do. |
| 265 if (!client_->is_registered()) { | 261 if (!client_->is_registered()) { |
| 266 CancelRefresh(); | 262 CancelRefresh(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 refresh_callback_.Cancel(); | 354 refresh_callback_.Cancel(); |
| 359 is_scheduled_for_soon_ = false; | 355 is_scheduled_for_soon_ = false; |
| 360 } | 356 } |
| 361 | 357 |
| 362 void CloudPolicyRefreshScheduler::UpdateLastRefresh() { | 358 void CloudPolicyRefreshScheduler::UpdateLastRefresh() { |
| 363 last_refresh_ = base::Time::NowFromSystemTime(); | 359 last_refresh_ = base::Time::NowFromSystemTime(); |
| 364 last_refresh_ticks_ = base::TimeTicks::Now(); | 360 last_refresh_ticks_ = base::TimeTicks::Now(); |
| 365 } | 361 } |
| 366 | 362 |
| 367 } // namespace policy | 363 } // namespace policy |
| OLD | NEW |