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

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

Issue 2285233002: Don't retry fetching policies if it's a blocking operation, don't wait if we will bypass the proxy … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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/device_management_service.cc
diff --git a/components/policy/core/common/cloud/device_management_service.cc b/components/policy/core/common/cloud/device_management_service.cc
index 7061e6f3661bff2270b26f61593b287d5ddb3c05..5b24d5f46e1e0adb6ace6a06a0d8e9a28a2214d9 100644
--- a/components/policy/core/common/cloud/device_management_service.cc
+++ b/components/policy/core/common/cloud/device_management_service.cc
@@ -176,17 +176,26 @@ class DeviceManagementRequestJobImpl : public DeviceManagementRequestJob {
// Configures the fetcher, setting up payload and headers.
void ConfigureRequest(net::URLFetcher* fetcher);
- // Returns true if this job should be retried. |fetcher| has just completed,
- // and can be inspected to determine if the request failed and should be
- // retried.
- bool ShouldRetry(const net::URLFetcher* fetcher);
+ enum RetryMethod {
+ // No retry required for this request.
+ NO_RETRY,
+ // Should retry immediately (no delay).
+ RETRY_IMMEDIATELY,
+ // Should retry after a delay.
+ RETRY_WITH_DELAY
+ };
+
+ // Returns if and how this job should be retried. |fetcher| has just
+ // completed, and can be inspected to determine if the request failed and
+ // should be retried.
+ RetryMethod ShouldRetry(const net::URLFetcher* fetcher);
+
+ // Returns the delay before the next retry with the specified RetryMethod.
+ int GetRetryDelay(RetryMethod method);
// Invoked right before retrying this job.
void PrepareRetry();
- // Number of times that this job has been retried due to connection errors.
- int retries_count() { return retries_count_; }
-
// Get weak pointer
base::WeakPtr<DeviceManagementRequestJobImpl> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
@@ -349,13 +358,13 @@ void DeviceManagementRequestJobImpl::ConfigureRequest(
fetcher->SetExtraRequestHeaders(extra_headers);
}
-bool DeviceManagementRequestJobImpl::ShouldRetry(
- const net::URLFetcher* fetcher) {
+DeviceManagementRequestJobImpl::RetryMethod
+DeviceManagementRequestJobImpl::ShouldRetry(const net::URLFetcher* fetcher) {
if (FailedWithProxy(fetcher) && !bypass_proxy_) {
- // Retry the job if it failed due to a broken proxy, by bypassing the
- // proxy on the next try.
+ // Retry the job immediately if it failed due to a broken proxy, by
+ // bypassing the proxy on the next try.
bypass_proxy_ = true;
- return true;
+ return RETRY_IMMEDIATELY;
}
// Early device policy fetches on ChromeOS and Auto-Enrollment checks are
@@ -364,12 +373,30 @@ bool DeviceManagementRequestJobImpl::ShouldRetry(
// it to retry up to 3 times just in case.
if (IsConnectionError(fetcher->GetStatus()) && retries_count_ < kMaxRetries) {
++retries_count_;
- return true;
+ if (type_ == DeviceManagementRequestJob::TYPE_POLICY_FETCH) {
+ // We must not delay when retrying policy fetch, because it is a blocking
+ // call when logging in.
+ return RETRY_IMMEDIATELY;
+ } else {
+ return RETRY_WITH_DELAY;
+ }
}
// The request didn't fail, or the limit of retry attempts has been reached;
// forward the result to the job owner.
- return false;
+ return NO_RETRY;
+}
+
+int DeviceManagementRequestJobImpl::GetRetryDelay(RetryMethod method) {
+ switch (method) {
+ case RETRY_WITH_DELAY:
+ return g_retry_delay_ms << (retries_count_ - 1);
+ case RETRY_IMMEDIATELY:
+ return 0;
+ default:
+ NOTREACHED();
+ return 0;
+ }
}
void DeviceManagementRequestJobImpl::PrepareRetry() {
@@ -407,7 +434,8 @@ em::DeviceManagementRequest* DeviceManagementRequestJob::GetRequest() {
DeviceManagementRequestJob::DeviceManagementRequestJob(
JobType type,
const std::string& agent_parameter,
- const std::string& platform_parameter) {
+ const std::string& platform_parameter)
+ : type_(type) {
AddParameter(dm_protocol::kParamRequest, JobTypeToRequestType(type));
AddParameter(dm_protocol::kParamDeviceType, dm_protocol::kValueDeviceType);
AddParameter(dm_protocol::kParamAppType, dm_protocol::kValueAppType);
@@ -542,9 +570,11 @@ void DeviceManagementService::OnURLFetchComplete(
DeviceManagementRequestJobImpl* job = entry->second;
pending_jobs_.erase(entry);
- if (job->ShouldRetry(source)) {
+ DeviceManagementRequestJobImpl::RetryMethod retry_method =
+ job->ShouldRetry(source);
+ if (retry_method != DeviceManagementRequestJobImpl::RetryMethod::NO_RETRY) {
job->PrepareRetry();
- int delay = g_retry_delay_ms << (job->retries_count() - 1);
+ int delay = job->GetRetryDelay(retry_method);
LOG(WARNING) << "Dmserver request failed, retrying in " << delay / 1000
<< "s.";
task_runner_->PostDelayedTask(

Powered by Google App Engine
This is Rietveld 408576698