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

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

Issue 920873003: Return created channels synchronously (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable a test for real and remove a wrong assertion Created 5 years, 10 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
« no previous file with comments | « android_webview/native/aw_message_port_service_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/aw_message_port_service_impl.h" 5 #include "android_webview/native/aw_message_port_service_impl.h"
6 6
7 #include "android_webview/browser/aw_browser_context.h" 7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_message_port_message_filter.h" 8 #include "android_webview/browser/aw_message_port_message_filter.h"
9 #include "android_webview/native/aw_contents.h" 9 #include "android_webview/native/aw_contents.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 Java_AwMessagePortService_unregisterNativeAwMessagePortService(env, 42 Java_AwMessagePortService_unregisterNativeAwMessagePortService(env,
43 obj.obj()); 43 obj.obj());
44 } 44 }
45 45
46 void AwMessagePortServiceImpl::Init(JNIEnv* env, jobject obj) { 46 void AwMessagePortServiceImpl::Init(JNIEnv* env, jobject obj) {
47 java_ref_ = JavaObjectWeakGlobalRef(env, obj); 47 java_ref_ = JavaObjectWeakGlobalRef(env, obj);
48 } 48 }
49 49
50 void AwMessagePortServiceImpl::CreateMessageChannel( 50 void AwMessagePortServiceImpl::CreateMessageChannel(
51 JNIEnv* env, 51 JNIEnv* env,
52 jobject callback, 52 jobjectArray ports,
53 scoped_refptr<AwMessagePortMessageFilter> filter) { 53 scoped_refptr<AwMessagePortMessageFilter> filter) {
54 DCHECK_CURRENTLY_ON(BrowserThread::UI); 54 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 55
56 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); 56 ScopedJavaGlobalRef<jobjectArray>* j_ports =
57 j_callback->Reset(env, callback); 57 new ScopedJavaGlobalRef<jobjectArray>();
58 j_ports->Reset(env, ports);
58 59
59 int* portId1 = new int; 60 int* portId1 = new int;
60 int* portId2 = new int; 61 int* portId2 = new int;
61 BrowserThread::PostTaskAndReply( 62 BrowserThread::PostTaskAndReply(
62 BrowserThread::IO, 63 BrowserThread::IO,
63 FROM_HERE, 64 FROM_HERE,
64 base::Bind(&AwMessagePortServiceImpl::CreateMessageChannelOnIOThread, 65 base::Bind(&AwMessagePortServiceImpl::CreateMessageChannelOnIOThread,
65 base::Unretained(this), 66 base::Unretained(this),
66 filter, 67 filter,
67 portId1, 68 portId1,
68 portId2), 69 portId2),
69 base::Bind(&AwMessagePortServiceImpl::OnMessageChannelCreated, 70 base::Bind(&AwMessagePortServiceImpl::OnMessageChannelCreated,
70 base::Unretained(this), 71 base::Unretained(this),
71 base::Owned(j_callback), 72 base::Owned(j_ports),
72 base::Owned(portId1), 73 base::Owned(portId1),
73 base::Owned(portId2))); 74 base::Owned(portId2)));
74 } 75 }
75 76
76 void AwMessagePortServiceImpl::OnConvertedWebToAppMessage( 77 void AwMessagePortServiceImpl::OnConvertedWebToAppMessage(
77 int message_port_id, 78 int message_port_id,
78 const base::ListValue& message, 79 const base::ListValue& message,
79 const std::vector<int>& sent_message_port_ids) { 80 const std::vector<int>& sent_message_port_ids) {
80 DCHECK_CURRENTLY_ON(BrowserThread::IO); 81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
81 JNIEnv* env = AttachCurrentThread(); 82 JNIEnv* env = AttachCurrentThread();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 void AwMessagePortServiceImpl::CreateMessageChannelOnIOThread( 155 void AwMessagePortServiceImpl::CreateMessageChannelOnIOThread(
155 scoped_refptr<AwMessagePortMessageFilter> filter, 156 scoped_refptr<AwMessagePortMessageFilter> filter,
156 int* portId1, 157 int* portId1,
157 int* portId2) { 158 int* portId2) {
158 MessagePortProvider::CreateMessageChannel(filter.get(), portId1, portId2); 159 MessagePortProvider::CreateMessageChannel(filter.get(), portId1, portId2);
159 AddPort(*portId1, filter.get()); 160 AddPort(*portId1, filter.get());
160 AddPort(*portId2, filter.get()); 161 AddPort(*portId2, filter.get());
161 } 162 }
162 163
163 void AwMessagePortServiceImpl::OnMessageChannelCreated( 164 void AwMessagePortServiceImpl::OnMessageChannelCreated(
164 ScopedJavaGlobalRef<jobject>* callback, 165 ScopedJavaGlobalRef<jobjectArray>* ports,
165 int* port1, 166 int* port1,
166 int* port2) { 167 int* port2) {
167 DCHECK_CURRENTLY_ON(BrowserThread::UI); 168 DCHECK_CURRENTLY_ON(BrowserThread::UI);
168 JNIEnv* env = AttachCurrentThread(); 169 JNIEnv* env = AttachCurrentThread();
169 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 170 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
170 if (obj.is_null()) 171 if (obj.is_null())
171 return; 172 return;
172 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1, 173 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1,
173 *port2, callback->obj()); 174 *port2, ports->obj());
174 } 175 }
175 176
176 void AwMessagePortServiceImpl::AddPort(int message_port_id, 177 void AwMessagePortServiceImpl::AddPort(int message_port_id,
177 AwMessagePortMessageFilter* filter) { 178 AwMessagePortMessageFilter* filter) {
178 DCHECK_CURRENTLY_ON(BrowserThread::IO); 179 DCHECK_CURRENTLY_ON(BrowserThread::IO);
179 if (ports_.count(message_port_id)) { 180 if (ports_.count(message_port_id)) {
180 NOTREACHED(); 181 NOTREACHED();
181 return; 182 return;
182 } 183 }
183 ports_[message_port_id] = filter; 184 ports_[message_port_id] = filter;
184 } 185 }
185 186
186 bool RegisterAwMessagePortService(JNIEnv* env) { 187 bool RegisterAwMessagePortService(JNIEnv* env) {
187 return RegisterNativesImpl(env); 188 return RegisterNativesImpl(env);
188 } 189 }
189 190
190 // static 191 // static
191 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { 192 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) {
192 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); 193 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance();
193 service->Init(env, obj); 194 service->Init(env, obj);
194 return reinterpret_cast<intptr_t>(service); 195 return reinterpret_cast<intptr_t>(service);
195 } 196 }
196 197
197 } // namespace android_webview 198 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_message_port_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698