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/hash.h" | 8 #include "base/hash.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 const int CloudPolicyInvalidator::kMissingPayloadDelay = 5; | 25 const int CloudPolicyInvalidator::kMissingPayloadDelay = 5; |
26 const int CloudPolicyInvalidator::kMaxFetchDelayDefault = 10000; | 26 const int CloudPolicyInvalidator::kMaxFetchDelayDefault = 10000; |
27 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; | 27 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; |
28 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; | 28 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; |
29 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; | 29 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; |
30 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; | 30 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; |
31 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; | 31 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; |
32 | 32 |
33 CloudPolicyInvalidator::CloudPolicyInvalidator( | 33 CloudPolicyInvalidator::CloudPolicyInvalidator( |
| 34 enterprise_management::DeviceRegisterRequest::Type type, |
34 CloudPolicyCore* core, | 35 CloudPolicyCore* core, |
35 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 36 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
36 scoped_ptr<base::Clock> clock) | 37 scoped_ptr<base::Clock> clock) |
37 : state_(UNINITIALIZED), | 38 : state_(UNINITIALIZED), |
| 39 type_(type), |
38 core_(core), | 40 core_(core), |
39 task_runner_(task_runner), | 41 task_runner_(task_runner), |
40 clock_(clock.Pass()), | 42 clock_(clock.Pass()), |
41 invalidation_service_(NULL), | 43 invalidation_service_(NULL), |
42 invalidations_enabled_(false), | 44 invalidations_enabled_(false), |
43 invalidation_service_enabled_(false), | 45 invalidation_service_enabled_(false), |
44 is_registered_(false), | 46 is_registered_(false), |
45 invalid_(false), | 47 invalid_(false), |
46 invalidation_version_(0), | 48 invalidation_version_(0), |
47 unknown_version_invalidation_count_(0), | 49 unknown_version_invalidation_count_(0), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 state_ = STOPPED; | 136 state_ = STOPPED; |
135 } | 137 } |
136 } | 138 } |
137 | 139 |
138 void CloudPolicyInvalidator::OnStoreLoaded(CloudPolicyStore* store) { | 140 void CloudPolicyInvalidator::OnStoreLoaded(CloudPolicyStore* store) { |
139 DCHECK(state_ == STARTED); | 141 DCHECK(state_ == STARTED); |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 142 DCHECK(thread_checker_.CalledOnValidThread()); |
141 bool policy_changed = IsPolicyChanged(store->policy()); | 143 bool policy_changed = IsPolicyChanged(store->policy()); |
142 | 144 |
143 if (is_registered_) { | 145 if (is_registered_) { |
144 // Update the kMetricPolicyRefresh histogram. | 146 // Update the kMetricDevicePolicyRefresh/kMetricUserPolicyRefresh histogram. |
145 UMA_HISTOGRAM_ENUMERATION( | 147 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { |
146 kMetricPolicyRefresh, | 148 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh, |
147 GetPolicyRefreshMetric(policy_changed), | 149 GetPolicyRefreshMetric(policy_changed), |
148 METRIC_POLICY_REFRESH_SIZE); | 150 METRIC_POLICY_REFRESH_SIZE); |
| 151 } else { |
| 152 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh, |
| 153 GetPolicyRefreshMetric(policy_changed), |
| 154 METRIC_POLICY_REFRESH_SIZE); |
| 155 } |
149 | 156 |
150 // If the policy was invalid and the version stored matches the latest | 157 // If the policy was invalid and the version stored matches the latest |
151 // invalidation version, acknowledge the latest invalidation. | 158 // invalidation version, acknowledge the latest invalidation. |
152 if (invalid_ && store->invalidation_version() == invalidation_version_) | 159 if (invalid_ && store->invalidation_version() == invalidation_version_) |
153 AcknowledgeInvalidation(); | 160 AcknowledgeInvalidation(); |
154 } | 161 } |
155 | 162 |
156 UpdateRegistration(store->policy()); | 163 UpdateRegistration(store->policy()); |
157 UpdateMaxFetchDelay(store->policy_map()); | 164 UpdateMaxFetchDelay(store->policy_map()); |
158 } | 165 } |
(...skipping 23 matching lines...) Expand all Loading... |
182 std::string payload; | 189 std::string payload; |
183 if (invalidation.is_unknown_version()) { | 190 if (invalidation.is_unknown_version()) { |
184 version = -(++unknown_version_invalidation_count_); | 191 version = -(++unknown_version_invalidation_count_); |
185 } else { | 192 } else { |
186 version = invalidation.version(); | 193 version = invalidation.version(); |
187 payload = invalidation.payload(); | 194 payload = invalidation.payload(); |
188 } | 195 } |
189 | 196 |
190 // Ignore the invalidation if it is expired. | 197 // Ignore the invalidation if it is expired. |
191 bool is_expired = IsInvalidationExpired(version); | 198 bool is_expired = IsInvalidationExpired(version); |
192 UMA_HISTOGRAM_ENUMERATION( | 199 |
193 kMetricPolicyInvalidations, | 200 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { |
194 GetInvalidationMetric(payload.empty(), is_expired), | 201 UMA_HISTOGRAM_ENUMERATION( |
195 POLICY_INVALIDATION_TYPE_SIZE); | 202 kMetricDevicePolicyInvalidations, |
| 203 GetInvalidationMetric(payload.empty(), is_expired), |
| 204 POLICY_INVALIDATION_TYPE_SIZE); |
| 205 } else { |
| 206 UMA_HISTOGRAM_ENUMERATION( |
| 207 kMetricUserPolicyInvalidations, |
| 208 GetInvalidationMetric(payload.empty(), is_expired), |
| 209 POLICY_INVALIDATION_TYPE_SIZE); |
| 210 } |
196 if (is_expired) { | 211 if (is_expired) { |
197 invalidation.Acknowledge(); | 212 invalidation.Acknowledge(); |
198 return; | 213 return; |
199 } | 214 } |
200 | 215 |
201 // Update invalidation state. | 216 // Update invalidation state. |
202 invalid_ = true; | 217 invalid_ = true; |
203 invalidation_.reset(new syncer::Invalidation(invalidation)); | 218 invalidation_.reset(new syncer::Invalidation(invalidation)); |
204 invalidation_version_ = version; | 219 invalidation_version_ = version; |
205 | 220 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { | 411 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { |
397 if (!invalidations_enabled_) | 412 if (!invalidations_enabled_) |
398 return false; | 413 return false; |
399 // If invalidations have been enabled for less than the grace period, then | 414 // If invalidations have been enabled for less than the grace period, then |
400 // consider invalidations to be disabled for metrics reporting. | 415 // consider invalidations to be disabled for metrics reporting. |
401 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; | 416 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; |
402 return elapsed.InSeconds() >= kInvalidationGracePeriod; | 417 return elapsed.InSeconds() >= kInvalidationGracePeriod; |
403 } | 418 } |
404 | 419 |
405 } // namespace policy | 420 } // namespace policy |
OLD | NEW |