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

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: 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
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 if (it->context->restrict_dispatch_group() ==
107 it->context == dispatching_context) { 107 dispatching_context->restrict_dispatch_group()) {
Josh Horwich 2012/03/29 18:29:22 In the old impl, we'd dispatch a message that wasn
piman 2012/03/29 18:56:47 Thanks for finding this. I thought we were doing t
108 message = it->message; 108 message = it->message;
109 context = it->context; 109 context = it->context;
110 it = message_queue_.erase(it); 110 it = message_queue_.erase(it);
111 message_queue_version_++; 111 message_queue_version_++;
112 expected_version = message_queue_version_; 112 expected_version = message_queue_version_;
113 break; 113 break;
114 } 114 }
115 } 115 }
116 } 116 }
117 117
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_ = 221 SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_ =
222 LAZY_INSTANCE_INITIALIZER; 222 LAZY_INSTANCE_INITIALIZER;
223 223
224 SyncChannel::SyncContext::SyncContext( 224 SyncChannel::SyncContext::SyncContext(
225 Channel::Listener* listener, 225 Channel::Listener* listener,
226 base::MessageLoopProxy* ipc_thread, 226 base::MessageLoopProxy* ipc_thread,
227 WaitableEvent* shutdown_event) 227 WaitableEvent* shutdown_event)
228 : ChannelProxy::Context(listener, ipc_thread), 228 : ChannelProxy::Context(listener, ipc_thread),
229 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()), 229 received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()),
230 shutdown_event_(shutdown_event), 230 shutdown_event_(shutdown_event),
231 restrict_dispatch_(false) { 231 restrict_dispatch_group_(0) {
Josh Horwich 2012/03/29 18:29:22 Nit: this 0 magically matches the enum in renderer
piman 2012/03/29 18:56:47 It wasn't intended to be magic, just the default v
232 } 232 }
233 233
234 SyncChannel::SyncContext::~SyncContext() { 234 SyncChannel::SyncContext::~SyncContext() {
235 while (!deserializers_.empty()) 235 while (!deserializers_.empty())
236 Pop(); 236 Pop();
237 } 237 }
238 238
239 // Adds information about an outgoing sync message to the context so that 239 // 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 240 // we know how to deserialize the reply. Returns a handle that's set when
241 // the reply has arrived. 241 // the reply has arrived.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 base::MessageLoopProxy* ipc_message_loop, 401 base::MessageLoopProxy* ipc_message_loop,
402 WaitableEvent* shutdown_event) 402 WaitableEvent* shutdown_event)
403 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)), 403 : ChannelProxy(new SyncContext(listener, ipc_message_loop, shutdown_event)),
404 sync_messages_with_no_timeout_allowed_(true) { 404 sync_messages_with_no_timeout_allowed_(true) {
405 StartWatching(); 405 StartWatching();
406 } 406 }
407 407
408 SyncChannel::~SyncChannel() { 408 SyncChannel::~SyncChannel() {
409 } 409 }
410 410
411 void SyncChannel::SetRestrictDispatchToSameChannel(bool value) { 411 void SyncChannel::SetRestrictDispatchChannelGroup(int group) {
412 sync_context()->set_restrict_dispatch(value); 412 sync_context()->set_restrict_dispatch_group(group);
413 } 413 }
414 414
415 bool SyncChannel::Send(Message* message) { 415 bool SyncChannel::Send(Message* message) {
416 return SendWithTimeout(message, base::kNoTimeout); 416 return SendWithTimeout(message, base::kNoTimeout);
417 } 417 }
418 418
419 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { 419 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) {
420 if (!message->is_sync()) { 420 if (!message->is_sync()) {
421 ChannelProxy::Send(message); 421 ChannelProxy::Send(message);
422 return true; 422 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 531 // 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 532 // 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 533 // 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 534 // 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 535 // manual reset since the object watcher might otherwise reset the event
536 // when we're doing a WaitMany. 536 // when we're doing a WaitMany.
537 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); 537 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this);
538 } 538 }
539 539
540 } // namespace IPC 540 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698