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

Unified Diff: chrome/browser/android/android_stream_reader_url_request_job.h

Issue 10832034: Upstreaming AndroidProtocolAdapter. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months 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: chrome/browser/android/android_stream_reader_url_request_job.h
diff --git a/chrome/browser/android/android_stream_reader_url_request_job.h b/chrome/browser/android/android_stream_reader_url_request_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..920070147b206e3b5f1b02bcd06d7c6beeb25fdc
--- /dev/null
+++ b/chrome/browser/android/android_stream_reader_url_request_job.h
@@ -0,0 +1,80 @@
+// 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 CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
+#define CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
+
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/scoped_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 net {
+class URLRequest;
+}
+
+// A request job that reads data from a Java InputStream.
+class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
+ public:
+ /*
+ * We use a delegate so that we can share code for this job in slightly
+ * different contexts.
+ */
+ class Delegate {
+ public:
+ virtual base::android::ScopedJavaLocalRef<jobject> OpenInputStream(
+ JNIEnv* env,
+ net::URLRequest* request) = 0;
+
+ virtual bool GetMimeType(
+ JNIEnv* env,
+ net::URLRequest* request,
+ jobject stream,
+ std::string* mime_type) = 0;
+
+ virtual bool GetCharset(
+ JNIEnv* env,
+ net::URLRequest* request,
+ jobject stream,
+ std::string* charset) = 0;
+
+ virtual ~Delegate() {}
+ };
+
+ explicit AndroidStreamReaderURLRequestJob(net::URLRequest* request,
+ scoped_ptr<Delegate> delegate);
+
+ // Register JNI methods.
+ static bool InitJNIBindings(JNIEnv* env);
+
+ // URLRequestJob:
+ virtual void Start() OVERRIDE;
+ virtual bool ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read) OVERRIDE;
+ virtual void SetExtraRequestHeaders(
+ const net::HttpRequestHeaders& headers) OVERRIDE;
+ virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
+ virtual bool GetCharset(std::string* charset) OVERRIDE;
+
+ protected:
+ virtual ~AndroidStreamReaderURLRequestJob();
+
+ private:
+ // Verify the requested range against the stream size.
+ bool VerifyRequestedRange(JNIEnv* env);
+
+ // Skip to the first byte of the requested read range.
+ bool SkipToRequestedRange(JNIEnv* env);
+
+ net::HttpByteRange byte_range_;
+ scoped_ptr<Delegate> delegate_;
+ base::android::ScopedJavaGlobalRef<jobject> stream_;
+ base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob);
+};
+
+#endif // CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
« no previous file with comments | « chrome/browser/android/android_protocol_adapter.cc ('k') | chrome/browser/android/android_stream_reader_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698