| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cloud_policy_invalidator.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | |
| 9 #include "base/hash.h" | 8 #include "base/hash.h" |
| 10 #include "base/location.h" | 9 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 13 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | |
| 15 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
| 16 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 17 #include "base/values.h" | 15 #include "base/values.h" |
| 18 #include "components/invalidation/invalidation_service.h" | 16 #include "components/invalidation/invalidation_service.h" |
| 19 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 17 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 20 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 18 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 21 #include "components/policy/core/common/cloud/enterprise_metrics.h" | 19 #include "components/policy/core/common/cloud/enterprise_metrics.h" |
| 22 #include "components/policy/core/common/policy_switches.h" | |
| 23 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
| 24 #include "sync/notifier/object_id_invalidation_map.h" | 21 #include "sync/notifier/object_id_invalidation_map.h" |
| 25 | 22 |
| 26 namespace policy { | 23 namespace policy { |
| 27 | 24 |
| 28 const int CloudPolicyInvalidator::kMissingPayloadDelay = 5; | 25 const int CloudPolicyInvalidator::kMissingPayloadDelay = 5; |
| 29 const int CloudPolicyInvalidator::kMaxFetchDelayDefault = 120000; | 26 const int CloudPolicyInvalidator::kMaxFetchDelayDefault = 10000; |
| 30 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; | 27 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; |
| 31 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; | 28 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; |
| 32 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; | 29 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; |
| 33 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; | 30 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; |
| 34 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; | 31 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; |
| 35 | 32 |
| 36 CloudPolicyInvalidator::CloudPolicyInvalidator( | 33 CloudPolicyInvalidator::CloudPolicyInvalidator( |
| 37 CloudPolicyCore* core, | 34 CloudPolicyCore* core, |
| 38 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 35 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 39 scoped_ptr<base::Clock> clock) | 36 scoped_ptr<base::Clock> clock) |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 int delay; | 286 int delay; |
| 290 | 287 |
| 291 // Try reading the delay from the policy. | 288 // Try reading the delay from the policy. |
| 292 const base::Value* delay_policy_value = | 289 const base::Value* delay_policy_value = |
| 293 policy_map.GetValue(key::kMaxInvalidationFetchDelay); | 290 policy_map.GetValue(key::kMaxInvalidationFetchDelay); |
| 294 if (delay_policy_value && delay_policy_value->GetAsInteger(&delay)) { | 291 if (delay_policy_value && delay_policy_value->GetAsInteger(&delay)) { |
| 295 set_max_fetch_delay(delay); | 292 set_max_fetch_delay(delay); |
| 296 return; | 293 return; |
| 297 } | 294 } |
| 298 | 295 |
| 299 // Try reading the delay from the command line switch. | |
| 300 std::string delay_string = | |
| 301 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 302 switches::kCloudPolicyInvalidationDelay); | |
| 303 if (base::StringToInt(delay_string, &delay)) { | |
| 304 set_max_fetch_delay(delay); | |
| 305 return; | |
| 306 } | |
| 307 | |
| 308 set_max_fetch_delay(kMaxFetchDelayDefault); | 296 set_max_fetch_delay(kMaxFetchDelayDefault); |
| 309 } | 297 } |
| 310 | 298 |
| 311 void CloudPolicyInvalidator::set_max_fetch_delay(int delay) { | 299 void CloudPolicyInvalidator::set_max_fetch_delay(int delay) { |
| 312 if (delay < kMaxFetchDelayMin) | 300 if (delay < kMaxFetchDelayMin) |
| 313 max_fetch_delay_ = kMaxFetchDelayMin; | 301 max_fetch_delay_ = kMaxFetchDelayMin; |
| 314 else if (delay > kMaxFetchDelayMax) | 302 else if (delay > kMaxFetchDelayMax) |
| 315 max_fetch_delay_ = kMaxFetchDelayMax; | 303 max_fetch_delay_ = kMaxFetchDelayMax; |
| 316 else | 304 else |
| 317 max_fetch_delay_ = delay; | 305 max_fetch_delay_ = delay; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { | 396 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { |
| 409 if (!invalidations_enabled_) | 397 if (!invalidations_enabled_) |
| 410 return false; | 398 return false; |
| 411 // If invalidations have been enabled for less than the grace period, then | 399 // If invalidations have been enabled for less than the grace period, then |
| 412 // consider invalidations to be disabled for metrics reporting. | 400 // consider invalidations to be disabled for metrics reporting. |
| 413 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; | 401 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; |
| 414 return elapsed.InSeconds() >= kInvalidationGracePeriod; | 402 return elapsed.InSeconds() >= kInvalidationGracePeriod; |
| 415 } | 403 } |
| 416 | 404 |
| 417 } // namespace policy | 405 } // namespace policy |
| OLD | NEW |