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

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

Issue 2231133002: Revert of Eliminate kMojoChannelToken usage for render processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
58 #include "content/public/common/content_switches.h" 57 #include "content/public/common/content_switches.h"
59 #include "content/public/common/mojo_channel_switches.h" 58 #include "content/public/common/mojo_channel_switches.h"
60 #include "content/public/common/mojo_shell_connection.h" 59 #include "content/public/common/mojo_shell_connection.h"
61 #include "ipc/attachment_broker.h" 60 #include "ipc/attachment_broker.h"
62 #include "ipc/attachment_broker_unprivileged.h" 61 #include "ipc/attachment_broker_unprivileged.h"
63 #include "ipc/ipc_channel_mojo.h" 62 #include "ipc/ipc_channel_mojo.h"
64 #include "ipc/ipc_logging.h" 63 #include "ipc/ipc_logging.h"
65 #include "ipc/ipc_platform_file.h" 64 #include "ipc/ipc_platform_file.h"
66 #include "ipc/ipc_switches.h" 65 #include "ipc/ipc_switches.h"
67 #include "ipc/ipc_sync_channel.h" 66 #include "ipc/ipc_sync_channel.h"
68 #include "ipc/ipc_sync_message_filter.h" 67 #include "ipc/ipc_sync_message_filter.h"
69 #include "mojo/edk/embedder/embedder.h" 68 #include "mojo/edk/embedder/embedder.h"
70 #include "mojo/edk/embedder/named_platform_channel_pair.h" 69 #include "mojo/edk/embedder/named_platform_channel_pair.h"
71 #include "mojo/edk/embedder/platform_channel_pair.h" 70 #include "mojo/edk/embedder/platform_channel_pair.h"
72 #include "mojo/edk/embedder/scoped_ipc_support.h" 71 #include "mojo/edk/embedder/scoped_ipc_support.h"
73 #include "services/shell/public/cpp/connector.h" 72 #include "services/shell/public/cpp/connector.h"
74 #include "services/shell/public/cpp/interface_factory.h"
75 #include "services/shell/public/cpp/interface_provider.h" 73 #include "services/shell/public/cpp/interface_provider.h"
76 #include "services/shell/public/cpp/interface_registry.h" 74 #include "services/shell/public/cpp/interface_registry.h"
77 #include "services/shell/runner/common/client_util.h" 75 #include "services/shell/runner/common/client_util.h"
78 76
79 #if defined(OS_POSIX) 77 #if defined(OS_POSIX)
80 #include "base/posix/global_descriptors.h" 78 #include "base/posix/global_descriptors.h"
81 #include "content/public/common/content_descriptors.h" 79 #include "content/public/common/content_descriptors.h"
82 #endif 80 #endif
83 81
84 using tracked_objects::ThreadData; 82 using tracked_objects::ThreadData;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 platform_channel.reset(mojo::edk::PlatformHandle( 250 platform_channel.reset(mojo::edk::PlatformHandle(
253 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); 251 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
254 #endif 252 #endif
255 // Mojo isn't supported on all child process types. 253 // Mojo isn't supported on all child process types.
256 // TODO(crbug.com/604282): Support Mojo in the remaining processes. 254 // TODO(crbug.com/604282): Support Mojo in the remaining processes.
257 if (!platform_channel.is_valid()) 255 if (!platform_channel.is_valid())
258 return; 256 return;
259 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); 257 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
260 } 258 }
261 259
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
293 } // namespace 260 } // namespace
294 261
295 ChildThread* ChildThread::Get() { 262 ChildThread* ChildThread::Get() {
296 return ChildThreadImpl::current(); 263 return ChildThreadImpl::current();
297 } 264 }
298 265
299 ChildThreadImpl::Options::Options() 266 ChildThreadImpl::Options::Options()
300 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 267 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
301 switches::kProcessChannelID)), 268 switches::kProcessChannelID)),
302 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( 269 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (IsInBrowserProcess()) 370 if (IsInBrowserProcess())
404 return browser_process_io_runner_; 371 return browser_process_io_runner_;
405 return ChildProcess::current()->io_task_runner(); 372 return ChildProcess::current()->io_task_runner();
406 } 373 }
407 374
408 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, 375 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel,
409 const std::string& ipc_token) { 376 const std::string& ipc_token) {
410 bool create_pipe_now = true; 377 bool create_pipe_now = true;
411 if (use_mojo_channel) { 378 if (use_mojo_channel) {
412 VLOG(1) << "Mojo is enabled on child"; 379 VLOG(1) << "Mojo is enabled on child";
413 std::string channel_token;
414 mojo::ScopedMessagePipeHandle handle; 380 mojo::ScopedMessagePipeHandle handle;
415 if (!IsInBrowserProcess()) { 381 if (!IsInBrowserProcess()) {
416 channel_token = 382 DCHECK(!handle.is_valid());
383 handle = mojo::edk::CreateChildMessagePipe(
417 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 384 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
418 switches::kMojoChannelToken); 385 switches::kMojoChannelToken));
419 } else { 386 } else {
420 channel_token = ipc_token; 387 handle = mojo::edk::CreateChildMessagePipe(ipc_token);
421 } 388 }
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
436 DCHECK(handle.is_valid()); 389 DCHECK(handle.is_valid());
437 channel_->Init( 390 channel_->Init(
438 IPC::ChannelMojo::CreateClientFactory( 391 IPC::ChannelMojo::CreateClientFactory(
439 std::move(handle), ChildProcess::current()->io_task_runner()), 392 std::move(handle), ChildProcess::current()->io_task_runner()),
440 create_pipe_now); 393 create_pipe_now);
441 return; 394 return;
442 } 395 }
443 396
444 VLOG(1) << "Mojo is disabled on child"; 397 VLOG(1) << "Mojo is disabled on child";
445 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); 398 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } else { 452 } else {
500 remote_interfaces = GetRemoteInterfaces(); 453 remote_interfaces = GetRemoteInterfaces();
501 } 454 }
502 455
503 // TODO(rockot): Remove this once all child-to-browser interface connections 456 // TODO(rockot): Remove this once all child-to-browser interface connections
504 // are made via a Connector rather than directly through an 457 // are made via a Connector rather than directly through an
505 // InterfaceProvider, and all exposed interfaces are exposed via a 458 // InterfaceProvider, and all exposed interfaces are exposed via a
506 // ConnectionFilter. 459 // ConnectionFilter.
507 mojo_shell_connection_->SetupInterfaceRequestProxies( 460 mojo_shell_connection_->SetupInterfaceRequestProxies(
508 GetInterfaceRegistry(), remote_interfaces); 461 GetInterfaceRegistry(), remote_interfaces);
462
463 if (options.auto_start_mojo_shell_connection)
464 StartMojoShellConnection();
509 } 465 }
510 466
511 sync_message_filter_ = channel_->CreateSyncMessageFilter(); 467 sync_message_filter_ = channel_->CreateSyncMessageFilter();
512 thread_safe_sender_ = new ThreadSafeSender( 468 thread_safe_sender_ = new ThreadSafeSender(
513 message_loop_->task_runner(), sync_message_filter_.get()); 469 message_loop_->task_runner(), sync_message_filter_.get());
514 470
515 resource_dispatcher_.reset(new ResourceDispatcher( 471 resource_dispatcher_.reset(new ResourceDispatcher(
516 this, message_loop()->task_runner())); 472 this, message_loop()->task_runner()));
517 websocket_dispatcher_.reset(new WebSocketDispatcher); 473 websocket_dispatcher_.reset(new WebSocketDispatcher);
518 file_system_dispatcher_.reset(new FileSystemDispatcher()); 474 file_system_dispatcher_.reset(new FileSystemDispatcher());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 #endif 525 #endif
570 526
571 // Add filters passed here via options. 527 // Add filters passed here via options.
572 for (auto* startup_filter : options.startup_filters) { 528 for (auto* startup_filter : options.startup_filters) {
573 channel_->AddFilter(startup_filter); 529 channel_->AddFilter(startup_filter);
574 } 530 }
575 531
576 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); 532 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
577 if (broker && !broker->IsPrivilegedBroker()) 533 if (broker && !broker->IsPrivilegedBroker())
578 broker->RegisterBrokerCommunicationChannel(channel_.get()); 534 broker->RegisterBrokerCommunicationChannel(channel_.get());
579
580 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); 535 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token);
581 536
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
587 int connection_timeout = kConnectionTimeoutS; 537 int connection_timeout = kConnectionTimeoutS;
588 std::string connection_override = 538 std::string connection_override =
589 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 539 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
590 switches::kIPCConnectionTimeout); 540 switches::kIPCConnectionTimeout);
591 if (!connection_override.empty()) { 541 if (!connection_override.empty()) {
592 int temp; 542 int temp;
593 if (base::StringToInt(connection_override, &temp)) 543 if (base::StringToInt(connection_override, &temp))
594 connection_timeout = temp; 544 connection_timeout = temp;
595 } 545 }
596 546
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 void ChildThreadImpl::EnsureConnected() { 810 void ChildThreadImpl::EnsureConnected() {
861 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; 811 VLOG(0) << "ChildThreadImpl::EnsureConnected()";
862 base::Process::Current().Terminate(0, false); 812 base::Process::Current().Terminate(0, false);
863 } 813 }
864 814
865 bool ChildThreadImpl::IsInBrowserProcess() const { 815 bool ChildThreadImpl::IsInBrowserProcess() const {
866 return static_cast<bool>(browser_process_io_runner_); 816 return static_cast<bool>(browser_process_io_runner_);
867 } 817 }
868 818
869 } // namespace content 819 } // 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