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