droger | f1ba207c | 2015-04-03 09:40:46 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_ |
| 6 | #define IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_ |
| 7 | |
| 8 | #import <Foundation/Foundation.h> |
| 9 | |
| 10 | #include "net/base/backoff_entry.h" |
| 11 | |
| 12 | namespace net { |
| 13 | class URLRequestContextGetter; |
| 14 | } // namespace net |
| 15 | |
| 16 | // Delegate protocol for RetryableURLFetcher object. |
| 17 | @protocol RetryableURLFetcherDelegate<NSObject> |
| 18 | |
| 19 | // Returns the HTTP URL for RetryableURLFetcher to fetch. |
| 20 | - (NSString*)urlToFetch; |
| 21 | |
| 22 | // Callback function after URL has been fetched. |response| is the content of |
pkl | 50cd6e2 | 2016-08-04 13:48:40 | [diff] [blame] | 23 | // the HTTP response. This method may be called with a nil |response| if the |
| 24 | // HTTP request failed. |
droger | f1ba207c | 2015-04-03 09:40:46 | [diff] [blame] | 25 | - (void)processSuccessResponse:(NSString*)response; |
| 26 | |
| 27 | @end |
| 28 | |
| 29 | @interface RetryableURLFetcher : NSObject |
| 30 | |
| 31 | // Designated initializer. |context| and |delegate| must not be nil. If |policy| |
| 32 | // is not null, it specifies how often to retry the URL fetch on a call to |
| 33 | // -startFetch. If |policy| is null, there is no retry. |
| 34 | - (instancetype) |
| 35 | initWithRequestContextGetter:(net::URLRequestContextGetter*)context |
| 36 | delegate:(id<RetryableURLFetcherDelegate>)delegate |
| 37 | backoffPolicy:(const net::BackoffEntry::Policy*)policy; |
| 38 | |
| 39 | // Starts fetching URL. Uses the backoff policy specified when the object was |
| 40 | // initialized. |
| 41 | - (void)startFetch; |
| 42 | |
| 43 | // Returns the number of times that this URL Fetcher failed to receive a |
| 44 | // success response. Returns 0 if this URL Fetcher was not set up to do retries. |
| 45 | - (int)failureCount; |
| 46 | |
| 47 | @end |
| 48 | |
| 49 | #endif // IOS_CHROME_BROWSER_NET_RETRYABLE_URL_FETCHER_H_ |