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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
6 #define CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
7
8 #include "base/android/scoped_java_ref.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "net/http/http_byte_range.h"
12 #include "net/url_request/url_request_job.h"
13
14 namespace net {
15 class URLRequest;
16 }
17
18 // A request job that reads data from a Java InputStream.
19 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
20 public:
21 /*
22 * We use a delegate so that we can share code for this job in slightly
23 * different contexts.
24 */
25 class Delegate {
26 public:
27 virtual base::android::ScopedJavaLocalRef<jobject> OpenInputStream(
28 JNIEnv* env,
29 net::URLRequest* request) = 0;
30
31 virtual bool GetMimeType(
32 JNIEnv* env,
33 net::URLRequest* request,
34 jobject stream,
35 std::string* mime_type) = 0;
36
37 virtual bool GetCharset(
38 JNIEnv* env,
39 net::URLRequest* request,
40 jobject stream,
41 std::string* charset) = 0;
42
43 virtual ~Delegate() {}
44 };
45
46 explicit AndroidStreamReaderURLRequestJob(net::URLRequest* request,
47 scoped_ptr<Delegate> delegate);
48
49 // Register JNI methods.
50 static bool InitJNIBindings(JNIEnv* env);
51
52 // URLRequestJob:
53 virtual void Start() OVERRIDE;
54 virtual bool ReadRawData(net::IOBuffer* buf,
55 int buf_size,
56 int* bytes_read) OVERRIDE;
57 virtual void SetExtraRequestHeaders(
58 const net::HttpRequestHeaders& headers) OVERRIDE;
59 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
60 virtual bool GetCharset(std::string* charset) OVERRIDE;
61
62 protected:
63 virtual ~AndroidStreamReaderURLRequestJob();
64
65 private:
66 // Verify the requested range against the stream size.
67 bool VerifyRequestedRange(JNIEnv* env);
68
69 // Skip to the first byte of the requested read range.
70 bool SkipToRequestedRange(JNIEnv* env);
71
72 net::HttpByteRange byte_range_;
73 scoped_ptr<Delegate> delegate_;
74 base::android::ScopedJavaGlobalRef<jobject> stream_;
75 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
76
77 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob);
78 };
79
80 #endif // CHROME_BROWSER_ANDROID_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
OLDNEW
« 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