| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/hash.h" | 10 #include "base/hash.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // previous policy's hash value. | 384 // previous policy's hash value. |
| 385 uint32_t new_hash_value = 0; | 385 uint32_t new_hash_value = 0; |
| 386 if (policy && policy->has_policy_value()) | 386 if (policy && policy->has_policy_value()) |
| 387 new_hash_value = base::Hash(policy->policy_value()); | 387 new_hash_value = base::Hash(policy->policy_value()); |
| 388 bool changed = new_hash_value != policy_hash_value_; | 388 bool changed = new_hash_value != policy_hash_value_; |
| 389 policy_hash_value_ = new_hash_value; | 389 policy_hash_value_ = new_hash_value; |
| 390 return changed; | 390 return changed; |
| 391 } | 391 } |
| 392 | 392 |
| 393 bool CloudPolicyInvalidator::IsInvalidationExpired(int64_t version) { | 393 bool CloudPolicyInvalidator::IsInvalidationExpired(int64_t version) { |
| 394 base::Time last_fetch_time = base::Time::UnixEpoch() + | 394 base::Time last_fetch_time = |
| 395 base::TimeDelta::FromMilliseconds(core_->store()->policy()->timestamp()); | 395 base::Time::FromJavaTime(core_->store()->policy()->timestamp()); |
| 396 | 396 |
| 397 // If the version is unknown, consider the invalidation invalid if the | 397 // If the version is unknown, consider the invalidation invalid if the |
| 398 // policy was fetched very recently. | 398 // policy was fetched very recently. |
| 399 if (version < 0) { | 399 if (version < 0) { |
| 400 base::TimeDelta elapsed = clock_->Now() - last_fetch_time; | 400 base::TimeDelta elapsed = clock_->Now() - last_fetch_time; |
| 401 return elapsed.InSeconds() < kUnknownVersionIgnorePeriod; | 401 return elapsed.InSeconds() < kUnknownVersionIgnorePeriod; |
| 402 } | 402 } |
| 403 | 403 |
| 404 // The invalidation version is the timestamp in microseconds. If the | 404 // The invalidation version is the timestamp in microseconds. If the |
| 405 // invalidation occurred before the last policy fetch, then the invalidation | 405 // invalidation occurred before the last policy fetch, then the invalidation |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { | 439 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { |
| 440 if (!invalidations_enabled_) | 440 if (!invalidations_enabled_) |
| 441 return false; | 441 return false; |
| 442 // If invalidations have been enabled for less than the grace period, then | 442 // If invalidations have been enabled for less than the grace period, then |
| 443 // consider invalidations to be disabled for metrics reporting. | 443 // consider invalidations to be disabled for metrics reporting. |
| 444 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; | 444 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; |
| 445 return elapsed.InSeconds() >= kInvalidationGracePeriod; | 445 return elapsed.InSeconds() >= kInvalidationGracePeriod; |
| 446 } | 446 } |
| 447 | 447 |
| 448 } // namespace policy | 448 } // namespace policy |
| OLD | NEW |