| 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 | 8 |
| 9 #include "android_webview/browser/input_stream.h" | 9 #include "android_webview/browser/input_stream.h" |
| 10 #include "android_webview/browser/net/input_stream_reader.h" | 10 #include "android_webview/browser/net/input_stream_reader.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 SetStatus(net::URLRequestStatus()); | 174 SetStatus(net::URLRequestStatus()); |
| 175 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText); | 175 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText); |
| 176 } | 176 } |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 scoped_ptr<InputStreamReader> input_stream_reader( | 180 scoped_ptr<InputStreamReader> input_stream_reader( |
| 181 CreateStreamReader(input_stream.get())); | 181 CreateStreamReader(input_stream.get())); |
| 182 DCHECK(input_stream_reader); | 182 DCHECK(input_stream_reader); |
| 183 | 183 |
| 184 DCHECK(!input_stream_reader_wrapper_); | 184 DCHECK(!input_stream_reader_wrapper_.get()); |
| 185 input_stream_reader_wrapper_ = new InputStreamReaderWrapper( | 185 input_stream_reader_wrapper_ = new InputStreamReaderWrapper( |
| 186 input_stream.Pass(), input_stream_reader.Pass()); | 186 input_stream.Pass(), input_stream_reader.Pass()); |
| 187 | 187 |
| 188 PostTaskAndReplyWithResult( | 188 PostTaskAndReplyWithResult( |
| 189 GetWorkerThreadRunner(), | 189 GetWorkerThreadRunner(), |
| 190 FROM_HERE, | 190 FROM_HERE, |
| 191 base::Bind(&InputStreamReaderWrapper::Seek, | 191 base::Bind(&InputStreamReaderWrapper::Seek, |
| 192 input_stream_reader_wrapper_, | 192 input_stream_reader_wrapper_, |
| 193 byte_range_), | 193 byte_range_), |
| 194 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted, | 194 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 229 } |
| 230 | 230 |
| 231 base::TaskRunner* AndroidStreamReaderURLRequestJob::GetWorkerThreadRunner() { | 231 base::TaskRunner* AndroidStreamReaderURLRequestJob::GetWorkerThreadRunner() { |
| 232 return static_cast<base::TaskRunner*>(BrowserThread::GetBlockingPool()); | 232 return static_cast<base::TaskRunner*>(BrowserThread::GetBlockingPool()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool AndroidStreamReaderURLRequestJob::ReadRawData(net::IOBuffer* dest, | 235 bool AndroidStreamReaderURLRequestJob::ReadRawData(net::IOBuffer* dest, |
| 236 int dest_size, | 236 int dest_size, |
| 237 int* bytes_read) { | 237 int* bytes_read) { |
| 238 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
| 239 if (!input_stream_reader_wrapper_) { | 239 if (!input_stream_reader_wrapper_.get()) { |
| 240 // This will happen if opening the InputStream fails in which case the | 240 // This will happen if opening the InputStream fails in which case the |
| 241 // error is communicated by setting the HTTP response status header rather | 241 // error is communicated by setting the HTTP response status header rather |
| 242 // than failing the request during the header fetch phase. | 242 // than failing the request during the header fetch phase. |
| 243 *bytes_read = 0; | 243 *bytes_read = 0; |
| 244 return true; | 244 return true; |
| 245 } | 245 } |
| 246 | 246 |
| 247 PostTaskAndReplyWithResult( | 247 PostTaskAndReplyWithResult( |
| 248 GetWorkerThreadRunner(), | 248 GetWorkerThreadRunner(), |
| 249 FROM_HERE, | 249 FROM_HERE, |
| 250 base::Bind(&InputStreamReaderWrapper::ReadRawData, | 250 base::Bind(&InputStreamReaderWrapper::ReadRawData, |
| 251 input_stream_reader_wrapper_, | 251 input_stream_reader_wrapper_, |
| 252 make_scoped_refptr(dest), | 252 make_scoped_refptr(dest), |
| 253 dest_size), | 253 dest_size), |
| 254 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderReadCompleted, | 254 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderReadCompleted, |
| 255 weak_factory_.GetWeakPtr())); | 255 weak_factory_.GetWeakPtr())); |
| 256 | 256 |
| 257 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, | 257 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, |
| 258 net::ERR_IO_PENDING)); | 258 net::ERR_IO_PENDING)); |
| 259 return false; | 259 return false; |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool AndroidStreamReaderURLRequestJob::GetMimeType( | 262 bool AndroidStreamReaderURLRequestJob::GetMimeType( |
| 263 std::string* mime_type) const { | 263 std::string* mime_type) const { |
| 264 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 265 JNIEnv* env = AttachCurrentThread(); | 265 JNIEnv* env = AttachCurrentThread(); |
| 266 DCHECK(env); | 266 DCHECK(env); |
| 267 | 267 |
| 268 if (!input_stream_reader_wrapper_) | 268 if (!input_stream_reader_wrapper_.get()) |
| 269 return false; | 269 return false; |
| 270 | 270 |
| 271 // Since it's possible for this call to alter the InputStream a | 271 // Since it's possible for this call to alter the InputStream a |
| 272 // Seek or ReadRawData operation running in the background is not permitted. | 272 // Seek or ReadRawData operation running in the background is not permitted. |
| 273 DCHECK(!request_->status().is_io_pending()); | 273 DCHECK(!request_->status().is_io_pending()); |
| 274 | 274 |
| 275 return delegate_->GetMimeType( | 275 return delegate_->GetMimeType( |
| 276 env, request(), input_stream_reader_wrapper_->input_stream(), mime_type); | 276 env, request(), input_stream_reader_wrapper_->input_stream(), mime_type); |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) { | 279 bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) { |
| 280 DCHECK(thread_checker_.CalledOnValidThread()); | 280 DCHECK(thread_checker_.CalledOnValidThread()); |
| 281 JNIEnv* env = AttachCurrentThread(); | 281 JNIEnv* env = AttachCurrentThread(); |
| 282 DCHECK(env); | 282 DCHECK(env); |
| 283 | 283 |
| 284 if (!input_stream_reader_wrapper_) | 284 if (!input_stream_reader_wrapper_.get()) |
| 285 return false; | 285 return false; |
| 286 | 286 |
| 287 // Since it's possible for this call to alter the InputStream a | 287 // Since it's possible for this call to alter the InputStream a |
| 288 // Seek or ReadRawData operation running in the background is not permitted. | 288 // Seek or ReadRawData operation running in the background is not permitted. |
| 289 DCHECK(!request_->status().is_io_pending()); | 289 DCHECK(!request_->status().is_io_pending()); |
| 290 | 290 |
| 291 return delegate_->GetCharset( | 291 return delegate_->GetCharset( |
| 292 env, request(), input_stream_reader_wrapper_->input_stream(), charset); | 292 env, request(), input_stream_reader_wrapper_->input_stream(), charset); |
| 293 } | 293 } |
| 294 | 294 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } else { | 353 } else { |
| 354 // We don't support multiple range requests in one single URL request, | 354 // We don't support multiple range requests in one single URL request, |
| 355 // because we need to do multipart encoding here. | 355 // because we need to do multipart encoding here. |
| 356 NotifyDone(net::URLRequestStatus( | 356 NotifyDone(net::URLRequestStatus( |
| 357 net::URLRequestStatus::FAILED, | 357 net::URLRequestStatus::FAILED, |
| 358 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 358 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 } | 362 } |
| OLD | NEW |