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

Side by Side Diff: ipc/ipc_channel_proxy.cc

Issue 2493623002: Remove IPC::Endpoint. (Closed)
Patch Set: Created 4 years, 1 month 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_channel_reader.h » ('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 30 matching lines...) Expand all
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 message_filter_router_(new MessageFilterRouter()), 50 message_filter_router_(new MessageFilterRouter()),
51 peer_pid_(base::kNullProcessId), 51 peer_pid_(base::kNullProcessId) {
52 attachment_broker_endpoint_(false) {
53 DCHECK(ipc_task_runner_.get()); 52 DCHECK(ipc_task_runner_.get());
54 // The Listener thread where Messages are handled must be a separate thread 53 // The Listener thread where Messages are handled must be a separate thread
55 // to avoid oversubscribing the IO thread. If you trigger this error, you 54 // to avoid oversubscribing the IO thread. If you trigger this error, you
56 // need to either: 55 // need to either:
57 // 1) Create the ChannelProxy on a different thread, or 56 // 1) Create the ChannelProxy on a different thread, or
58 // 2) Just use Channel 57 // 2) Just use Channel
59 // Note, we currently make an exception for a NULL listener. That usage 58 // Note, we currently make an exception for a NULL listener. That usage
60 // basically works, but is outside the intent of ChannelProxy. This support 59 // basically works, but is outside the intent of ChannelProxy. This support
61 // will disappear, so please don't rely on it. See crbug.com/364241 60 // will disappear, so please don't rely on it. See crbug.com/364241
62 DCHECK(!listener || (ipc_task_runner_.get() != listener_task_runner_.get())); 61 DCHECK(!listener || (ipc_task_runner_.get() != listener_task_runner_.get()));
63 } 62 }
64 63
65 ChannelProxy::Context::~Context() { 64 ChannelProxy::Context::~Context() {
66 } 65 }
67 66
68 void ChannelProxy::Context::ClearIPCTaskRunner() { 67 void ChannelProxy::Context::ClearIPCTaskRunner() {
69 ipc_task_runner_ = NULL; 68 ipc_task_runner_ = NULL;
70 } 69 }
71 70
72 void ChannelProxy::Context::CreateChannel( 71 void ChannelProxy::Context::CreateChannel(
73 std::unique_ptr<ChannelFactory> factory) { 72 std::unique_ptr<ChannelFactory> factory) {
74 base::AutoLock l(channel_lifetime_lock_); 73 base::AutoLock l(channel_lifetime_lock_);
75 DCHECK(!channel_); 74 DCHECK(!channel_);
76 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_); 75 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_);
77 channel_id_ = factory->GetName(); 76 channel_id_ = factory->GetName();
78 channel_ = factory->BuildChannel(this); 77 channel_ = factory->BuildChannel(this);
79 channel_->SetAttachmentBrokerEndpoint(attachment_broker_endpoint_);
80 78
81 Channel::AssociatedInterfaceSupport* support = 79 Channel::AssociatedInterfaceSupport* support =
82 channel_->GetAssociatedInterfaceSupport(); 80 channel_->GetAssociatedInterfaceSupport();
83 if (support) { 81 if (support) {
84 associated_group_ = *support->GetAssociatedGroup(); 82 associated_group_ = *support->GetAssociatedGroup();
85 83
86 base::AutoLock l(pending_filters_lock_); 84 base::AutoLock l(pending_filters_lock_);
87 for (auto& entry : pending_interfaces_) 85 for (auto& entry : pending_interfaces_)
88 support->AddGenericAssociatedInterface(entry.first, entry.second); 86 support->AddGenericAssociatedInterface(entry.first, entry.second);
89 pending_interfaces_.clear(); 87 pending_interfaces_.clear();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 listener_task_runner_->PostTask( 141 listener_task_runner_->PostTask(
144 FROM_HERE, base::Bind(&Context::OnDispatchMessage, this, message)); 142 FROM_HERE, base::Bind(&Context::OnDispatchMessage, this, message));
145 return true; 143 return true;
146 } 144 }
147 145
148 // Called on the IPC::Channel thread 146 // Called on the IPC::Channel thread
149 void ChannelProxy::Context::OnChannelConnected(int32_t peer_pid) { 147 void ChannelProxy::Context::OnChannelConnected(int32_t peer_pid) {
150 // We cache off the peer_pid so it can be safely accessed from both threads. 148 // We cache off the peer_pid so it can be safely accessed from both threads.
151 { 149 {
152 base::AutoLock l(peer_pid_lock_); 150 base::AutoLock l(peer_pid_lock_);
153 peer_pid_ = channel_->GetPeerPID(); 151 peer_pid_ = peer_pid;
154 } 152 }
155 153
156 // Add any pending filters. This avoids a race condition where someone 154 // Add any pending filters. This avoids a race condition where someone
157 // creates a ChannelProxy, calls AddFilter, and then right after starts the 155 // creates a ChannelProxy, calls AddFilter, and then right after starts the
158 // peer process. The IO thread could receive a message before the task to add 156 // peer process. The IO thread could receive a message before the task to add
159 // the filter is run on the IO thread. 157 // the filter is run on the IO thread.
160 OnAddFilter(); 158 OnAddFilter();
161 159
162 // See above comment about using listener_task_runner_ here. 160 // See above comment about using listener_task_runner_ here.
163 listener_task_runner_->PostTask( 161 listener_task_runner_->PostTask(
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface, 610 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface,
613 context_, name, base::Passed(&handle))); 611 context_, name, base::Passed(&handle)));
614 } 612 }
615 613
616 void ChannelProxy::ClearIPCTaskRunner() { 614 void ChannelProxy::ClearIPCTaskRunner() {
617 DCHECK(CalledOnValidThread()); 615 DCHECK(CalledOnValidThread());
618 616
619 context()->ClearIPCTaskRunner(); 617 context()->ClearIPCTaskRunner();
620 } 618 }
621 619
622 base::ProcessId ChannelProxy::GetPeerPID() const {
623 base::AutoLock l(context_->peer_pid_lock_);
624 return context_->peer_pid_;
625 }
626
627 void ChannelProxy::OnSetAttachmentBrokerEndpoint() {
628 CHECK(!did_init_);
629 context()->set_attachment_broker_endpoint(is_attachment_broker_endpoint());
630 }
631
632 void ChannelProxy::OnChannelInit() { 620 void ChannelProxy::OnChannelInit() {
633 } 621 }
634 622
635 //----------------------------------------------------------------------------- 623 //-----------------------------------------------------------------------------
636 624
637 } // namespace IPC 625 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_channel_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698