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

Side by Side Diff: ipc/ipc_channel_proxy.cc

Issue 2343033002: IPC: Delete thread-safe send support (Closed)
Patch Set: Created 4 years, 3 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_channel_proxy.h ('k') | ipc/ipc_sync_channel.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_channel_proxy.h" 5 #include "ipc/ipc_channel_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 29 matching lines...) Expand all
40 40
41 //------------------------------------------------------------------------------ 41 //------------------------------------------------------------------------------
42 42
43 ChannelProxy::Context::Context( 43 ChannelProxy::Context::Context(
44 Listener* listener, 44 Listener* listener,
45 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) 45 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner)
46 : listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), 46 : listener_task_runner_(base::ThreadTaskRunnerHandle::Get()),
47 listener_(listener), 47 listener_(listener),
48 ipc_task_runner_(ipc_task_runner), 48 ipc_task_runner_(ipc_task_runner),
49 channel_connected_called_(false), 49 channel_connected_called_(false),
50 channel_send_thread_safe_(false),
51 message_filter_router_(new MessageFilterRouter()), 50 message_filter_router_(new MessageFilterRouter()),
52 peer_pid_(base::kNullProcessId), 51 peer_pid_(base::kNullProcessId),
53 attachment_broker_endpoint_(false) { 52 attachment_broker_endpoint_(false) {
54 DCHECK(ipc_task_runner_.get()); 53 DCHECK(ipc_task_runner_.get());
55 // The Listener thread where Messages are handled must be a separate thread 54 // The Listener thread where Messages are handled must be a separate thread
56 // to avoid oversubscribing the IO thread. If you trigger this error, you 55 // to avoid oversubscribing the IO thread. If you trigger this error, you
57 // need to either: 56 // need to either:
58 // 1) Create the ChannelProxy on a different thread, or 57 // 1) Create the ChannelProxy on a different thread, or
59 // 2) Just use Channel 58 // 2) Just use Channel
60 // Note, we currently make an exception for a NULL listener. That usage 59 // Note, we currently make an exception for a NULL listener. That usage
61 // basically works, but is outside the intent of ChannelProxy. This support 60 // basically works, but is outside the intent of ChannelProxy. This support
62 // will disappear, so please don't rely on it. See crbug.com/364241 61 // will disappear, so please don't rely on it. See crbug.com/364241
63 DCHECK(!listener || (ipc_task_runner_.get() != listener_task_runner_.get())); 62 DCHECK(!listener || (ipc_task_runner_.get() != listener_task_runner_.get()));
64 } 63 }
65 64
66 ChannelProxy::Context::~Context() { 65 ChannelProxy::Context::~Context() {
67 } 66 }
68 67
69 void ChannelProxy::Context::ClearIPCTaskRunner() { 68 void ChannelProxy::Context::ClearIPCTaskRunner() {
70 ipc_task_runner_ = NULL; 69 ipc_task_runner_ = NULL;
71 } 70 }
72 71
73 void ChannelProxy::Context::CreateChannel( 72 void ChannelProxy::Context::CreateChannel(
74 std::unique_ptr<ChannelFactory> factory) { 73 std::unique_ptr<ChannelFactory> factory) {
75 base::AutoLock l(channel_lifetime_lock_); 74 base::AutoLock l(channel_lifetime_lock_);
76 DCHECK(!channel_); 75 DCHECK(!channel_);
77 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_); 76 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_);
78 channel_id_ = factory->GetName(); 77 channel_id_ = factory->GetName();
79 channel_ = factory->BuildChannel(this); 78 channel_ = factory->BuildChannel(this);
80 channel_send_thread_safe_ = channel_->IsSendThreadSafe();
81 channel_->SetAttachmentBrokerEndpoint(attachment_broker_endpoint_); 79 channel_->SetAttachmentBrokerEndpoint(attachment_broker_endpoint_);
82 80
83 Channel::AssociatedInterfaceSupport* support = 81 Channel::AssociatedInterfaceSupport* support =
84 channel_->GetAssociatedInterfaceSupport(); 82 channel_->GetAssociatedInterfaceSupport();
85 if (support) { 83 if (support) {
86 associated_group_ = *support->GetAssociatedGroup(); 84 associated_group_ = *support->GetAssociatedGroup();
87 85
88 base::AutoLock l(pending_filters_lock_); 86 base::AutoLock l(pending_filters_lock_);
89 for (auto& entry : pending_interfaces_) 87 for (auto& entry : pending_interfaces_)
90 support->AddGenericAssociatedInterface(entry.first, entry.second); 88 support->AddGenericAssociatedInterface(entry.first, entry.second);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 base::AutoLock l(pending_filters_lock_); 403 base::AutoLock l(pending_filters_lock_);
406 pending_interfaces_.emplace_back(name, factory); 404 pending_interfaces_.emplace_back(name, factory);
407 return; 405 return;
408 } 406 }
409 Channel::AssociatedInterfaceSupport* support = 407 Channel::AssociatedInterfaceSupport* support =
410 channel_->GetAssociatedInterfaceSupport(); 408 channel_->GetAssociatedInterfaceSupport();
411 DCHECK(support); 409 DCHECK(support);
412 support->AddGenericAssociatedInterface(name, factory); 410 support->AddGenericAssociatedInterface(name, factory);
413 } 411 }
414 412
415 void ChannelProxy::Context::SendFromThisThread(Message* message) {
416 base::AutoLock l(channel_lifetime_lock_);
417 if (!channel_)
418 return;
419 DCHECK(channel_->IsSendThreadSafe());
420 channel_->Send(message);
421 }
422
423 void ChannelProxy::Context::Send(Message* message) { 413 void ChannelProxy::Context::Send(Message* message) {
424 if (channel_send_thread_safe_) {
425 SendFromThisThread(message);
426 return;
427 }
428
429 ipc_task_runner()->PostTask( 414 ipc_task_runner()->PostTask(
430 FROM_HERE, base::Bind(&ChannelProxy::Context::OnSendMessage, this, 415 FROM_HERE, base::Bind(&ChannelProxy::Context::OnSendMessage, this,
431 base::Passed(base::WrapUnique(message)))); 416 base::Passed(base::WrapUnique(message))));
432 } 417 }
433 418
434 bool ChannelProxy::Context::IsChannelSendThreadSafe() const {
435 return channel_send_thread_safe_;
436 }
437
438 // Called on the IPC::Channel thread 419 // Called on the IPC::Channel thread
439 void ChannelProxy::Context::GetRemoteAssociatedInterface( 420 void ChannelProxy::Context::GetRemoteAssociatedInterface(
440 const std::string& name, 421 const std::string& name,
441 mojo::ScopedInterfaceEndpointHandle handle) { 422 mojo::ScopedInterfaceEndpointHandle handle) {
442 if (!channel_) 423 if (!channel_)
443 return; 424 return;
444 Channel::AssociatedInterfaceSupport* associated_interface_support = 425 Channel::AssociatedInterfaceSupport* associated_interface_support =
445 channel_->GetAssociatedInterfaceSupport(); 426 channel_->GetAssociatedInterfaceSupport();
446 DCHECK(associated_interface_support); 427 DCHECK(associated_interface_support);
447 associated_interface_support->GetGenericRemoteAssociatedInterface( 428 associated_interface_support->GetGenericRemoteAssociatedInterface(
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 return channel->TakeClientFileDescriptor(); 646 return channel->TakeClientFileDescriptor();
666 } 647 }
667 #endif 648 #endif
668 649
669 void ChannelProxy::OnChannelInit() { 650 void ChannelProxy::OnChannelInit() {
670 } 651 }
671 652
672 //----------------------------------------------------------------------------- 653 //-----------------------------------------------------------------------------
673 654
674 } // namespace IPC 655 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_sync_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698