summaryrefslogtreecommitdiffstats
path: root/chrome/common/net/url_fetcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/net/url_fetcher.cc')
-rw-r--r--chrome/common/net/url_fetcher.cc71
1 files changed, 64 insertions, 7 deletions
diff --git a/chrome/common/net/url_fetcher.cc b/chrome/common/net/url_fetcher.cc
index 53112f3..150dbab 100644
--- a/chrome/common/net/url_fetcher.cc
+++ b/chrome/common/net/url_fetcher.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,7 +8,6 @@
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
-#include "base/lock.h"
#include "base/message_loop_proxy.h"
#include "base/scoped_ptr.h"
#include "base/stl_util-inl.h"
@@ -95,7 +94,7 @@ class URLFetcher::Core
void StartURLRequest();
void StartURLRequestWhenAppropriate();
void CancelURLRequest();
- void OnCompletedURLRequest(const URLRequestStatus& status);
+ void OnCompletedURLRequest(const net::URLRequestStatus& status);
void NotifyMalformedContent();
// Deletes the request, removes it from the registry, and removes the
@@ -106,6 +105,12 @@ class URLFetcher::Core
// |original_url_| and |url_|.
base::TimeTicks GetBackoffReleaseTime();
+ void CompleteAddingUploadDataChunk(const std::string& data);
+
+ // Adds a block of data to be uploaded in a POST body. This can only be called
+ // after Start().
+ 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
@@ -131,6 +136,8 @@ class URLFetcher::Core
std::string upload_content_; // HTTP POST payload
std::string upload_content_type_; // MIME type of POST payload
+ std::string referrer_; // HTTP Referer header value
+ 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.
@@ -230,6 +237,7 @@ URLFetcher::Core::Core(URLFetcher* fetcher,
load_flags_(net::LOAD_NORMAL),
response_code_(-1),
buffer_(new net::IOBuffer(kBufferSize)),
+ is_chunked_upload_(false),
num_retries_(0),
was_cancelled_(false) {
}
@@ -291,6 +299,26 @@ void URLFetcher::Core::OnResponseStarted(net::URLRequest* request) {
OnReadCompleted(request_.get(), bytes_read);
}
+void URLFetcher::Core::CompleteAddingUploadDataChunk(
+ const std::string& content) {
+ DCHECK(is_chunked_upload_);
+ DCHECK(request_.get());
+ if (content.length()) {
+ request_->AppendChunkToUpload(content.data(),
+ static_cast<int>(content.length()));
+ } 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::CompleteAddingUploadDataChunk, content));
+}
+
void URLFetcher::Core::OnReadCompleted(net::URLRequest* request,
int bytes_read) {
DCHECK(request == request_);
@@ -343,22 +371,27 @@ 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());
+ request_->set_referrer(referrer_);
switch (request_type_) {
case GET:
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_.length()));
+ }
break;
case HEAD:
@@ -417,7 +450,8 @@ void URLFetcher::Core::CancelURLRequest() {
was_cancelled_ = true;
}
-void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) {
+void URLFetcher::Core::OnCompletedURLRequest(
+ const net::URLRequestStatus& status) {
DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
// Checks the response from server.
@@ -481,14 +515,37 @@ 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(std::string());
+}
+
const std::string& URLFetcher::upload_data() const {
return core_->upload_content_;
}
+void URLFetcher::set_referrer(const std::string& referrer) {
+ core_->referrer_ = referrer;
+}
+
void URLFetcher::set_load_flags(int load_flags) {
core_->load_flags_ = load_flags;
}