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

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

Issue 2419783002: Add retry and lasterror parameters to DMServer requests. (Closed)
Patch Set: Add tests Created 4 years, 2 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
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 // Pointer to the service this job is associated with. 214 // Pointer to the service this job is associated with.
215 DeviceManagementService* service_; 215 DeviceManagementService* service_;
216 216
217 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest(). 217 // Whether the BYPASS_PROXY flag should be set by ConfigureRequest().
218 bool bypass_proxy_; 218 bool bypass_proxy_;
219 219
220 // Number of times that this job has been retried due to connection errors. 220 // Number of times that this job has been retried due to connection errors.
221 int retries_count_; 221 int retries_count_;
222 222
223 // The last error why we had to retry.
224 int last_error_ = 0;
225
223 // The request context to use for this job. 226 // The request context to use for this job.
224 scoped_refptr<net::URLRequestContextGetter> request_context_; 227 scoped_refptr<net::URLRequestContextGetter> request_context_;
225 228
226 // Used to get notified if the job has been canceled while waiting for retry. 229 // Used to get notified if the job has been canceled while waiting for retry.
227 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_; 230 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_;
228 231
229 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl); 232 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl);
230 }; 233 };
231 234
232 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl( 235 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 else 324 else
322 ReportError(DM_STATUS_HTTP_STATUS_ERROR); 325 ReportError(DM_STATUS_HTTP_STATUS_ERROR);
323 return; 326 return;
324 } 327 }
325 } 328 }
326 329
327 GURL DeviceManagementRequestJobImpl::GetURL( 330 GURL DeviceManagementRequestJobImpl::GetURL(
328 const std::string& server_url) { 331 const std::string& server_url) {
329 std::string result(server_url); 332 std::string result(server_url);
330 result += '?'; 333 result += '?';
331 for (ParameterMap::const_iterator entry(query_params_.begin()); 334 ParameterMap current_query_params(query_params_);
332 entry != query_params_.end(); 335 if (last_error_ == 0) {
333 ++entry) { 336 // Not a retry.
334 if (entry != query_params_.begin()) 337 current_query_params.push_back(
338 std::make_pair(dm_protocol::kParamRetry, "false"));
Andrew T Wilson (Slow) 2016/10/13 14:03:13 This is fine, or you could just omit it.
Marton Hunyady 2016/10/13 14:17:19 I planned to send it so we see immediately (withou
339 } else {
340 current_query_params.push_back(
341 std::make_pair(dm_protocol::kParamRetry, "true"));
342 current_query_params.push_back(std::make_pair(dm_protocol::kParamLastError,
343 std::to_string(last_error_)));
344 }
345 for (ParameterMap::const_iterator entry(current_query_params.begin());
346 entry != current_query_params.end(); ++entry) {
347 if (entry != current_query_params.begin())
335 result += '&'; 348 result += '&';
336 result += net::EscapeQueryParamValue(entry->first, true); 349 result += net::EscapeQueryParamValue(entry->first, true);
337 result += '='; 350 result += '=';
338 result += net::EscapeQueryParamValue(entry->second, true); 351 result += net::EscapeQueryParamValue(entry->second, true);
339 } 352 }
340 return GURL(result); 353 return GURL(result);
341 } 354 }
342 355
343 void DeviceManagementRequestJobImpl::ConfigureRequest( 356 void DeviceManagementRequestJobImpl::ConfigureRequest(
344 net::URLFetcher* fetcher) { 357 net::URLFetcher* fetcher) {
(...skipping 10 matching lines...) Expand all
355 std::string extra_headers; 368 std::string extra_headers;
356 if (!gaia_token_.empty()) 369 if (!gaia_token_.empty())
357 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n"; 370 extra_headers += kServiceTokenAuthHeader + gaia_token_ + "\n";
358 if (!dm_token_.empty()) 371 if (!dm_token_.empty())
359 extra_headers += kDMTokenAuthHeader + dm_token_ + "\n"; 372 extra_headers += kDMTokenAuthHeader + dm_token_ + "\n";
360 fetcher->SetExtraRequestHeaders(extra_headers); 373 fetcher->SetExtraRequestHeaders(extra_headers);
361 } 374 }
362 375
363 DeviceManagementRequestJobImpl::RetryMethod 376 DeviceManagementRequestJobImpl::RetryMethod
364 DeviceManagementRequestJobImpl::ShouldRetry(const net::URLFetcher* fetcher) { 377 DeviceManagementRequestJobImpl::ShouldRetry(const net::URLFetcher* fetcher) {
378 last_error_ = fetcher->GetStatus().error();
365 if (FailedWithProxy(fetcher) && !bypass_proxy_) { 379 if (FailedWithProxy(fetcher) && !bypass_proxy_) {
366 // Retry the job immediately if it failed due to a broken proxy, by 380 // Retry the job immediately if it failed due to a broken proxy, by
367 // bypassing the proxy on the next try. 381 // bypassing the proxy on the next try.
368 bypass_proxy_ = true; 382 bypass_proxy_ = true;
369 return RETRY_IMMEDIATELY; 383 return RETRY_IMMEDIATELY;
370 } 384 }
371 385
372 // Early device policy fetches on ChromeOS and Auto-Enrollment checks are 386 // Early device policy fetches on ChromeOS and Auto-Enrollment checks are
373 // often interrupted during ChromeOS startup when network is not yet ready. 387 // often interrupted during ChromeOS startup when network is not yet ready.
374 // Allowing the fetcher to retry once after that is enough to recover; allow 388 // Allowing the fetcher to retry once after that is enough to recover; allow
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 624 }
611 } 625 }
612 626
613 const JobQueue::iterator elem = 627 const JobQueue::iterator elem =
614 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); 628 std::find(queued_jobs_.begin(), queued_jobs_.end(), job);
615 if (elem != queued_jobs_.end()) 629 if (elem != queued_jobs_.end())
616 queued_jobs_.erase(elem); 630 queued_jobs_.erase(elem);
617 } 631 }
618 632
619 } // namespace policy 633 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698