OLD | NEW |
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 #ifndef NET_URL_REQUEST_URL_FETCHER_CORE_H_ | 5 #ifndef NET_URL_REQUEST_URL_FETCHER_CORE_H_ |
6 #define NET_URL_REQUEST_URL_FETCHER_CORE_H_ | 6 #define NET_URL_REQUEST_URL_FETCHER_CORE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 class URLFetcherCore | 39 class URLFetcherCore |
40 : public base::RefCountedThreadSafe<URLFetcherCore>, | 40 : public base::RefCountedThreadSafe<URLFetcherCore>, |
41 public URLRequest::Delegate { | 41 public URLRequest::Delegate { |
42 public: | 42 public: |
43 URLFetcherCore(URLFetcher* fetcher, | 43 URLFetcherCore(URLFetcher* fetcher, |
44 const GURL& original_url, | 44 const GURL& original_url, |
45 URLFetcher::RequestType request_type, | 45 URLFetcher::RequestType request_type, |
46 URLFetcherDelegate* d); | 46 URLFetcherDelegate* d); |
47 | 47 |
48 // Starts the load. It's important that this not happen in the constructor | 48 // Starts the load. It's important that this not happen in the constructor |
49 // because it causes the IO thread to begin AddRef()ing and Release()ing | 49 // because it causes the IO thread to begin AddRef()ing and Release()ing |
50 // us. If our caller hasn't had time to fully construct us and take a | 50 // us. If our caller hasn't had time to fully construct us and take a |
51 // reference, the IO thread could interrupt things, run a task, Release() | 51 // reference, the IO thread could interrupt things, run a task, Release() |
52 // us, and destroy us, leaving the caller with an already-destroyed object | 52 // us, and destroy us, leaving the caller with an already-destroyed object |
53 // when construction finishes. | 53 // when construction finishes. |
54 void Start(); | 54 void Start(); |
55 | 55 |
56 // Stops any in-progress load and ensures no callback will happen. It is | 56 // Stops any in-progress load and ensures no callback will happen. It is |
57 // safe to call this multiple times. | 57 // safe to call this multiple times. |
58 void Stop(); | 58 void Stop(); |
59 | 59 |
60 // URLFetcher-like functions. | 60 // URLFetcher-like functions. |
61 | 61 |
62 // For POST requests, set |content_type| to the MIME type of the | 62 // For POST requests, set |content_type| to the MIME type of the |
63 // content and set |content| to the data to upload. | 63 // content and set |content| to the data to upload. |
64 void SetUploadData(const std::string& upload_content_type, | 64 void SetUploadData(const std::string& upload_content_type, |
65 const std::string& upload_content); | 65 const std::string& upload_content); |
66 void SetUploadFilePath(const std::string& upload_content_type, | 66 void SetUploadFilePath(const std::string& upload_content_type, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 scoped_ptr<URLFetcherResponseWriter> response_writer); | 104 scoped_ptr<URLFetcherResponseWriter> response_writer); |
105 HttpResponseHeaders* GetResponseHeaders() const; | 105 HttpResponseHeaders* GetResponseHeaders() const; |
106 HostPortPair GetSocketAddress() const; | 106 HostPortPair GetSocketAddress() const; |
107 bool WasFetchedViaProxy() const; | 107 bool WasFetchedViaProxy() const; |
108 const GURL& GetOriginalURL() const; | 108 const GURL& GetOriginalURL() const; |
109 const GURL& GetURL() const; | 109 const GURL& GetURL() const; |
110 const URLRequestStatus& GetStatus() const; | 110 const URLRequestStatus& GetStatus() const; |
111 int GetResponseCode() const; | 111 int GetResponseCode() const; |
112 const ResponseCookies& GetCookies() const; | 112 const ResponseCookies& GetCookies() const; |
113 // Reports that the received content was malformed (i.e. failed parsing | 113 // Reports that the received content was malformed (i.e. failed parsing |
114 // or validation). This makes the throttling logic that does exponential | 114 // or validation). This makes the throttling logic that does exponential |
115 // back-off when servers are having problems treat the current request as | 115 // back-off when servers are having problems treat the current request as |
116 // a failure. Your call to this method will be ignored if your request is | 116 // a failure. Your call to this method will be ignored if your request is |
117 // already considered a failure based on the HTTP response code or response | 117 // already considered a failure based on the HTTP response code or response |
118 // headers. | 118 // headers. |
119 void ReceivedContentWasMalformed(); | 119 void ReceivedContentWasMalformed(); |
120 bool GetResponseAsString(std::string* out_response_string) const; | 120 bool GetResponseAsString(std::string* out_response_string) const; |
121 bool GetResponseAsFilePath(bool take_ownership, | 121 bool GetResponseAsFilePath(bool take_ownership, |
122 base::FilePath* out_response_path); | 122 base::FilePath* out_response_path); |
123 | 123 |
124 // Overridden from URLRequest::Delegate: | 124 // Overridden from URLRequest::Delegate: |
125 virtual void OnReceivedRedirect(URLRequest* request, | 125 virtual void OnReceivedRedirect(URLRequest* request, |
126 const RedirectInfo& redirect_info, | 126 const RedirectInfo& redirect_info, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 std::string upload_content_type_; // MIME type of POST payload | 244 std::string upload_content_type_; // MIME type of POST payload |
245 std::string referrer_; // HTTP Referer header value and policy | 245 std::string referrer_; // HTTP Referer header value and policy |
246 URLRequest::ReferrerPolicy referrer_policy_; | 246 URLRequest::ReferrerPolicy referrer_policy_; |
247 bool is_chunked_upload_; // True if using chunked transfer encoding | 247 bool is_chunked_upload_; // True if using chunked transfer encoding |
248 | 248 |
249 // Used to determine how long to wait before making a request or doing a | 249 // Used to determine how long to wait before making a request or doing a |
250 // retry. | 250 // retry. |
251 // | 251 // |
252 // Both of them can only be accessed on the IO thread. | 252 // Both of them can only be accessed on the IO thread. |
253 // | 253 // |
254 // We need not only the throttler entry for |original_URL|, but also | 254 // To determine the proper backoff timing, throttler entries for |
255 // the one for |url|. For example, consider the case that URL A | 255 // both |original_URL| and |url| are needed. For example, consider |
256 // redirects to URL B, for which the server returns a 500 | 256 // the case that URL A redirects to URL B, for which the server |
257 // response. In this case, the exponential back-off release time of | 257 // returns a 500 response. In this case, the exponential back-off |
258 // URL A won't increase. If we retry without considering the | 258 // release time of URL A won't increase. If only the backoff |
259 // back-off constraint of URL B, we may send out too many requests | 259 // constraints for URL A are considered, too many requests for URL A |
260 // for URL A in a short period of time. | 260 // may be sent in a short period of time. |
261 // | 261 // |
262 // Both of these will be NULL if | 262 // Both of these will be NULL if |
263 // URLRequestContext::throttler_manager() is NULL. | 263 // URLRequestContext::throttler_manager() is NULL. |
264 scoped_refptr<URLRequestThrottlerEntryInterface> | 264 scoped_refptr<URLRequestThrottlerEntryInterface> |
265 original_url_throttler_entry_; | 265 original_url_throttler_entry_; |
266 scoped_refptr<URLRequestThrottlerEntryInterface> url_throttler_entry_; | 266 scoped_refptr<URLRequestThrottlerEntryInterface> url_throttler_entry_; |
267 | 267 |
268 // True if the URLFetcher has been cancelled. | 268 // True if the URLFetcher has been cancelled. |
269 bool was_cancelled_; | 269 bool was_cancelled_; |
270 | 270 |
271 // Writer object to write response to the destination like file and string. | 271 // Writer object to write response to the destination like file and string. |
272 scoped_ptr<URLFetcherResponseWriter> response_writer_; | 272 scoped_ptr<URLFetcherResponseWriter> response_writer_; |
273 | 273 |
274 // By default any server-initiated redirects are automatically followed. If | 274 // By default any server-initiated redirects are automatically followed. If |
275 // this flag is set to true, however, a redirect will halt the fetch and call | 275 // this flag is set to true, however, a redirect will halt the fetch and call |
276 // back to to the delegate immediately. | 276 // back to to the delegate immediately. |
277 bool stop_on_redirect_; | 277 bool stop_on_redirect_; |
278 // True when we're actually stopped due to a redirect halted by the above. We | 278 // True when we're actually stopped due to a redirect halted by the above. We |
279 // use this to ensure that |url_| is set to the redirect destination rather | 279 // use this to ensure that |url_| is set to the redirect destination rather |
280 // than the originally-fetched URL. | 280 // than the originally-fetched URL. |
281 bool stopped_on_redirect_; | 281 bool stopped_on_redirect_; |
282 | 282 |
283 // If |automatically_retry_on_5xx_| is false, 5xx responses will be | 283 // If |automatically_retry_on_5xx_| is false, 5xx responses will be |
284 // propagated to the observer, if it is true URLFetcher will automatically | 284 // propagated to the observer, if it is true URLFetcher will automatically |
285 // re-execute the request, after the back-off delay has expired. | 285 // re-execute the request, after the back-off delay has expired. |
286 // true by default. | 286 // true by default. |
287 bool automatically_retry_on_5xx_; | 287 bool automatically_retry_on_5xx_; |
288 // |num_retries_on_5xx_| indicates how many times we've failed to successfully | 288 // |num_retries_on_5xx_| indicates how many times we've failed to successfully |
289 // fetch this URL due to 5xx responses. Once this value exceeds the maximum | 289 // fetch this URL due to 5xx responses. Once this value exceeds the maximum |
290 // number of retries specified by the owner URLFetcher instance, | 290 // number of retries specified by the owner URLFetcher instance, |
291 // we'll give up. | 291 // we'll give up. |
292 int num_retries_on_5xx_; | 292 int num_retries_on_5xx_; |
293 // Maximum retries allowed when 5xx responses are received. | 293 // Maximum retries allowed when 5xx responses are received. |
294 int max_retries_on_5xx_; | 294 int max_retries_on_5xx_; |
295 // Back-off time delay. 0 by default. | 295 // Back-off time delay. 0 by default. |
296 base::TimeDelta backoff_delay_; | 296 base::TimeDelta backoff_delay_; |
297 | 297 |
298 // The number of retries that have been attempted due to ERR_NETWORK_CHANGED. | 298 // The number of retries that have been attempted due to ERR_NETWORK_CHANGED. |
299 int num_retries_on_network_changes_; | 299 int num_retries_on_network_changes_; |
(...skipping 16 matching lines...) Expand all Loading... |
316 base::debug::StackTrace stack_trace_; | 316 base::debug::StackTrace stack_trace_; |
317 | 317 |
318 static base::LazyInstance<Registry> g_registry; | 318 static base::LazyInstance<Registry> g_registry; |
319 | 319 |
320 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore); | 320 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore); |
321 }; | 321 }; |
322 | 322 |
323 } // namespace net | 323 } // namespace net |
324 | 324 |
325 #endif // NET_URL_REQUEST_URL_FETCHER_CORE_H_ | 325 #endif // NET_URL_REQUEST_URL_FETCHER_CORE_H_ |
OLD | NEW |