Chromium Code Reviews| Index: chrome/common/net/url_fetcher.cc |
| diff --git a/chrome/common/net/url_fetcher.cc b/chrome/common/net/url_fetcher.cc |
| index 53487b712215e56ff585fef3947a97382261e39f..9247946cb64a21e0ddac0c391f3e69c13f72850a 100644 |
| --- a/chrome/common/net/url_fetcher.cc |
| +++ b/chrome/common/net/url_fetcher.cc |
| @@ -102,6 +102,13 @@ class URLFetcher::Core |
| // |original_url_| and |url_|. |
| base::TimeTicks GetBackoffReleaseTime(); |
| + void AddUploadDataChunkInThread(const std::string& data); |
|
vandebo (ex-Chrome)
2011/01/14 05:53:44
Should this be private?
Satish
2011/01/14 18:09:29
All these functions are in the private block, but
|
| + |
| + // Adds a block of data to be uploaded in a POST body. This can be called |
| + // before or after Start() is called. |
| + void AppendChunkToUpload(const std::string& data); |
| + void MarkEndOfChunks(); |
| + |
| URLFetcher* fetcher_; // Corresponding fetcher object |
| GURL original_url_; // The URL we were asked to fetch |
| GURL url_; // The URL we eventually wound up at |
| @@ -127,6 +134,7 @@ class URLFetcher::Core |
| std::string upload_content_; // HTTP POST payload |
| std::string upload_content_type_; // MIME type of POST payload |
| + bool is_chunked_upload_; // True if using chunked transfer encoding |
|
wtc
2011/01/14 03:09:31
Please document this issue:
If is_chunked_upload
Satish
2011/01/14 18:09:29
No, only one of them can be valid and the setters
|
| // Used to determine how long to wait before making a request or doing a |
| // retry. |
| @@ -222,6 +230,7 @@ URLFetcher::Core::Core(URLFetcher* fetcher, |
| response_code_(-1), |
| buffer_(new net::IOBuffer(kBufferSize)), |
| num_retries_(0), |
| + is_chunked_upload_(false), |
| was_cancelled_(false) { |
| } |
| @@ -282,6 +291,35 @@ void URLFetcher::Core::OnResponseStarted(net::URLRequest* request) { |
| OnReadCompleted(request_.get(), bytes_read); |
| } |
| +void URLFetcher::Core::AddUploadDataChunkInThread(const std::string& content) { |
| + DCHECK(is_chunked_upload_); |
| + DCHECK(request_.get()); |
| + if (content.length() > 0) { |
| + request_->AppendChunkToUpload(content.data(), |
| + static_cast<int>(content.size())); |
| + } else { |
| + request_->MarkEndOfChunks(); |
| + } |
| +} |
| + |
| +void URLFetcher::Core::AppendChunkToUpload(const std::string& content) { |
| + DCHECK(content.length() > 0); |
| + DCHECK(delegate_loop_proxy_); |
| + CHECK(io_message_loop_proxy_.get()); |
| + io_message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &Core::AddUploadDataChunkInThread, content)); |
| +} |
| + |
| +void URLFetcher::Core::MarkEndOfChunks() { |
|
vandebo (ex-Chrome)
2011/01/14 05:53:44
Seems you don't need both of these in the ::core c
Satish
2011/01/14 18:09:29
Done.
|
| + DCHECK(delegate_loop_proxy_); |
| + CHECK(io_message_loop_proxy_.get()); |
| + std::string empty; |
| + io_message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &Core::AddUploadDataChunkInThread, empty)); |
| +} |
| + |
| void URLFetcher::Core::OnReadCompleted(net::URLRequest* request, |
| int bytes_read) { |
| DCHECK(request == request_); |
| @@ -334,6 +372,8 @@ void URLFetcher::Core::StartURLRequest() { |
| if (!g_interception_enabled) { |
| flags = flags | net::LOAD_DISABLE_INTERCEPT; |
| } |
| + if (is_chunked_upload_) |
| + request_->set_chunked_upload(); |
| request_->set_load_flags(flags); |
| request_->set_context(request_context_getter_->GetURLRequestContext()); |
| @@ -342,14 +382,16 @@ void URLFetcher::Core::StartURLRequest() { |
| break; |
| case POST: |
| - DCHECK(!upload_content_.empty()); |
| + DCHECK(!upload_content_.empty() || is_chunked_upload_); |
| DCHECK(!upload_content_type_.empty()); |
| request_->set_method("POST"); |
| extra_request_headers_.SetHeader(net::HttpRequestHeaders::kContentType, |
| upload_content_type_); |
| - request_->AppendBytesToUpload(upload_content_.data(), |
| - static_cast<int>(upload_content_.size())); |
| + if (!upload_content_.empty()) { |
| + request_->AppendBytesToUpload(upload_content_.data(), |
| + static_cast<int>(upload_content_.size())); |
| + } |
| break; |
| case HEAD: |
| @@ -475,6 +517,20 @@ void URLFetcher::set_upload_data(const std::string& upload_content_type, |
| const std::string& upload_content) { |
| core_->upload_content_type_ = upload_content_type; |
| core_->upload_content_ = upload_content; |
| + core_->is_chunked_upload_ = false; |
|
vandebo (ex-Chrome)
2011/01/14 05:53:44
Seems that this should just be a DCHECK?
Satish
2011/01/14 18:09:29
Done.
|
| +} |
| + |
| +void URLFetcher::set_chunked_upload(const std::string& content_type) { |
| + core_->upload_content_type_ = content_type; |
| + core_->is_chunked_upload_ = true; |
| +} |
| + |
| +void URLFetcher::AppendChunkToUpload(const std::string& data) { |
| + core_->AppendChunkToUpload(data); |
| +} |
| + |
| +void URLFetcher::MarkEndOfChunks() { |
| + core_->MarkEndOfChunks(); |
| } |
| const std::string& URLFetcher::upload_data() const { |