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/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"
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() {
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
,
38 scoped_refptr
<base::TaskRunner
> file_task_runner
) {
39 core_
->SetUploadFilePath(upload_content_type
,
46 void URLFetcherImpl::SetChunkedUpload(const std::string
& content_type
) {
47 core_
->SetChunkedUpload(content_type
);
50 void URLFetcherImpl::AppendChunkToUpload(const std::string
& data
,
52 DCHECK(data
.length());
53 core_
->AppendChunkToUpload(data
, is_last_chunk
);
56 void URLFetcherImpl::SetReferrer(const std::string
& referrer
) {
57 core_
->SetReferrer(referrer
);
60 void URLFetcherImpl::SetReferrerPolicy(
61 URLRequest::ReferrerPolicy referrer_policy
) {
62 core_
->SetReferrerPolicy(referrer_policy
);
65 void URLFetcherImpl::SetLoadFlags(int load_flags
) {
66 core_
->SetLoadFlags(load_flags
);
69 int URLFetcherImpl::GetLoadFlags() const {
70 return core_
->GetLoadFlags();
73 void URLFetcherImpl::SetExtraRequestHeaders(
74 const std::string
& extra_request_headers
) {
75 core_
->SetExtraRequestHeaders(extra_request_headers
);
78 void URLFetcherImpl::AddExtraRequestHeader(const std::string
& header_line
) {
79 core_
->AddExtraRequestHeader(header_line
);
82 void URLFetcherImpl::SetRequestContext(
83 URLRequestContextGetter
* request_context_getter
) {
84 core_
->SetRequestContext(request_context_getter
);
87 void URLFetcherImpl::SetFirstPartyForCookies(
88 const GURL
& first_party_for_cookies
) {
89 core_
->SetFirstPartyForCookies(first_party_for_cookies
);
92 void URLFetcherImpl::SetURLRequestUserData(
94 const CreateDataCallback
& create_data_callback
) {
95 core_
->SetURLRequestUserData(key
, create_data_callback
);
98 void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect
) {
99 core_
->SetStopOnRedirect(stop_on_redirect
);
102 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry
) {
103 core_
->SetAutomaticallyRetryOn5xx(retry
);
106 void URLFetcherImpl::SetMaxRetriesOn5xx(int max_retries
) {
107 core_
->SetMaxRetriesOn5xx(max_retries
);
110 int URLFetcherImpl::GetMaxRetriesOn5xx() const {
111 return core_
->GetMaxRetriesOn5xx();
115 base::TimeDelta
URLFetcherImpl::GetBackoffDelay() const {
116 return core_
->GetBackoffDelay();
119 void URLFetcherImpl::SetAutomaticallyRetryOnNetworkChanges(int max_retries
) {
120 core_
->SetAutomaticallyRetryOnNetworkChanges(max_retries
);
123 void URLFetcherImpl::SaveResponseToFileAtPath(
124 const base::FilePath
& file_path
,
125 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner
) {
126 core_
->SaveResponseToFileAtPath(file_path
, file_task_runner
);
129 void URLFetcherImpl::SaveResponseToTemporaryFile(
130 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner
) {
131 core_
->SaveResponseToTemporaryFile(file_task_runner
);
134 void URLFetcherImpl::SaveResponseWithWriter(
135 scoped_ptr
<URLFetcherResponseWriter
> response_writer
) {
136 core_
->SaveResponseWithWriter(response_writer
.Pass());
139 HttpResponseHeaders
* URLFetcherImpl::GetResponseHeaders() const {
140 return core_
->GetResponseHeaders();
143 HostPortPair
URLFetcherImpl::GetSocketAddress() const {
144 return core_
->GetSocketAddress();
147 bool URLFetcherImpl::WasFetchedViaProxy() const {
148 return core_
->WasFetchedViaProxy();
151 void URLFetcherImpl::Start() {
155 const GURL
& URLFetcherImpl::GetOriginalURL() const {
156 return core_
->GetOriginalURL();
159 const GURL
& URLFetcherImpl::GetURL() const {
160 return core_
->GetURL();
163 const URLRequestStatus
& URLFetcherImpl::GetStatus() const {
164 return core_
->GetStatus();
167 int URLFetcherImpl::GetResponseCode() const {
168 return core_
->GetResponseCode();
171 const ResponseCookies
& URLFetcherImpl::GetCookies() const {
172 return core_
->GetCookies();
175 void URLFetcherImpl::ReceivedContentWasMalformed() {
176 core_
->ReceivedContentWasMalformed();
179 bool URLFetcherImpl::GetResponseAsString(
180 std::string
* out_response_string
) const {
181 return core_
->GetResponseAsString(out_response_string
);
184 bool URLFetcherImpl::GetResponseAsFilePath(
186 base::FilePath
* out_response_path
) const {
187 return core_
->GetResponseAsFilePath(take_ownership
, out_response_path
);
191 void URLFetcherImpl::CancelAll() {
192 URLFetcherCore::CancelAll();
196 void URLFetcherImpl::SetEnableInterceptionForTests(bool enabled
) {
197 URLFetcherCore::SetEnableInterceptionForTests(enabled
);
201 void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored
) {
202 URLFetcherCore::SetIgnoreCertificateRequests(ignored
);
206 int URLFetcherImpl::GetNumFetcherCores() {
207 return URLFetcherCore::GetNumFetcherCores();
210 URLFetcherDelegate
* URLFetcherImpl::delegate() const {
211 return core_
->delegate();
215 URLFetcherFactory
* URLFetcherImpl::factory() {
220 void URLFetcherImpl::set_factory(URLFetcherFactory
* factory
) {