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

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

Issue 2389193004: Always use ChannelMojo for content child processes. (Closed)
Patch Set: Created 4 years, 2 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') | content/common/child_process_host_impl.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 "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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "content/public/common/connection_filter.h" 54 #include "content/public/common/connection_filter.h"
55 #include "content/public/common/content_switches.h" 55 #include "content/public/common/content_switches.h"
56 #include "content/public/common/mojo_channel_switches.h" 56 #include "content/public/common/mojo_channel_switches.h"
57 #include "content/public/common/mojo_shell_connection.h" 57 #include "content/public/common/mojo_shell_connection.h"
58 #include "content/public/common/service_names.h" 58 #include "content/public/common/service_names.h"
59 #include "ipc/attachment_broker.h" 59 #include "ipc/attachment_broker.h"
60 #include "ipc/attachment_broker_unprivileged.h" 60 #include "ipc/attachment_broker_unprivileged.h"
61 #include "ipc/ipc_channel_mojo.h" 61 #include "ipc/ipc_channel_mojo.h"
62 #include "ipc/ipc_logging.h" 62 #include "ipc/ipc_logging.h"
63 #include "ipc/ipc_platform_file.h" 63 #include "ipc/ipc_platform_file.h"
64 #include "ipc/ipc_switches.h"
65 #include "ipc/ipc_sync_channel.h" 64 #include "ipc/ipc_sync_channel.h"
66 #include "ipc/ipc_sync_message_filter.h" 65 #include "ipc/ipc_sync_message_filter.h"
67 #include "mojo/edk/embedder/embedder.h" 66 #include "mojo/edk/embedder/embedder.h"
68 #include "mojo/edk/embedder/named_platform_channel_pair.h" 67 #include "mojo/edk/embedder/named_platform_channel_pair.h"
69 #include "mojo/edk/embedder/platform_channel_pair.h" 68 #include "mojo/edk/embedder/platform_channel_pair.h"
70 #include "mojo/edk/embedder/scoped_ipc_support.h" 69 #include "mojo/edk/embedder/scoped_ipc_support.h"
71 #include "services/shell/public/cpp/connector.h" 70 #include "services/shell/public/cpp/connector.h"
72 #include "services/shell/public/cpp/interface_factory.h" 71 #include "services/shell/public/cpp/interface_factory.h"
73 #include "services/shell/public/cpp/interface_provider.h" 72 #include "services/shell/public/cpp/interface_provider.h"
74 #include "services/shell/public/cpp/interface_registry.h" 73 #include "services/shell/public/cpp/interface_registry.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); 285 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter);
287 }; 286 };
288 287
289 } // namespace 288 } // namespace
290 289
291 ChildThread* ChildThread::Get() { 290 ChildThread* ChildThread::Get() {
292 return ChildThreadImpl::current(); 291 return ChildThreadImpl::current();
293 } 292 }
294 293
295 ChildThreadImpl::Options::Options() 294 ChildThreadImpl::Options::Options()
296 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 295 : auto_start_mojo_shell_connection(true), connect_to_browser(false) {}
297 switches::kProcessChannelID)),
298 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
299 switches::kMojoApplicationChannelToken) ||
300 base::CommandLine::ForCurrentProcess()->HasSwitch(
301 switches::kMojoChannelToken)),
302 auto_start_mojo_shell_connection(true),
303 connect_to_browser(false) {}
304 296
305 ChildThreadImpl::Options::Options(const Options& other) = default; 297 ChildThreadImpl::Options::Options(const Options& other) = default;
306 298
307 ChildThreadImpl::Options::~Options() { 299 ChildThreadImpl::Options::~Options() {
308 } 300 }
309 301
310 ChildThreadImpl::Options::Builder::Builder() { 302 ChildThreadImpl::Options::Builder::Builder() {
311 } 303 }
312 304
313 ChildThreadImpl::Options::Builder& 305 ChildThreadImpl::Options::Builder&
314 ChildThreadImpl::Options::Builder::InBrowserProcess( 306 ChildThreadImpl::Options::Builder::InBrowserProcess(
315 const InProcessChildThreadParams& params) { 307 const InProcessChildThreadParams& params) {
316 options_.browser_process_io_runner = params.io_runner(); 308 options_.browser_process_io_runner = params.io_runner();
317 options_.channel_name = params.channel_name();
318 options_.in_process_application_token = params.application_token(); 309 options_.in_process_application_token = params.application_token();
319 return *this; 310 return *this;
320 } 311 }
321 312
322 ChildThreadImpl::Options::Builder& 313 ChildThreadImpl::Options::Builder&
323 ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel) {
324 options_.use_mojo_channel = use_mojo_channel;
325 return *this;
326 }
327
328 ChildThreadImpl::Options::Builder&
329 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection( 314 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection(
330 bool auto_start) { 315 bool auto_start) {
331 options_.auto_start_mojo_shell_connection = auto_start; 316 options_.auto_start_mojo_shell_connection = auto_start;
332 return *this; 317 return *this;
333 } 318 }
334 319
335 ChildThreadImpl::Options::Builder& 320 ChildThreadImpl::Options::Builder&
336 ChildThreadImpl::Options::Builder::ConnectToBrowser( 321 ChildThreadImpl::Options::Builder::ConnectToBrowser(
337 bool connect_to_browser) { 322 bool connect_to_browser) {
338 options_.connect_to_browser = connect_to_browser; 323 options_.connect_to_browser = connect_to_browser;
339 return *this; 324 return *this;
340 } 325 }
341 326
342 ChildThreadImpl::Options::Builder& 327 ChildThreadImpl::Options::Builder&
343 ChildThreadImpl::Options::Builder::WithChannelName(
344 const std::string& channel_name) {
345 options_.channel_name = channel_name;
346 return *this;
347 }
348
349 ChildThreadImpl::Options::Builder&
350 ChildThreadImpl::Options::Builder::AddStartupFilter( 328 ChildThreadImpl::Options::Builder::AddStartupFilter(
351 IPC::MessageFilter* filter) { 329 IPC::MessageFilter* filter) {
352 options_.startup_filters.push_back(filter); 330 options_.startup_filters.push_back(filter);
353 return *this; 331 return *this;
354 } 332 }
355 333
356 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { 334 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() {
357 return options_; 335 return options_;
358 } 336 }
359 337
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 weak_factory_(this) { 378 weak_factory_(this) {
401 Init(options); 379 Init(options);
402 } 380 }
403 381
404 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { 382 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() {
405 if (IsInBrowserProcess()) 383 if (IsInBrowserProcess())
406 return browser_process_io_runner_; 384 return browser_process_io_runner_;
407 return ChildProcess::current()->io_task_runner(); 385 return ChildProcess::current()->io_task_runner();
408 } 386 }
409 387
410 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { 388 void ChildThreadImpl::ConnectChannel() {
411 bool create_pipe_now = true; 389 std::string channel_token;
412 if (use_mojo_channel) { 390 mojo::ScopedMessagePipeHandle handle;
413 VLOG(1) << "Mojo is enabled on child"; 391 if (!IsInBrowserProcess()) {
414 std::string channel_token; 392 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
415 mojo::ScopedMessagePipeHandle handle; 393 switches::kMojoChannelToken);
416 if (!IsInBrowserProcess()) {
417 channel_token =
418 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
419 switches::kMojoChannelToken);
420 }
421
422 if (!channel_token.empty()) {
423 // TODO(rockot): Remove all paths which lead to this branch. The Channel
424 // connection should always be established by a shell connection from the
425 // browser. http://crbug.com/623396.
426 handle = mojo::edk::CreateChildMessagePipe(channel_token);
427 } else {
428 DCHECK(mojo_shell_connection_);
429 IPC::mojom::ChannelBootstrapPtr bootstrap;
430 handle = mojo::GetProxy(&bootstrap).PassMessagePipe();
431 mojo_shell_connection_->AddConnectionFilter(
432 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
433 }
434
435 DCHECK(handle.is_valid());
436 channel_->Init(
437 IPC::ChannelMojo::CreateClientFactory(
438 std::move(handle), ChildProcess::current()->io_task_runner()),
439 create_pipe_now);
440 return;
441 } 394 }
442 395
443 VLOG(1) << "Mojo is disabled on child"; 396 if (!channel_token.empty()) {
444 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); 397 // TODO(rockot): Remove all paths which lead to this branch. The Channel
398 // connection should always be established by a shell connection from the
399 // browser. http://crbug.com/623396.
400 handle = mojo::edk::CreateChildMessagePipe(channel_token);
401 } else {
402 DCHECK(mojo_shell_connection_);
403 IPC::mojom::ChannelBootstrapPtr bootstrap;
404 handle = mojo::GetProxy(&bootstrap).PassMessagePipe();
405 mojo_shell_connection_->AddConnectionFilter(
406 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
407 }
408
409 DCHECK(handle.is_valid());
410 channel_->Init(
411 IPC::ChannelMojo::CreateClientFactory(
412 std::move(handle), ChildProcess::current()->io_task_runner()),
413 true /* create_pipe_now */);
445 } 414 }
446 415
447 void ChildThreadImpl::Init(const Options& options) { 416 void ChildThreadImpl::Init(const Options& options) {
448 channel_name_ = options.channel_name;
449
450 g_lazy_tls.Pointer()->Set(this); 417 g_lazy_tls.Pointer()->Set(this);
451 on_channel_error_called_ = false; 418 on_channel_error_called_ = false;
452 message_loop_ = base::MessageLoop::current(); 419 message_loop_ = base::MessageLoop::current();
453 #ifdef IPC_MESSAGE_LOG_ENABLED 420 #ifdef IPC_MESSAGE_LOG_ENABLED
454 // We must make sure to instantiate the IPC Logger *before* we create the 421 // We must make sure to instantiate the IPC Logger *before* we create the
455 // channel, otherwise we can get a callback on the IO thread which creates 422 // channel, otherwise we can get a callback on the IO thread which creates
456 // the logger, and the logger does not like being created on the IO thread. 423 // the logger, and the logger does not like being created on the IO thread.
457 IPC::Logging::GetInstance(); 424 IPC::Logging::GetInstance();
458 #endif 425 #endif
459 426
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 535 }
569 536
570 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); 537 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
571 if (broker && !broker->IsPrivilegedBroker()) 538 if (broker && !broker->IsPrivilegedBroker())
572 broker->RegisterBrokerCommunicationChannel(channel_.get()); 539 broker->RegisterBrokerCommunicationChannel(channel_.get());
573 540
574 channel_->AddAssociatedInterface( 541 channel_->AddAssociatedInterface(
575 base::Bind(&ChildThreadImpl::OnRouteProviderRequest, 542 base::Bind(&ChildThreadImpl::OnRouteProviderRequest,
576 base::Unretained(this))); 543 base::Unretained(this)));
577 544
578 ConnectChannel(options.use_mojo_channel); 545 ConnectChannel();
579 546
580 // This must always be done after ConnectChannel, because ConnectChannel() may 547 // This must always be done after ConnectChannel, because ConnectChannel() may
581 // add a ConnectionFilter to the connection. 548 // add a ConnectionFilter to the connection.
582 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_) 549 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_)
583 StartMojoShellConnection(); 550 StartMojoShellConnection();
584 551
585 int connection_timeout = kConnectionTimeoutS; 552 int connection_timeout = kConnectionTimeoutS;
586 std::string connection_override = 553 std::string connection_override =
587 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 554 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
588 switches::kIPCConnectionTimeout); 555 switches::kIPCConnectionTimeout);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 Listener* route = router_.GetRoute(routing_id); 861 Listener* route = router_.GetRoute(routing_id);
895 if (route) 862 if (route)
896 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); 863 route->OnAssociatedInterfaceRequest(name, request.PassHandle());
897 } 864 }
898 865
899 bool ChildThreadImpl::IsInBrowserProcess() const { 866 bool ChildThreadImpl::IsInBrowserProcess() const {
900 return static_cast<bool>(browser_process_io_runner_); 867 return static_cast<bool>(browser_process_io_runner_);
901 } 868 }
902 869
903 } // namespace content 870 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_thread_impl.h ('k') | content/common/child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698