Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Unified Diff: net/url_request/url_fetcher_core.cc

Issue 809663003: net: Add SetUploadStream method to URLFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix retrying. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_fetcher_core.cc
diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc
index 420e83147b48c09c24c5967edef462a7357cef0d..2037ac851ebb7f5d0fbc293a20cccbd2c1468f92 100644
--- a/net/url_request/url_fetcher_core.cc
+++ b/net/url_request/url_fetcher_core.cc
@@ -142,6 +142,7 @@ void URLFetcherCore::SetUploadData(const std::string& upload_content_type,
DCHECK(upload_content_.empty());
DCHECK(upload_file_path_.empty());
DCHECK(upload_content_type_.empty());
+ DCHECK(upload_stream_factory_.is_null());
// Empty |upload_content_type| is allowed iff the |upload_content| is empty.
DCHECK(upload_content.empty() || !upload_content_type.empty());
@@ -165,6 +166,7 @@ void URLFetcherCore::SetUploadFilePath(
DCHECK_EQ(upload_range_length_, 0ULL);
DCHECK(upload_content_type_.empty());
DCHECK(!upload_content_type.empty());
+ DCHECK(upload_stream_factory_.is_null());
upload_content_type_ = upload_content_type;
upload_file_path_ = file_path;
@@ -174,10 +176,25 @@ void URLFetcherCore::SetUploadFilePath(
upload_content_set_ = true;
}
+void URLFetcherCore::SetUploadStreamFactory(
+ const std::string& upload_content_type,
+ const URLFetcher::CreateUploadStreamCallback& factory) {
+ DCHECK(!is_chunked_upload_);
+ DCHECK(!upload_content_set_);
+ DCHECK(upload_content_.empty());
+ DCHECK(upload_file_path_.empty());
+ DCHECK(upload_content_type_.empty());
+ DCHECK(upload_stream_factory_.is_null());
mmenke 2015/01/09 17:42:25 Mind making a private method for all these shared
hirono 2015/01/15 08:14:27 I added IsUploadDataSet to check upload_content_,
+
+ upload_content_type_ = upload_content_type;
+ upload_stream_factory_ = factory;
+ upload_content_set_ = true;
+}
+
void URLFetcherCore::SetChunkedUpload(const std::string& content_type) {
DCHECK(is_chunked_upload_ ||
- (upload_content_type_.empty() &&
- upload_content_.empty()));
+ (upload_content_type_.empty() && upload_content_.empty() &&
+ upload_file_path_.empty() && upload_stream_factory_.is_null()));
// Empty |content_type| is not allowed here, because it is impossible
// to ensure non-empty upload content as it is not yet supplied.
@@ -587,10 +604,6 @@ void URLFetcherCore::StartURLRequest() {
request_->set_method(
request_type_ == URLFetcher::POST ? "POST" :
request_type_ == URLFetcher::PUT ? "PUT" : "PATCH");
- if (!upload_content_type_.empty()) {
- extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType,
- upload_content_type_);
- }
if (!upload_content_.empty()) {
scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader(
upload_content_.data(), upload_content_.size()));
@@ -605,8 +618,13 @@ void URLFetcherCore::StartURLRequest() {
base::Time()));
request_->set_upload(
ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
+ } else if (!upload_stream_factory_.is_null()) {
+ request_->set_upload(upload_stream_factory_.Run().Pass());
mmenke 2015/01/09 18:13:51 We should DCHECK that we don't get a null stream.
hirono 2015/01/15 08:14:27 Done.
+ }
+ if (!upload_content_type_.empty()) {
+ extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType,
+ upload_content_type_);
}
-
current_upload_bytes_ = -1;
// TODO(kinaba): http://crbug.com/118103. Implement upload callback in the
// layer and avoid using timer here.

Powered by Google App Engine
This is Rietveld 408576698