Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / url_request / url_fetcher_impl.cc
blobab14571b3fa7a554048ffa7a6d1c965a85e6574e
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.
5 #include "net/url_request/url_fetcher_impl.h"
7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h"
9 #include "net/base/upload_data_stream.h"
10 #include "net/url_request/url_fetcher_core.h"
11 #include "net/url_request/url_fetcher_factory.h"
12 #include "net/url_request/url_fetcher_response_writer.h"
14 namespace net {
16 static URLFetcherFactory* g_factory = NULL;
18 URLFetcherImpl::URLFetcherImpl(const GURL& url,
19 RequestType request_type,
20 URLFetcherDelegate* d)
21 : core_(new URLFetcherCore(this, url, request_type, d)) {
24 URLFetcherImpl::~URLFetcherImpl() {
25 core_->Stop();
28 void URLFetcherImpl::SetUploadData(const std::string& upload_content_type,
29 const std::string& upload_content) {
30 core_->SetUploadData(upload_content_type, upload_content);
33 void URLFetcherImpl::SetUploadFilePath(
34 const std::string& upload_content_type,
35 const base::FilePath& file_path,
36 uint64 range_offset,
37 uint64 range_length,
38 scoped_refptr<base::TaskRunner> file_task_runner) {
39 core_->SetUploadFilePath(upload_content_type,
40 file_path,
41 range_offset,
42 range_length,
43 file_task_runner);
46 void URLFetcherImpl::SetUploadStreamFactory(
47 const std::string& upload_content_type,
48 const CreateUploadStreamCallback& callback) {
49 core_->SetUploadStreamFactory(upload_content_type, callback);
52 void URLFetcherImpl::SetChunkedUpload(const std::string& content_type) {
53 core_->SetChunkedUpload(content_type);
56 void URLFetcherImpl::AppendChunkToUpload(const std::string& data,
57 bool is_last_chunk) {
58 DCHECK(data.length());
59 core_->AppendChunkToUpload(data, is_last_chunk);
62 void URLFetcherImpl::SetReferrer(const std::string& referrer) {
63 core_->SetReferrer(referrer);
66 void URLFetcherImpl::SetReferrerPolicy(
67 URLRequest::ReferrerPolicy referrer_policy) {
68 core_->SetReferrerPolicy(referrer_policy);
71 void URLFetcherImpl::SetLoadFlags(int load_flags) {
72 core_->SetLoadFlags(load_flags);
75 int URLFetcherImpl::GetLoadFlags() const {
76 return core_->GetLoadFlags();
79 void URLFetcherImpl::SetExtraRequestHeaders(
80 const std::string& extra_request_headers) {
81 core_->SetExtraRequestHeaders(extra_request_headers);
84 void URLFetcherImpl::AddExtraRequestHeader(const std::string& header_line) {
85 core_->AddExtraRequestHeader(header_line);
88 void URLFetcherImpl::SetRequestContext(
89 URLRequestContextGetter* request_context_getter) {
90 core_->SetRequestContext(request_context_getter);
93 void URLFetcherImpl::SetFirstPartyForCookies(
94 const GURL& first_party_for_cookies) {
95 core_->SetFirstPartyForCookies(first_party_for_cookies);
98 void URLFetcherImpl::SetURLRequestUserData(
99 const void* key,
100 const CreateDataCallback& create_data_callback) {
101 core_->SetURLRequestUserData(key, create_data_callback);
104 void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect) {
105 core_->SetStopOnRedirect(stop_on_redirect);
108 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
109 core_->SetAutomaticallyRetryOn5xx(retry);
112 void URLFetcherImpl::SetMaxRetriesOn5xx(int max_retries) {
113 core_->SetMaxRetriesOn5xx(max_retries);
116 int URLFetcherImpl::GetMaxRetriesOn5xx() const {
117 return core_->GetMaxRetriesOn5xx();
121 base::TimeDelta URLFetcherImpl::GetBackoffDelay() const {
122 return core_->GetBackoffDelay();
125 void URLFetcherImpl::SetAutomaticallyRetryOnNetworkChanges(int max_retries) {
126 core_->SetAutomaticallyRetryOnNetworkChanges(max_retries);
129 void URLFetcherImpl::SaveResponseToFileAtPath(
130 const base::FilePath& file_path,
131 scoped_refptr<base::SequencedTaskRunner> file_task_runner) {
132 core_->SaveResponseToFileAtPath(file_path, file_task_runner);
135 void URLFetcherImpl::SaveResponseToTemporaryFile(
136 scoped_refptr<base::SequencedTaskRunner> file_task_runner) {
137 core_->SaveResponseToTemporaryFile(file_task_runner);
140 void URLFetcherImpl::SaveResponseWithWriter(
141 scoped_ptr<URLFetcherResponseWriter> response_writer) {
142 core_->SaveResponseWithWriter(response_writer.Pass());
145 HttpResponseHeaders* URLFetcherImpl::GetResponseHeaders() const {
146 return core_->GetResponseHeaders();
149 HostPortPair URLFetcherImpl::GetSocketAddress() const {
150 return core_->GetSocketAddress();
153 bool URLFetcherImpl::WasFetchedViaProxy() const {
154 return core_->WasFetchedViaProxy();
157 bool URLFetcherImpl::WasCached() const {
158 return core_->WasCached();
161 int64_t URLFetcherImpl::GetReceivedResponseContentLength() const {
162 return core_->GetReceivedResponseContentLength();
165 int64_t URLFetcherImpl::GetTotalReceivedBytes() const {
166 return core_->GetTotalReceivedBytes();
169 void URLFetcherImpl::Start() {
170 core_->Start();
173 const GURL& URLFetcherImpl::GetOriginalURL() const {
174 return core_->GetOriginalURL();
177 const GURL& URLFetcherImpl::GetURL() const {
178 return core_->GetURL();
181 const URLRequestStatus& URLFetcherImpl::GetStatus() const {
182 return core_->GetStatus();
185 int URLFetcherImpl::GetResponseCode() const {
186 return core_->GetResponseCode();
189 const ResponseCookies& URLFetcherImpl::GetCookies() const {
190 return core_->GetCookies();
193 void URLFetcherImpl::ReceivedContentWasMalformed() {
194 core_->ReceivedContentWasMalformed();
197 bool URLFetcherImpl::GetResponseAsString(
198 std::string* out_response_string) const {
199 return core_->GetResponseAsString(out_response_string);
202 bool URLFetcherImpl::GetResponseAsFilePath(
203 bool take_ownership,
204 base::FilePath* out_response_path) const {
205 return core_->GetResponseAsFilePath(take_ownership, out_response_path);
208 // static
209 void URLFetcherImpl::CancelAll() {
210 URLFetcherCore::CancelAll();
213 // static
214 void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored) {
215 URLFetcherCore::SetIgnoreCertificateRequests(ignored);
218 // static
219 int URLFetcherImpl::GetNumFetcherCores() {
220 return URLFetcherCore::GetNumFetcherCores();
223 URLFetcherDelegate* URLFetcherImpl::delegate() const {
224 return core_->delegate();
227 // static
228 URLFetcherFactory* URLFetcherImpl::factory() {
229 return g_factory;
232 // static
233 void URLFetcherImpl::set_factory(URLFetcherFactory* factory) {
234 g_factory = factory;
237 } // namespace net