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