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

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: Created 5 years, 11 months 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 c9f028f7be5752f3c58f8201d96c00d27212c0b4..2cabb3952ad54dd5668cf3479f068144c11eb6cd 100644
--- a/net/url_request/url_fetcher_core.cc
+++ b/net/url_request/url_fetcher_core.cc
@@ -83,7 +83,6 @@ URLFetcherCore::URLFetcherCore(URLFetcher* fetcher,
buffer_(new IOBuffer(kBufferSize)),
url_request_data_key_(NULL),
was_fetched_via_proxy_(false),
- upload_content_set_(false),
upload_range_offset_(0),
upload_range_length_(0),
referrer_policy_(
@@ -138,9 +137,7 @@ void URLFetcherCore::Stop() {
void URLFetcherCore::SetUploadData(const std::string& upload_content_type,
const std::string& upload_content) {
DCHECK(!is_chunked_upload_);
- DCHECK(!upload_content_set_);
- DCHECK(upload_content_.empty());
- DCHECK(upload_file_path_.empty());
+ DCHECK(!IsUploadDataSet());
DCHECK(upload_content_type_.empty());
// Empty |upload_content_type| is allowed iff the |upload_content| is empty.
@@ -148,7 +145,6 @@ void URLFetcherCore::SetUploadData(const std::string& upload_content_type,
upload_content_type_ = upload_content_type;
upload_content_ = upload_content;
- upload_content_set_ = true;
}
void URLFetcherCore::SetUploadFilePath(
@@ -158,9 +154,7 @@ void URLFetcherCore::SetUploadFilePath(
uint64 range_length,
scoped_refptr<base::TaskRunner> file_task_runner) {
DCHECK(!is_chunked_upload_);
- DCHECK(!upload_content_set_);
- DCHECK(upload_content_.empty());
- DCHECK(upload_file_path_.empty());
+ DCHECK(!IsUploadDataSet());
DCHECK_EQ(upload_range_offset_, 0ULL);
DCHECK_EQ(upload_range_length_, 0ULL);
DCHECK(upload_content_type_.empty());
@@ -171,13 +165,23 @@ void URLFetcherCore::SetUploadFilePath(
upload_range_offset_ = range_offset;
upload_range_length_ = range_length;
upload_file_task_runner_ = file_task_runner;
- upload_content_set_ = true;
+}
+
+void URLFetcherCore::SetUploadStreamFactory(
+ const std::string& upload_content_type,
+ const URLFetcher::CreateUploadStreamCallback& factory) {
+ DCHECK(!is_chunked_upload_);
+ DCHECK(!IsUploadDataSet());
+ DCHECK(upload_content_type_.empty());
+
+ upload_content_type_ = upload_content_type;
+ upload_stream_factory_ = factory;
}
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.
@@ -582,15 +586,11 @@ void URLFetcherCore::StartURLRequest() {
case URLFetcher::PUT:
case URLFetcher::PATCH:
// Upload content must be set.
- DCHECK(is_chunked_upload_ || upload_content_set_);
+ DCHECK(is_chunked_upload_ || IsUploadDataSet());
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 +605,15 @@ void URLFetcherCore::StartURLRequest() {
base::Time()));
request_->set_upload(
ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
+ } else if (!upload_stream_factory_.is_null()) {
+ scoped_ptr<UploadDataStream> stream = upload_stream_factory_.Run();
+ DCHECK(stream);
+ request_->set_upload(stream.Pass());
+ }
+ 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.
@@ -957,4 +964,9 @@ void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread(
delegate_->OnURLFetchDownloadProgress(fetcher_, current, total);
}
+bool URLFetcherCore::IsUploadDataSet() const {
+ return !(upload_content_.empty() && upload_file_path_.empty() &&
+ upload_stream_factory_.is_null());
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698