| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 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 | 
| 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 #include <vector> | 
| 20 | 20 | 
| 21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" | 
| 22 #include "base/ref_counted.h" | 22 #include "base/ref_counted.h" | 
| 23 #include "base/time.h" | 23 #include "base/time.h" | 
| 24 | 24 | 
| 25 class GURL; | 25 class GURL; | 
| 26 typedef std::vector<std::string> ResponseCookies; | 26 typedef std::vector<std::string> ResponseCookies; | 
| 27 class URLFetcher; | 27 class URLFetcher; | 
| 28 class URLRequestContextGetter; | 28 class URLRequestContextGetter; | 
| 29 class URLRequestStatus; |  | 
| 30 | 29 | 
| 31 namespace net { | 30 namespace net { | 
| 32 class HttpResponseHeaders; | 31 class HttpResponseHeaders; | 
| 33 } | 32 class URLRequestStatus; | 
|  | 33 }  // namespace net | 
| 34 | 34 | 
| 35 // To use this class, create an instance with the desired URL and a pointer to | 35 // To use this class, create an instance with the desired URL and a pointer to | 
| 36 // the object to be notified when the URL has been loaded: | 36 // the object to be notified when the URL has been loaded: | 
| 37 //   URLFetcher* fetcher = new URLFetcher("http://www.google.com", this); | 37 //   URLFetcher* fetcher = new URLFetcher("http://www.google.com", this); | 
| 38 // | 38 // | 
| 39 // Then, optionally set properties on this object, like the request context or | 39 // Then, optionally set properties on this object, like the request context or | 
| 40 // extra headers: | 40 // extra headers: | 
| 41 //   fetcher->SetExtraRequestHeaders("X-Foo: bar"); | 41 //   fetcher->SetExtraRequestHeaders("X-Foo: bar"); | 
| 42 // | 42 // | 
| 43 // Finally, start the request: | 43 // Finally, start the request: | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 68   }; | 68   }; | 
| 69 | 69 | 
| 70   class Delegate { | 70   class Delegate { | 
| 71    public: | 71    public: | 
| 72     // This will be called when the URL has been fetched, successfully or not. | 72     // This will be called when the URL has been fetched, successfully or not. | 
| 73     // |response_code| is the HTTP response code (200, 404, etc.) if | 73     // |response_code| is the HTTP response code (200, 404, etc.) if | 
| 74     // applicable.  |url|, |status| and |data| are all valid until the | 74     // applicable.  |url|, |status| and |data| are all valid until the | 
| 75     // URLFetcher instance is destroyed. | 75     // URLFetcher instance is destroyed. | 
| 76     virtual void OnURLFetchComplete(const URLFetcher* source, | 76     virtual void OnURLFetchComplete(const URLFetcher* source, | 
| 77                                     const GURL& url, | 77                                     const GURL& url, | 
| 78                                     const URLRequestStatus& status, | 78                                     const net::URLRequestStatus& status, | 
| 79                                     int response_code, | 79                                     int response_code, | 
| 80                                     const ResponseCookies& cookies, | 80                                     const ResponseCookies& cookies, | 
| 81                                     const std::string& data) = 0; | 81                                     const std::string& data) = 0; | 
| 82 | 82 | 
| 83    protected: | 83    protected: | 
| 84     virtual ~Delegate() {} | 84     virtual ~Delegate() {} | 
| 85   }; | 85   }; | 
| 86 | 86 | 
| 87   // URLFetcher::Create uses the currently registered Factory to create the | 87   // URLFetcher::Create uses the currently registered Factory to create the | 
| 88   // URLFetcher. Factory is intended for testing. | 88   // URLFetcher. Factory is intended for testing. | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 213   base::TimeDelta backoff_delay_; | 213   base::TimeDelta backoff_delay_; | 
| 214   // Maximum retries allowed. | 214   // Maximum retries allowed. | 
| 215   int max_retries_; | 215   int max_retries_; | 
| 216 | 216 | 
| 217   static bool g_interception_enabled; | 217   static bool g_interception_enabled; | 
| 218 | 218 | 
| 219   DISALLOW_COPY_AND_ASSIGN(URLFetcher); | 219   DISALLOW_COPY_AND_ASSIGN(URLFetcher); | 
| 220 }; | 220 }; | 
| 221 | 221 | 
| 222 #endif  // CHROME_COMMON_NET_URL_FETCHER_H_ | 222 #endif  // CHROME_COMMON_NET_URL_FETCHER_H_ | 
| OLD | NEW | 
|---|