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

Side by Side Diff: content/child/child_thread_impl.cc

Issue 2201183005: Eliminate kMojoChannelToken usage for render processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 | « content/child/child_thread_impl.h ('k') | ipc/ipc.mojom » ('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 "content/child/child_thread_impl.h" 5 #include "content/child/child_thread_impl.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "content/child/quota_dispatcher.h" 47 #include "content/child/quota_dispatcher.h"
48 #include "content/child/quota_message_filter.h" 48 #include "content/child/quota_message_filter.h"
49 #include "content/child/resource_dispatcher.h" 49 #include "content/child/resource_dispatcher.h"
50 #include "content/child/service_worker/service_worker_message_filter.h" 50 #include "content/child/service_worker/service_worker_message_filter.h"
51 #include "content/child/thread_safe_sender.h" 51 #include "content/child/thread_safe_sender.h"
52 #include "content/child/websocket_dispatcher.h" 52 #include "content/child/websocket_dispatcher.h"
53 #include "content/child/websocket_message_filter.h" 53 #include "content/child/websocket_message_filter.h"
54 #include "content/common/child_process_messages.h" 54 #include "content/common/child_process_messages.h"
55 #include "content/common/in_process_child_thread_params.h" 55 #include "content/common/in_process_child_thread_params.h"
56 #include "content/common/mojo/constants.h" 56 #include "content/common/mojo/constants.h"
57 #include "content/public/common/connection_filter.h"
57 #include "content/public/common/content_switches.h" 58 #include "content/public/common/content_switches.h"
58 #include "content/public/common/mojo_channel_switches.h" 59 #include "content/public/common/mojo_channel_switches.h"
59 #include "content/public/common/mojo_shell_connection.h" 60 #include "content/public/common/mojo_shell_connection.h"
60 #include "ipc/attachment_broker.h" 61 #include "ipc/attachment_broker.h"
61 #include "ipc/attachment_broker_unprivileged.h" 62 #include "ipc/attachment_broker_unprivileged.h"
62 #include "ipc/ipc_channel_mojo.h" 63 #include "ipc/ipc_channel_mojo.h"
63 #include "ipc/ipc_logging.h" 64 #include "ipc/ipc_logging.h"
64 #include "ipc/ipc_platform_file.h" 65 #include "ipc/ipc_platform_file.h"
65 #include "ipc/ipc_switches.h" 66 #include "ipc/ipc_switches.h"
66 #include "ipc/ipc_sync_channel.h" 67 #include "ipc/ipc_sync_channel.h"
67 #include "ipc/ipc_sync_message_filter.h" 68 #include "ipc/ipc_sync_message_filter.h"
68 #include "mojo/edk/embedder/embedder.h" 69 #include "mojo/edk/embedder/embedder.h"
69 #include "mojo/edk/embedder/named_platform_channel_pair.h" 70 #include "mojo/edk/embedder/named_platform_channel_pair.h"
70 #include "mojo/edk/embedder/platform_channel_pair.h" 71 #include "mojo/edk/embedder/platform_channel_pair.h"
71 #include "mojo/edk/embedder/scoped_ipc_support.h" 72 #include "mojo/edk/embedder/scoped_ipc_support.h"
72 #include "services/shell/public/cpp/connector.h" 73 #include "services/shell/public/cpp/connector.h"
74 #include "services/shell/public/cpp/interface_factory.h"
73 #include "services/shell/public/cpp/interface_provider.h" 75 #include "services/shell/public/cpp/interface_provider.h"
74 #include "services/shell/public/cpp/interface_registry.h" 76 #include "services/shell/public/cpp/interface_registry.h"
75 #include "services/shell/runner/common/client_util.h" 77 #include "services/shell/runner/common/client_util.h"
76 78
77 #if defined(OS_POSIX) 79 #if defined(OS_POSIX)
78 #include "base/posix/global_descriptors.h" 80 #include "base/posix/global_descriptors.h"
79 #include "content/public/common/content_descriptors.h" 81 #include "content/public/common/content_descriptors.h"
80 #endif 82 #endif
81 83
82 using tracked_objects::ThreadData; 84 using tracked_objects::ThreadData;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 platform_channel.reset(mojo::edk::PlatformHandle( 252 platform_channel.reset(mojo::edk::PlatformHandle(
251 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); 253 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
252 #endif 254 #endif
253 // Mojo isn't supported on all child process types. 255 // Mojo isn't supported on all child process types.
254 // TODO(crbug.com/604282): Support Mojo in the remaining processes. 256 // TODO(crbug.com/604282): Support Mojo in the remaining processes.
255 if (!platform_channel.is_valid()) 257 if (!platform_channel.is_valid())
256 return; 258 return;
257 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); 259 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
258 } 260 }
259 261
262 class ChannelBootstrapFilter
263 : public ConnectionFilter,
264 public shell::InterfaceFactory<IPC::mojom::ChannelBootstrap> {
265 public:
266 explicit ChannelBootstrapFilter(IPC::mojom::ChannelBootstrapPtrInfo bootstrap)
267 : bootstrap_(std::move(bootstrap)) {}
268
269 private:
270 // ConnectionFilter:
271 bool OnConnect(const shell::Identity& remote_identity,
272 shell::InterfaceRegistry* registry,
273 shell::Connector* connector) override {
274 if (remote_identity.name() != kBrowserMojoApplicationName)
275 return false;
276
277 registry->AddInterface<IPC::mojom::ChannelBootstrap>(this);
278 return true;
279 }
280
281 // shell::InterfaceFactory<IPC::mojom::ChannelBootstrap>:
282 void Create(const shell::Identity& remote_identity,
283 IPC::mojom::ChannelBootstrapRequest request) override {
284 DCHECK(bootstrap_.is_valid());
285 mojo::FuseInterface(std::move(request), std::move(bootstrap_));
286 }
287
288 IPC::mojom::ChannelBootstrapPtrInfo bootstrap_;
289
290 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter);
291 };
292
260 } // namespace 293 } // namespace
261 294
262 ChildThread* ChildThread::Get() { 295 ChildThread* ChildThread::Get() {
263 return ChildThreadImpl::current(); 296 return ChildThreadImpl::current();
264 } 297 }
265 298
266 ChildThreadImpl::Options::Options() 299 ChildThreadImpl::Options::Options()
267 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 300 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
268 switches::kProcessChannelID)), 301 switches::kProcessChannelID)),
269 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( 302 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (IsInBrowserProcess()) 403 if (IsInBrowserProcess())
371 return browser_process_io_runner_; 404 return browser_process_io_runner_;
372 return ChildProcess::current()->io_task_runner(); 405 return ChildProcess::current()->io_task_runner();
373 } 406 }
374 407
375 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, 408 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel,
376 const std::string& ipc_token) { 409 const std::string& ipc_token) {
377 bool create_pipe_now = true; 410 bool create_pipe_now = true;
378 if (use_mojo_channel) { 411 if (use_mojo_channel) {
379 VLOG(1) << "Mojo is enabled on child"; 412 VLOG(1) << "Mojo is enabled on child";
413 std::string channel_token;
380 mojo::ScopedMessagePipeHandle handle; 414 mojo::ScopedMessagePipeHandle handle;
381 if (!IsInBrowserProcess()) { 415 if (!IsInBrowserProcess()) {
382 DCHECK(!handle.is_valid()); 416 channel_token =
383 handle = mojo::edk::CreateChildMessagePipe(
384 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 417 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
385 switches::kMojoChannelToken)); 418 switches::kMojoChannelToken);
386 } else { 419 } else {
387 handle = mojo::edk::CreateChildMessagePipe(ipc_token); 420 channel_token = ipc_token;
388 } 421 }
422
423 if (!channel_token.empty()) {
424 // TODO(rockot): Remove all paths which lead to this branch. The Channel
425 // connection should always be established by a shell connection from the
426 // browser. http://crbug.com/623396.
427 handle = mojo::edk::CreateChildMessagePipe(channel_token);
428 } else {
429 DCHECK(mojo_shell_connection_);
430 IPC::mojom::ChannelBootstrapPtr bootstrap;
431 handle = mojo::GetProxy(&bootstrap).PassMessagePipe();
432 mojo_shell_connection_->AddConnectionFilter(
433 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
434 }
435
389 DCHECK(handle.is_valid()); 436 DCHECK(handle.is_valid());
390 channel_->Init( 437 channel_->Init(
391 IPC::ChannelMojo::CreateClientFactory( 438 IPC::ChannelMojo::CreateClientFactory(
392 std::move(handle), ChildProcess::current()->io_task_runner()), 439 std::move(handle), ChildProcess::current()->io_task_runner()),
393 create_pipe_now); 440 create_pipe_now);
394 return; 441 return;
395 } 442 }
396 443
397 VLOG(1) << "Mojo is disabled on child"; 444 VLOG(1) << "Mojo is disabled on child";
398 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); 445 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } else { 499 } else {
453 remote_interfaces = GetRemoteInterfaces(); 500 remote_interfaces = GetRemoteInterfaces();
454 } 501 }
455 502
456 // TODO(rockot): Remove this once all child-to-browser interface connections 503 // TODO(rockot): Remove this once all child-to-browser interface connections
457 // are made via a Connector rather than directly through an 504 // are made via a Connector rather than directly through an
458 // InterfaceProvider, and all exposed interfaces are exposed via a 505 // InterfaceProvider, and all exposed interfaces are exposed via a
459 // ConnectionFilter. 506 // ConnectionFilter.
460 mojo_shell_connection_->SetupInterfaceRequestProxies( 507 mojo_shell_connection_->SetupInterfaceRequestProxies(
461 GetInterfaceRegistry(), remote_interfaces); 508 GetInterfaceRegistry(), remote_interfaces);
462
463 if (options.auto_start_mojo_shell_connection)
464 StartMojoShellConnection();
465 } 509 }
466 510
467 sync_message_filter_ = channel_->CreateSyncMessageFilter(); 511 sync_message_filter_ = channel_->CreateSyncMessageFilter();
468 thread_safe_sender_ = new ThreadSafeSender( 512 thread_safe_sender_ = new ThreadSafeSender(
469 message_loop_->task_runner(), sync_message_filter_.get()); 513 message_loop_->task_runner(), sync_message_filter_.get());
470 514
471 resource_dispatcher_.reset(new ResourceDispatcher( 515 resource_dispatcher_.reset(new ResourceDispatcher(
472 this, message_loop()->task_runner())); 516 this, message_loop()->task_runner()));
473 websocket_dispatcher_.reset(new WebSocketDispatcher); 517 websocket_dispatcher_.reset(new WebSocketDispatcher);
474 file_system_dispatcher_.reset(new FileSystemDispatcher()); 518 file_system_dispatcher_.reset(new FileSystemDispatcher());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 #endif 569 #endif
526 570
527 // Add filters passed here via options. 571 // Add filters passed here via options.
528 for (auto* startup_filter : options.startup_filters) { 572 for (auto* startup_filter : options.startup_filters) {
529 channel_->AddFilter(startup_filter); 573 channel_->AddFilter(startup_filter);
530 } 574 }
531 575
532 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); 576 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
533 if (broker && !broker->IsPrivilegedBroker()) 577 if (broker && !broker->IsPrivilegedBroker())
534 broker->RegisterBrokerCommunicationChannel(channel_.get()); 578 broker->RegisterBrokerCommunicationChannel(channel_.get());
579
535 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); 580 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token);
536 581
582 // This must always be done after ConnectChannel, because ConnectChannel() may
583 // add a ConnectionFilter to the connection.
584 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_)
585 StartMojoShellConnection();
586
537 int connection_timeout = kConnectionTimeoutS; 587 int connection_timeout = kConnectionTimeoutS;
538 std::string connection_override = 588 std::string connection_override =
539 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 589 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
540 switches::kIPCConnectionTimeout); 590 switches::kIPCConnectionTimeout);
541 if (!connection_override.empty()) { 591 if (!connection_override.empty()) {
542 int temp; 592 int temp;
543 if (base::StringToInt(connection_override, &temp)) 593 if (base::StringToInt(connection_override, &temp))
544 connection_timeout = temp; 594 connection_timeout = temp;
545 } 595 }
546 596
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 void ChildThreadImpl::EnsureConnected() { 860 void ChildThreadImpl::EnsureConnected() {
811 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; 861 VLOG(0) << "ChildThreadImpl::EnsureConnected()";
812 base::Process::Current().Terminate(0, false); 862 base::Process::Current().Terminate(0, false);
813 } 863 }
814 864
815 bool ChildThreadImpl::IsInBrowserProcess() const { 865 bool ChildThreadImpl::IsInBrowserProcess() const {
816 return static_cast<bool>(browser_process_io_runner_); 866 return static_cast<bool>(browser_process_io_runner_);
817 } 867 }
818 868
819 } // namespace content 869 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_thread_impl.h ('k') | ipc/ipc.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698