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

Side by Side Diff: ipc/ipc_channel_proxy.cc

Issue 2163633003: Support early associated interface binding on ChannelMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-channel-ipc-task-runner
Patch Set: . Created 4 years, 5 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_message_pipe_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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void ChannelProxy::Context::CreateChannel( 73 void ChannelProxy::Context::CreateChannel(
74 std::unique_ptr<ChannelFactory> factory) { 74 std::unique_ptr<ChannelFactory> factory) {
75 base::AutoLock l(channel_lifetime_lock_); 75 base::AutoLock l(channel_lifetime_lock_);
76 DCHECK(!channel_); 76 DCHECK(!channel_);
77 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_); 77 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_);
78 channel_id_ = factory->GetName(); 78 channel_id_ = factory->GetName();
79 channel_ = factory->BuildChannel(this); 79 channel_ = factory->BuildChannel(this);
80 channel_send_thread_safe_ = channel_->IsSendThreadSafe(); 80 channel_send_thread_safe_ = channel_->IsSendThreadSafe();
81 channel_->SetAttachmentBrokerEndpoint(attachment_broker_endpoint_); 81 channel_->SetAttachmentBrokerEndpoint(attachment_broker_endpoint_);
82
83 Channel::AssociatedInterfaceSupport* support =
84 channel_->GetAssociatedInterfaceSupport();
85 if (support) {
86 associated_group_ = *support->GetAssociatedGroup();
87
88 base::AutoLock l(pending_filters_lock_);
89 for (auto& entry : pending_interfaces_)
90 support->AddGenericAssociatedInterface(entry.first, entry.second);
91 pending_interfaces_.clear();
92 }
82 } 93 }
83 94
84 bool ChannelProxy::Context::TryFilters(const Message& message) { 95 bool ChannelProxy::Context::TryFilters(const Message& message) {
85 DCHECK(message_filter_router_); 96 DCHECK(message_filter_router_);
86 #ifdef IPC_MESSAGE_LOG_ENABLED 97 #ifdef IPC_MESSAGE_LOG_ENABLED
87 Logging* logger = Logging::GetInstance(); 98 Logging* logger = Logging::GetInstance();
88 if (logger->Enabled()) 99 if (logger->Enabled())
89 logger->OnPreDispatchMessage(message); 100 logger->OnPreDispatchMessage(message);
90 #endif 101 #endif
91 102
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // will be released when we are closed. 166 // will be released when we are closed.
156 AddRef(); 167 AddRef();
157 168
158 if (!channel_->Connect()) { 169 if (!channel_->Connect()) {
159 OnChannelError(); 170 OnChannelError();
160 return; 171 return;
161 } 172 }
162 173
163 for (size_t i = 0; i < filters_.size(); ++i) 174 for (size_t i = 0; i < filters_.size(); ++i)
164 filters_[i]->OnFilterAdded(channel_.get()); 175 filters_[i]->OnFilterAdded(channel_.get());
165
166 Channel::AssociatedInterfaceSupport* support =
167 channel_->GetAssociatedInterfaceSupport();
168 if (support) {
169 support->SetProxyTaskRunner(listener_task_runner_);
170 for (auto& entry : io_thread_interfaces_)
171 support->AddGenericAssociatedInterface(entry.first, entry.second);
172 for (auto& entry : proxy_thread_interfaces_) {
173 support->AddGenericAssociatedInterface(
174 entry.first, base::Bind(&BindAssociatedInterfaceOnTaskRunner,
175 listener_task_runner_, entry.second));
176 }
177 } else {
178 // Sanity check to ensure nobody's expecting to use associated interfaces on
179 // a Channel that doesn't support them.
180 DCHECK(io_thread_interfaces_.empty() && proxy_thread_interfaces_.empty());
181 }
182 } 176 }
183 177
184 // Called on the IPC::Channel thread 178 // Called on the IPC::Channel thread
185 void ChannelProxy::Context::OnChannelClosed() { 179 void ChannelProxy::Context::OnChannelClosed() {
186 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 180 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
187 tracked_objects::ScopedTracker tracking_profile( 181 tracked_objects::ScopedTracker tracking_profile(
188 FROM_HERE_WITH_EXPLICIT_FUNCTION( 182 FROM_HERE_WITH_EXPLICIT_FUNCTION(
189 "477117 ChannelProxy::Context::OnChannelClosed")); 183 "477117 ChannelProxy::Context::OnChannelClosed"));
190 // It's okay for IPC::ChannelProxy::Close to be called more than once, which 184 // It's okay for IPC::ChannelProxy::Close to be called more than once, which
191 // would result in this branch being taken. 185 // would result in this branch being taken.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (logger->Enabled()) 319 if (logger->Enabled())
326 logger->OnPostDispatchMessage(message, channel_id_); 320 logger->OnPostDispatchMessage(message, channel_id_);
327 #endif 321 #endif
328 } 322 }
329 323
330 // Called on the listener's thread 324 // Called on the listener's thread
331 void ChannelProxy::Context::OnDispatchConnected() { 325 void ChannelProxy::Context::OnDispatchConnected() {
332 if (channel_connected_called_) 326 if (channel_connected_called_)
333 return; 327 return;
334 328
335 {
336 base::AutoLock l(channel_lifetime_lock_);
337 if (channel_) {
338 Channel::AssociatedInterfaceSupport* associated_interface_support =
339 channel_->GetAssociatedInterfaceSupport();
340 if (associated_interface_support) {
341 channel_associated_group_.reset(new mojo::AssociatedGroup(
342 *associated_interface_support->GetAssociatedGroup()));
343 }
344 }
345 }
346
347 base::ProcessId peer_pid; 329 base::ProcessId peer_pid;
348 { 330 {
349 base::AutoLock l(peer_pid_lock_); 331 base::AutoLock l(peer_pid_lock_);
350 peer_pid = peer_pid_; 332 peer_pid = peer_pid_;
351 } 333 }
352 channel_connected_called_ = true; 334 channel_connected_called_ = true;
353 if (listener_) 335 if (listener_)
354 listener_->OnChannelConnected(peer_pid); 336 listener_->OnChannelConnected(peer_pid);
355 } 337 }
356 338
357 // Called on the listener's thread 339 // Called on the listener's thread
358 void ChannelProxy::Context::OnDispatchError() { 340 void ChannelProxy::Context::OnDispatchError() {
359 if (listener_) 341 if (listener_)
360 listener_->OnChannelError(); 342 listener_->OnChannelError();
361 } 343 }
362 344
363 // Called on the listener's thread 345 // Called on the listener's thread
364 void ChannelProxy::Context::OnDispatchBadMessage(const Message& message) { 346 void ChannelProxy::Context::OnDispatchBadMessage(const Message& message) {
365 if (listener_) 347 if (listener_)
366 listener_->OnBadMessageReceived(message); 348 listener_->OnBadMessageReceived(message);
367 } 349 }
368 350
369 void ChannelProxy::Context::ClearChannel() { 351 void ChannelProxy::Context::ClearChannel() {
370 base::AutoLock l(channel_lifetime_lock_); 352 base::AutoLock l(channel_lifetime_lock_);
371 channel_.reset(); 353 channel_.reset();
354 associated_group_ = mojo::AssociatedGroup();
355 }
356
357 void ChannelProxy::Context::AddGenericAssociatedInterface(
358 const std::string& name,
359 const GenericAssociatedInterfaceFactory& factory) {
360 AddGenericAssociatedInterfaceForIOThread(
361 name, base::Bind(&BindAssociatedInterfaceOnTaskRunner,
362 listener_task_runner_, factory));
363 }
364
365 void ChannelProxy::Context::AddGenericAssociatedInterfaceForIOThread(
366 const std::string& name,
367 const GenericAssociatedInterfaceFactory& factory) {
368 base::AutoLock l(channel_lifetime_lock_);
369 if (!channel_) {
370 base::AutoLock l(pending_filters_lock_);
371 pending_interfaces_.emplace_back(name, factory);
372 return;
373 }
374 Channel::AssociatedInterfaceSupport* support =
375 channel_->GetAssociatedInterfaceSupport();
376 DCHECK(support);
377 support->AddGenericAssociatedInterface(name, factory);
372 } 378 }
373 379
374 void ChannelProxy::Context::SendFromThisThread(Message* message) { 380 void ChannelProxy::Context::SendFromThisThread(Message* message) {
375 base::AutoLock l(channel_lifetime_lock_); 381 base::AutoLock l(channel_lifetime_lock_);
376 if (!channel_) 382 if (!channel_)
377 return; 383 return;
378 DCHECK(channel_->IsSendThreadSafe()); 384 DCHECK(channel_->IsSendThreadSafe());
379 channel_->Send(message); 385 channel_->Send(message);
380 } 386 }
381 387
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 545 }
540 546
541 void ChannelProxy::RemoveFilter(MessageFilter* filter) { 547 void ChannelProxy::RemoveFilter(MessageFilter* filter) {
542 DCHECK(CalledOnValidThread()); 548 DCHECK(CalledOnValidThread());
543 549
544 context_->ipc_task_runner()->PostTask( 550 context_->ipc_task_runner()->PostTask(
545 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(), 551 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(),
546 base::RetainedRef(filter))); 552 base::RetainedRef(filter)));
547 } 553 }
548 554
555 void ChannelProxy::AddGenericAssociatedInterface(
556 const std::string& name,
557 const GenericAssociatedInterfaceFactory& factory) {
558 context()->AddGenericAssociatedInterface(name, factory);
559 }
560
549 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( 561 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread(
550 const std::string& name, 562 const std::string& name,
551 const GenericAssociatedInterfaceFactory& factory) { 563 const GenericAssociatedInterfaceFactory& factory) {
552 DCHECK(CalledOnValidThread()); 564 context()->AddGenericAssociatedInterfaceForIOThread(name, factory);
553 DCHECK(!did_init_);
554 context_->io_thread_interfaces_.insert({ name, factory });
555 }
556
557 void ChannelProxy::AddGenericAssociatedInterface(
558 const std::string& name,
559 const GenericAssociatedInterfaceFactory& factory) {
560 DCHECK(CalledOnValidThread());
561 DCHECK(!did_init_);
562 context_->proxy_thread_interfaces_.insert({ name, factory });
563 } 565 }
564 566
565 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() { 567 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() {
566 return context_->channel_associated_group_.get(); 568 return context()->associated_group();
567 } 569 }
568 570
569 void ChannelProxy::GetGenericRemoteAssociatedInterface( 571 void ChannelProxy::GetGenericRemoteAssociatedInterface(
570 const std::string& name, 572 const std::string& name,
571 mojo::ScopedInterfaceEndpointHandle handle) { 573 mojo::ScopedInterfaceEndpointHandle handle) {
572 context_->ipc_task_runner()->PostTask( 574 context_->ipc_task_runner()->PostTask(
573 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface, 575 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface,
574 context_.get(), name, base::Passed(&handle))); 576 context_.get(), name, base::Passed(&handle)));
575 } 577 }
576 578
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 return channel->TakeClientFileDescriptor(); 613 return channel->TakeClientFileDescriptor();
612 } 614 }
613 #endif 615 #endif
614 616
615 void ChannelProxy::OnChannelInit() { 617 void ChannelProxy::OnChannelInit() {
616 } 618 }
617 619
618 //----------------------------------------------------------------------------- 620 //-----------------------------------------------------------------------------
619 621
620 } // namespace IPC 622 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_message_pipe_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698