Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_invalidator.cc

Issue 1548133002: Switch to standard integer types in chrome/browser/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
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 enterprise_management::DeviceRegisterRequest::Type type,
35 CloudPolicyCore* core, 35 CloudPolicyCore* core,
36 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 36 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
37 scoped_ptr<base::Clock> clock, 37 scoped_ptr<base::Clock> clock,
38 int64 highest_handled_invalidation_version) 38 int64_t highest_handled_invalidation_version)
39 : state_(UNINITIALIZED), 39 : state_(UNINITIALIZED),
40 type_(type), 40 type_(type),
41 core_(core), 41 core_(core),
42 task_runner_(task_runner), 42 task_runner_(task_runner),
43 clock_(clock.Pass()), 43 clock_(clock.Pass()),
44 invalidation_service_(NULL), 44 invalidation_service_(NULL),
45 invalidations_enabled_(false), 45 invalidations_enabled_(false),
46 invalidation_service_enabled_(false), 46 invalidation_service_enabled_(false),
47 is_registered_(false), 47 is_registered_(false),
48 invalid_(false), 48 invalid_(false),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { 160 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) {
161 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh, 161 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh,
162 GetPolicyRefreshMetric(policy_changed), 162 GetPolicyRefreshMetric(policy_changed),
163 METRIC_POLICY_REFRESH_SIZE); 163 METRIC_POLICY_REFRESH_SIZE);
164 } else { 164 } else {
165 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh, 165 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh,
166 GetPolicyRefreshMetric(policy_changed), 166 GetPolicyRefreshMetric(policy_changed),
167 METRIC_POLICY_REFRESH_SIZE); 167 METRIC_POLICY_REFRESH_SIZE);
168 } 168 }
169 169
170 const int64 store_invalidation_version = store->invalidation_version(); 170 const int64_t store_invalidation_version = store->invalidation_version();
171 171
172 // If the policy was invalid and the version stored matches the latest 172 // If the policy was invalid and the version stored matches the latest
173 // invalidation version, acknowledge the latest invalidation. 173 // invalidation version, acknowledge the latest invalidation.
174 if (invalid_ && store_invalidation_version == invalidation_version_) 174 if (invalid_ && store_invalidation_version == invalidation_version_)
175 AcknowledgeInvalidation(); 175 AcknowledgeInvalidation();
176 176
177 // Update the highest invalidation version that was handled already. 177 // Update the highest invalidation version that was handled already.
178 if (store_invalidation_version > highest_handled_invalidation_version_) 178 if (store_invalidation_version > highest_handled_invalidation_version_)
179 highest_handled_invalidation_version_ = store_invalidation_version; 179 highest_handled_invalidation_version_ = store_invalidation_version;
180 } 180 }
(...skipping 24 matching lines...) Expand all
205 // If there is still a pending invalidation, acknowledge it, since we only 205 // If there is still a pending invalidation, acknowledge it, since we only
206 // care about the latest invalidation. 206 // care about the latest invalidation.
207 if (invalid_) 207 if (invalid_)
208 AcknowledgeInvalidation(); 208 AcknowledgeInvalidation();
209 209
210 // Get the version and payload from the invalidation. 210 // Get the version and payload from the invalidation.
211 // When an invalidation with unknown version is received, use negative 211 // When an invalidation with unknown version is received, use negative
212 // numbers based on the number of such invalidations received. This 212 // numbers based on the number of such invalidations received. This
213 // ensures that the version numbers do not collide with "real" versions 213 // ensures that the version numbers do not collide with "real" versions
214 // (which are positive) or previous invalidations with unknown version. 214 // (which are positive) or previous invalidations with unknown version.
215 int64 version; 215 int64_t version;
216 std::string payload; 216 std::string payload;
217 if (invalidation.is_unknown_version()) { 217 if (invalidation.is_unknown_version()) {
218 version = -(++unknown_version_invalidation_count_); 218 version = -(++unknown_version_invalidation_count_);
219 } else { 219 } else {
220 version = invalidation.version(); 220 version = invalidation.version();
221 payload = invalidation.payload(); 221 payload = invalidation.payload();
222 } 222 }
223 223
224 // Ignore the invalidation if it is expired. 224 // Ignore the invalidation if it is expired.
225 bool is_expired = IsInvalidationExpired(version); 225 bool is_expired = IsInvalidationExpired(version);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 invalidation_->Acknowledge(); 373 invalidation_->Acknowledge();
374 invalidation_.reset(); 374 invalidation_.reset();
375 // Cancel any scheduled policy refreshes. 375 // Cancel any scheduled policy refreshes.
376 weak_factory_.InvalidateWeakPtrs(); 376 weak_factory_.InvalidateWeakPtrs();
377 } 377 }
378 378
379 bool CloudPolicyInvalidator::IsPolicyChanged( 379 bool CloudPolicyInvalidator::IsPolicyChanged(
380 const enterprise_management::PolicyData* policy) { 380 const enterprise_management::PolicyData* policy) {
381 // Determine if the policy changed by comparing its hash value to the 381 // Determine if the policy changed by comparing its hash value to the
382 // previous policy's hash value. 382 // previous policy's hash value.
383 uint32 new_hash_value = 0; 383 uint32_t new_hash_value = 0;
384 if (policy && policy->has_policy_value()) 384 if (policy && policy->has_policy_value())
385 new_hash_value = base::Hash(policy->policy_value()); 385 new_hash_value = base::Hash(policy->policy_value());
386 bool changed = new_hash_value != policy_hash_value_; 386 bool changed = new_hash_value != policy_hash_value_;
387 policy_hash_value_ = new_hash_value; 387 policy_hash_value_ = new_hash_value;
388 return changed; 388 return changed;
389 } 389 }
390 390
391 bool CloudPolicyInvalidator::IsInvalidationExpired(int64 version) { 391 bool CloudPolicyInvalidator::IsInvalidationExpired(int64_t version) {
392 base::Time last_fetch_time = base::Time::UnixEpoch() + 392 base::Time last_fetch_time = base::Time::UnixEpoch() +
393 base::TimeDelta::FromMilliseconds(core_->store()->policy()->timestamp()); 393 base::TimeDelta::FromMilliseconds(core_->store()->policy()->timestamp());
394 394
395 // If the version is unknown, consider the invalidation invalid if the 395 // If the version is unknown, consider the invalidation invalid if the
396 // policy was fetched very recently. 396 // policy was fetched very recently.
397 if (version < 0) { 397 if (version < 0) {
398 base::TimeDelta elapsed = clock_->Now() - last_fetch_time; 398 base::TimeDelta elapsed = clock_->Now() - last_fetch_time;
399 return elapsed.InSeconds() < kUnknownVersionIgnorePeriod; 399 return elapsed.InSeconds() < kUnknownVersionIgnorePeriod;
400 } 400 }
401 401
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { 437 bool CloudPolicyInvalidator::GetInvalidationsEnabled() {
438 if (!invalidations_enabled_) 438 if (!invalidations_enabled_)
439 return false; 439 return false;
440 // If invalidations have been enabled for less than the grace period, then 440 // If invalidations have been enabled for less than the grace period, then
441 // consider invalidations to be disabled for metrics reporting. 441 // consider invalidations to be disabled for metrics reporting.
442 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; 442 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_;
443 return elapsed.InSeconds() >= kInvalidationGracePeriod; 443 return elapsed.InSeconds() >= kInvalidationGracePeriod;
444 } 444 }
445 445
446 } // namespace policy 446 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698