[email protected] | 78376af | 2012-02-07 06:56:28 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 71e1ac4 | 2011-03-23 00:46:53 | [diff] [blame] | 4 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 5 | // This file contains URLFetcher, a wrapper around URLRequest that handles |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 |
| 8 | // URL and don't care about all the nitty-gritty details. |
[email protected] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 9 | // |
| 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" |
| 12 | // threads per process. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 14 | #ifndef NET_URL_REQUEST_URL_FETCHER_IMPL_H_ |
| 15 | #define NET_URL_REQUEST_URL_FETCHER_IMPL_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 17 | #include "base/basictypes.h" |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 19 | #include "net/base/net_export.h" |
| 20 | #include "net/url_request/url_fetcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | |
[email protected] | 83822c3 | 2012-06-13 04:21:32 | [diff] [blame] | 22 | namespace net { |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 23 | class URLFetcherCore; |
| 24 | class URLFetcherDelegate; |
[email protected] | 56ed95a | 2012-05-25 01:11:15 | [diff] [blame] | 25 | class URLFetcherFactory; |
[email protected] | 56ed95a | 2012-05-25 01:11:15 | [diff] [blame] | 26 | |
[email protected] | 8f2d8bdd | 2012-06-19 23:44:05 | [diff] [blame] | 27 | class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | // |url| is the URL to send the request to. |
| 30 | // |request_type| is the type of request to make. |
| 31 | // |d| the object that will receive the callback on fetch completion. |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 32 | URLFetcherImpl(const GURL& url, |
| 33 | RequestType request_type, |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 34 | URLFetcherDelegate* d); |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 35 | virtual ~URLFetcherImpl(); |
[email protected] | b6c911a | 2009-04-21 21:58:45 | [diff] [blame] | 36 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 37 | // URLFetcher implementation: |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 38 | virtual void SetUploadData(const std::string& upload_content_type, |
| 39 | const std::string& upload_content) OVERRIDE; |
[email protected] | e81652c | 2013-03-02 21:46:15 | [diff] [blame] | 40 | virtual void SetUploadFilePath( |
| 41 | const std::string& upload_content_type, |
| 42 | const base::FilePath& file_path, |
[email protected] | 7b0db73 | 2013-05-02 09:42:06 | [diff] [blame^] | 43 | uint64 range_offset, |
| 44 | uint64 range_length, |
[email protected] | e81652c | 2013-03-02 21:46:15 | [diff] [blame] | 45 | scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 46 | virtual void SetChunkedUpload( |
| 47 | const std::string& upload_content_type) OVERRIDE; |
| 48 | virtual void AppendChunkToUpload(const std::string& data, |
| 49 | bool is_last_chunk) OVERRIDE; |
| 50 | virtual void SetLoadFlags(int load_flags) OVERRIDE; |
| 51 | virtual int GetLoadFlags() const OVERRIDE; |
| 52 | virtual void SetReferrer(const std::string& referrer) OVERRIDE; |
| 53 | virtual void SetExtraRequestHeaders( |
| 54 | const std::string& extra_request_headers) OVERRIDE; |
[email protected] | 78376af | 2012-02-07 06:56:28 | [diff] [blame] | 55 | virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 56 | virtual void GetExtraRequestHeaders( |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 57 | HttpRequestHeaders* headers) const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 58 | virtual void SetRequestContext( |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 59 | URLRequestContextGetter* request_context_getter) OVERRIDE; |
[email protected] | 7c3bb86 | 2012-05-22 00:14:41 | [diff] [blame] | 60 | virtual void SetFirstPartyForCookies( |
| 61 | const GURL& first_party_for_cookies) OVERRIDE; |
| 62 | virtual void SetURLRequestUserData( |
| 63 | const void* key, |
| 64 | const CreateDataCallback& create_data_callback) OVERRIDE; |
[email protected] | df11714 | 2012-06-07 05:43:44 | [diff] [blame] | 65 | virtual void SetStopOnRedirect(bool stop_on_redirect) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 66 | virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; |
[email protected] | 7af985a | 2012-12-14 22:40:42 | [diff] [blame] | 67 | virtual void SetMaxRetriesOn5xx(int max_retries) OVERRIDE; |
| 68 | virtual int GetMaxRetriesOn5xx() const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 69 | virtual base::TimeDelta GetBackoffDelay() const OVERRIDE; |
[email protected] | 7af985a | 2012-12-14 22:40:42 | [diff] [blame] | 70 | virtual void SetAutomaticallyRetryOnNetworkChanges(int max_retries) OVERRIDE; |
[email protected] | 32c8201 | 2012-03-09 23:25:44 | [diff] [blame] | 71 | virtual void SaveResponseToFileAtPath( |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 72 | const base::FilePath& file_path, |
[email protected] | 0ec0ef73 | 2012-09-19 13:48:06 | [diff] [blame] | 73 | scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 74 | virtual void SaveResponseToTemporaryFile( |
[email protected] | 0ec0ef73 | 2012-09-19 13:48:06 | [diff] [blame] | 75 | scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE; |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 76 | virtual HttpResponseHeaders* GetResponseHeaders() const OVERRIDE; |
| 77 | virtual HostPortPair GetSocketAddress() const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 78 | virtual bool WasFetchedViaProxy() const OVERRIDE; |
| 79 | virtual void Start() OVERRIDE; |
[email protected] | 5645d5b | 2011-10-28 00:40:48 | [diff] [blame] | 80 | virtual const GURL& GetOriginalURL() const OVERRIDE; |
| 81 | virtual const GURL& GetURL() const OVERRIDE; |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 82 | virtual const URLRequestStatus& GetStatus() const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 83 | virtual int GetResponseCode() const OVERRIDE; |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 84 | virtual const ResponseCookies& GetCookies() const OVERRIDE; |
[email protected] | 1dd4060e | 2013-03-13 13:15:13 | [diff] [blame] | 85 | virtual bool FileErrorOccurred(int* out_error_code) const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 86 | virtual void ReceivedContentWasMalformed() OVERRIDE; |
| 87 | virtual bool GetResponseAsString( |
| 88 | std::string* out_response_string) const OVERRIDE; |
| 89 | virtual bool GetResponseAsFilePath( |
| 90 | bool take_ownership, |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 91 | base::FilePath* out_response_path) const OVERRIDE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | |
[email protected] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 93 | static void CancelAll(); |
| 94 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 95 | static void SetEnableInterceptionForTests(bool enabled); |
[email protected] | 73c77e4 | 2013-01-31 11:37:40 | [diff] [blame] | 96 | static void SetIgnoreCertificateRequests(bool ignored); |
[email protected] | b6c911a | 2009-04-21 21:58:45 | [diff] [blame] | 97 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 98 | // TODO(akalin): Make these private again once URLFetcher::Create() |
| 99 | // is in net/. |
[email protected] | b3aced0 | 2011-05-23 12:40:43 | [diff] [blame] | 100 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 101 | static URLFetcherFactory* factory(); |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 102 | |
| 103 | // Sets the factory used by the static method Create to create a URLFetcher. |
| 104 | // URLFetcher does not take ownership of |factory|. A value of NULL results |
| 105 | // in a URLFetcher being created directly. |
| 106 | // |
| 107 | // NOTE: for safety, this should only be used through ScopedURLFetcherFactory! |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 108 | static void set_factory(URLFetcherFactory* factory); |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 109 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 110 | protected: |
| 111 | // Returns the delegate. |
| 112 | URLFetcherDelegate* delegate() const; |
| 113 | |
| 114 | private: |
| 115 | friend class URLFetcherTest; |
| 116 | |
| 117 | // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects |
| 118 | // actively running. |
| 119 | static int GetNumFetcherCores(); |
| 120 | |
| 121 | const scoped_refptr<URLFetcherCore> core_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | }; |
| 125 | |
[email protected] | 8368a0a3 | 2012-06-15 07:51:46 | [diff] [blame] | 126 | } // namespace net |
| 127 | |
| 128 | #endif // NET_URL_REQUEST_URL_FETCHER_IMPL_H_ |