| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 14 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 15 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
| 16 #include "base/time/tick_clock.h" | 15 #include "base/time/tick_clock.h" |
| 17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 16 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 18 #include "components/policy/core/common/policy_switches.h" | |
| 19 | 17 |
| 20 namespace policy { | 18 namespace policy { |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 // The maximum rate at which to refresh policies. | 22 // The maximum rate at which to refresh policies. |
| 25 const size_t kMaxRefreshesPerHour = 5; | 23 const size_t kMaxRefreshesPerHour = 5; |
| 26 | 24 |
| 27 // The maximum time to wait for the invalidations service to become available | 25 // The maximum time to wait for the invalidations service to become available |
| 28 // before starting to issue requests. | 26 // before starting to issue requests. |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 344 } |
| 347 | 345 |
| 348 void CloudPolicyRefreshScheduler::WaitForInvalidationService() { | 346 void CloudPolicyRefreshScheduler::WaitForInvalidationService() { |
| 349 DCHECK(!WaitingForInvalidationService()); | 347 DCHECK(!WaitingForInvalidationService()); |
| 350 wait_for_invalidations_timeout_callback_.Reset( | 348 wait_for_invalidations_timeout_callback_.Reset( |
| 351 base::Bind( | 349 base::Bind( |
| 352 &CloudPolicyRefreshScheduler::OnWaitForInvalidationServiceTimeout, | 350 &CloudPolicyRefreshScheduler::OnWaitForInvalidationServiceTimeout, |
| 353 base::Unretained(this))); | 351 base::Unretained(this))); |
| 354 base::TimeDelta delay = | 352 base::TimeDelta delay = |
| 355 base::TimeDelta::FromSeconds(kWaitForInvalidationsTimeoutSeconds); | 353 base::TimeDelta::FromSeconds(kWaitForInvalidationsTimeoutSeconds); |
| 356 // Do not wait for the invalidation service if the feature is disabled. | |
| 357 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 358 switches::kDisableCloudPolicyPush)) { | |
| 359 delay = base::TimeDelta(); | |
| 360 } | |
| 361 task_runner_->PostDelayedTask( | 354 task_runner_->PostDelayedTask( |
| 362 FROM_HERE, | 355 FROM_HERE, |
| 363 wait_for_invalidations_timeout_callback_.callback(), | 356 wait_for_invalidations_timeout_callback_.callback(), |
| 364 delay); | 357 delay); |
| 365 } | 358 } |
| 366 | 359 |
| 367 void CloudPolicyRefreshScheduler::OnWaitForInvalidationServiceTimeout() { | 360 void CloudPolicyRefreshScheduler::OnWaitForInvalidationServiceTimeout() { |
| 368 wait_for_invalidations_timeout_callback_.Cancel(); | 361 wait_for_invalidations_timeout_callback_.Cancel(); |
| 369 ScheduleRefresh(); | 362 ScheduleRefresh(); |
| 370 } | 363 } |
| 371 | 364 |
| 372 bool CloudPolicyRefreshScheduler::WaitingForInvalidationService() const { | 365 bool CloudPolicyRefreshScheduler::WaitingForInvalidationService() const { |
| 373 return !wait_for_invalidations_timeout_callback_.IsCancelled(); | 366 return !wait_for_invalidations_timeout_callback_.IsCancelled(); |
| 374 } | 367 } |
| 375 | 368 |
| 376 } // namespace policy | 369 } // namespace policy |
| OLD | NEW |