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..611fc6bc407ab5abb95322124c426cadb5199c42 100644 |
--- a/chrome/common/net/url_fetcher.cc |
+++ b/chrome/common/net/url_fetcher.cc |
@@ -102,6 +102,12 @@ class URLFetcher::Core |
// |original_url_| and |url_|. |
base::TimeTicks GetBackoffReleaseTime(); |
+ void AddUploadDataChunkInThread(const std::string& data); |
wtc
2011/01/20 00:29:47
Nit: we seem to use the naming convention Complete
Satish
2011/01/20 18:02:36
Any examples? Most functions I see are of the form
wtc
2011/01/21 19:35:54
I found only four examples:
- src/chrome/browser/s
|
+ |
+ // Adds a block of data to be uploaded in a POST body. This can be called |
+ // before or after Start() is called. |
vandebo (ex-Chrome)
2011/01/18 21:51:17
The header says this can be called only after Star
|
+ void AppendChunkToUpload(const std::string& data); |
+ |
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 +133,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 |
// Used to determine how long to wait before making a request or doing a |
// retry. |
@@ -222,6 +229,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 +290,25 @@ 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()) { |
wtc
2011/01/20 00:29:47
Nit: use content.length() or content.size() consis
|
+ request_->AppendChunkToUpload(content.data(), |
+ static_cast<int>(content.size())); |
+ } else { |
+ request_->MarkEndOfChunks(); |
+ } |
+} |
+ |
+void URLFetcher::Core::AppendChunkToUpload(const std::string& content) { |
+ 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::OnReadCompleted(net::URLRequest* request, |
int bytes_read) { |
DCHECK(request == request_); |
@@ -334,6 +361,8 @@ void URLFetcher::Core::StartURLRequest() { |
if (!g_interception_enabled) { |
flags = flags | net::LOAD_DISABLE_INTERCEPT; |
} |
+ if (is_chunked_upload_) |
+ request_->EnableChunkedUpload(); |
request_->set_load_flags(flags); |
request_->set_context(request_context_getter_->GetURLRequestContext()); |
@@ -342,14 +371,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: |
@@ -473,10 +504,29 @@ base::TimeTicks URLFetcher::Core::GetBackoffReleaseTime() { |
void URLFetcher::set_upload_data(const std::string& upload_content_type, |
const std::string& upload_content) { |
+ DCHECK(!core_->is_chunked_upload_); |
core_->upload_content_type_ = upload_content_type; |
core_->upload_content_ = upload_content; |
} |
+void URLFetcher::set_chunked_upload(const std::string& content_type) { |
+ DCHECK(core_->is_chunked_upload_ || |
+ (core_->upload_content_type_.empty() && |
+ core_->upload_content_.empty())); |
+ core_->upload_content_type_ = content_type; |
+ core_->upload_content_.clear(); |
+ core_->is_chunked_upload_ = true; |
+} |
+ |
+void URLFetcher::AppendChunkToUpload(const std::string& data) { |
+ DCHECK(data.length()); |
+ core_->AppendChunkToUpload(data); |
+} |
+ |
+void URLFetcher::MarkEndOfChunks() { |
+ core_->AppendChunkToUpload(""); |
wtc
2011/01/20 00:29:47
Nit: "" => std::string()
|
+} |
+ |
const std::string& URLFetcher::upload_data() const { |
return core_->upload_content_; |
} |