Chromium Code Reviews| 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..cb777760b6d3dbc18ab2ead078bc1bc789bc5e0b 100644 |
| --- a/net/url_request/url_fetcher_core.cc |
| +++ b/net/url_request/url_fetcher_core.cc |
| @@ -138,9 +138,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(CheckIfHasNoUploadData()); |
| DCHECK(upload_content_type_.empty()); |
| // Empty |upload_content_type| is allowed iff the |upload_content| is empty. |
| @@ -158,9 +156,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(CheckIfHasNoUploadData()); |
| DCHECK_EQ(upload_range_offset_, 0ULL); |
| DCHECK_EQ(upload_range_length_, 0ULL); |
| DCHECK(upload_content_type_.empty()); |
| @@ -174,10 +170,21 @@ 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(CheckIfHasNoUploadData()); |
| + DCHECK(upload_content_type_.empty()); |
| + |
| + upload_content_type_ = upload_content_type; |
| + upload_stream_factory_ = factory; |
| + upload_content_set_ = true; |
|
mmenke
2015/01/16 16:47:18
Why is this still needed?
hirono
2015/01/19 04:59:35
Because the class allows to set the empty upload_c
|
| +} |
| + |
| void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { |
| DCHECK(is_chunked_upload_ || |
| - (upload_content_type_.empty() && |
| - upload_content_.empty())); |
| + CheckIfHasNoUploadData() && upload_content_type_.empty()); |
|
mmenke
2015/01/16 16:47:18
Add parens before Check (Mixing || and && without
hirono
2015/01/19 04:59:35
Done.
|
| // Empty |content_type| is not allowed here, because it is impossible |
| // to ensure non-empty upload content as it is not yet supplied. |
| @@ -605,6 +612,10 @@ 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()); |
| } |
| current_upload_bytes_ = -1; |
| @@ -957,4 +968,9 @@ void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( |
| delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); |
| } |
| +bool URLFetcherCore::CheckIfHasNoUploadData() const { |
| + return !upload_content_set_ && upload_content_.empty() && |
| + upload_file_path_.empty() && upload_stream_factory_.is_null(); |
| +} |
| + |
| } // namespace net |