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

Unified Diff: android_webview/native/input_stream_reader.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_reader.h
diff --git a/android_webview/native/input_stream_reader.h b/android_webview/native/input_stream_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..109295d2fdb96c56bd731c7cfb26c89b7a8c68c7
--- /dev/null
+++ b/android_webview/native/input_stream_reader.h
@@ -0,0 +1,74 @@
+// 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_READER_H_
+#define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_
+
+#include "base/android/jni_android.h"
+#include "net/base/completion_callback.h"
+
+namespace net {
+class HttpByteRange;
+class IOBuffer;
+}
+
+namespace android_webview {
+
+class InputStream;
+
+// Class responsible for reading the InputStream.
+class InputStreamReader {
benm (inactive) 2012/11/15 17:39:01 As joth noted looks like we could abstract the pub
+ public:
+ // The constructor is called on the IO thread, not on the WorkerThread.
+ InputStreamReader(android_webview::InputStream* stream);
+
+ virtual ~InputStreamReader();
+
+ // Perform a seek operation on the InputStream associated with this job.
+ // On successful completion the InputStream would have skipped reading the
+ // number of bytes equal to the lower range of |byte_range|.
+ // This method should be called on the |g_worker_thread| thread.
+ //
+ // |byte_range| is the range of bytes to be read from |stream|
+ // |on_seek_complete| will be called on the IO thread after the operation
+ // completes. A negative number will indicate an error
+ // code, a positive number will indicate the expected size
+ // of the content.
+ virtual void Seek(net::HttpByteRange byte_range,
+ net::CompletionCallback on_seek_completion);
+
+ // Read data from |stream_|. This method should be called on the
+ // |g_worker_thread| thread.
+ //
+ // |on_completion| will be called on the IO thread after the operation
+ // completes.
+ virtual void ReadRawData(net::IOBuffer* buffer,
+ int buffer_size,
+ net::CompletionCallback on_read_completion);
+
+ protected:
+ // Posts callbacks. Default implementation will post to the IO thread.
+ // Overriding this method is useful for testing.
+ virtual void PostCompletionCallback(const net::CompletionCallback& callback,
+ int result);
+
+ private:
+ // Verify the requested range against the stream size.
+ // net::OK is returned on success, the error code otherwise.
+ int VerifyRequestedRange(JNIEnv* env,
+ net::HttpByteRange* byte_range,
+ int* content_size);
+
+ // Skip to the first byte of the requested read range.
+ // net::OK is returned on success, the error code otherwise.
+ int SkipToRequestedRange(JNIEnv* env, const net::HttpByteRange& byte_range);
+
+ android_webview::InputStream* stream_;
+
+ DISALLOW_COPY_AND_ASSIGN(InputStreamReader);
+};
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_

Powered by Google App Engine
This is Rietveld 408576698