Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/url_request/url_fetcher_impl.h" |
| 6 | |
| 7 | #include "base/bind.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 8 | #include "base/message_loop/message_loop_proxy.h" |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 9 | #include "base/sequenced_task_runner.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "net/url_request/url_fetcher_core.h" |
| 11 | #include "net/url_request/url_fetcher_factory.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 12 | #include "net/url_request/url_fetcher_response_writer.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | static URLFetcherFactory* g_factory = NULL; |
| 17 | |
| 18 | URLFetcherImpl::URLFetcherImpl(const GURL& url, |
| 19 | RequestType request_type, |
| 20 | URLFetcherDelegate* d) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 21 | : core_(new URLFetcherCore(this, url, request_type, d)) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | URLFetcherImpl::~URLFetcherImpl() { |
| 25 | core_->Stop(); |
| 26 | } |
| 27 | |
| 28 | void URLFetcherImpl::SetUploadData(const std::string& upload_content_type, |
| 29 | const std::string& upload_content) { |
| 30 | core_->SetUploadData(upload_content_type, upload_content); |
| 31 | } |
| 32 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 33 | void URLFetcherImpl::SetUploadFilePath( |
| 34 | const std::string& upload_content_type, |
| 35 | const base::FilePath& file_path, |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 36 | uint64 range_offset, |
| 37 | uint64 range_length, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 38 | scoped_refptr<base::TaskRunner> file_task_runner) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 39 | core_->SetUploadFilePath(upload_content_type, |
| 40 | file_path, |
| 41 | range_offset, |
| 42 | range_length, |
| 43 | file_task_runner); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | void URLFetcherImpl::SetChunkedUpload(const std::string& content_type) { |
| 47 | core_->SetChunkedUpload(content_type); |
| 48 | } |
| 49 | |
| 50 | void URLFetcherImpl::AppendChunkToUpload(const std::string& data, |
| 51 | bool is_last_chunk) { |
| 52 | DCHECK(data.length()); |
| 53 | core_->AppendChunkToUpload(data, is_last_chunk); |
| 54 | } |
| 55 | |
| 56 | void URLFetcherImpl::SetReferrer(const std::string& referrer) { |
| 57 | core_->SetReferrer(referrer); |
| 58 | } |
| 59 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 60 | void URLFetcherImpl::SetReferrerPolicy( |
| 61 | URLRequest::ReferrerPolicy referrer_policy) { |
| 62 | core_->SetReferrerPolicy(referrer_policy); |
| 63 | } |
| 64 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 65 | void URLFetcherImpl::SetLoadFlags(int load_flags) { |
| 66 | core_->SetLoadFlags(load_flags); |
| 67 | } |
| 68 | |
| 69 | int URLFetcherImpl::GetLoadFlags() const { |
| 70 | return core_->GetLoadFlags(); |
| 71 | } |
| 72 | |
| 73 | void URLFetcherImpl::SetExtraRequestHeaders( |
| 74 | const std::string& extra_request_headers) { |
| 75 | core_->SetExtraRequestHeaders(extra_request_headers); |
| 76 | } |
| 77 | |
| 78 | void URLFetcherImpl::AddExtraRequestHeader(const std::string& header_line) { |
| 79 | core_->AddExtraRequestHeader(header_line); |
| 80 | } |
| 81 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 82 | void URLFetcherImpl::SetRequestContext( |
| 83 | URLRequestContextGetter* request_context_getter) { |
| 84 | core_->SetRequestContext(request_context_getter); |
| 85 | } |
| 86 | |
| 87 | void URLFetcherImpl::SetFirstPartyForCookies( |
| 88 | const GURL& first_party_for_cookies) { |
| 89 | core_->SetFirstPartyForCookies(first_party_for_cookies); |
| 90 | } |
| 91 | |
| 92 | void URLFetcherImpl::SetURLRequestUserData( |
| 93 | const void* key, |
| 94 | const CreateDataCallback& create_data_callback) { |
| 95 | core_->SetURLRequestUserData(key, create_data_callback); |
| 96 | } |
| 97 | |
| 98 | void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect) { |
| 99 | core_->SetStopOnRedirect(stop_on_redirect); |
| 100 | } |
| 101 | |
| 102 | void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { |
| 103 | core_->SetAutomaticallyRetryOn5xx(retry); |
| 104 | } |
| 105 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 106 | void URLFetcherImpl::SetMaxRetriesOn5xx(int max_retries) { |
| 107 | core_->SetMaxRetriesOn5xx(max_retries); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 110 | int URLFetcherImpl::GetMaxRetriesOn5xx() const { |
| 111 | return core_->GetMaxRetriesOn5xx(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | base::TimeDelta URLFetcherImpl::GetBackoffDelay() const { |
| 116 | return core_->GetBackoffDelay(); |
| 117 | } |
| 118 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 119 | void URLFetcherImpl::SetAutomaticallyRetryOnNetworkChanges(int max_retries) { |
| 120 | core_->SetAutomaticallyRetryOnNetworkChanges(max_retries); |
| 121 | } |
| 122 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 123 | void URLFetcherImpl::SaveResponseToFileAtPath( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 124 | const base::FilePath& file_path, |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 125 | scoped_refptr<base::SequencedTaskRunner> file_task_runner) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 126 | core_->SaveResponseToFileAtPath(file_path, file_task_runner); |
| 127 | } |
| 128 | |
| 129 | void URLFetcherImpl::SaveResponseToTemporaryFile( |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 130 | scoped_refptr<base::SequencedTaskRunner> file_task_runner) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 131 | core_->SaveResponseToTemporaryFile(file_task_runner); |
| 132 | } |
| 133 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 134 | void URLFetcherImpl::SaveResponseWithWriter( |
| 135 | scoped_ptr<URLFetcherResponseWriter> response_writer) { |
| 136 | core_->SaveResponseWithWriter(response_writer.Pass()); |
| 137 | } |
| 138 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 139 | HttpResponseHeaders* URLFetcherImpl::GetResponseHeaders() const { |
| 140 | return core_->GetResponseHeaders(); |
| 141 | } |
| 142 | |
| 143 | HostPortPair URLFetcherImpl::GetSocketAddress() const { |
| 144 | return core_->GetSocketAddress(); |
| 145 | } |
| 146 | |
| 147 | bool URLFetcherImpl::WasFetchedViaProxy() const { |
| 148 | return core_->WasFetchedViaProxy(); |
| 149 | } |
| 150 | |
| 151 | void URLFetcherImpl::Start() { |
| 152 | core_->Start(); |
| 153 | } |
| 154 | |
| 155 | const GURL& URLFetcherImpl::GetOriginalURL() const { |
| 156 | return core_->GetOriginalURL(); |
| 157 | } |
| 158 | |
| 159 | const GURL& URLFetcherImpl::GetURL() const { |
| 160 | return core_->GetURL(); |
| 161 | } |
| 162 | |
| 163 | const URLRequestStatus& URLFetcherImpl::GetStatus() const { |
| 164 | return core_->GetStatus(); |
| 165 | } |
| 166 | |
| 167 | int URLFetcherImpl::GetResponseCode() const { |
| 168 | return core_->GetResponseCode(); |
| 169 | } |
| 170 | |
| 171 | const ResponseCookies& URLFetcherImpl::GetCookies() const { |
| 172 | return core_->GetCookies(); |
| 173 | } |
| 174 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 175 | void URLFetcherImpl::ReceivedContentWasMalformed() { |
| 176 | core_->ReceivedContentWasMalformed(); |
| 177 | } |
| 178 | |
| 179 | bool URLFetcherImpl::GetResponseAsString( |
| 180 | std::string* out_response_string) const { |
| 181 | return core_->GetResponseAsString(out_response_string); |
| 182 | } |
| 183 | |
| 184 | bool URLFetcherImpl::GetResponseAsFilePath( |
| 185 | bool take_ownership, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 186 | base::FilePath* out_response_path) const { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 187 | return core_->GetResponseAsFilePath(take_ownership, out_response_path); |
| 188 | } |
| 189 | |
| 190 | // static |
| 191 | void URLFetcherImpl::CancelAll() { |
| 192 | URLFetcherCore::CancelAll(); |
| 193 | } |
| 194 | |
| 195 | // static |
| 196 | void URLFetcherImpl::SetEnableInterceptionForTests(bool enabled) { |
| 197 | URLFetcherCore::SetEnableInterceptionForTests(enabled); |
| 198 | } |
| 199 | |
| 200 | // static |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 201 | void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored) { |
| 202 | URLFetcherCore::SetIgnoreCertificateRequests(ignored); |
| 203 | } |
| 204 | |
| 205 | // static |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 206 | int URLFetcherImpl::GetNumFetcherCores() { |
| 207 | return URLFetcherCore::GetNumFetcherCores(); |
| 208 | } |
| 209 | |
| 210 | URLFetcherDelegate* URLFetcherImpl::delegate() const { |
| 211 | return core_->delegate(); |
| 212 | } |
| 213 | |
| 214 | // static |
| 215 | URLFetcherFactory* URLFetcherImpl::factory() { |
| 216 | return g_factory; |
| 217 | } |
| 218 | |
| 219 | // static |
| 220 | void URLFetcherImpl::set_factory(URLFetcherFactory* factory) { |
| 221 | g_factory = factory; |
| 222 | } |
| 223 | |
| 224 | } // namespace net |