Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / net / retryable_url_fetcher.h
blobcd153980bc4f61f0e5381e194ef02a32c9e33d06
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_
6 #define IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_
8 #import <Foundation/Foundation.h>
10 #include "net/base/backoff_entry.h"
12 namespace net {
13 class URLRequestContextGetter;
14 } // namespace net
16 // Delegate protocol for RetryableURLFetcher object.
17 @protocol RetryableURLFetcherDelegate<NSObject>
19 // Returns the HTTP URL for RetryableURLFetcher to fetch.
20 - (NSString*)urlToFetch;
22 // Callback function after URL has been fetched. |response| is the content of
23 // the HTTP response. |response| may be nil if the HTTP request failed.
24 - (void)processSuccessResponse:(NSString*)response;
26 @end
28 @interface RetryableURLFetcher : NSObject
30 // Designated initializer. |context| and |delegate| must not be nil. If |policy|
31 // is not null, it specifies how often to retry the URL fetch on a call to
32 // -startFetch. If |policy| is null, there is no retry.
33 - (instancetype)
34 initWithRequestContextGetter:(net::URLRequestContextGetter*)context
35 delegate:(id<RetryableURLFetcherDelegate>)delegate
36 backoffPolicy:(const net::BackoffEntry::Policy*)policy;
38 // Starts fetching URL. Uses the backoff policy specified when the object was
39 // initialized.
40 - (void)startFetch;
42 // Returns the number of times that this URL Fetcher failed to receive a
43 // success response. Returns 0 if this URL Fetcher was not set up to do retries.
44 - (int)failureCount;
46 @end
48 #endif // IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_