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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/native/aw_message_port_service_impl.cc
diff --git a/android_webview/native/aw_message_port_service_impl.cc b/android_webview/native/aw_message_port_service_impl.cc
index d2e1fa44614c9b559c8d0a39de0458992a31c121..6e5fb3da9a887d949d06c83e07b3f2bdf01e7725 100644
--- a/android_webview/native/aw_message_port_service_impl.cc
+++ b/android_webview/native/aw_message_port_service_impl.cc
@@ -132,7 +132,28 @@ void AwMessagePortServiceImpl::PostAppToWebMessage(JNIEnv* env, jobject obj,
base::Unretained(this),
sender_id,
base::Owned(j_message),
- base::Owned(j_sent_ports)));
+ base::Owned(j_sent_ports),
+ false));
+}
+
+// The message port service cannot immediately close the port, because
+// it is possible that messages are still queued in the renderer process
+// waiting for a conversion. Instead, it sends a special message with
+// a flag which indicates that this message port should be closed.
+void AwMessagePortServiceImpl::ClosePort(JNIEnv* env, jobject obj,
+ int message_port_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ base::string16* j_message = new base::string16;
+ std::vector<int>* j_sent_ports = new std::vector<int>;
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread,
+ base::Unretained(this),
+ message_port_id,
+ base::Owned(j_message),
+ base::Owned(j_sent_ports),
+ true /* close the port */));
}
void AwMessagePortServiceImpl::RemoveSentPorts(
@@ -146,11 +167,20 @@ void AwMessagePortServiceImpl::RemoveSentPorts(
void AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread(
int sender_id,
base::string16* message,
- std::vector<int>* sent_ports) {
+ std::vector<int>* sent_ports,
+ bool close_port) {
RemoveSentPorts(*sent_ports);
- ports_[sender_id]->SendAppToWebMessage(sender_id, *message, *sent_ports);
+ if (!ports_[sender_id]) {
+ NOTREACHED();
+ }
+ ports_[sender_id]->SendAppToWebMessage(sender_id, *message, *sent_ports,
+ close_port);
}
+void AwMessagePortServiceImpl::CleanupPort(int message_port_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ports_.erase(message_port_id);
+}
void AwMessagePortServiceImpl::CreateMessageChannelOnIOThread(
scoped_refptr<AwMessagePortMessageFilter> filter,

Powered by Google App Engine
This is Rietveld 408576698