| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/net/url_fetcher.h" | 5 #include "chrome/common/net/url_fetcher.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 void NotifyMalformedContent(); | 94 void NotifyMalformedContent(); |
| 95 | 95 |
| 96 // Deletes the request, removes it from the registry, and removes the | 96 // Deletes the request, removes it from the registry, and removes the |
| 97 // destruction observer. | 97 // destruction observer. |
| 98 void ReleaseRequest(); | 98 void ReleaseRequest(); |
| 99 | 99 |
| 100 // Returns the max value of exponential back-off release time for | 100 // Returns the max value of exponential back-off release time for |
| 101 // |original_url_| and |url_|. | 101 // |original_url_| and |url_|. |
| 102 base::TimeTicks GetBackoffReleaseTime(); | 102 base::TimeTicks GetBackoffReleaseTime(); |
| 103 | 103 |
| 104 void CompleteAddingUploadDataChunk(const std::string& data); | 104 void CompleteAddingUploadDataChunk(const std::string& data, |
| 105 bool is_last_chunk); |
| 105 | 106 |
| 106 // Adds a block of data to be uploaded in a POST body. This can only be called | 107 // Adds a block of data to be uploaded in a POST body. This can only be called |
| 107 // after Start(). | 108 // after Start(). |
| 108 void AppendChunkToUpload(const std::string& data); | 109 void AppendChunkToUpload(const std::string& data, bool is_last_chunk); |
| 109 | 110 |
| 110 URLFetcher* fetcher_; // Corresponding fetcher object | 111 URLFetcher* fetcher_; // Corresponding fetcher object |
| 111 GURL original_url_; // The URL we were asked to fetch | 112 GURL original_url_; // The URL we were asked to fetch |
| 112 GURL url_; // The URL we eventually wound up at | 113 GURL url_; // The URL we eventually wound up at |
| 113 RequestType request_type_; // What type of request is this? | 114 RequestType request_type_; // What type of request is this? |
| 114 URLFetcher::Delegate* delegate_; // Object to notify on completion | 115 URLFetcher::Delegate* delegate_; // Object to notify on completion |
| 115 scoped_refptr<base::MessageLoopProxy> delegate_loop_proxy_; | 116 scoped_refptr<base::MessageLoopProxy> delegate_loop_proxy_; |
| 116 // Message loop proxy of the creating | 117 // Message loop proxy of the creating |
| 117 // thread. | 118 // thread. |
| 118 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 119 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // Some servers may treat HEAD requests as GET requests. To free up the | 285 // Some servers may treat HEAD requests as GET requests. To free up the |
| 285 // network connection as soon as possible, signal that the request has | 286 // network connection as soon as possible, signal that the request has |
| 286 // completed immediately, without trying to read any data back (all we care | 287 // completed immediately, without trying to read any data back (all we care |
| 287 // about is the response code and headers, which we already have). | 288 // about is the response code and headers, which we already have). |
| 288 if (request_->status().is_success() && (request_type_ != HEAD)) | 289 if (request_->status().is_success() && (request_type_ != HEAD)) |
| 289 request_->Read(buffer_, kBufferSize, &bytes_read); | 290 request_->Read(buffer_, kBufferSize, &bytes_read); |
| 290 OnReadCompleted(request_.get(), bytes_read); | 291 OnReadCompleted(request_.get(), bytes_read); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void URLFetcher::Core::CompleteAddingUploadDataChunk( | 294 void URLFetcher::Core::CompleteAddingUploadDataChunk( |
| 294 const std::string& content) { | 295 const std::string& content, bool is_last_chunk) { |
| 295 DCHECK(is_chunked_upload_); | 296 DCHECK(is_chunked_upload_); |
| 296 DCHECK(request_.get()); | 297 DCHECK(request_.get()); |
| 297 if (content.length()) { | 298 DCHECK(!content.empty()); |
| 298 request_->AppendChunkToUpload(content.data(), | 299 request_->AppendChunkToUpload(content.data(), |
| 299 static_cast<int>(content.length())); | 300 static_cast<int>(content.length()), |
| 300 } else { | 301 is_last_chunk); |
| 301 request_->MarkEndOfChunks(); | |
| 302 } | |
| 303 } | 302 } |
| 304 | 303 |
| 305 void URLFetcher::Core::AppendChunkToUpload(const std::string& content) { | 304 void URLFetcher::Core::AppendChunkToUpload(const std::string& content, |
| 305 bool is_last_chunk) { |
| 306 DCHECK(delegate_loop_proxy_); | 306 DCHECK(delegate_loop_proxy_); |
| 307 CHECK(io_message_loop_proxy_.get()); | 307 CHECK(io_message_loop_proxy_.get()); |
| 308 io_message_loop_proxy_->PostTask( | 308 io_message_loop_proxy_->PostTask( |
| 309 FROM_HERE, | 309 FROM_HERE, |
| 310 NewRunnableMethod(this, &Core::CompleteAddingUploadDataChunk, content)); | 310 NewRunnableMethod(this, &Core::CompleteAddingUploadDataChunk, content, |
| 311 is_last_chunk)); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void URLFetcher::Core::OnReadCompleted(net::URLRequest* request, | 314 void URLFetcher::Core::OnReadCompleted(net::URLRequest* request, |
| 314 int bytes_read) { | 315 int bytes_read) { |
| 315 DCHECK(request == request_); | 316 DCHECK(request == request_); |
| 316 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 317 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 317 | 318 |
| 318 url_ = request->url(); | 319 url_ = request->url(); |
| 319 url_throttler_entry_ = | 320 url_throttler_entry_ = |
| 320 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl(url_); | 321 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl(url_); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 514 |
| 514 void URLFetcher::set_chunked_upload(const std::string& content_type) { | 515 void URLFetcher::set_chunked_upload(const std::string& content_type) { |
| 515 DCHECK(core_->is_chunked_upload_ || | 516 DCHECK(core_->is_chunked_upload_ || |
| 516 (core_->upload_content_type_.empty() && | 517 (core_->upload_content_type_.empty() && |
| 517 core_->upload_content_.empty())); | 518 core_->upload_content_.empty())); |
| 518 core_->upload_content_type_ = content_type; | 519 core_->upload_content_type_ = content_type; |
| 519 core_->upload_content_.clear(); | 520 core_->upload_content_.clear(); |
| 520 core_->is_chunked_upload_ = true; | 521 core_->is_chunked_upload_ = true; |
| 521 } | 522 } |
| 522 | 523 |
| 523 void URLFetcher::AppendChunkToUpload(const std::string& data) { | 524 void URLFetcher::AppendChunkToUpload(const std::string& data, |
| 525 bool is_last_chunk) { |
| 524 DCHECK(data.length()); | 526 DCHECK(data.length()); |
| 525 core_->AppendChunkToUpload(data); | 527 core_->AppendChunkToUpload(data, is_last_chunk); |
| 526 } | |
| 527 | |
| 528 void URLFetcher::MarkEndOfChunks() { | |
| 529 core_->AppendChunkToUpload(std::string()); | |
| 530 } | 528 } |
| 531 | 529 |
| 532 const std::string& URLFetcher::upload_data() const { | 530 const std::string& URLFetcher::upload_data() const { |
| 533 return core_->upload_content_; | 531 return core_->upload_content_; |
| 534 } | 532 } |
| 535 | 533 |
| 536 void URLFetcher::set_referrer(const std::string& referrer) { | 534 void URLFetcher::set_referrer(const std::string& referrer) { |
| 537 core_->referrer_ = referrer; | 535 core_->referrer_ = referrer; |
| 538 } | 536 } |
| 539 | 537 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 575 } |
| 578 | 576 |
| 579 // static | 577 // static |
| 580 void URLFetcher::CancelAll() { | 578 void URLFetcher::CancelAll() { |
| 581 Core::CancelAll(); | 579 Core::CancelAll(); |
| 582 } | 580 } |
| 583 | 581 |
| 584 URLFetcher::Delegate* URLFetcher::delegate() const { | 582 URLFetcher::Delegate* URLFetcher::delegate() const { |
| 585 return core_->delegate(); | 583 return core_->delegate(); |
| 586 } | 584 } |
| OLD | NEW |