| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 net::URLRequest that handles | 5 // This file contains URLFetcher, a wrapper around net::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 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 // Cancels all existing URLFetchers. Will notify the URLFetcher::Delegates. | 257 // Cancels all existing URLFetchers. Will notify the URLFetcher::Delegates. |
| 258 // Note that any new URLFetchers created while this is running will not be | 258 // Note that any new URLFetchers created while this is running will not be |
| 259 // cancelled. Typically, one would call this in the CleanUp() method of an IO | 259 // cancelled. Typically, one would call this in the CleanUp() method of an IO |
| 260 // thread, so that no new URLRequests would be able to start on the IO thread | 260 // thread, so that no new URLRequests would be able to start on the IO thread |
| 261 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO | 261 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO |
| 262 // thread though, even though the task won't ever run. | 262 // thread though, even though the task won't ever run. |
| 263 static void CancelAll(); | 263 static void CancelAll(); |
| 264 | 264 |
| 265 protected: | 265 protected: |
| 266 // How should the response be stored? | |
| 267 enum ResponseDestinationType { | |
| 268 STRING, // Default: In a std::string | |
| 269 TEMP_FILE // Write to a temp file | |
| 270 }; | |
| 271 | |
| 272 // Returns the delegate. | 266 // Returns the delegate. |
| 273 Delegate* delegate() const; | 267 Delegate* delegate() const; |
| 274 | 268 |
| 275 // Used by tests. | 269 // Used by tests. |
| 276 const std::string& upload_data() const; | 270 const std::string& upload_data() const; |
| 277 | 271 |
| 278 // Return a reference to the string data fetched. Response type must | 272 // Return a reference to the string data fetched. Response type must |
| 279 // be STRING, or this will CHECK. This method exists to support the | 273 // be STRING, or this will CHECK. This method exists to support the |
| 280 // old signiture to OnURLFetchComplete(), and will be removed as part | 274 // old signiture to OnURLFetchComplete(), and will be removed as part |
| 281 // of crbug.com/83592 . | 275 // of crbug.com/83592 . |
| 282 const std::string& GetResponseStringRef() const; | 276 const std::string& GetResponseStringRef() const; |
| 283 | 277 |
| 284 void SetResponseDestinationForTesting(ResponseDestinationType); | |
| 285 ResponseDestinationType GetResponseDestinationForTesting() const; | |
| 286 | |
| 287 private: | 278 private: |
| 288 friend class URLFetcherTest; | 279 friend class URLFetcherTest; |
| 289 friend class TestURLFetcher; | 280 friend class TestURLFetcher; |
| 290 | 281 |
| 282 // How should the response be stored? |
| 283 enum ResponseDestinationType { |
| 284 STRING, // Default: In a std::string |
| 285 TEMP_FILE // Write to a temp file |
| 286 }; |
| 287 |
| 291 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects | 288 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects |
| 292 // actively running. | 289 // actively running. |
| 293 static int GetNumFetcherCores(); | 290 static int GetNumFetcherCores(); |
| 294 | 291 |
| 295 class Core; | 292 class Core; |
| 296 scoped_refptr<Core> core_; | 293 scoped_refptr<Core> core_; |
| 297 | 294 |
| 298 static Factory* factory_; | 295 static Factory* factory_; |
| 299 | 296 |
| 300 // If |automatically_retry_on_5xx_| is false, 5xx responses will be | 297 // If |automatically_retry_on_5xx_| is false, 5xx responses will be |
| 301 // propagated to the observer, if it is true URLFetcher will automatically | 298 // propagated to the observer, if it is true URLFetcher will automatically |
| 302 // re-execute the request, after the back-off delay has expired. | 299 // re-execute the request, after the back-off delay has expired. |
| 303 // true by default. | 300 // true by default. |
| 304 bool automatically_retry_on_5xx_; | 301 bool automatically_retry_on_5xx_; |
| 305 // Back-off time delay. 0 by default. | 302 // Back-off time delay. 0 by default. |
| 306 base::TimeDelta backoff_delay_; | 303 base::TimeDelta backoff_delay_; |
| 307 // Maximum retries allowed. | 304 // Maximum retries allowed. |
| 308 int max_retries_; | 305 int max_retries_; |
| 309 | 306 |
| 307 // Where should responses be saved? |
| 308 ResponseDestinationType response_destination_; |
| 309 |
| 310 static bool g_interception_enabled; | 310 static bool g_interception_enabled; |
| 311 | 311 |
| 312 DISALLOW_COPY_AND_ASSIGN(URLFetcher); | 312 DISALLOW_COPY_AND_ASSIGN(URLFetcher); |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 #endif // CHROME_COMMON_NET_URL_FETCHER_H_ | 315 #endif // CHROME_COMMON_NET_URL_FETCHER_H_ |
| OLD | NEW |