• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
URLFetcherImpl(const GURL & url,RequestType request_type,URLFetcherDelegate * d)18 URLFetcherImpl::URLFetcherImpl(const GURL& url,
19                                RequestType request_type,
20                                URLFetcherDelegate* d)
21     : core_(new URLFetcherCore(this, url, request_type, d)) {
22 }
23 
~URLFetcherImpl()24 URLFetcherImpl::~URLFetcherImpl() {
25   core_->Stop();
26 }
27 
SetUploadData(const std::string & upload_content_type,const std::string & upload_content)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 
SetUploadFilePath(const std::string & upload_content_type,const base::FilePath & file_path,uint64 range_offset,uint64 range_length,scoped_refptr<base::TaskRunner> file_task_runner)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 
SetChunkedUpload(const std::string & content_type)46 void URLFetcherImpl::SetChunkedUpload(const std::string& content_type) {
47   core_->SetChunkedUpload(content_type);
48 }
49 
AppendChunkToUpload(const std::string & data,bool is_last_chunk)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 
SetReferrer(const std::string & referrer)56 void URLFetcherImpl::SetReferrer(const std::string& referrer) {
57   core_->SetReferrer(referrer);
58 }
59 
SetReferrerPolicy(URLRequest::ReferrerPolicy referrer_policy)60 void URLFetcherImpl::SetReferrerPolicy(
61     URLRequest::ReferrerPolicy referrer_policy) {
62   core_->SetReferrerPolicy(referrer_policy);
63 }
64 
SetLoadFlags(int load_flags)65 void URLFetcherImpl::SetLoadFlags(int load_flags) {
66   core_->SetLoadFlags(load_flags);
67 }
68 
GetLoadFlags() const69 int URLFetcherImpl::GetLoadFlags() const {
70   return core_->GetLoadFlags();
71 }
72 
SetExtraRequestHeaders(const std::string & extra_request_headers)73 void URLFetcherImpl::SetExtraRequestHeaders(
74     const std::string& extra_request_headers) {
75   core_->SetExtraRequestHeaders(extra_request_headers);
76 }
77 
AddExtraRequestHeader(const std::string & header_line)78 void URLFetcherImpl::AddExtraRequestHeader(const std::string& header_line) {
79   core_->AddExtraRequestHeader(header_line);
80 }
81 
SetRequestContext(URLRequestContextGetter * request_context_getter)82 void URLFetcherImpl::SetRequestContext(
83     URLRequestContextGetter* request_context_getter) {
84   core_->SetRequestContext(request_context_getter);
85 }
86 
SetFirstPartyForCookies(const GURL & first_party_for_cookies)87 void URLFetcherImpl::SetFirstPartyForCookies(
88     const GURL& first_party_for_cookies) {
89   core_->SetFirstPartyForCookies(first_party_for_cookies);
90 }
91 
SetURLRequestUserData(const void * key,const CreateDataCallback & create_data_callback)92 void URLFetcherImpl::SetURLRequestUserData(
93     const void* key,
94     const CreateDataCallback& create_data_callback) {
95   core_->SetURLRequestUserData(key, create_data_callback);
96 }
97 
SetStopOnRedirect(bool stop_on_redirect)98 void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect) {
99   core_->SetStopOnRedirect(stop_on_redirect);
100 }
101 
SetAutomaticallyRetryOn5xx(bool retry)102 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
103   core_->SetAutomaticallyRetryOn5xx(retry);
104 }
105 
SetMaxRetriesOn5xx(int max_retries)106 void URLFetcherImpl::SetMaxRetriesOn5xx(int max_retries) {
107   core_->SetMaxRetriesOn5xx(max_retries);
108 }
109 
GetMaxRetriesOn5xx() const110 int URLFetcherImpl::GetMaxRetriesOn5xx() const {
111   return core_->GetMaxRetriesOn5xx();
112 }
113 
114 
GetBackoffDelay() const115 base::TimeDelta URLFetcherImpl::GetBackoffDelay() const {
116   return core_->GetBackoffDelay();
117 }
118 
SetAutomaticallyRetryOnNetworkChanges(int max_retries)119 void URLFetcherImpl::SetAutomaticallyRetryOnNetworkChanges(int max_retries) {
120   core_->SetAutomaticallyRetryOnNetworkChanges(max_retries);
121 }
122 
SaveResponseToFileAtPath(const base::FilePath & file_path,scoped_refptr<base::SequencedTaskRunner> file_task_runner)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 
SaveResponseToTemporaryFile(scoped_refptr<base::SequencedTaskRunner> file_task_runner)129 void URLFetcherImpl::SaveResponseToTemporaryFile(
130     scoped_refptr<base::SequencedTaskRunner> file_task_runner) {
131   core_->SaveResponseToTemporaryFile(file_task_runner);
132 }
133 
SaveResponseWithWriter(scoped_ptr<URLFetcherResponseWriter> response_writer)134 void URLFetcherImpl::SaveResponseWithWriter(
135     scoped_ptr<URLFetcherResponseWriter> response_writer) {
136   core_->SaveResponseWithWriter(response_writer.Pass());
137 }
138 
GetResponseHeaders() const139 HttpResponseHeaders* URLFetcherImpl::GetResponseHeaders() const {
140   return core_->GetResponseHeaders();
141 }
142 
GetSocketAddress() const143 HostPortPair URLFetcherImpl::GetSocketAddress() const {
144   return core_->GetSocketAddress();
145 }
146 
WasFetchedViaProxy() const147 bool URLFetcherImpl::WasFetchedViaProxy() const {
148   return core_->WasFetchedViaProxy();
149 }
150 
Start()151 void URLFetcherImpl::Start() {
152   core_->Start();
153 }
154 
GetOriginalURL() const155 const GURL& URLFetcherImpl::GetOriginalURL() const {
156   return core_->GetOriginalURL();
157 }
158 
GetURL() const159 const GURL& URLFetcherImpl::GetURL() const {
160   return core_->GetURL();
161 }
162 
GetStatus() const163 const URLRequestStatus& URLFetcherImpl::GetStatus() const {
164   return core_->GetStatus();
165 }
166 
GetResponseCode() const167 int URLFetcherImpl::GetResponseCode() const {
168   return core_->GetResponseCode();
169 }
170 
GetCookies() const171 const ResponseCookies& URLFetcherImpl::GetCookies() const {
172   return core_->GetCookies();
173 }
174 
ReceivedContentWasMalformed()175 void URLFetcherImpl::ReceivedContentWasMalformed() {
176   core_->ReceivedContentWasMalformed();
177 }
178 
GetResponseAsString(std::string * out_response_string) const179 bool URLFetcherImpl::GetResponseAsString(
180     std::string* out_response_string) const {
181   return core_->GetResponseAsString(out_response_string);
182 }
183 
GetResponseAsFilePath(bool take_ownership,base::FilePath * out_response_path) const184 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
CancelAll()191 void URLFetcherImpl::CancelAll() {
192   URLFetcherCore::CancelAll();
193 }
194 
195 // static
SetEnableInterceptionForTests(bool enabled)196 void URLFetcherImpl::SetEnableInterceptionForTests(bool enabled) {
197   URLFetcherCore::SetEnableInterceptionForTests(enabled);
198 }
199 
200 // static
SetIgnoreCertificateRequests(bool ignored)201 void URLFetcherImpl::SetIgnoreCertificateRequests(bool ignored) {
202   URLFetcherCore::SetIgnoreCertificateRequests(ignored);
203 }
204 
205 // static
GetNumFetcherCores()206 int URLFetcherImpl::GetNumFetcherCores() {
207   return URLFetcherCore::GetNumFetcherCores();
208 }
209 
delegate() const210 URLFetcherDelegate* URLFetcherImpl::delegate() const {
211   return core_->delegate();
212 }
213 
214 // static
factory()215 URLFetcherFactory* URLFetcherImpl::factory() {
216   return g_factory;
217 }
218 
219 // static
set_factory(URLFetcherFactory * factory)220 void URLFetcherImpl::set_factory(URLFetcherFactory* factory) {
221   g_factory = factory;
222 }
223 
224 }  // namespace net
225