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 "base/android/scoped_java_ref.h" | |
9 | |
10 namespace net { | |
11 class IOBuffer; | |
12 } | |
13 | |
14 namespace android_webview { | |
15 | |
16 class InputStream { | |
17 public: | |
18 // Maximum size of |buffer_|. | |
19 static const int kBufferSize; | |
benm (inactive)
2012/11/15 17:39:01
could this be a local const in input_stream.cc?
| |
20 | |
21 // |stream| should be an instance of the InputStream Java class. | |
22 InputStream(const base::android::JavaRef<jobject>& stream); | |
23 virtual ~InputStream(); | |
24 | |
25 // Sets |bytes_available| to the number of bytes that can be read (or skipped | |
26 // over) from this input stream without blocking by the next caller of a | |
27 // method for this input stream. | |
28 // Returns true if completed successfully or false if an exception was | |
29 // thrown. | |
30 virtual bool BytesAvailable(JNIEnv* env, int* bytes_available) const; | |
31 | |
32 // Skips over and discards |n| bytes of data from this input stream. Sets | |
33 // |bytes_skipped| to the number of of bytes skipped. | |
34 // Returns true if completed successfully or false if an exception was | |
35 // thrown. | |
36 virtual bool Skip(JNIEnv* env, int64_t n, int64_t* bytes_skipped); | |
37 | |
38 // Reads |length| bytes into |dest|. Sets |bytes_read| to the total number of | |
39 // bytes read into |dest| or -1 if there is no more data because the end of | |
40 // the stream was reached. | |
41 // |dest| must be at least |length| in size. | |
42 // Returns true if completed successfully or false if an exception was | |
43 // thrown. | |
44 virtual bool Read(JNIEnv* env, | |
45 net::IOBuffer* dest, | |
46 int length, | |
47 int* bytes_read); | |
48 | |
49 // Gets the underlying Java ref | |
50 const base::android::JavaRef<jobject>& jref() const { return jobject_; } | |
51 // Gets the underlying Java object. Guaranteed non-NULL. | |
52 const jobject jobj() const { return jobject_.obj(); } | |
53 | |
54 protected: | |
55 // Parameterless constructor exposed for testing. | |
56 InputStream(); | |
57 | |
58 private: | |
59 base::android::ScopedJavaGlobalRef<jobject> jobject_; | |
60 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(InputStream); | |
63 }; | |
64 | |
65 bool RegisterInputStream(JNIEnv* env); | |
66 | |
67 } // namespace android_webview | |
68 | |
69 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ | |
OLD | NEW |