Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_fetcher_core.h" | 5 #include "net/url_request/url_fetcher_core.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } else { | 131 } else { |
| 132 network_task_runner_->PostTask( | 132 network_task_runner_->PostTask( |
| 133 FROM_HERE, | 133 FROM_HERE, |
| 134 base::Bind(&URLFetcherCore::CancelURLRequest, this, ERR_ABORTED)); | 134 base::Bind(&URLFetcherCore::CancelURLRequest, this, ERR_ABORTED)); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, | 138 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, |
| 139 const std::string& upload_content) { | 139 const std::string& upload_content) { |
| 140 DCHECK(!is_chunked_upload_); | 140 DCHECK(!is_chunked_upload_); |
| 141 DCHECK(!upload_content_set_); | 141 DCHECK(CheckIfHasNoUploadData()); |
| 142 DCHECK(upload_content_.empty()); | |
| 143 DCHECK(upload_file_path_.empty()); | |
| 144 DCHECK(upload_content_type_.empty()); | 142 DCHECK(upload_content_type_.empty()); |
| 145 | 143 |
| 146 // Empty |upload_content_type| is allowed iff the |upload_content| is empty. | 144 // Empty |upload_content_type| is allowed iff the |upload_content| is empty. |
| 147 DCHECK(upload_content.empty() || !upload_content_type.empty()); | 145 DCHECK(upload_content.empty() || !upload_content_type.empty()); |
| 148 | 146 |
| 149 upload_content_type_ = upload_content_type; | 147 upload_content_type_ = upload_content_type; |
| 150 upload_content_ = upload_content; | 148 upload_content_ = upload_content; |
| 151 upload_content_set_ = true; | 149 upload_content_set_ = true; |
| 152 } | 150 } |
| 153 | 151 |
| 154 void URLFetcherCore::SetUploadFilePath( | 152 void URLFetcherCore::SetUploadFilePath( |
| 155 const std::string& upload_content_type, | 153 const std::string& upload_content_type, |
| 156 const base::FilePath& file_path, | 154 const base::FilePath& file_path, |
| 157 uint64 range_offset, | 155 uint64 range_offset, |
| 158 uint64 range_length, | 156 uint64 range_length, |
| 159 scoped_refptr<base::TaskRunner> file_task_runner) { | 157 scoped_refptr<base::TaskRunner> file_task_runner) { |
| 160 DCHECK(!is_chunked_upload_); | 158 DCHECK(!is_chunked_upload_); |
| 161 DCHECK(!upload_content_set_); | 159 DCHECK(CheckIfHasNoUploadData()); |
| 162 DCHECK(upload_content_.empty()); | |
| 163 DCHECK(upload_file_path_.empty()); | |
| 164 DCHECK_EQ(upload_range_offset_, 0ULL); | 160 DCHECK_EQ(upload_range_offset_, 0ULL); |
| 165 DCHECK_EQ(upload_range_length_, 0ULL); | 161 DCHECK_EQ(upload_range_length_, 0ULL); |
| 166 DCHECK(upload_content_type_.empty()); | 162 DCHECK(upload_content_type_.empty()); |
| 167 DCHECK(!upload_content_type.empty()); | 163 DCHECK(!upload_content_type.empty()); |
| 168 | 164 |
| 169 upload_content_type_ = upload_content_type; | 165 upload_content_type_ = upload_content_type; |
| 170 upload_file_path_ = file_path; | 166 upload_file_path_ = file_path; |
| 171 upload_range_offset_ = range_offset; | 167 upload_range_offset_ = range_offset; |
| 172 upload_range_length_ = range_length; | 168 upload_range_length_ = range_length; |
| 173 upload_file_task_runner_ = file_task_runner; | 169 upload_file_task_runner_ = file_task_runner; |
| 174 upload_content_set_ = true; | 170 upload_content_set_ = true; |
| 175 } | 171 } |
| 176 | 172 |
| 173 void URLFetcherCore::SetUploadStreamFactory( | |
| 174 const std::string& upload_content_type, | |
| 175 const URLFetcher::CreateUploadStreamCallback& factory) { | |
| 176 DCHECK(!is_chunked_upload_); | |
| 177 DCHECK(CheckIfHasNoUploadData()); | |
| 178 DCHECK(upload_content_type_.empty()); | |
| 179 | |
| 180 upload_content_type_ = upload_content_type; | |
| 181 upload_stream_factory_ = factory; | |
| 182 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
| |
| 183 } | |
| 184 | |
| 177 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { | 185 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { |
| 178 DCHECK(is_chunked_upload_ || | 186 DCHECK(is_chunked_upload_ || |
| 179 (upload_content_type_.empty() && | 187 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.
| |
| 180 upload_content_.empty())); | |
| 181 | 188 |
| 182 // Empty |content_type| is not allowed here, because it is impossible | 189 // Empty |content_type| is not allowed here, because it is impossible |
| 183 // to ensure non-empty upload content as it is not yet supplied. | 190 // to ensure non-empty upload content as it is not yet supplied. |
| 184 DCHECK(!content_type.empty()); | 191 DCHECK(!content_type.empty()); |
| 185 | 192 |
| 186 upload_content_type_ = content_type; | 193 upload_content_type_ = content_type; |
| 187 upload_content_.clear(); | 194 upload_content_.clear(); |
| 188 is_chunked_upload_ = true; | 195 is_chunked_upload_ = true; |
| 189 } | 196 } |
| 190 | 197 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 605 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 599 } else if (!upload_file_path_.empty()) { | 606 } else if (!upload_file_path_.empty()) { |
| 600 scoped_ptr<UploadElementReader> reader( | 607 scoped_ptr<UploadElementReader> reader( |
| 601 new UploadFileElementReader(upload_file_task_runner_.get(), | 608 new UploadFileElementReader(upload_file_task_runner_.get(), |
| 602 upload_file_path_, | 609 upload_file_path_, |
| 603 upload_range_offset_, | 610 upload_range_offset_, |
| 604 upload_range_length_, | 611 upload_range_length_, |
| 605 base::Time())); | 612 base::Time())); |
| 606 request_->set_upload( | 613 request_->set_upload( |
| 607 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 614 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 615 } else if (!upload_stream_factory_.is_null()) { | |
| 616 scoped_ptr<UploadDataStream> stream = upload_stream_factory_.Run(); | |
| 617 DCHECK(stream); | |
| 618 request_->set_upload(stream.Pass()); | |
| 608 } | 619 } |
| 609 | 620 |
| 610 current_upload_bytes_ = -1; | 621 current_upload_bytes_ = -1; |
| 611 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 622 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
| 612 // layer and avoid using timer here. | 623 // layer and avoid using timer here. |
| 613 upload_progress_checker_timer_.reset( | 624 upload_progress_checker_timer_.reset( |
| 614 new base::RepeatingTimer<URLFetcherCore>()); | 625 new base::RepeatingTimer<URLFetcherCore>()); |
| 615 upload_progress_checker_timer_->Start( | 626 upload_progress_checker_timer_->Start( |
| 616 FROM_HERE, | 627 FROM_HERE, |
| 617 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), | 628 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 this, current_response_bytes_, total_response_bytes_)); | 961 this, current_response_bytes_, total_response_bytes_)); |
| 951 } | 962 } |
| 952 | 963 |
| 953 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( | 964 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( |
| 954 int64 current, int64 total) { | 965 int64 current, int64 total) { |
| 955 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 966 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 956 if (delegate_) | 967 if (delegate_) |
| 957 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); | 968 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); |
| 958 } | 969 } |
| 959 | 970 |
| 971 bool URLFetcherCore::CheckIfHasNoUploadData() const { | |
| 972 return !upload_content_set_ && upload_content_.empty() && | |
| 973 upload_file_path_.empty() && upload_stream_factory_.is_null(); | |
| 974 } | |
| 975 | |
| 960 } // namespace net | 976 } // namespace net |
| OLD | NEW |