+bool CloudPolicyInvalidator::IsInvalidationExpired(int64 version) {
+ base::Time last_fetch_time = base::Time::UnixEpoch() +
+ base::TimeDelta::FromMilliseconds(core_->store()->policy()->timestamp());
+
+ // If the version is unknown, consider the invalidation invalid if the
+ // policy was fetched very recently.
+ if (version < 0) {
+ base::TimeDelta elapsed = clock_->Now() - last_fetch_time;
+ return elapsed.InSeconds() < kUnknownVersionIgnorePeriod;
+ }
+
+ // The invalidation version is the timestamp in microseconds. If the
+ // invalidation occurred before the last policy fetch, then the invalidation
+ // is expired. Time is added to the invalidation to err on the side of not
+ // expired.
+ base::Time invalidation_time = base::Time::UnixEpoch() +
+ base::TimeDelta::FromMicroseconds(version) +
+ base::TimeDelta::FromSeconds(kMaxInvalidationTimeDelta);
+ return invalidation_time < last_fetch_time;
+}
+