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_H_ | |
6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "android_webview/browser/input_stream.h" | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/macros.h" | |
14 | |
15 namespace net { | |
16 class IOBuffer; | |
17 } | |
18 | |
19 namespace android_webview { | |
20 | |
21 class InputStreamImpl : public InputStream { | |
22 public: | |
23 // Maximum size of |buffer_|. | |
24 static const int kBufferSize; | |
25 | |
26 static const InputStreamImpl* FromInputStream( | |
27 const InputStream* input_stream); | |
28 | |
29 // |stream| should be an instance of the InputStream Java class. | |
30 // |stream| can't be null. | |
31 InputStreamImpl(const base::android::JavaRef<jobject>& stream); | |
32 ~InputStreamImpl() override; | |
33 | |
34 // Gets the underlying Java object. Guaranteed non-NULL. | |
35 const base::android::JavaRef<jobject>& jobj() const { return jobject_; } | |
36 | |
37 // InputStream implementation. | |
38 bool BytesAvailable(int* bytes_available) const override; | |
39 bool Skip(int64_t n, int64_t* bytes_skipped) override; | |
40 bool Read(net::IOBuffer* dest, int length, int* bytes_read) override; | |
41 | |
42 protected: | |
43 // Parameterless constructor exposed for testing. | |
44 InputStreamImpl(); | |
45 | |
46 private: | |
47 base::android::ScopedJavaGlobalRef<jobject> jobject_; | |
48 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(InputStreamImpl); | |
51 }; | |
52 | |
53 } // namespace android_webview | |
54 | |
55 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ | |
OLD | NEW |