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

Side by Side Diff: ipc/ipc_sync_channel.cc

Issue 9917002: IPC: change sync channel dispatch restriction to allow dispatch to other channels within the same "… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: docs Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_channel_unittest.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_channel.h" 5 #include "ipc/ipc_sync_channel.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 while (true) { 96 while (true) {
97 Message* message = NULL; 97 Message* message = NULL;
98 scoped_refptr<SyncChannel::SyncContext> context; 98 scoped_refptr<SyncChannel::SyncContext> context;
99 { 99 {
100 base::AutoLock auto_lock(message_lock_); 100 base::AutoLock auto_lock(message_lock_);
101 if (first_time || message_queue_version_ != expected_version) { 101 if (first_time || message_queue_version_ != expected_version) {
102 it = message_queue_.begin(); 102 it = message_queue_.begin();
103 first_time = false; 103 first_time = false;
104 } 104 }
105 for (; it != message_queue_.end(); it++) { 105 for (; it != message_queue_.end(); it++) {
106 if (!it->context->restrict_dispatch() || 106 int message_group = it->context->restrict_dispatch_group();
107 it->context == dispatching_context) { 107 if (message_group == kRestrictDispatchGroup_None ||
108 message_group == dispatching_context->restrict_dispatch_group()) {
108 message = it->message; 109 message = it->message;
109 context = it->context; 110 context = it->context;
110 it = message_queue_.erase(it); 111 it = message_queue_.erase(it);
111 message_queue_version_++; 112 message_queue_version_++;
112 expected_version = message_queue_version_; 113 expected_version = message_queue_version_;
113 break; 114 break;
114 } 115 }
115 } 116 }
116 } 117 }
117 118
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_ = 222 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_ =
222 LAZY_INSTANCE_INITIALIZER; 223 LAZY_INSTANCE_INITIALIZER;
223 224
224 SyncChannel::SyncContext::SyncContext( 225 SyncChannel::SyncContext::SyncContext(
225 Channel::Listener* listener, 226 Channel::Listener* listener,
226 base::MessageLoopProxy* ipc_thread, 227 base::MessageLoopProxy* ipc_thread,
227 WaitableEvent* shutdown_event) 228 WaitableEvent* shutdown_event)
228 : ChannelProxy::Context(listener, ipc_thread), 229 : ChannelProxy::Context(listener, ipc_thread),
229 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()), 230 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()),
230 shutdown_event_(shutdown_event), 231 shutdown_event_(shutdown_event),
231 restrict_dispatch_(false) { 232 restrict_dispatch_group_(kRestrictDispatchGroup_None) {
232 } 233 }
233 234
234 SyncChannel::SyncContext::~SyncContext() { 235 SyncChannel::SyncContext::~SyncContext() {
235 while (!deserializers_.empty()) 236 while (!deserializers_.empty())
236 Pop(); 237 Pop();
237 } 238 }
238 239
239 // Adds information about an outgoing sync message to the context so that 240 // Adds information about an outgoing sync message to the context so that
240 // we know how to deserialize the reply. Returns a handle that's set when 241 // we know how to deserialize the reply. Returns a handle that's set when
241 // the reply has arrived. 242 // the reply has arrived.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 base::MessageLoopProxy* ipc_message_loop, 402 base::MessageLoopProxy* ipc_message_loop,
402 WaitableEvent* shutdown_event) 403 WaitableEvent* shutdown_event)
403 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), 404 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)),
404 sync_messages_with_no_timeout_allowed_(true) { 405 sync_messages_with_no_timeout_allowed_(true) {
405 StartWatching(); 406 StartWatching();
406 } 407 }
407 408
408 SyncChannel::~SyncChannel() { 409 SyncChannel::~SyncChannel() {
409 } 410 }
410 411
411 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { 412 void SyncChannel::SetRestrictDispatchChannelGroup(int group) {
412 sync_context()->set_restrict_dispatch(value); 413 sync_context()->set_restrict_dispatch_group(group);
413 } 414 }
414 415
415 bool SyncChannel::Send(Message* message) { 416 bool SyncChannel::Send(Message* message) {
416 return SendWithTimeout(message, base::kNoTimeout); 417 return SendWithTimeout(message, base::kNoTimeout);
417 } 418 }
418 419
419 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { 420 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) {
420 if (!message->is_sync()) { 421 if (!message->is_sync()) {
421 ChannelProxy::Send(message); 422 ChannelProxy::Send(message);
422 return true; 423 return true;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // Ideally we only want to watch this object when running a nested message 532 // Ideally we only want to watch this object when running a nested message
532 // loop. However, we don't know when it exits if there's another nested 533 // loop. However, we don't know when it exits if there's another nested
533 // message loop running under it or not, so we wouldn't know whether to 534 // message loop running under it or not, so we wouldn't know whether to
534 // stop or keep watching. So we always watch it, and create the event as 535 // stop or keep watching. So we always watch it, and create the event as
535 // manual reset since the object watcher might otherwise reset the event 536 // manual reset since the object watcher might otherwise reset the event
536 // when we're doing a WaitMany. 537 // when we're doing a WaitMany.
537 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); 538 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this);
538 } 539 }
539 540
540 } // namespace IPC 541 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698