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

Unified Diff: android_webview/native/input_stream_impl.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: 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_impl.h
diff --git a/android_webview/native/input_stream_impl.h b/android_webview/native/input_stream_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..164aa5f4ce1d0ad298e3ac9b8ccb2200023e8084
--- /dev/null
+++ b/android_webview/native/input_stream_impl.h
@@ -0,0 +1,53 @@
+// 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 "android_webview/browser/input_stream.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/compiler_specific.h"
+
+namespace net {
+class IOBuffer;
+}
+
+namespace android_webview {
+
+class InputStreamImpl : public InputStream {
+ public:
+ // Maximum size of |buffer_|.
+ static const int kBufferSize;
+
+ static const InputStreamImpl* FromInputStream(
+ const InputStream* input_stream);
+
+ // |stream| should be an instance of the InputStream Java class.
+ // |stream| can't be null.
+ InputStreamImpl(const base::android::JavaRef<jobject>& stream);
+ virtual ~InputStreamImpl();
+
+ // Gets the underlying Java object. Guaranteed non-NULL.
+ const jobject jobj() const { return jobject_.obj(); }
+
+ // InputStream implementation.
+ virtual bool BytesAvailable(int* bytes_available) const OVERRIDE;
+ virtual bool Skip(int64_t n, int64_t* bytes_skipped) OVERRIDE;
+ virtual bool Read(net::IOBuffer* dest, int length, int* bytes_read) OVERRIDE;
+ protected:
+ // Parameterless constructor exposed for testing.
+ InputStreamImpl();
+
+ private:
+ base::android::ScopedJavaGlobalRef<jobject> jobject_;
+ base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(InputStreamImpl);
+};
+
+bool RegisterInputStream(JNIEnv* env);
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
« no previous file with comments | « android_webview/native/android_webview_jni_registrar.cc ('k') | android_webview/native/input_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698