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