Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2095)

Unified Diff: android_webview/native/input_stream.h

Issue 11363123: [android_webview] Don't block the IO thread when reading from an InputStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/native/input_stream.h
diff --git a/android_webview/native/input_stream.h b/android_webview/native/input_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..b211d5c3c6adb8f74089757a96c154cbc1aa30fd
--- /dev/null
+++ b/android_webview/native/input_stream.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
+#define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
+
+#include "base/android/scoped_java_ref.h"
+
+namespace net {
+class IOBuffer;
+}
+
+namespace android_webview {
+
+class InputStream {
+ public:
+ // Maximum size of |buffer_|.
+ static const int kBufferSize;
benm (inactive) 2012/11/15 17:39:01 could this be a local const in input_stream.cc?
+
+ // |stream| should be an instance of the InputStream Java class.
+ InputStream(const base::android::JavaRef<jobject>& stream);
+ virtual ~InputStream();
+
+ // Sets |bytes_available| to the number of bytes that can be read (or skipped
+ // over) from this input stream without blocking by the next caller of a
+ // method for this input stream.
+ // Returns true if completed successfully or false if an exception was
+ // thrown.
+ virtual bool BytesAvailable(JNIEnv* env, int* bytes_available) const;
+
+ // Skips over and discards |n| bytes of data from this input stream. Sets
+ // |bytes_skipped| to the number of of bytes skipped.
+ // Returns true if completed successfully or false if an exception was
+ // thrown.
+ virtual bool Skip(JNIEnv* env, int64_t n, int64_t* bytes_skipped);
+
+ // Reads |length| bytes into |dest|. Sets |bytes_read| to the total number of
+ // bytes read into |dest| or -1 if there is no more data because the end of
+ // the stream was reached.
+ // |dest| must be at least |length| in size.
+ // Returns true if completed successfully or false if an exception was
+ // thrown.
+ virtual bool Read(JNIEnv* env,
+ net::IOBuffer* dest,
+ int length,
+ int* bytes_read);
+
+ // Gets the underlying Java ref
+ const base::android::JavaRef<jobject>& jref() const { return jobject_; }
+ // Gets the underlying Java object. Guaranteed non-NULL.
+ const jobject jobj() const { return jobject_.obj(); }
+
+ protected:
+ // Parameterless constructor exposed for testing.
+ InputStream();
+
+ private:
+ base::android::ScopedJavaGlobalRef<jobject> jobject_;
+ base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(InputStream);
+};
+
+bool RegisterInputStream(JNIEnv* env);
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698