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

Unified Diff: android_webview/browser/net/android_stream_reader_url_request_job.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: reinterpret_cast->static_cast 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/browser/net/android_stream_reader_url_request_job.h
diff --git a/android_webview/native/android_stream_reader_url_request_job.h b/android_webview/browser/net/android_stream_reader_url_request_job.h
similarity index 71%
rename from android_webview/native/android_stream_reader_url_request_job.h
rename to android_webview/browser/net/android_stream_reader_url_request_job.h
index e29acd86e90045dfcb2265d78d2d80fc217e9c53..725ca259bf8e459e34b3f78062a33fc99ae67957 100644
--- a/android_webview/native/android_stream_reader_url_request_job.h
+++ b/android_webview/browser/net/android_stream_reader_url_request_job.h
@@ -6,12 +6,22 @@
#define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
#include "base/android/scoped_java_ref.h"
+#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "net/http/http_byte_range.h"
#include "net/url_request/url_request_job.h"
+namespace android_webview {
+class InputStream;
+class InputStreamReader;
+}
+
+namespace base {
+class TaskRunner;
+}
+
namespace net {
class URLRequest;
}
@@ -25,20 +35,20 @@ class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
*/
class Delegate {
public:
- virtual base::android::ScopedJavaLocalRef<jobject> OpenInputStream(
+ virtual scoped_ptr<android_webview::InputStream> OpenInputStream(
JNIEnv* env,
net::URLRequest* request) = 0;
virtual bool GetMimeType(
JNIEnv* env,
net::URLRequest* request,
- jobject stream,
+ const android_webview::InputStream& stream,
std::string* mime_type) = 0;
virtual bool GetCharset(
JNIEnv* env,
net::URLRequest* request,
- jobject stream,
+ const android_webview::InputStream& stream,
std::string* charset) = 0;
virtual ~Delegate() {}
@@ -51,6 +61,7 @@ class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
// URLRequestJob:
virtual void Start() OVERRIDE;
+ virtual void Kill() OVERRIDE;
virtual bool ReadRawData(net::IOBuffer* buf,
int buf_size,
int* bytes_read) OVERRIDE;
@@ -62,24 +73,27 @@ class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
protected:
virtual ~AndroidStreamReaderURLRequestJob();
- private:
- // Verify the requested range against the stream size.
- bool VerifyRequestedRange(JNIEnv* env);
+ // Gets the TaskRunner for the worker thread.
+ // Useful to override in tests.
+ virtual base::TaskRunner* GetWorkerThreadRunner();
- // Skip to the first byte of the requested read range.
- bool SkipToRequestedRange(JNIEnv* env);
+ // Creates an InputStreamReader instance.
+ virtual android_webview::InputStreamReader*
+ CreateStreamReader(android_webview::InputStream* stream);
+ private:
void StartAsync();
+ void OnReaderSeekCompleted(int content_size);
+ void OnReaderReadCompleted(int bytes_read);
+
net::HttpByteRange byte_range_;
scoped_ptr<Delegate> delegate_;
- base::android::ScopedJavaGlobalRef<jobject> stream_;
- base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
+ scoped_refptr<android_webview::InputStreamReader> input_stream_reader_;
+ scoped_ptr<android_webview::InputStream> stream_;
base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob);
};
-bool RegisterAndroidStreamReaderUrlRequestJob(JNIEnv* env);
-
#endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698