OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // URLRequest | 95 // URLRequest |
96 | 96 |
97 URLRequest::URLRequest(const GURL& url, Delegate* delegate) | 97 URLRequest::URLRequest(const GURL& url, Delegate* delegate) |
98 : url_(url), | 98 : url_(url), |
99 original_url_(url), | 99 original_url_(url), |
100 method_("GET"), | 100 method_("GET"), |
101 load_flags_(net::LOAD_NORMAL), | 101 load_flags_(net::LOAD_NORMAL), |
102 delegate_(delegate), | 102 delegate_(delegate), |
103 is_pending_(false), | 103 is_pending_(false), |
104 enable_profiling_(false), | 104 enable_profiling_(false), |
105 is_chunked_upload_(false), | |
105 redirect_limit_(kMaxRedirects), | 106 redirect_limit_(kMaxRedirects), |
106 final_upload_progress_(0), | 107 final_upload_progress_(0), |
107 priority_(net::LOWEST) { | 108 priority_(net::LOWEST) { |
108 SIMPLE_STATS_COUNTER("URLRequestCount"); | 109 SIMPLE_STATS_COUNTER("URLRequestCount"); |
109 | 110 |
110 // Sanity check out environment. | 111 // Sanity check out environment. |
111 DCHECK(MessageLoop::current()) << | 112 DCHECK(MessageLoop::current()) << |
112 "The current MessageLoop must exist"; | 113 "The current MessageLoop must exist"; |
113 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 114 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
114 "The current MessageLoop must be TYPE_IO"; | 115 "The current MessageLoop must be TYPE_IO"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 uint64 offset, | 154 uint64 offset, |
154 uint64 length, | 155 uint64 length, |
155 const base::Time& expected_modification_time) { | 156 const base::Time& expected_modification_time) { |
156 DCHECK(file_path.value().length() > 0 && length > 0); | 157 DCHECK(file_path.value().length() > 0 && length > 0); |
157 if (!upload_) | 158 if (!upload_) |
158 upload_ = new UploadData(); | 159 upload_ = new UploadData(); |
159 upload_->AppendFileRange(file_path, offset, length, | 160 upload_->AppendFileRange(file_path, offset, length, |
160 expected_modification_time); | 161 expected_modification_time); |
161 } | 162 } |
162 | 163 |
164 void URLRequest::AppendChunkToUpload(const char* bytes, int bytes_len) { | |
165 DCHECK(is_chunked_upload_); | |
166 DCHECK(bytes_len > 0); | |
wtc
2011/01/14 03:09:31
Nit: use DCHECK_GT here.
Satish
2011/01/14 18:09:29
Done.
| |
167 DCHECK(upload_); | |
168 upload_->AppendChunk(bytes, bytes_len); | |
169 } | |
170 | |
171 void URLRequest::MarkEndOfChunks() { | |
172 DCHECK(upload_); | |
173 upload_->AppendChunk(NULL, 0); | |
174 } | |
175 | |
163 void URLRequest::set_upload(net::UploadData* upload) { | 176 void URLRequest::set_upload(net::UploadData* upload) { |
164 upload_ = upload; | 177 upload_ = upload; |
165 } | 178 } |
166 | 179 |
167 // Get the upload data directly. | 180 // Get the upload data directly. |
168 net::UploadData* URLRequest::get_upload() { | 181 net::UploadData* URLRequest::get_upload() { |
169 return upload_.get(); | 182 return upload_.get(); |
170 } | 183 } |
171 | 184 |
172 bool URLRequest::has_upload() const { | 185 bool URLRequest::has_upload() const { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 GURL::Replacements referrer_mods; | 322 GURL::Replacements referrer_mods; |
310 referrer_mods.ClearUsername(); | 323 referrer_mods.ClearUsername(); |
311 referrer_mods.ClearPassword(); | 324 referrer_mods.ClearPassword(); |
312 ret = ret.ReplaceComponents(referrer_mods); | 325 ret = ret.ReplaceComponents(referrer_mods); |
313 } | 326 } |
314 | 327 |
315 return ret; | 328 return ret; |
316 } | 329 } |
317 | 330 |
318 void URLRequest::Start() { | 331 void URLRequest::Start() { |
332 if (is_chunked_upload_) { | |
vandebo (ex-Chrome)
2011/01/14 05:53:44
Should this go into "set_chunked_upload" ?
Satish
2011/01/14 18:09:29
Done.
| |
333 DCHECK(!upload_); | |
334 upload_ = new UploadData(); | |
335 upload_->set_is_chunked(true); | |
336 } | |
337 | |
319 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 338 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); |
320 } | 339 } |
321 | 340 |
322 /////////////////////////////////////////////////////////////////////////////// | 341 /////////////////////////////////////////////////////////////////////////////// |
323 | 342 |
324 void URLRequest::StartJob(URLRequestJob* job) { | 343 void URLRequest::StartJob(URLRequestJob* job) { |
325 DCHECK(!is_pending_); | 344 DCHECK(!is_pending_); |
326 DCHECK(!job_); | 345 DCHECK(!job_); |
327 | 346 |
328 net_log_.BeginEvent( | 347 net_log_.BeginEvent( |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 if (found != user_data_.end()) | 615 if (found != user_data_.end()) |
597 return found->second.get(); | 616 return found->second.get(); |
598 return NULL; | 617 return NULL; |
599 } | 618 } |
600 | 619 |
601 void URLRequest::SetUserData(const void* key, UserData* data) { | 620 void URLRequest::SetUserData(const void* key, UserData* data) { |
602 user_data_[key] = linked_ptr<UserData>(data); | 621 user_data_[key] = linked_ptr<UserData>(data); |
603 } | 622 } |
604 | 623 |
605 } // namespace net | 624 } // namespace net |
OLD | NEW |