| 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 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 5 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| 7 | 7 |
| 8 #include <string> |
| 9 |
| 8 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 14 #include "net/http/http_byte_range.h" | 16 #include "net/http/http_byte_range.h" |
| 15 #include "net/url_request/url_request_job.h" | 17 #include "net/url_request/url_request_job.h" |
| 16 | 18 |
| 17 namespace android_webview { | 19 namespace android_webview { |
| 18 class InputStream; | 20 class InputStream; |
| 19 class InputStreamReader; | 21 class InputStreamReader; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace base { | 24 namespace base { |
| 23 class TaskRunner; | 25 class TaskRunner; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 29 class HttpResponseInfo; |
| 27 class URLRequest; | 30 class URLRequest; |
| 28 } | 31 } |
| 29 | 32 |
| 30 class InputStreamReaderWrapper; | 33 class InputStreamReaderWrapper; |
| 31 | 34 |
| 32 // A request job that reads data from a Java InputStream. | 35 // A request job that reads data from a Java InputStream. |
| 33 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { | 36 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { |
| 34 public: | 37 public: |
| 35 /* | 38 /* |
| 36 * We use a delegate so that we can share code for this job in slightly | 39 * We use a delegate so that we can share code for this job in slightly |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // URLRequestJob: | 77 // URLRequestJob: |
| 75 virtual void Start() OVERRIDE; | 78 virtual void Start() OVERRIDE; |
| 76 virtual void Kill() OVERRIDE; | 79 virtual void Kill() OVERRIDE; |
| 77 virtual bool ReadRawData(net::IOBuffer* buf, | 80 virtual bool ReadRawData(net::IOBuffer* buf, |
| 78 int buf_size, | 81 int buf_size, |
| 79 int* bytes_read) OVERRIDE; | 82 int* bytes_read) OVERRIDE; |
| 80 virtual void SetExtraRequestHeaders( | 83 virtual void SetExtraRequestHeaders( |
| 81 const net::HttpRequestHeaders& headers) OVERRIDE; | 84 const net::HttpRequestHeaders& headers) OVERRIDE; |
| 82 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 85 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 83 virtual bool GetCharset(std::string* charset) OVERRIDE; | 86 virtual bool GetCharset(std::string* charset) OVERRIDE; |
| 87 virtual int GetResponseCode() const OVERRIDE; |
| 88 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
| 84 | 89 |
| 85 protected: | 90 protected: |
| 86 virtual ~AndroidStreamReaderURLRequestJob(); | 91 virtual ~AndroidStreamReaderURLRequestJob(); |
| 87 | 92 |
| 88 // Gets the TaskRunner for the worker thread. | 93 // Gets the TaskRunner for the worker thread. |
| 89 // Overridden in unittests. | 94 // Overridden in unittests. |
| 90 virtual base::TaskRunner* GetWorkerThreadRunner(); | 95 virtual base::TaskRunner* GetWorkerThreadRunner(); |
| 91 | 96 |
| 92 // Creates an InputStreamReader instance. | 97 // Creates an InputStreamReader instance. |
| 93 // Overridden in unittests to return a mock. | 98 // Overridden in unittests to return a mock. |
| 94 virtual scoped_ptr<android_webview::InputStreamReader> | 99 virtual scoped_ptr<android_webview::InputStreamReader> |
| 95 CreateStreamReader(android_webview::InputStream* stream); | 100 CreateStreamReader(android_webview::InputStream* stream); |
| 96 | 101 |
| 97 private: | 102 private: |
| 103 void HeadersComplete(int status_code, const std::string& status_text); |
| 104 |
| 98 void OnInputStreamOpened( | 105 void OnInputStreamOpened( |
| 99 scoped_ptr<Delegate> delegate, | 106 scoped_ptr<Delegate> delegate, |
| 100 scoped_ptr<android_webview::InputStream> input_stream); | 107 scoped_ptr<android_webview::InputStream> input_stream); |
| 101 void OnReaderSeekCompleted(int content_size); | 108 void OnReaderSeekCompleted(int content_size); |
| 102 void OnReaderReadCompleted(int bytes_read); | 109 void OnReaderReadCompleted(int bytes_read); |
| 103 | 110 |
| 104 net::HttpByteRange byte_range_; | 111 net::HttpByteRange byte_range_; |
| 112 scoped_ptr<net::HttpResponseInfo> response_info_; |
| 105 scoped_ptr<Delegate> delegate_; | 113 scoped_ptr<Delegate> delegate_; |
| 106 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_; | 114 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_; |
| 107 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; | 115 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; |
| 108 base::ThreadChecker thread_checker_; | 116 base::ThreadChecker thread_checker_; |
| 109 | 117 |
| 110 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); | 118 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); |
| 111 }; | 119 }; |
| 112 | 120 |
| 113 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 121 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| OLD | NEW |