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

Side by Side Diff: ipc/ipc_sync_message_filter.cc

Issue 1262253004: Let IPC::SyncMessageFilter take advantage of thread-safe Send. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minus some code Created 5 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
« no previous file with comments | « ipc/ipc_sync_message_filter.h ('k') | ppapi/nacl_irt/manifest_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ipc/ipc_sync_message_filter.h" 5 #include "ipc/ipc_sync_message_filter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "ipc/ipc_channel.h" 13 #include "ipc/ipc_channel.h"
14 #include "ipc/ipc_sync_message.h" 14 #include "ipc/ipc_sync_message.h"
15 15
16 namespace IPC { 16 namespace IPC {
17 17
18 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event)
19 : sender_(NULL),
20 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()),
21 shutdown_event_(shutdown_event) {
22 }
23
24 bool SyncMessageFilter::Send(Message* message) { 18 bool SyncMessageFilter::Send(Message* message) {
25 if (!message->is_sync()) { 19 if (!message->is_sync()) {
26 { 20 {
27 base::AutoLock auto_lock(lock_); 21 base::AutoLock auto_lock(lock_);
28 if (!io_task_runner_.get()) { 22 if (sender_ && is_channel_send_thread_safe_) {
23 sender_->Send(message);
24 return true;
25 } else if (!io_task_runner_.get()) {
29 pending_messages_.push_back(message); 26 pending_messages_.push_back(message);
30 return true; 27 return true;
31 } 28 }
32 } 29 }
33 io_task_runner_->PostTask( 30 io_task_runner_->PostTask(
34 FROM_HERE, 31 FROM_HERE,
35 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); 32 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message));
36 return true; 33 return true;
37 } 34 }
38 35
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 (*iter)->deserializer->SerializeOutputParameters(message); 102 (*iter)->deserializer->SerializeOutputParameters(message);
106 } 103 }
107 (*iter)->done_event->Signal(); 104 (*iter)->done_event->Signal();
108 return true; 105 return true;
109 } 106 }
110 } 107 }
111 108
112 return false; 109 return false;
113 } 110 }
114 111
112 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event,
113 bool is_channel_send_thread_safe)
114 : sender_(NULL),
115 is_channel_send_thread_safe_(is_channel_send_thread_safe),
116 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()),
117 shutdown_event_(shutdown_event) {
118 }
119
115 SyncMessageFilter::~SyncMessageFilter() { 120 SyncMessageFilter::~SyncMessageFilter() {
116 } 121 }
117 122
118 void SyncMessageFilter::SendOnIOThread(Message* message) { 123 void SyncMessageFilter::SendOnIOThread(Message* message) {
119 if (sender_) { 124 if (sender_) {
120 sender_->Send(message); 125 sender_->Send(message);
121 return; 126 return;
122 } 127 }
123 128
124 if (message->is_sync()) { 129 if (message->is_sync()) {
125 // We don't know which thread sent it, but it doesn't matter, just signal 130 // We don't know which thread sent it, but it doesn't matter, just signal
126 // them all. 131 // them all.
127 SignalAllEvents(); 132 SignalAllEvents();
128 } 133 }
129 134
130 delete message; 135 delete message;
131 } 136 }
132 137
133 void SyncMessageFilter::SignalAllEvents() { 138 void SyncMessageFilter::SignalAllEvents() {
134 base::AutoLock auto_lock(lock_); 139 base::AutoLock auto_lock(lock_);
135 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); 140 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin();
136 iter != pending_sync_messages_.end(); ++iter) { 141 iter != pending_sync_messages_.end(); ++iter) {
137 (*iter)->done_event->Signal(); 142 (*iter)->done_event->Signal();
138 } 143 }
139 } 144 }
140 145
141 } // namespace IPC 146 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_sync_message_filter.h ('k') | ppapi/nacl_irt/manifest_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698