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"
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"
17 static URLFetcherFactory
* g_factory
= NULL
;
19 URLFetcherImpl::URLFetcherImpl(const GURL
& url
,
20 RequestType request_type
,
21 URLFetcherDelegate
* d
)
22 : core_(new URLFetcherCore(this, url
, request_type
, d
)) {
25 URLFetcherImpl::~URLFetcherImpl() {
29 void URLFetcherImpl::SetUploadData(const std::string
& upload_content_type
,
30 const std::string
& upload_content
) {
31 core_
->SetUploadData(upload_content_type
, upload_content
);
34 void URLFetcherImpl::SetUploadFilePath(
35 const std::string
& upload_content_type
,
36 const base::FilePath
& file_path
,
39 scoped_refptr
<base::TaskRunner
> file_task_runner
) {
40 core_
->SetUploadFilePath(upload_content_type
,
47 void URLFetcherImpl::SetUploadStreamFactory(
48 const std::string
& upload_content_type
,
49 const CreateUploadStreamCallback
& callback
) {
50 core_
->SetUploadStreamFactory(upload_content_type
, callback
);
53 void URLFetcherImpl::SetChunkedUpload(const std::string
& content_type
) {
54 core_
->SetChunkedUpload(content_type
);
57 void URLFetcherImpl::AppendChunkToUpload(const std::string
& data
,
59 DCHECK(data
.length());
60 core_
->AppendChunkToUpload(data
, is_last_chunk
);
63 void URLFetcherImpl::SetReferrer(const std::string
& referrer
) {
64 core_
->SetReferrer(referrer
);
67 void URLFetcherImpl::SetReferrerPolicy(
68 URLRequest::ReferrerPolicy referrer_policy
) {
69 core_
->SetReferrerPolicy(referrer_policy
);
72 void URLFetcherImpl::SetLoadFlags(int load_flags
) {
73 core_
->SetLoadFlags(load_flags
);
76 int URLFetcherImpl::GetLoadFlags() const {
77 return core_
->GetLoadFlags();
80 void URLFetcherImpl::SetExtraRequestHeaders(
81 const std::string
& extra_request_headers
) {
82 core_
->SetExtraRequestHeaders(extra_request_headers
);
85 void URLFetcherImpl::AddExtraRequestHeader(const std::string
& header_line
) {
86 core_
->AddExtraRequestHeader(header_line
);
89 void URLFetcherImpl::SetRequestContext(
90 URLRequestContextGetter
* request_context_getter
) {
91 core_
->SetRequestContext(request_context_getter
);
94 void URLFetcherImpl::SetFirstPartyForCookies(
95 const GURL
& first_party_for_cookies
) {
96 core_
->SetFirstPartyForCookies(first_party_for_cookies
);
99 void URLFetcherImpl::SetURLRequestUserData(
101 const CreateDataCallback
& create_data_callback
) {
102 core_
->SetURLRequestUserData(key
, create_data_callback
);
105 void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect
) {
106 core_
->SetStopOnRedirect(stop_on_redirect
);
109 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry
) {
110 core_
->SetAutomaticallyRetryOn5xx(retry
);
113 void URLFetcherImpl::SetMaxRetriesOn5xx(int max_retries
) {
114 core_
->SetMaxRetriesOn5xx(max_retries
);
117 int URLFetcherImpl::GetMaxRetriesOn5xx() const {
118 return core_
->GetMaxRetriesOn5xx();
122 base::TimeDelta
URLFetcherImpl::GetBackoffDelay() const {
123 return core_
->GetBackoffDelay();
126 void URLFetcherImpl::SetAutomaticallyRetryOnNetworkChanges(int max_retries
) {
127 core_
->SetAutomaticallyRetryOnNetworkChanges(max_retries
);
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
);
136 void URLFetcherImpl::SaveResponseToTemporaryFile(
137 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner
) {
138 core_
->SaveResponseToTemporaryFile(file_task_runner
);
141 void URLFetcherImpl::SaveResponseWithWriter(
142 scoped_ptr
<URLFetcherResponseWriter
> response_writer
) {
143 core_
->SaveResponseWithWriter(response_writer
.Pass());
146 HttpResponseHeaders
* URLFetcherImpl::GetResponseHeaders() const {
147 return core_
->GetResponseHeaders();
150 HostPortPair
URLFetcherImpl::GetSocketAddress() const {
151 return core_
->GetSocketAddress();
154 bool URLFetcherImpl::WasFetchedViaProxy() const {
155 return core_
->WasFetchedViaProxy();
158 void URLFetcherImpl::Start() {
162 const GURL
& URLFetcherImpl::GetOriginalURL() const {
163 return core_
->GetOriginalURL();
166 const GURL
& URLFetcherImpl::GetURL() const {
167 return core_
->GetURL();
170 const URLRequestStatus
& URLFetcherImpl::GetStatus() const {
171 return core_
->GetStatus();
174 int URLFetcherImpl::GetResponseCode() const {
175 return core_
->GetResponseCode();
178 const ResponseCookies
& URLFetcherImpl::GetCookies() const {
179 return core_
->GetCookies();
182 void URLFetcherImpl::ReceivedContentWasMalformed() {
183 core_
->ReceivedContentWasMalformed();
186 bool URLFetcherImpl::GetResponseAsString(
187 std::string
* out_response_string
) const {
188 return core_
->GetResponseAsString(out_response_string
);
191 bool URLFetcherImpl::GetResponseAsFilePath(
193 base::FilePath
* out_response_path
) const {
194 return core_
->GetResponseAsFilePath(take_ownership
, out_response_path
);
198 void URLFetcherImpl::CancelAll() {
199 URLFetcherCore::CancelAll();
203 void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored
) {
204 URLFetcherCore::SetIgnoreCertificateRequests(ignored
);
208 int URLFetcherImpl::GetNumFetcherCores() {
209 return URLFetcherCore::GetNumFetcherCores();
212 URLFetcherDelegate
* URLFetcherImpl::delegate() const {
213 return core_
->delegate();
217 URLFetcherFactory
* URLFetcherImpl::factory() {
222 void URLFetcherImpl::set_factory(URLFetcherFactory
* factory
) {