| 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 chunked_transfer_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(bytes_len > 0); |
| 166 DCHECK(upload_); |
| 167 upload_->AppendChunk(bytes, bytes_len); |
| 168 } |
| 169 |
| 170 void URLRequest::MarkEndOfChunks() { |
| 171 DCHECK(upload_); |
| 172 upload_->AppendChunk(NULL, 0); |
| 173 } |
| 174 |
| 163 void URLRequest::set_upload(net::UploadData* upload) { | 175 void URLRequest::set_upload(net::UploadData* upload) { |
| 164 upload_ = upload; | 176 upload_ = upload; |
| 165 } | 177 } |
| 166 | 178 |
| 167 // Get the upload data directly. | 179 // Get the upload data directly. |
| 168 net::UploadData* URLRequest::get_upload() { | 180 net::UploadData* URLRequest::get_upload() { |
| 169 return upload_.get(); | 181 return upload_.get(); |
| 170 } | 182 } |
| 171 | 183 |
| 172 bool URLRequest::has_upload() const { | 184 bool URLRequest::has_upload() const { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 GURL::Replacements referrer_mods; | 321 GURL::Replacements referrer_mods; |
| 310 referrer_mods.ClearUsername(); | 322 referrer_mods.ClearUsername(); |
| 311 referrer_mods.ClearPassword(); | 323 referrer_mods.ClearPassword(); |
| 312 ret = ret.ReplaceComponents(referrer_mods); | 324 ret = ret.ReplaceComponents(referrer_mods); |
| 313 } | 325 } |
| 314 | 326 |
| 315 return ret; | 327 return ret; |
| 316 } | 328 } |
| 317 | 329 |
| 318 void URLRequest::Start() { | 330 void URLRequest::Start() { |
| 331 if (chunked_transfer_upload_) { |
| 332 DCHECK(!upload_); |
| 333 upload_ = new UploadData(); |
| 334 upload_->set_is_chunked(true); |
| 335 } |
| 336 |
| 319 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 337 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); |
| 320 } | 338 } |
| 321 | 339 |
| 322 /////////////////////////////////////////////////////////////////////////////// | 340 /////////////////////////////////////////////////////////////////////////////// |
| 323 | 341 |
| 324 void URLRequest::StartJob(URLRequestJob* job) { | 342 void URLRequest::StartJob(URLRequestJob* job) { |
| 325 DCHECK(!is_pending_); | 343 DCHECK(!is_pending_); |
| 326 DCHECK(!job_); | 344 DCHECK(!job_); |
| 327 | 345 |
| 328 net_log_.BeginEvent( | 346 net_log_.BeginEvent( |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 if (found != user_data_.end()) | 614 if (found != user_data_.end()) |
| 597 return found->second.get(); | 615 return found->second.get(); |
| 598 return NULL; | 616 return NULL; |
| 599 } | 617 } |
| 600 | 618 |
| 601 void URLRequest::SetUserData(const void* key, UserData* data) { | 619 void URLRequest::SetUserData(const void* key, UserData* data) { |
| 602 user_data_[key] = linked_ptr<UserData>(data); | 620 user_data_[key] = linked_ptr<UserData>(data); |
| 603 } | 621 } |
| 604 | 622 |
| 605 } // namespace net | 623 } // namespace net |
| OLD | NEW |