Update component_updater to use the new version of LaunchProcess.
[chromium-blink-merge.git] / net / url_request / url_fetcher_impl.cc
blob179adfb5ae393bd6942b69bfae10d4eecf85f262
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/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"
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::SetChunkedUpload(const std::string& content_type) {
47 core_->SetChunkedUpload(content_type);
50 void URLFetcherImpl::AppendChunkToUpload(const std::string& data,
51 bool is_last_chunk) {
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(
93 const void* key,
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() {
152 core_->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(
185 bool take_ownership,
186 base::FilePath* out_response_path) const {
187 return core_->GetResponseAsFilePath(take_ownership, out_response_path);
190 // static
191 void URLFetcherImpl::CancelAll() {
192 URLFetcherCore::CancelAll();
195 // static
196 void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored) {
197 URLFetcherCore::SetIgnoreCertificateRequests(ignored);
200 // static
201 int URLFetcherImpl::GetNumFetcherCores() {
202 return URLFetcherCore::GetNumFetcherCores();
205 URLFetcherDelegate* URLFetcherImpl::delegate() const {
206 return core_->delegate();
209 // static
210 URLFetcherFactory* URLFetcherImpl::factory() {
211 return g_factory;
214 // static
215 void URLFetcherImpl::set_factory(URLFetcherFactory* factory) {
216 g_factory = factory;
219 } // namespace net