| 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_INPUT_STREAM_READER_H_ | 5 #ifndef ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ |
| 6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ | 6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 class HttpByteRange; | 11 class HttpByteRange; |
| 12 class IOBuffer; | 12 class IOBuffer; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace android_webview { | 15 namespace android_webview { |
| 16 | 16 |
| 17 class InputStream; | 17 class InputStream; |
| 18 | 18 |
| 19 // Class responsible for reading the InputStream. | 19 // Class responsible for reading the InputStream. |
| 20 class InputStreamReader | 20 class InputStreamReader { |
| 21 : public base::RefCountedThreadSafe<InputStreamReader> { | |
| 22 public: | 21 public: |
| 23 // The constructor is called on the IO thread, not on the worker thread. | 22 // The constructor is called on the IO thread, not on the worker thread. |
| 24 InputStreamReader(android_webview::InputStream* stream); | 23 InputStreamReader(android_webview::InputStream* stream); |
| 24 virtual ~InputStreamReader(); |
| 25 | 25 |
| 26 // Perform a seek operation on the InputStream associated with this job. | 26 // Perform a seek operation on the InputStream associated with this job. |
| 27 // On successful completion the InputStream would have skipped reading the | 27 // On successful completion the InputStream would have skipped reading the |
| 28 // number of bytes equal to the lower range of |byte_range|. | 28 // number of bytes equal to the lower range of |byte_range|. |
| 29 // This method should be called on the |g_worker_thread| thread. | 29 // This method should be called on the |g_worker_thread| thread. |
| 30 // | 30 // |
| 31 // |byte_range| is the range of bytes to be read from |stream| | 31 // |byte_range| is the range of bytes to be read from |stream| |
| 32 // | 32 // |
| 33 // A negative return value will indicate an error code, a positive value | 33 // A negative return value will indicate an error code, a positive value |
| 34 // will indicate the expected size of the content. | 34 // will indicate the expected size of the content. |
| 35 virtual int Seek(const net::HttpByteRange& byte_range); | 35 virtual int Seek(const net::HttpByteRange& byte_range); |
| 36 | 36 |
| 37 // Read data from |stream_|. This method should be called on the | 37 // Read data from |stream_|. This method should be called on the |
| 38 // |g_worker_thread| thread. | 38 // |g_worker_thread| thread. |
| 39 // | 39 // |
| 40 // A negative return value will indicate an error code, a positive value | 40 // A negative return value will indicate an error code, a positive value |
| 41 // will indicate the expected size of the content. | 41 // will indicate the expected size of the content. |
| 42 virtual int ReadRawData(net::IOBuffer* buffer, int buffer_size); | 42 virtual int ReadRawData(net::IOBuffer* buffer, int buffer_size); |
| 43 | 43 |
| 44 protected: | |
| 45 virtual ~InputStreamReader(); | |
| 46 | |
| 47 private: | 44 private: |
| 48 friend class base::RefCountedThreadSafe<InputStreamReader>; | |
| 49 | |
| 50 // Verify the requested range against the stream size. | 45 // Verify the requested range against the stream size. |
| 51 // net::OK is returned on success, the error code otherwise. | 46 // net::OK is returned on success, the error code otherwise. |
| 52 int VerifyRequestedRange(net::HttpByteRange* byte_range, | 47 int VerifyRequestedRange(net::HttpByteRange* byte_range, |
| 53 int* content_size); | 48 int* content_size); |
| 54 | 49 |
| 55 // Skip to the first byte of the requested read range. | 50 // Skip to the first byte of the requested read range. |
| 56 // net::OK is returned on success, the error code otherwise. | 51 // net::OK is returned on success, the error code otherwise. |
| 57 int SkipToRequestedRange(const net::HttpByteRange& byte_range); | 52 int SkipToRequestedRange(const net::HttpByteRange& byte_range); |
| 58 | 53 |
| 59 android_webview::InputStream* stream_; | 54 android_webview::InputStream* stream_; |
| 60 | 55 |
| 61 DISALLOW_COPY_AND_ASSIGN(InputStreamReader); | 56 DISALLOW_COPY_AND_ASSIGN(InputStreamReader); |
| 62 }; | 57 }; |
| 63 | 58 |
| 64 } // namespace android_webview | 59 } // namespace android_webview |
| 65 | 60 |
| 66 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ | 61 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ |
| OLD | NEW |