Commit 0b753000 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

SimpleURLLoader: Add retry support on 5xx and network errors.

These are the cases in which URLFetcher supports retries.
Unlike URLFetcher, there's a single method to enable both
types of retries, and a single counter.

Unlike URLFetcher, this does not support backoff via the
ThrottleManager (Something only used in the service process).
We may want to implement something simpler, or just let the
service process consumers themselves deal with backoff.

Bug: 746977
Change-Id: I31c81652176856231289ad88d082713bad6df61d
Reviewed-on: https://chromium-review.googlesource.com/701215
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarRandy Smith <rdsmith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509642}
parent 9d9211d5
This diff is collapsed.
......@@ -41,15 +41,27 @@ class URLLoaderFactory;
// Each SimpleURLLoader can only be used for a single request.
//
// TODO(mmenke): Support the following:
// * Save to (temp) file.
// * Save to temp file.
// * Consumer-provided methods to receive streaming (with backpressure).
// * Monitoring (And cancelling during) redirects.
// * Uploads (Fixed strings, files, data streams (with backpressure), chunked
// uploads). ResourceRequest may already have some support, but should make it
// simple.
// * Retrying.
// * Maybe some sort of retry backoff or delay? ServiceURLLoaderContext enables
// throttling for its URLFetchers. Could additionally/alternatively support
// 503 + Retry-After.
class CONTENT_EXPORT SimpleURLLoader {
public:
// When a failed request should automatically be retried. These are intended
// to be ORed together.
enum RetryMode {
RETRY_NEVER = 0x0,
// Retries whenever the server returns a 5xx response code.
RETRY_ON_5XX = 0x1,
// Retries on net::ERR_NETWORK_CHANGED.
RETRY_ON_NETWORK_CHANGE = 0x2,
};
// The maximum size DownloadToString will accept.
const size_t kMaxBoundedStringDownloadSize = 1024 * 1024;
......@@ -142,6 +154,21 @@ class CONTENT_EXPORT SimpleURLLoader {
// TODO(mmenke): Consider adding a new error code for this.
virtual void SetAllowHttpErrorResults(bool allow_http_error_results) = 0;
// Sets the when to try and the max number of times to retry a request, if
// any. |max_retries| is the number of times to retry the request, not
// counting the initial request. |retry_mode| is a combination of one or more
// RetryModes, indicating when the request should be retried. If it is
// RETRY_NEVER, |max_retries| must be 0.
//
// By default, a request will not be retried.
//
// When a request is retried, the the request will start again using the
// initial content::ResourceRequest, even if the request was redirected.
//
// Calling this multiple times will overwrite the values previously passed to
// this method. May only be called before the request is started.
virtual void SetRetryOptions(int max_retries, int retry_mode) = 0;
// Returns the net::Error representing the final status of the request. May
// only be called once the loader has informed the caller of completion.
virtual int NetError() const = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment