| 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 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 23 #include "net/base/mime_util.h" | 23 #include "net/base/mime_util.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_response_info.h" | 27 #include "net/http/http_response_info.h" |
| 28 #include "net/http/http_util.h" | 28 #include "net/http/http_util.h" |
| 29 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 30 #include "net/url_request/url_request_job_manager.h" | 30 #include "net/url_request/url_request_job_manager.h" |
| 31 | 31 |
| 32 using android_webview::InputStream; | |
| 33 using android_webview::InputStreamReader; | |
| 34 using base::android::AttachCurrentThread; | 32 using base::android::AttachCurrentThread; |
| 35 using base::PostTaskAndReplyWithResult; | 33 using base::PostTaskAndReplyWithResult; |
| 36 using content::BrowserThread; | 34 using content::BrowserThread; |
| 37 | 35 |
| 36 namespace android_webview { |
| 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const int kHTTPOk = 200; | 40 const int kHTTPOk = 200; |
| 41 const int kHTTPNotFound = 404; | 41 const int kHTTPNotFound = 404; |
| 42 | 42 |
| 43 const char kResponseHeaderViaShouldInterceptRequest[] = | 43 const char kResponseHeaderViaShouldInterceptRequest[] = |
| 44 "Client-Via: shouldInterceptRequest"; | 44 "Client-Via: shouldInterceptRequest"; |
| 45 const char kHTTPOkText[] = "OK"; | 45 const char kHTTPOkText[] = "OK"; |
| 46 const char kHTTPNotFoundText[] = "Not Found"; | 46 const char kHTTPNotFoundText[] = "Not Found"; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 // The requests posted to the worker thread might outlive the job. Thread-safe | 50 // The requests posted to the worker thread might outlive the job. Thread-safe |
| 51 // ref counting is used to ensure that the InputStream and InputStreamReader | 51 // ref counting is used to ensure that the InputStream and InputStreamReader |
| 52 // members of this class are still there when the closure is run on the worker | 52 // members of this class are still there when the closure is run on the worker |
| 53 // thread. | 53 // thread. |
| 54 class InputStreamReaderWrapper : | 54 class InputStreamReaderWrapper : |
| 55 public base::RefCountedThreadSafe<InputStreamReaderWrapper> { | 55 public base::RefCountedThreadSafe<InputStreamReaderWrapper> { |
| 56 public: | 56 public: |
| 57 InputStreamReaderWrapper( | 57 InputStreamReaderWrapper( |
| 58 scoped_ptr<InputStream> input_stream, | 58 scoped_ptr<InputStream> input_stream, |
| 59 scoped_ptr<InputStreamReader> input_stream_reader) | 59 scoped_ptr<InputStreamReader> input_stream_reader) |
| 60 : input_stream_(input_stream.Pass()), | 60 : input_stream_(input_stream.Pass()), |
| 61 input_stream_reader_(input_stream_reader.Pass()) { | 61 input_stream_reader_(input_stream_reader.Pass()) { |
| 62 DCHECK(input_stream_); | 62 DCHECK(input_stream_); |
| 63 DCHECK(input_stream_reader_); | 63 DCHECK(input_stream_reader_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 android_webview::InputStream* input_stream() { | 66 InputStream* input_stream() { |
| 67 return input_stream_.get(); | 67 return input_stream_.get(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 int Seek(const net::HttpByteRange& byte_range) { | 70 int Seek(const net::HttpByteRange& byte_range) { |
| 71 return input_stream_reader_->Seek(byte_range); | 71 return input_stream_reader_->Seek(byte_range); |
| 72 } | 72 } |
| 73 | 73 |
| 74 int ReadRawData(net::IOBuffer* buffer, int buffer_size) { | 74 int ReadRawData(net::IOBuffer* buffer, int buffer_size) { |
| 75 return input_stream_reader_->ReadRawData(buffer, buffer_size); | 75 return input_stream_reader_->ReadRawData(buffer, buffer_size); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 friend class base::RefCountedThreadSafe<InputStreamReaderWrapper>; | 79 friend class base::RefCountedThreadSafe<InputStreamReaderWrapper>; |
| 80 ~InputStreamReaderWrapper() {} | 80 ~InputStreamReaderWrapper() {} |
| 81 | 81 |
| 82 scoped_ptr<android_webview::InputStream> input_stream_; | 82 scoped_ptr<InputStream> input_stream_; |
| 83 scoped_ptr<android_webview::InputStreamReader> input_stream_reader_; | 83 scoped_ptr<InputStreamReader> input_stream_reader_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(InputStreamReaderWrapper); | 85 DISALLOW_COPY_AND_ASSIGN(InputStreamReaderWrapper); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( | 88 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( |
| 89 net::URLRequest* request, | 89 net::URLRequest* request, |
| 90 net::NetworkDelegate* network_delegate, | 90 net::NetworkDelegate* network_delegate, |
| 91 scoped_ptr<Delegate> delegate) | 91 scoped_ptr<Delegate> delegate) |
| 92 : URLRequestJob(request, network_delegate), | 92 : URLRequestJob(request, network_delegate), |
| 93 delegate_(delegate.Pass()), | 93 delegate_(delegate.Pass()), |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } else { | 358 } else { |
| 359 // We don't support multiple range requests in one single URL request, | 359 // We don't support multiple range requests in one single URL request, |
| 360 // because we need to do multipart encoding here. | 360 // because we need to do multipart encoding here. |
| 361 NotifyDone(net::URLRequestStatus( | 361 NotifyDone(net::URLRequestStatus( |
| 362 net::URLRequestStatus::FAILED, | 362 net::URLRequestStatus::FAILED, |
| 363 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 363 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 |
| 369 } // namespace android_webview |
| OLD | NEW |