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 "android_webview/browser/net/android_stream_reader_url_request_job.h" | 5 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "android_webview/browser/input_stream.h" | 10 #include "android_webview/browser/input_stream.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 DCHECK(thread_checker_.CalledOnValidThread()); | 167 DCHECK(thread_checker_.CalledOnValidThread()); |
168 DCHECK(returned_delegate); | 168 DCHECK(returned_delegate); |
169 delegate_ = std::move(returned_delegate); | 169 delegate_ = std::move(returned_delegate); |
170 | 170 |
171 if (!input_stream) { | 171 if (!input_stream) { |
172 bool restart_required = false; | 172 bool restart_required = false; |
173 delegate_->OnInputStreamOpenFailed(request(), &restart_required); | 173 delegate_->OnInputStreamOpenFailed(request(), &restart_required); |
174 if (restart_required) { | 174 if (restart_required) { |
175 NotifyRestartRequired(); | 175 NotifyRestartRequired(); |
176 } else { | 176 } else { |
177 // Clear the IO_PENDING status set in Start(). | |
178 SetStatus(net::URLRequestStatus()); | |
179 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText); | 177 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText); |
180 } | 178 } |
181 return; | 179 return; |
182 } | 180 } |
183 | 181 |
184 scoped_ptr<InputStreamReader> input_stream_reader( | 182 scoped_ptr<InputStreamReader> input_stream_reader( |
185 CreateStreamReader(input_stream.get())); | 183 CreateStreamReader(input_stream.get())); |
186 DCHECK(input_stream_reader); | 184 DCHECK(input_stream_reader); |
187 | 185 |
188 DCHECK(!input_stream_reader_wrapper_.get()); | 186 DCHECK(!input_stream_reader_wrapper_.get()); |
189 input_stream_reader_wrapper_ = new InputStreamReaderWrapper( | 187 input_stream_reader_wrapper_ = new InputStreamReaderWrapper( |
190 std::move(input_stream), std::move(input_stream_reader)); | 188 std::move(input_stream), std::move(input_stream_reader)); |
191 | 189 |
192 PostTaskAndReplyWithResult( | 190 PostTaskAndReplyWithResult( |
193 GetWorkerThreadRunner(), | 191 GetWorkerThreadRunner(), |
194 FROM_HERE, | 192 FROM_HERE, |
195 base::Bind(&InputStreamReaderWrapper::Seek, | 193 base::Bind(&InputStreamReaderWrapper::Seek, |
196 input_stream_reader_wrapper_, | 194 input_stream_reader_wrapper_, |
197 byte_range_), | 195 byte_range_), |
198 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted, | 196 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted, |
199 weak_factory_.GetWeakPtr())); | 197 weak_factory_.GetWeakPtr())); |
200 } | 198 } |
201 | 199 |
202 void AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted(int result) { | 200 void AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted(int result) { |
203 DCHECK(thread_checker_.CalledOnValidThread()); | 201 DCHECK(thread_checker_.CalledOnValidThread()); |
204 // Clear the IO_PENDING status set in Start(). | |
205 SetStatus(net::URLRequestStatus()); | |
206 if (result >= 0) { | 202 if (result >= 0) { |
207 set_expected_content_size(result); | 203 set_expected_content_size(result); |
208 HeadersComplete(kHTTPOk, kHTTPOkText); | 204 HeadersComplete(kHTTPOk, kHTTPOkText); |
209 } else { | 205 } else { |
210 NotifyStartError( | 206 NotifyStartError( |
211 net::URLRequestStatus(net::URLRequestStatus::FAILED, result)); | 207 net::URLRequestStatus(net::URLRequestStatus::FAILED, result)); |
212 } | 208 } |
213 } | 209 } |
214 | 210 |
215 void AndroidStreamReaderURLRequestJob::OnReaderReadCompleted(int result) { | 211 void AndroidStreamReaderURLRequestJob::OnReaderReadCompleted(int result) { |
(...skipping 29 matching lines...) Expand all Loading... | |
245 | 241 |
246 bool AndroidStreamReaderURLRequestJob::GetMimeType( | 242 bool AndroidStreamReaderURLRequestJob::GetMimeType( |
247 std::string* mime_type) const { | 243 std::string* mime_type) const { |
248 DCHECK(thread_checker_.CalledOnValidThread()); | 244 DCHECK(thread_checker_.CalledOnValidThread()); |
249 JNIEnv* env = AttachCurrentThread(); | 245 JNIEnv* env = AttachCurrentThread(); |
250 DCHECK(env); | 246 DCHECK(env); |
251 | 247 |
252 if (!input_stream_reader_wrapper_.get()) | 248 if (!input_stream_reader_wrapper_.get()) |
253 return false; | 249 return false; |
254 | 250 |
255 // Since it's possible for this call to alter the InputStream a | |
256 // Seek or ReadRawData operation running in the background is not permitted. | |
257 DCHECK(!request_->status().is_io_pending()); | |
mmenke
2016/01/07 15:54:55
This removal is needed because this used to partia
Randy Smith (Not in Mondays)
2016/01/11 02:27:48
Is it worth replacing the DCHECK with one based on
mmenke
2016/01/11 06:17:11
I've been trying to avoid learning this class, so
| |
258 | |
259 return delegate_->GetMimeType( | 251 return delegate_->GetMimeType( |
260 env, request(), input_stream_reader_wrapper_->input_stream(), mime_type); | 252 env, request(), input_stream_reader_wrapper_->input_stream(), mime_type); |
261 } | 253 } |
262 | 254 |
263 bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) { | 255 bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) { |
264 DCHECK(thread_checker_.CalledOnValidThread()); | 256 DCHECK(thread_checker_.CalledOnValidThread()); |
265 JNIEnv* env = AttachCurrentThread(); | 257 JNIEnv* env = AttachCurrentThread(); |
266 DCHECK(env); | 258 DCHECK(env); |
267 | 259 |
268 if (!input_stream_reader_wrapper_.get()) | 260 if (!input_stream_reader_wrapper_.get()) |
(...skipping 19 matching lines...) Expand all Loading... | |
288 } | 280 } |
289 } | 281 } |
290 | 282 |
291 void AndroidStreamReaderURLRequestJob::DoStart() { | 283 void AndroidStreamReaderURLRequestJob::DoStart() { |
292 DCHECK(thread_checker_.CalledOnValidThread()); | 284 DCHECK(thread_checker_.CalledOnValidThread()); |
293 if (range_parse_result_ != net::OK) { | 285 if (range_parse_result_ != net::OK) { |
294 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 286 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
295 range_parse_result_)); | 287 range_parse_result_)); |
296 return; | 288 return; |
297 } | 289 } |
298 // Start reading asynchronously so that all error reporting and data | |
299 // callbacks happen as they would for network requests. | |
300 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, | |
301 net::ERR_IO_PENDING)); | |
302 | 290 |
303 // This could be done in the InputStreamReader but would force more | 291 // This could be done in the InputStreamReader but would force more |
304 // complex synchronization in the delegate. | 292 // complex synchronization in the delegate. |
305 GetWorkerThreadRunner()->PostTask( | 293 GetWorkerThreadRunner()->PostTask( |
306 FROM_HERE, | 294 FROM_HERE, |
307 base::Bind( | 295 base::Bind( |
308 &OpenInputStreamOnWorkerThread, | 296 &OpenInputStreamOnWorkerThread, |
309 base::MessageLoop::current()->task_runner(), | 297 base::MessageLoop::current()->task_runner(), |
310 // This is intentional - the job could be deleted while the callback | 298 // This is intentional - the job could be deleted while the callback |
311 // is executing on the background thread. | 299 // is executing on the background thread. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 byte_range_ = ranges[0]; | 373 byte_range_ = ranges[0]; |
386 } else { | 374 } else { |
387 // We don't support multiple range requests in one single URL request, | 375 // We don't support multiple range requests in one single URL request, |
388 // because we need to do multipart encoding here. | 376 // because we need to do multipart encoding here. |
389 range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE; | 377 range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE; |
390 } | 378 } |
391 } | 379 } |
392 } | 380 } |
393 | 381 |
394 } // namespace android_webview | 382 } // namespace android_webview |
OLD | NEW |