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

Side by Side Diff: components/policy/core/common/cloud/device_management_service.cc

Issue 2275553002: Don't retry fetching policies if it's a blocking operation, (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « components/policy/core/common/cloud/device_management_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/policy/core/common/cloud/device_management_service.h" 5 #include "components/policy/core/common/cloud/device_management_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void ConfigureRequest(net::URLFetcher* fetcher); 177 void ConfigureRequest(net::URLFetcher* fetcher);
178 178
179 // Returns true if this job should be retried. |fetcher| has just completed, 179 // Returns true if this job should be retried. |fetcher| has just completed,
180 // and can be inspected to determine if the request failed and should be 180 // and can be inspected to determine if the request failed and should be
181 // retried. 181 // retried.
182 bool ShouldRetry(const net::URLFetcher* fetcher); 182 bool ShouldRetry(const net::URLFetcher* fetcher);
183 183
184 // Invoked right before retrying this job. 184 // Invoked right before retrying this job.
185 void PrepareRetry(); 185 void PrepareRetry();
186 186
187 // Returns whether the retry should happen after a delay.
188 bool IsRetryWithDelay() { return retry_with_delay_; }
189
187 // Number of times that this job has been retried due to connection errors. 190 // Number of times that this job has been retried due to connection errors.
188 int retries_count() { return retries_count_; } 191 int retries_count() { return retries_count_; }
189 192
190 // Get weak pointer 193 // Get weak pointer
191 base::WeakPtr<DeviceManagementRequestJobImpl> GetWeakPtr() { 194 base::WeakPtr<DeviceManagementRequestJobImpl> GetWeakPtr() {
192 return weak_ptr_factory_.GetWeakPtr(); 195 return weak_ptr_factory_.GetWeakPtr();
193 } 196 }
194 197
195 protected: 198 protected:
196 // DeviceManagementRequestJob: 199 // DeviceManagementRequestJob:
197 void Run() override; 200 void Run() override;
198 201
199 private: 202 private:
200 // Invokes the callback with the given error code. 203 // Invokes the callback with the given error code.
201 void ReportError(DeviceManagementStatus code); 204 void ReportError(DeviceManagementStatus code);
202 205
203 // Pointer to the service this job is associated with. 206 // Pointer to the service this job is associated with.
204 DeviceManagementService* service_; 207 DeviceManagementService* service_;
205 208
206 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest(). 209 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest().
207 bool bypass_proxy_; 210 bool bypass_proxy_;
208 211
212 // Whether the retry should happen after a delay.
213 bool retry_with_delay_;
214
209 // Number of times that this job has been retried due to connection errors. 215 // Number of times that this job has been retried due to connection errors.
210 int retries_count_; 216 int retries_count_;
211 217
212 // The request context to use for this job. 218 // The request context to use for this job.
213 scoped_refptr<net::URLRequestContextGetter> request_context_; 219 scoped_refptr<net::URLRequestContextGetter> request_context_;
214 220
215 // Used to get notified if the job has been canceled while waiting for retry. 221 // Used to get notified if the job has been canceled while waiting for retry.
216 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_; 222 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_;
217 223
218 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl); 224 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 CHECK(request_.SerializeToString(&payload)); 348 CHECK(request_.SerializeToString(&payload));
343 fetcher->SetUploadData(kPostContentType, payload); 349 fetcher->SetUploadData(kPostContentType, payload);
344 std::string extra_headers; 350 std::string extra_headers;
345 if (!gaia_token_.empty()) 351 if (!gaia_token_.empty())
346 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n"; 352 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n";
347 if (!dm_token_.empty()) 353 if (!dm_token_.empty())
348 extra_headers += kDMTokenAuthHeader + dm_token_ + "\n"; 354 extra_headers += kDMTokenAuthHeader + dm_token_ + "\n";
349 fetcher->SetExtraRequestHeaders(extra_headers); 355 fetcher->SetExtraRequestHeaders(extra_headers);
350 } 356 }
351 357
352 bool DeviceManagementRequestJobImpl::ShouldRetry( 358 bool DeviceManagementRequestJobImpl::ShouldRetry(
Andrew T Wilson (Slow) 2016/08/23 13:46:27 I think a better change would be to have ShouldRet
Marton Hunyady 2016/08/23 14:09:44 Done.
353 const net::URLFetcher* fetcher) { 359 const net::URLFetcher* fetcher) {
354 if (FailedWithProxy(fetcher) && !bypass_proxy_) { 360 if (FailedWithProxy(fetcher) && !bypass_proxy_) {
355 // Retry the job if it failed due to a broken proxy, by bypassing the 361 // Retry the job if it failed due to a broken proxy, by bypassing the
356 // proxy on the next try. 362 // proxy on the next try.
357 bypass_proxy_ = true; 363 bypass_proxy_ = true;
364 retry_with_delay_ = false;
358 return true; 365 return true;
359 } 366 }
360 367
361 // Early device policy fetches on ChromeOS and Auto-Enrollment checks are 368 // Early device policy fetches on ChromeOS and Auto-Enrollment checks are
362 // often interrupted during ChromeOS startup when network is not yet ready. 369 // often interrupted during ChromeOS startup when network is not yet ready.
363 // Allowing the fetcher to retry once after that is enough to recover; allow 370 // Allowing the fetcher to retry once after that is enough to recover; allow
364 // it to retry up to 3 times just in case. 371 // it to retry up to 3 times just in case.
365 if (IsConnectionError(fetcher->GetStatus()) && retries_count_ < kMaxRetries) { 372 if (IsConnectionError(fetcher->GetStatus()) && retries_count_ < kMaxRetries &&
373 type_ != DeviceManagementRequestJob::TYPE_POLICY_FETCH) {
366 ++retries_count_; 374 ++retries_count_;
375 retry_with_delay_ = true;
367 return true; 376 return true;
368 } 377 }
369 378
370 // The request didn't fail, or the limit of retry attempts has been reached; 379 // The request didn't fail, or the limit of retry attempts has been reached;
371 // forward the result to the job owner. 380 // forward the result to the job owner.
372 return false; 381 return false;
373 } 382 }
374 383
375 void DeviceManagementRequestJobImpl::PrepareRetry() { 384 void DeviceManagementRequestJobImpl::PrepareRetry() {
376 if (!retry_callback_.is_null()) 385 if (!retry_callback_.is_null())
(...skipping 23 matching lines...) Expand all
400 AddParameter(dm_protocol::kParamDeviceID, client_id); 409 AddParameter(dm_protocol::kParamDeviceID, client_id);
401 } 410 }
402 411
403 em::DeviceManagementRequest* DeviceManagementRequestJob::GetRequest() { 412 em::DeviceManagementRequest* DeviceManagementRequestJob::GetRequest() {
404 return &request_; 413 return &request_;
405 } 414 }
406 415
407 DeviceManagementRequestJob::DeviceManagementRequestJob( 416 DeviceManagementRequestJob::DeviceManagementRequestJob(
408 JobType type, 417 JobType type,
409 const std::string& agent_parameter, 418 const std::string& agent_parameter,
410 const std::string& platform_parameter) { 419 const std::string& platform_parameter)
420 : type_(type) {
411 AddParameter(dm_protocol::kParamRequest, JobTypeToRequestType(type)); 421 AddParameter(dm_protocol::kParamRequest, JobTypeToRequestType(type));
412 AddParameter(dm_protocol::kParamDeviceType, dm_protocol::kValueDeviceType); 422 AddParameter(dm_protocol::kParamDeviceType, dm_protocol::kValueDeviceType);
413 AddParameter(dm_protocol::kParamAppType, dm_protocol::kValueAppType); 423 AddParameter(dm_protocol::kParamAppType, dm_protocol::kValueAppType);
414 AddParameter(dm_protocol::kParamAgent, agent_parameter); 424 AddParameter(dm_protocol::kParamAgent, agent_parameter);
415 AddParameter(dm_protocol::kParamPlatform, platform_parameter); 425 AddParameter(dm_protocol::kParamPlatform, platform_parameter);
416 } 426 }
417 427
418 void DeviceManagementRequestJob::SetRetryCallback( 428 void DeviceManagementRequestJob::SetRetryCallback(
419 const RetryCallback& retry_callback) { 429 const RetryCallback& retry_callback) {
420 retry_callback_ = retry_callback; 430 retry_callback_ = retry_callback;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (entry == pending_jobs_.end()) { 547 if (entry == pending_jobs_.end()) {
538 NOTREACHED() << "Callback from foreign URL fetcher"; 548 NOTREACHED() << "Callback from foreign URL fetcher";
539 return; 549 return;
540 } 550 }
541 551
542 DeviceManagementRequestJobImpl* job = entry->second; 552 DeviceManagementRequestJobImpl* job = entry->second;
543 pending_jobs_.erase(entry); 553 pending_jobs_.erase(entry);
544 554
545 if (job->ShouldRetry(source)) { 555 if (job->ShouldRetry(source)) {
546 job->PrepareRetry(); 556 job->PrepareRetry();
547 int delay = g_retry_delay_ms << (job->retries_count() - 1); 557 int delay = job->IsRetryWithDelay()
558 ? g_retry_delay_ms << (job->retries_count() - 1)
559 : 0;
548 LOG(WARNING) << "Dmserver request failed, retrying in " << delay / 1000 560 LOG(WARNING) << "Dmserver request failed, retrying in " << delay / 1000
549 << "s."; 561 << "s.";
550 task_runner_->PostDelayedTask( 562 task_runner_->PostDelayedTask(
551 FROM_HERE, 563 FROM_HERE,
552 base::Bind(&DeviceManagementService::StartJobAfterDelay, 564 base::Bind(&DeviceManagementService::StartJobAfterDelay,
553 weak_ptr_factory_.GetWeakPtr(), job->GetWeakPtr()), 565 weak_ptr_factory_.GetWeakPtr(), job->GetWeakPtr()),
554 base::TimeDelta::FromMilliseconds(delay)); 566 base::TimeDelta::FromMilliseconds(delay));
555 } else { 567 } else {
556 std::string data; 568 std::string data;
557 source->GetResponseAsString(&data); 569 source->GetResponseAsString(&data);
(...skipping 20 matching lines...) Expand all
578 } 590 }
579 } 591 }
580 592
581 const JobQueue::iterator elem = 593 const JobQueue::iterator elem =
582 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); 594 std::find(queued_jobs_.begin(), queued_jobs_.end(), job);
583 if (elem != queued_jobs_.end()) 595 if (elem != queued_jobs_.end())
584 queued_jobs_.erase(elem); 596 queued_jobs_.erase(elem);
585 } 597 }
586 598
587 } // namespace policy 599 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/device_management_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698