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

Unified Diff: components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc

Issue 2159223002: Fixed cloud policy refresh API to return correct value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc
diff --git a/components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc b/components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc
index 441be0f7a3fb753d7a0ac555a135f8a3d8befbaa..161746609e4b0ca3d181bb1a07bc2d2c0d3722d1 100644
--- a/components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc
+++ b/components/policy/core/common/cloud/cloud_policy_refresh_scheduler.cc
@@ -79,12 +79,26 @@ CloudPolicyRefreshScheduler::~CloudPolicyRefreshScheduler() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-void CloudPolicyRefreshScheduler::SetRefreshDelay(int64_t refresh_delay) {
+void CloudPolicyRefreshScheduler::SetDesiredRefreshDelay(
+ int64_t refresh_delay) {
refresh_delay_ms_ = std::min(std::max(refresh_delay, kRefreshDelayMinMs),
kRefreshDelayMaxMs);
ScheduleRefresh();
}
+int64_t CloudPolicyRefreshScheduler::GetActualRefreshDelay() const {
+ // Returns the refresh delay, possibly modified/lengthened due to the presence
+ // of invalidations (we don't have to poll as often if we have policy
+ // invalidations because policy invalidations provide for timely refreshes.
+ if (invalidations_available_) {
+ // If policy invalidations are available then periodic updates are done at
+ // a much lower rate; otherwise use the |refresh_delay_ms_| value.
+ return std::max(refresh_delay_ms_, kWithInvalidationsRefreshDelayMs);
+ } else {
+ return refresh_delay_ms_;
+ }
+}
+
void CloudPolicyRefreshScheduler::RefreshSoon() {
RefreshNow();
}
@@ -227,24 +241,18 @@ void CloudPolicyRefreshScheduler::ScheduleRefresh() {
return;
}
- // If policy invalidations are available then periodic updates are done at
- // a much lower rate; otherwise use the |refresh_delay_ms_| value.
- int64_t refresh_delay_ms = invalidations_available_
- ? kWithInvalidationsRefreshDelayMs
- : refresh_delay_ms_;
-
// If there is a registration, go by the client's status. That will tell us
// what the appropriate refresh delay should be.
switch (client_->status()) {
case DM_STATUS_SUCCESS:
if (store_->is_managed())
- RefreshAfter(refresh_delay_ms);
+ RefreshAfter(GetActualRefreshDelay());
else
RefreshAfter(kUnmanagedRefreshDelayMs);
return;
case DM_STATUS_SERVICE_ACTIVATION_PENDING:
case DM_STATUS_SERVICE_POLICY_NOT_FOUND:
- RefreshAfter(refresh_delay_ms);
+ RefreshAfter(GetActualRefreshDelay());
return;
case DM_STATUS_REQUEST_FAILED:
case DM_STATUS_TEMPORARY_UNAVAILABLE:

Powered by Google App Engine
This is Rietveld 408576698