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

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

Issue 956763002: Implement the close() API for Message ports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Nasko review 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
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 BrowserThread::PostTask( 128 BrowserThread::PostTask(
129 BrowserThread::IO, 129 BrowserThread::IO,
130 FROM_HERE, 130 FROM_HERE,
131 base::Bind(&AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread, 131 base::Bind(&AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread,
132 base::Unretained(this), 132 base::Unretained(this),
133 sender_id, 133 sender_id,
134 base::Owned(j_message), 134 base::Owned(j_message),
135 base::Owned(j_sent_ports))); 135 base::Owned(j_sent_ports)));
136 } 136 }
137 137
138 // The message port service cannot immediately close the port, because
139 // it is possible that messages are still queued in the renderer process
140 // waiting for a conversion. Instead, it sends a special message with
141 // a flag which indicates that this message port should be closed.
142 void AwMessagePortServiceImpl::ClosePort(JNIEnv* env, jobject obj,
143 int message_port_id) {
144 DCHECK_CURRENTLY_ON(BrowserThread::UI);
145 BrowserThread::PostTask(
146 BrowserThread::IO,
147 FROM_HERE,
148 base::Bind(&AwMessagePortServiceImpl::PostClosePortMessage,
149 base::Unretained(this),
150 message_port_id));
151 }
152
138 void AwMessagePortServiceImpl::RemoveSentPorts( 153 void AwMessagePortServiceImpl::RemoveSentPorts(
139 const std::vector<int>& sent_ports) { 154 const std::vector<int>& sent_ports) {
140 DCHECK_CURRENTLY_ON(BrowserThread::IO); 155 DCHECK_CURRENTLY_ON(BrowserThread::IO);
141 // Remove the filters that are associated with the transferred ports 156 // Remove the filters that are associated with the transferred ports
142 for (const auto& iter : sent_ports) 157 for (const auto& iter : sent_ports)
143 ports_.erase(iter); 158 ports_.erase(iter);
144 } 159 }
145 160
146 void AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread( 161 void AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread(
147 int sender_id, 162 int sender_id,
148 base::string16* message, 163 base::string16* message,
149 std::vector<int>* sent_ports) { 164 std::vector<int>* sent_ports) {
150 RemoveSentPorts(*sent_ports); 165 RemoveSentPorts(*sent_ports);
151 ports_[sender_id]->SendAppToWebMessage(sender_id, *message, *sent_ports); 166 ports_[sender_id]->SendAppToWebMessage(sender_id, *message, *sent_ports);
152 } 167 }
153 168
169 void AwMessagePortServiceImpl::PostClosePortMessage(int message_port_id) {
170 DCHECK_CURRENTLY_ON(BrowserThread::IO);
171 ports_[message_port_id]->SendClosePortMessage(message_port_id);
172 }
173
174 void AwMessagePortServiceImpl::CleanupPort(int message_port_id) {
175 DCHECK_CURRENTLY_ON(BrowserThread::IO);
176 ports_.erase(message_port_id);
177 }
154 178
155 void AwMessagePortServiceImpl::CreateMessageChannelOnIOThread( 179 void AwMessagePortServiceImpl::CreateMessageChannelOnIOThread(
156 scoped_refptr<AwMessagePortMessageFilter> filter, 180 scoped_refptr<AwMessagePortMessageFilter> filter,
157 int* portId1, 181 int* portId1,
158 int* portId2) { 182 int* portId2) {
159 MessagePortProvider::CreateMessageChannel(filter.get(), portId1, portId2); 183 MessagePortProvider::CreateMessageChannel(filter.get(), portId1, portId2);
160 AddPort(*portId1, filter.get()); 184 AddPort(*portId1, filter.get());
161 AddPort(*portId2, filter.get()); 185 AddPort(*portId2, filter.get());
162 } 186 }
163 187
(...skipping 25 matching lines...) Expand all
189 } 213 }
190 214
191 // static 215 // static
192 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { 216 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) {
193 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); 217 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance();
194 service->Init(env, obj); 218 service->Init(env, obj);
195 return reinterpret_cast<intptr_t>(service); 219 return reinterpret_cast<intptr_t>(service);
196 } 220 }
197 221
198 } // namespace android_webview 222 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_message_port_service_impl.h ('k') | android_webview/renderer/aw_message_port_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698