OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ | |
6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ | |
7 | |
8 #include "base/android/jni_android.h" | |
9 #include "net/base/completion_callback.h" | |
10 | |
11 namespace net { | |
12 class HttpByteRange; | |
13 class IOBuffer; | |
14 } | |
15 | |
16 namespace android_webview { | |
17 | |
18 class InputStream; | |
19 | |
20 // Class responsible for reading the InputStream. | |
21 class InputStreamReader { | |
benm (inactive)
2012/11/15 17:39:01
As joth noted looks like we could abstract the pub
| |
22 public: | |
23 // The constructor is called on the IO thread, not on the WorkerThread. | |
24 InputStreamReader(android_webview::InputStream* stream); | |
25 | |
26 virtual ~InputStreamReader(); | |
27 | |
28 // Perform a seek operation on the InputStream associated with this job. | |
29 // On successful completion the InputStream would have skipped reading the | |
30 // number of bytes equal to the lower range of |byte_range|. | |
31 // This method should be called on the |g_worker_thread| thread. | |
32 // | |
33 // |byte_range| is the range of bytes to be read from |stream| | |
34 // |on_seek_complete| will be called on the IO thread after the operation | |
35 // completes. A negative number will indicate an error | |
36 // code, a positive number will indicate the expected size | |
37 // of the content. | |
38 virtual void Seek(net::HttpByteRange byte_range, | |
39 net::CompletionCallback on_seek_completion); | |
40 | |
41 // Read data from |stream_|. This method should be called on the | |
42 // |g_worker_thread| thread. | |
43 // | |
44 // |on_completion| will be called on the IO thread after the operation | |
45 // completes. | |
46 virtual void ReadRawData(net::IOBuffer* buffer, | |
47 int buffer_size, | |
48 net::CompletionCallback on_read_completion); | |
49 | |
50 protected: | |
51 // Posts callbacks. Default implementation will post to the IO thread. | |
52 // Overriding this method is useful for testing. | |
53 virtual void PostCompletionCallback(const net::CompletionCallback& callback, | |
54 int result); | |
55 | |
56 private: | |
57 // Verify the requested range against the stream size. | |
58 // net::OK is returned on success, the error code otherwise. | |
59 int VerifyRequestedRange(JNIEnv* env, | |
60 net::HttpByteRange* byte_range, | |
61 int* content_size); | |
62 | |
63 // Skip to the first byte of the requested read range. | |
64 // net::OK is returned on success, the error code otherwise. | |
65 int SkipToRequestedRange(JNIEnv* env, const net::HttpByteRange& byte_range); | |
66 | |
67 android_webview::InputStream* stream_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(InputStreamReader); | |
70 }; | |
71 | |
72 } // namespace android_webview | |
73 | |
74 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_ | |
OLD | NEW |