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

Side by Side Diff: android_webview/native/intercepted_request_data_impl.cc

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/intercepted_request_data_impl.h" 5 #include "android_webview/native/intercepted_request_data_impl.h"
6 6
7 #include "android_webview/native/android_stream_reader_url_request_job.h" 7 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
8 #include "android_webview/native/input_stream_impl.h"
8 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
10 #include "jni/InterceptedRequestData_jni.h" 11 #include "jni/InterceptedRequestData_jni.h"
11 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_job.h" 13 #include "net/url_request/url_request_job.h"
13 14
14 using base::android::ScopedJavaLocalRef; 15 using base::android::ScopedJavaLocalRef;
15 16
16 namespace android_webview { 17 namespace android_webview {
17 18
18 namespace { 19 namespace {
19 20
20 class StreamReaderJobDelegateImpl : 21 class StreamReaderJobDelegateImpl :
21 public AndroidStreamReaderURLRequestJob::Delegate { 22 public AndroidStreamReaderURLRequestJob::Delegate {
22 public: 23 public:
23 StreamReaderJobDelegateImpl( 24 StreamReaderJobDelegateImpl(
24 const InterceptedRequestDataImpl* intercepted_request_data) 25 const InterceptedRequestDataImpl* intercepted_request_data)
25 : intercepted_request_data_impl_(intercepted_request_data) { 26 : intercepted_request_data_impl_(intercepted_request_data) {
26 DCHECK(intercepted_request_data_impl_); 27 DCHECK(intercepted_request_data_impl_);
27 } 28 }
28 29
29 virtual base::android::ScopedJavaLocalRef<jobject> OpenInputStream( 30 virtual scoped_ptr<InputStream> OpenInputStream(
30 JNIEnv* env, 31 JNIEnv* env,
31 net::URLRequest* request) OVERRIDE { 32 net::URLRequest* request) OVERRIDE {
32 return intercepted_request_data_impl_->GetInputStream(env); 33 return intercepted_request_data_impl_->GetInputStream(env).Pass();
33 } 34 }
34 35
35 virtual bool GetMimeType(JNIEnv* env, 36 virtual bool GetMimeType(JNIEnv* env,
36 net::URLRequest* request, 37 net::URLRequest* request,
37 jobject stream, 38 const android_webview::InputStream& stream,
38 std::string* mime_type) OVERRIDE { 39 std::string* mime_type) OVERRIDE {
39 return intercepted_request_data_impl_->GetMimeType(env, mime_type); 40 return intercepted_request_data_impl_->GetMimeType(env, mime_type);
40 } 41 }
41 42
42 virtual bool GetCharset(JNIEnv* env, 43 virtual bool GetCharset(JNIEnv* env,
43 net::URLRequest* request, 44 net::URLRequest* request,
44 jobject stream, 45 const android_webview::InputStream& stream,
45 std::string* charset) OVERRIDE { 46 std::string* charset) OVERRIDE {
46 return intercepted_request_data_impl_->GetCharset(env, charset); 47 return intercepted_request_data_impl_->GetCharset(env, charset);
47 } 48 }
48 49
49 private: 50 private:
50 const InterceptedRequestDataImpl* intercepted_request_data_impl_; 51 const InterceptedRequestDataImpl* intercepted_request_data_impl_;
51 }; 52 };
52 53
53 } // namespace 54 } // namespace
54 55
55 InterceptedRequestDataImpl::InterceptedRequestDataImpl( 56 InterceptedRequestDataImpl::InterceptedRequestDataImpl(
56 const base::android::JavaRef<jobject>& obj) 57 const base::android::JavaRef<jobject>& obj)
57 : java_object_(obj) { 58 : java_object_(obj) {
58 } 59 }
59 60
60 InterceptedRequestDataImpl::~InterceptedRequestDataImpl() { 61 InterceptedRequestDataImpl::~InterceptedRequestDataImpl() {
61 } 62 }
62 63
63 ScopedJavaLocalRef<jobject> 64 scoped_ptr<InputStream>
64 InterceptedRequestDataImpl::GetInputStream(JNIEnv* env) const { 65 InterceptedRequestDataImpl::GetInputStream(JNIEnv* env) const {
65 return Java_InterceptedRequestData_getData(env, java_object_.obj()); 66 ScopedJavaLocalRef<jobject> jstream =
67 Java_InterceptedRequestData_getData(env, java_object_.obj());
68 if (jstream.is_null())
69 return scoped_ptr<InputStream>();
70 return make_scoped_ptr<InputStream>(new InputStreamImpl(jstream));
66 } 71 }
67 72
68 bool InterceptedRequestDataImpl::GetMimeType(JNIEnv* env, 73 bool InterceptedRequestDataImpl::GetMimeType(JNIEnv* env,
69 std::string* mime_type) const { 74 std::string* mime_type) const {
70 ScopedJavaLocalRef<jstring> jstring_mime_type = 75 ScopedJavaLocalRef<jstring> jstring_mime_type =
71 Java_InterceptedRequestData_getMimeType(env, java_object_.obj()); 76 Java_InterceptedRequestData_getMimeType(env, java_object_.obj());
72 if (jstring_mime_type.is_null()) 77 if (jstring_mime_type.is_null())
73 return false; 78 return false;
74 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type); 79 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type);
75 return true; 80 return true;
(...skipping 16 matching lines...) Expand all
92 net::URLRequestJob* InterceptedRequestDataImpl::CreateJobFor( 97 net::URLRequestJob* InterceptedRequestDataImpl::CreateJobFor(
93 net::URLRequest* request, 98 net::URLRequest* request,
94 net::NetworkDelegate* network_delegate) const { 99 net::NetworkDelegate* network_delegate) const {
95 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate> 100 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>
96 stream_reader_job_delegate_impl(new StreamReaderJobDelegateImpl(this)); 101 stream_reader_job_delegate_impl(new StreamReaderJobDelegateImpl(this));
97 return new AndroidStreamReaderURLRequestJob( 102 return new AndroidStreamReaderURLRequestJob(
98 request, network_delegate, stream_reader_job_delegate_impl.Pass()); 103 request, network_delegate, stream_reader_job_delegate_impl.Pass());
99 } 104 }
100 105
101 } // namespace android_webview 106 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/intercepted_request_data_impl.h ('k') | android_webview/native/webview_native.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698