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