OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
6 | 6 |
7 #include "base/basictypes.h" | |
8 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
9 #include "base/process_util.h" | 8 #include "base/process_util.h" |
10 #include "base/singleton.h" | 9 #include "base/singleton.h" |
11 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "googleurl/src/gurl.h" | |
14 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
15 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
16 #include "net/base/upload_data.h" | 14 #include "net/base/upload_data.h" |
| 15 #include "net/http/http_response_headers.h" |
17 #include "net/http/http_util.h" | 16 #include "net/http/http_util.h" |
| 17 #include "net/url_request/url_request_context.h" |
18 #include "net/url_request/url_request_job.h" | 18 #include "net/url_request/url_request_job.h" |
19 #include "net/url_request/url_request_job_manager.h" | 19 #include "net/url_request/url_request_job_manager.h" |
20 | 20 |
21 #ifndef NDEBUG | 21 #ifndef NDEBUG |
22 URLRequestMetrics url_request_metrics; | 22 URLRequestMetrics url_request_metrics; |
23 #endif | 23 #endif |
24 | 24 |
25 using base::Time; | 25 using base::Time; |
26 using net::UploadData; | 26 using net::UploadData; |
27 using std::string; | 27 using std::string; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 void URLRequest::AppendFileRangeToUpload(const wstring& file_path, | 96 void URLRequest::AppendFileRangeToUpload(const wstring& file_path, |
97 uint64 offset, uint64 length) { | 97 uint64 offset, uint64 length) { |
98 DCHECK(file_path.length() > 0 && length > 0); | 98 DCHECK(file_path.length() > 0 && length > 0); |
99 if (!upload_) | 99 if (!upload_) |
100 upload_ = new UploadData(); | 100 upload_ = new UploadData(); |
101 upload_->AppendFileRange(file_path, offset, length); | 101 upload_->AppendFileRange(file_path, offset, length); |
102 } | 102 } |
103 | 103 |
| 104 void URLRequest::set_upload(net::UploadData* upload) { |
| 105 upload_ = upload; |
| 106 } |
| 107 |
| 108 // Get the upload data directly. |
| 109 net::UploadData* URLRequest::get_upload() { |
| 110 return upload_.get(); |
| 111 } |
| 112 |
| 113 bool URLRequest::has_upload() const { |
| 114 return upload_ != NULL; |
| 115 } |
| 116 |
104 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, | 117 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, |
105 bool overwrite) { | 118 bool overwrite) { |
106 DCHECK(!is_pending_); | 119 DCHECK(!is_pending_); |
107 NOTREACHED() << "implement me!"; | 120 NOTREACHED() << "implement me!"; |
108 } | 121 } |
109 | 122 |
110 void URLRequest::SetExtraRequestHeaderByName(const string& name, | 123 void URLRequest::SetExtraRequestHeaderByName(const string& name, |
111 const string& value, | 124 const string& value, |
112 bool overwrite) { | 125 bool overwrite) { |
113 DCHECK(!is_pending_); | 126 DCHECK(!is_pending_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 177 |
165 void URLRequest::GetAllResponseHeaders(string* headers) { | 178 void URLRequest::GetAllResponseHeaders(string* headers) { |
166 DCHECK(headers); | 179 DCHECK(headers); |
167 if (response_info_.headers) { | 180 if (response_info_.headers) { |
168 response_info_.headers->GetNormalizedHeaders(headers); | 181 response_info_.headers->GetNormalizedHeaders(headers); |
169 } else { | 182 } else { |
170 headers->clear(); | 183 headers->clear(); |
171 } | 184 } |
172 } | 185 } |
173 | 186 |
| 187 net::HttpResponseHeaders* URLRequest::response_headers() const { |
| 188 return response_info_.headers.get(); |
| 189 } |
| 190 |
174 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) { | 191 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) { |
175 DCHECK(job_); | 192 DCHECK(job_); |
176 return job_->GetResponseCookies(cookies); | 193 return job_->GetResponseCookies(cookies); |
177 } | 194 } |
178 | 195 |
179 void URLRequest::GetMimeType(string* mime_type) { | 196 void URLRequest::GetMimeType(string* mime_type) { |
180 DCHECK(job_); | 197 DCHECK(job_); |
181 job_->GetMimeType(mime_type); | 198 job_->GetMimeType(mime_type); |
182 } | 199 } |
183 | 200 |
(...skipping 15 matching lines...) Expand all Loading... |
199 // static | 216 // static |
200 bool URLRequest::IsHandledURL(const GURL& url) { | 217 bool URLRequest::IsHandledURL(const GURL& url) { |
201 if (!url.is_valid()) { | 218 if (!url.is_valid()) { |
202 // We handle error cases. | 219 // We handle error cases. |
203 return true; | 220 return true; |
204 } | 221 } |
205 | 222 |
206 return IsHandledProtocol(url.scheme()); | 223 return IsHandledProtocol(url.scheme()); |
207 } | 224 } |
208 | 225 |
| 226 void URLRequest::set_policy_url(const GURL& policy_url) { |
| 227 DCHECK(!is_pending_); |
| 228 policy_url_ = policy_url; |
| 229 } |
| 230 |
| 231 void URLRequest::set_method(const std::string& method) { |
| 232 DCHECK(!is_pending_); |
| 233 method_ = method; |
| 234 } |
| 235 |
| 236 void URLRequest::set_referrer(const std::string& referrer) { |
| 237 DCHECK(!is_pending_); |
| 238 referrer_ = referrer; |
| 239 } |
| 240 |
209 void URLRequest::Start() { | 241 void URLRequest::Start() { |
210 DCHECK(!is_pending_); | 242 DCHECK(!is_pending_); |
211 DCHECK(!job_); | 243 DCHECK(!job_); |
212 | 244 |
213 job_ = GetJobManager()->CreateJob(this); | 245 job_ = GetJobManager()->CreateJob(this); |
214 job_->SetExtraRequestHeaders(extra_request_headers_); | 246 job_->SetExtraRequestHeaders(extra_request_headers_); |
215 | 247 |
216 if (upload_.get()) | 248 if (upload_.get()) |
217 job_->SetUpload(upload_.get()); | 249 job_->SetUpload(upload_.get()); |
218 | 250 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 final_upload_progress_ = job_->GetUploadProgress(); | 402 final_upload_progress_ = job_->GetUploadProgress(); |
371 } | 403 } |
372 | 404 |
373 OrphanJob(); | 405 OrphanJob(); |
374 | 406 |
375 is_pending_ = false; | 407 is_pending_ = false; |
376 Start(); | 408 Start(); |
377 return net::OK; | 409 return net::OK; |
378 } | 410 } |
379 | 411 |
| 412 URLRequestContext* URLRequest::context() { |
| 413 return context_.get(); |
| 414 } |
| 415 |
| 416 void URLRequest::set_context(URLRequestContext* context) { |
| 417 context_ = context; |
| 418 } |
| 419 |
380 int64 URLRequest::GetExpectedContentSize() const { | 420 int64 URLRequest::GetExpectedContentSize() const { |
381 int64 expected_content_size = -1; | 421 int64 expected_content_size = -1; |
382 if (job_) | 422 if (job_) |
383 expected_content_size = job_->expected_content_size(); | 423 expected_content_size = job_->expected_content_size(); |
384 | 424 |
385 return expected_content_size; | 425 return expected_content_size; |
386 } | 426 } |
| 427 |
| 428 #ifndef NDEBUG |
| 429 |
| 430 URLRequestMetrics::~URLRequestMetrics() { |
| 431 DLOG_IF(WARNING, object_count != 0) << |
| 432 "Leaking " << object_count << " URLRequest object(s)"; |
| 433 } |
| 434 |
| 435 #endif |
OLD | NEW |