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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 CancelURLRequest(ERR_ABORTED); | 130 CancelURLRequest(ERR_ABORTED); |
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 AssertHasNoUploadData(); |
140 DCHECK(!is_chunked_upload_); | 141 DCHECK(!is_chunked_upload_); |
141 DCHECK(!upload_content_set_); | |
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) { |
| 158 AssertHasNoUploadData(); |
160 DCHECK(!is_chunked_upload_); | 159 DCHECK(!is_chunked_upload_); |
161 DCHECK(!upload_content_set_); | |
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 AssertHasNoUploadData(); |
| 177 DCHECK(!is_chunked_upload_); |
| 178 DCHECK(upload_content_type_.empty()); |
| 179 |
| 180 upload_content_type_ = upload_content_type; |
| 181 upload_stream_factory_ = factory; |
| 182 upload_content_set_ = true; |
| 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 if (!is_chunked_upload_) { |
179 (upload_content_type_.empty() && | 187 AssertHasNoUploadData(); |
180 upload_content_.empty())); | 188 DCHECK(upload_content_type_.empty()); |
| 189 } |
181 | 190 |
182 // Empty |content_type| is not allowed here, because it is impossible | 191 // Empty |content_type| is not allowed here, because it is impossible |
183 // to ensure non-empty upload content as it is not yet supplied. | 192 // to ensure non-empty upload content as it is not yet supplied. |
184 DCHECK(!content_type.empty()); | 193 DCHECK(!content_type.empty()); |
185 | 194 |
186 upload_content_type_ = content_type; | 195 upload_content_type_ = content_type; |
187 upload_content_.clear(); | 196 upload_content_.clear(); |
188 is_chunked_upload_ = true; | 197 is_chunked_upload_ = true; |
189 } | 198 } |
190 | 199 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 607 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
599 } else if (!upload_file_path_.empty()) { | 608 } else if (!upload_file_path_.empty()) { |
600 scoped_ptr<UploadElementReader> reader( | 609 scoped_ptr<UploadElementReader> reader( |
601 new UploadFileElementReader(upload_file_task_runner_.get(), | 610 new UploadFileElementReader(upload_file_task_runner_.get(), |
602 upload_file_path_, | 611 upload_file_path_, |
603 upload_range_offset_, | 612 upload_range_offset_, |
604 upload_range_length_, | 613 upload_range_length_, |
605 base::Time())); | 614 base::Time())); |
606 request_->set_upload( | 615 request_->set_upload( |
607 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 616 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 617 } else if (!upload_stream_factory_.is_null()) { |
| 618 scoped_ptr<UploadDataStream> stream = upload_stream_factory_.Run(); |
| 619 DCHECK(stream); |
| 620 request_->set_upload(stream.Pass()); |
608 } | 621 } |
609 | 622 |
610 current_upload_bytes_ = -1; | 623 current_upload_bytes_ = -1; |
611 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 624 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
612 // layer and avoid using timer here. | 625 // layer and avoid using timer here. |
613 upload_progress_checker_timer_.reset( | 626 upload_progress_checker_timer_.reset( |
614 new base::RepeatingTimer<URLFetcherCore>()); | 627 new base::RepeatingTimer<URLFetcherCore>()); |
615 upload_progress_checker_timer_->Start( | 628 upload_progress_checker_timer_->Start( |
616 FROM_HERE, | 629 FROM_HERE, |
617 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), | 630 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_)); | 963 this, current_response_bytes_, total_response_bytes_)); |
951 } | 964 } |
952 | 965 |
953 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( | 966 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( |
954 int64 current, int64 total) { | 967 int64 current, int64 total) { |
955 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 968 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
956 if (delegate_) | 969 if (delegate_) |
957 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); | 970 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); |
958 } | 971 } |
959 | 972 |
| 973 void URLFetcherCore::AssertHasNoUploadData() const { |
| 974 DCHECK(!upload_content_set_); |
| 975 DCHECK(upload_content_.empty()); |
| 976 DCHECK(upload_file_path_.empty()); |
| 977 DCHECK(upload_stream_factory_.is_null()); |
| 978 } |
| 979 |
960 } // namespace net | 980 } // namespace net |
OLD | NEW |