| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file contains URLFetcher, a wrapper around URLRequest that handles | 5 // This file contains URLFetcher, a wrapper around URLRequest that handles |
| 6 // low-level details like thread safety, ref counting, and incremental buffer | 6 // low-level details like thread safety, ref counting, and incremental buffer |
| 7 // reading. This is useful for callers who simply want to get the data from a | 7 // reading. This is useful for callers who simply want to get the data from a |
| 8 // URL and don't care about all the nitty-gritty details. | 8 // URL and don't care about all the nitty-gritty details. |
| 9 // | 9 // |
| 10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a | 10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a |
| 11 // temporary situation. We will work on allowing support for multiple "io" | 11 // temporary situation. We will work on allowing support for multiple "io" |
| 12 // threads per process. | 12 // threads per process. |
| 13 | 13 |
| 14 #ifndef CHROME_COMMON_NET_URL_FETCHER_H_ | 14 #ifndef CHROME_COMMON_NET_URL_FETCHER_H_ |
| 15 #define CHROME_COMMON_NET_URL_FETCHER_H_ | 15 #define CHROME_COMMON_NET_URL_FETCHER_H_ |
| 16 #pragma once | 16 #pragma once |
| 17 | 17 |
| 18 #include <string> | 18 #include <string> |
| 19 #include <vector> |
| 19 | 20 |
| 20 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 21 #include "base/ref_counted.h" | 22 #include "base/ref_counted.h" |
| 22 #include "base/time.h" | 23 #include "base/time.h" |
| 23 | 24 |
| 24 class GURL; | 25 class GURL; |
| 25 typedef std::vector<std::string> ResponseCookies; | 26 typedef std::vector<std::string> ResponseCookies; |
| 26 class URLFetcher; | 27 class URLFetcher; |
| 27 class URLRequestContextGetter; | 28 class URLRequestContextGetter; |
| 28 class URLRequestStatus; | 29 class URLRequestStatus; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Set the URLRequestContext on the request. Must be called before the | 146 // Set the URLRequestContext on the request. Must be called before the |
| 146 // request is started. | 147 // request is started. |
| 147 void set_request_context( | 148 void set_request_context( |
| 148 URLRequestContextGetter* request_context_getter); | 149 URLRequestContextGetter* request_context_getter); |
| 149 | 150 |
| 150 // If |retry| is false, 5xx responses will be propagated to the observer, | 151 // If |retry| is false, 5xx responses will be propagated to the observer, |
| 151 // if it is true URLFetcher will automatically re-execute the request, | 152 // if it is true URLFetcher will automatically re-execute the request, |
| 152 // after backoff_delay() elapses. URLFetcher has it set to true by default. | 153 // after backoff_delay() elapses. URLFetcher has it set to true by default. |
| 153 void set_automatically_retry_on_5xx(bool retry); | 154 void set_automatically_retry_on_5xx(bool retry); |
| 154 | 155 |
| 156 int max_retries() const { return max_retries_; } |
| 157 |
| 158 void set_max_retries(int max_retries) { max_retries_ = max_retries; } |
| 159 |
| 155 // Returns the back-off delay before the request will be retried, | 160 // Returns the back-off delay before the request will be retried, |
| 156 // when a 5xx response was received. | 161 // when a 5xx response was received. |
| 157 base::TimeDelta backoff_delay() const { return backoff_delay_; } | 162 base::TimeDelta backoff_delay() const { return backoff_delay_; } |
| 158 | 163 |
| 159 // Sets the back-off delay, allowing to mock 5xx requests in unit-tests. | 164 // Sets the back-off delay, allowing to mock 5xx requests in unit-tests. |
| 160 #if defined(UNIT_TEST) | 165 #if defined(UNIT_TEST) |
| 161 void set_backoff_delay(base::TimeDelta backoff_delay) { | 166 void set_backoff_delay(base::TimeDelta backoff_delay) { |
| 162 backoff_delay_ = backoff_delay; | 167 backoff_delay_ = backoff_delay; |
| 163 } | 168 } |
| 164 #endif // defined(UNIT_TEST) | 169 #endif // defined(UNIT_TEST) |
| 165 | 170 |
| 166 // Retrieve the response headers from the request. Must only be called after | 171 // Retrieve the response headers from the request. Must only be called after |
| 167 // the OnURLFetchComplete callback has run. | 172 // the OnURLFetchComplete callback has run. |
| 168 virtual net::HttpResponseHeaders* response_headers() const; | 173 virtual net::HttpResponseHeaders* response_headers() const; |
| 169 | 174 |
| 170 // Start the request. After this is called, you may not change any other | 175 // Start the request. After this is called, you may not change any other |
| 171 // settings. | 176 // settings. |
| 172 virtual void Start(); | 177 virtual void Start(); |
| 173 | 178 |
| 174 // Return the URL that this fetcher is processing. | 179 // Return the URL that this fetcher is processing. |
| 175 const GURL& url() const; | 180 const GURL& url() const; |
| 176 | 181 |
| 182 // Reports that the received content was malformed. |
| 183 void ReceivedContentWasMalformed(); |
| 184 |
| 177 // Cancels all existing URLRequests. Will notify the URLFetcher::Delegates. | 185 // Cancels all existing URLRequests. Will notify the URLFetcher::Delegates. |
| 178 // Note that any new URLFetchers created while this is running will not be | 186 // Note that any new URLFetchers created while this is running will not be |
| 179 // cancelled. Typically, one would call this in the CleanUp() method of an IO | 187 // cancelled. Typically, one would call this in the CleanUp() method of an IO |
| 180 // thread, so that no new URLRequests would be able to start on the IO thread | 188 // thread, so that no new URLRequests would be able to start on the IO thread |
| 181 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO | 189 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO |
| 182 // thread though, even though the task won't ever run. | 190 // thread though, even though the task won't ever run. |
| 183 static void CancelAll(); | 191 static void CancelAll(); |
| 184 | 192 |
| 185 protected: | 193 protected: |
| 186 // Returns the delegate. | 194 // Returns the delegate. |
| 187 Delegate* delegate() const; | 195 Delegate* delegate() const; |
| 188 | 196 |
| 189 // Used by tests. | 197 // Used by tests. |
| 190 const std::string& upload_data() const; | 198 const std::string& upload_data() const; |
| 191 | 199 |
| 192 private: | 200 private: |
| 193 class Core; | 201 class Core; |
| 194 | 202 |
| 195 scoped_refptr<Core> core_; | 203 scoped_refptr<Core> core_; |
| 196 | 204 |
| 197 static Factory* factory_; | 205 static Factory* factory_; |
| 198 | 206 |
| 199 // If |automatically_retry_on_5xx_| is false, 5xx responses will be | 207 // If |automatically_retry_on_5xx_| is false, 5xx responses will be |
| 200 // propagated to the observer, if it is true URLFetcher will automatically | 208 // propagated to the observer, if it is true URLFetcher will automatically |
| 201 // re-execute the request, after the back-off delay has expired. | 209 // re-execute the request, after the back-off delay has expired. |
| 202 // true by default. | 210 // true by default. |
| 203 bool automatically_retry_on_5xx_; | 211 bool automatically_retry_on_5xx_; |
| 204 // Back-off time delay. 0 by default. | 212 // Back-off time delay. 0 by default. |
| 205 base::TimeDelta backoff_delay_; | 213 base::TimeDelta backoff_delay_; |
| 214 // Maximum retries allowed. |
| 215 int max_retries_; |
| 206 | 216 |
| 207 static bool g_interception_enabled; | 217 static bool g_interception_enabled; |
| 208 | 218 |
| 209 DISALLOW_COPY_AND_ASSIGN(URLFetcher); | 219 DISALLOW_COPY_AND_ASSIGN(URLFetcher); |
| 210 }; | 220 }; |
| 211 | 221 |
| 212 #endif // CHROME_COMMON_NET_URL_FETCHER_H_ | 222 #endif // CHROME_COMMON_NET_URL_FETCHER_H_ |
| OLD | NEW |