OLD | NEW |
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 Loading... |
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/common/child_process_messages.h" | 52 #include "content/common/child_process_messages.h" |
53 #include "content/common/in_process_child_thread_params.h" | 53 #include "content/common/in_process_child_thread_params.h" |
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/service_manager_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_sync_channel.h" | 64 #include "ipc/ipc_sync_channel.h" |
65 #include "ipc/ipc_sync_message_filter.h" | 65 #include "ipc/ipc_sync_message_filter.h" |
66 #include "mojo/edk/embedder/embedder.h" | 66 #include "mojo/edk/embedder/embedder.h" |
67 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 67 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 class ChannelBootstrapFilter : public ConnectionFilter { | 259 class ChannelBootstrapFilter : public ConnectionFilter { |
260 public: | 260 public: |
261 explicit ChannelBootstrapFilter(IPC::mojom::ChannelBootstrapPtrInfo bootstrap) | 261 explicit ChannelBootstrapFilter(IPC::mojom::ChannelBootstrapPtrInfo bootstrap) |
262 : bootstrap_(std::move(bootstrap)), weak_factory_(this) {} | 262 : bootstrap_(std::move(bootstrap)), weak_factory_(this) {} |
263 | 263 |
264 private: | 264 private: |
265 // ConnectionFilter: | 265 // ConnectionFilter: |
266 bool OnConnect(const shell::Identity& remote_identity, | 266 bool OnConnect(const shell::Identity& remote_identity, |
267 shell::InterfaceRegistry* registry, | 267 shell::InterfaceRegistry* registry, |
268 shell::Connector* connector) override { | 268 shell::Connector* connector) override { |
269 if (remote_identity.name() != kBrowserMojoApplicationName) | 269 if (remote_identity.name() != kBrowserServiceName) |
270 return false; | 270 return false; |
271 | 271 |
272 registry->AddInterface(base::Bind(&ChannelBootstrapFilter::CreateBootstrap, | 272 registry->AddInterface(base::Bind(&ChannelBootstrapFilter::CreateBootstrap, |
273 weak_factory_.GetWeakPtr())); | 273 weak_factory_.GetWeakPtr())); |
274 return true; | 274 return true; |
275 } | 275 } |
276 | 276 |
277 void CreateBootstrap(IPC::mojom::ChannelBootstrapRequest request) { | 277 void CreateBootstrap(IPC::mojom::ChannelBootstrapRequest request) { |
278 DCHECK(bootstrap_.is_valid()); | 278 DCHECK(bootstrap_.is_valid()); |
279 mojo::FuseInterface(std::move(request), std::move(bootstrap_)); | 279 mojo::FuseInterface(std::move(request), std::move(bootstrap_)); |
280 } | 280 } |
281 | 281 |
282 IPC::mojom::ChannelBootstrapPtrInfo bootstrap_; | 282 IPC::mojom::ChannelBootstrapPtrInfo bootstrap_; |
283 base::WeakPtrFactory<ChannelBootstrapFilter> weak_factory_; | 283 base::WeakPtrFactory<ChannelBootstrapFilter> weak_factory_; |
284 | 284 |
285 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); | 285 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); |
286 }; | 286 }; |
287 | 287 |
288 } // namespace | 288 } // namespace |
289 | 289 |
290 ChildThread* ChildThread::Get() { | 290 ChildThread* ChildThread::Get() { |
291 return ChildThreadImpl::current(); | 291 return ChildThreadImpl::current(); |
292 } | 292 } |
293 | 293 |
294 ChildThreadImpl::Options::Options() | 294 ChildThreadImpl::Options::Options() |
295 : auto_start_mojo_shell_connection(true), connect_to_browser(false) {} | 295 : auto_start_service_manager_connection(true), connect_to_browser(false) {} |
296 | 296 |
297 ChildThreadImpl::Options::Options(const Options& other) = default; | 297 ChildThreadImpl::Options::Options(const Options& other) = default; |
298 | 298 |
299 ChildThreadImpl::Options::~Options() { | 299 ChildThreadImpl::Options::~Options() { |
300 } | 300 } |
301 | 301 |
302 ChildThreadImpl::Options::Builder::Builder() { | 302 ChildThreadImpl::Options::Builder::Builder() { |
303 } | 303 } |
304 | 304 |
305 ChildThreadImpl::Options::Builder& | 305 ChildThreadImpl::Options::Builder& |
306 ChildThreadImpl::Options::Builder::InBrowserProcess( | 306 ChildThreadImpl::Options::Builder::InBrowserProcess( |
307 const InProcessChildThreadParams& params) { | 307 const InProcessChildThreadParams& params) { |
308 options_.browser_process_io_runner = params.io_runner(); | 308 options_.browser_process_io_runner = params.io_runner(); |
309 options_.in_process_application_token = params.application_token(); | 309 options_.in_process_service_request_token = params.service_request_token(); |
310 return *this; | 310 return *this; |
311 } | 311 } |
312 | 312 |
313 ChildThreadImpl::Options::Builder& | 313 ChildThreadImpl::Options::Builder& |
314 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection( | 314 ChildThreadImpl::Options::Builder::AutoStartServiceManagerConnection( |
315 bool auto_start) { | 315 bool auto_start) { |
316 options_.auto_start_mojo_shell_connection = auto_start; | 316 options_.auto_start_service_manager_connection = auto_start; |
317 return *this; | 317 return *this; |
318 } | 318 } |
319 | 319 |
320 ChildThreadImpl::Options::Builder& | 320 ChildThreadImpl::Options::Builder& |
321 ChildThreadImpl::Options::Builder::ConnectToBrowser( | 321 ChildThreadImpl::Options::Builder::ConnectToBrowser( |
322 bool connect_to_browser) { | 322 bool connect_to_browser) { |
323 options_.connect_to_browser = connect_to_browser; | 323 options_.connect_to_browser = connect_to_browser; |
324 return *this; | 324 return *this; |
325 } | 325 } |
326 | 326 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 392 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
393 switches::kMojoChannelToken); | 393 switches::kMojoChannelToken); |
394 } | 394 } |
395 | 395 |
396 if (!channel_token.empty()) { | 396 if (!channel_token.empty()) { |
397 // TODO(rockot): Remove all paths which lead to this branch. The Channel | 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 | 398 // connection should always be established by a shell connection from the |
399 // browser. http://crbug.com/623396. | 399 // browser. http://crbug.com/623396. |
400 handle = mojo::edk::CreateChildMessagePipe(channel_token); | 400 handle = mojo::edk::CreateChildMessagePipe(channel_token); |
401 } else { | 401 } else { |
402 DCHECK(mojo_shell_connection_); | 402 DCHECK(service_manager_connection_); |
403 IPC::mojom::ChannelBootstrapPtr bootstrap; | 403 IPC::mojom::ChannelBootstrapPtr bootstrap; |
404 handle = mojo::GetProxy(&bootstrap).PassMessagePipe(); | 404 handle = mojo::GetProxy(&bootstrap).PassMessagePipe(); |
405 mojo_shell_connection_->AddConnectionFilter( | 405 service_manager_connection_->AddConnectionFilter( |
406 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface())); | 406 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface())); |
407 } | 407 } |
408 | 408 |
409 DCHECK(handle.is_valid()); | 409 DCHECK(handle.is_valid()); |
410 channel_->Init( | 410 channel_->Init( |
411 IPC::ChannelMojo::CreateClientFactory( | 411 IPC::ChannelMojo::CreateClientFactory( |
412 std::move(handle), ChildProcess::current()->io_task_runner()), | 412 std::move(handle), ChildProcess::current()->io_task_runner()), |
413 true /* create_pipe_now */); | 413 true /* create_pipe_now */); |
414 } | 414 } |
415 | 415 |
(...skipping 16 matching lines...) Expand all Loading... |
432 #ifdef IPC_MESSAGE_LOG_ENABLED | 432 #ifdef IPC_MESSAGE_LOG_ENABLED |
433 if (!IsInBrowserProcess()) | 433 if (!IsInBrowserProcess()) |
434 IPC::Logging::GetInstance()->SetIPCSender(this); | 434 IPC::Logging::GetInstance()->SetIPCSender(this); |
435 #endif | 435 #endif |
436 | 436 |
437 if (!IsInBrowserProcess()) { | 437 if (!IsInBrowserProcess()) { |
438 // Don't double-initialize IPC support in single-process mode. | 438 // Don't double-initialize IPC support in single-process mode. |
439 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(GetIOTaskRunner())); | 439 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(GetIOTaskRunner())); |
440 InitializeMojoIPCChannel(); | 440 InitializeMojoIPCChannel(); |
441 } | 441 } |
442 std::string mojo_application_token; | 442 std::string service_request_token; |
443 if (!IsInBrowserProcess()) { | 443 if (!IsInBrowserProcess()) { |
444 mojo_application_token = | 444 service_request_token = |
445 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 445 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
446 switches::kMojoApplicationChannelToken); | 446 switches::kServiceRequestChannelToken); |
447 } else { | 447 } else { |
448 mojo_application_token = options.in_process_application_token; | 448 service_request_token = options.in_process_service_request_token; |
449 } | 449 } |
450 if (!mojo_application_token.empty()) { | 450 if (!service_request_token.empty()) { |
451 mojo::ScopedMessagePipeHandle handle = | 451 mojo::ScopedMessagePipeHandle handle = |
452 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 452 mojo::edk::CreateChildMessagePipe(service_request_token); |
453 DCHECK(handle.is_valid()); | 453 DCHECK(handle.is_valid()); |
454 mojo_shell_connection_ = MojoShellConnection::Create( | 454 service_manager_connection_ = ServiceManagerConnection::Create( |
455 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), | 455 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), |
456 GetIOTaskRunner()); | 456 GetIOTaskRunner()); |
457 | 457 |
458 // When connect_to_browser is true, we obtain interfaces from the browser | 458 // When connect_to_browser is true, we obtain interfaces from the browser |
459 // process by connecting to it, rather than from the incoming interface | 459 // process by connecting to it, rather than from the incoming interface |
460 // provider. Exposed interfaces are subject to manifest capability spec. | 460 // provider. Exposed interfaces are subject to manifest capability spec. |
461 shell::InterfaceProvider* remote_interfaces = nullptr; | 461 shell::InterfaceProvider* remote_interfaces = nullptr; |
462 if (options.connect_to_browser) { | 462 if (options.connect_to_browser) { |
463 browser_connection_ = mojo_shell_connection_->GetConnector()->Connect( | 463 browser_connection_ = |
464 kBrowserMojoApplicationName); | 464 service_manager_connection_->GetConnector()->Connect( |
| 465 kBrowserServiceName); |
465 } else { | 466 } else { |
466 remote_interfaces = GetRemoteInterfaces(); | 467 remote_interfaces = GetRemoteInterfaces(); |
467 } | 468 } |
468 | 469 |
469 // TODO(rockot): Remove this once all child-to-browser interface connections | 470 // TODO(rockot): Remove this once all child-to-browser interface connections |
470 // are made via a Connector rather than directly through an | 471 // are made via a Connector rather than directly through an |
471 // InterfaceProvider, and all exposed interfaces are exposed via a | 472 // InterfaceProvider, and all exposed interfaces are exposed via a |
472 // ConnectionFilter. | 473 // ConnectionFilter. |
473 mojo_shell_connection_->SetupInterfaceRequestProxies( | 474 service_manager_connection_->SetupInterfaceRequestProxies( |
474 GetInterfaceRegistry(), remote_interfaces); | 475 GetInterfaceRegistry(), remote_interfaces); |
475 } | 476 } |
476 | 477 |
477 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 478 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
478 thread_safe_sender_ = new ThreadSafeSender( | 479 thread_safe_sender_ = new ThreadSafeSender( |
479 message_loop_->task_runner(), sync_message_filter_.get()); | 480 message_loop_->task_runner(), sync_message_filter_.get()); |
480 | 481 |
481 resource_dispatcher_.reset(new ResourceDispatcher( | 482 resource_dispatcher_.reset(new ResourceDispatcher( |
482 this, message_loop()->task_runner())); | 483 this, message_loop()->task_runner())); |
483 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 484 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 broker->RegisterBrokerCommunicationChannel(channel_.get()); | 540 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
540 | 541 |
541 channel_->AddAssociatedInterface( | 542 channel_->AddAssociatedInterface( |
542 base::Bind(&ChildThreadImpl::OnRouteProviderRequest, | 543 base::Bind(&ChildThreadImpl::OnRouteProviderRequest, |
543 base::Unretained(this))); | 544 base::Unretained(this))); |
544 | 545 |
545 ConnectChannel(); | 546 ConnectChannel(); |
546 | 547 |
547 // This must always be done after ConnectChannel, because ConnectChannel() may | 548 // This must always be done after ConnectChannel, because ConnectChannel() may |
548 // add a ConnectionFilter to the connection. | 549 // add a ConnectionFilter to the connection. |
549 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_) | 550 if (options.auto_start_service_manager_connection && |
550 StartMojoShellConnection(); | 551 service_manager_connection_) { |
| 552 StartServiceManagerConnection(); |
| 553 } |
551 | 554 |
552 int connection_timeout = kConnectionTimeoutS; | 555 int connection_timeout = kConnectionTimeoutS; |
553 std::string connection_override = | 556 std::string connection_override = |
554 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 557 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
555 switches::kIPCConnectionTimeout); | 558 switches::kIPCConnectionTimeout); |
556 if (!connection_override.empty()) { | 559 if (!connection_override.empty()) { |
557 int temp; | 560 int temp; |
558 if (base::StringToInt(connection_override, &temp)) | 561 if (base::StringToInt(connection_override, &temp)) |
559 connection_timeout = temp; | 562 connection_timeout = temp; |
560 } | 563 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 #endif | 644 #endif |
642 | 645 |
643 void ChildThreadImpl::RecordAction(const base::UserMetricsAction& action) { | 646 void ChildThreadImpl::RecordAction(const base::UserMetricsAction& action) { |
644 NOTREACHED(); | 647 NOTREACHED(); |
645 } | 648 } |
646 | 649 |
647 void ChildThreadImpl::RecordComputedAction(const std::string& action) { | 650 void ChildThreadImpl::RecordComputedAction(const std::string& action) { |
648 NOTREACHED(); | 651 NOTREACHED(); |
649 } | 652 } |
650 | 653 |
651 MojoShellConnection* ChildThreadImpl::GetMojoShellConnection() { | 654 ServiceManagerConnection* ChildThreadImpl::GetServiceManagerConnection() { |
652 return mojo_shell_connection_.get(); | 655 return service_manager_connection_.get(); |
653 } | 656 } |
654 | 657 |
655 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { | 658 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { |
656 if (!interface_registry_.get()) | 659 if (!interface_registry_.get()) |
657 interface_registry_.reset(new shell::InterfaceRegistry); | 660 interface_registry_.reset(new shell::InterfaceRegistry); |
658 return interface_registry_.get(); | 661 return interface_registry_.get(); |
659 } | 662 } |
660 | 663 |
661 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 664 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
662 if (browser_connection_) | 665 if (browser_connection_) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 753 |
751 if (handled) | 754 if (handled) |
752 return true; | 755 return true; |
753 | 756 |
754 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 757 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
755 return OnControlMessageReceived(msg); | 758 return OnControlMessageReceived(msg); |
756 | 759 |
757 return router_.OnMessageReceived(msg); | 760 return router_.OnMessageReceived(msg); |
758 } | 761 } |
759 | 762 |
760 void ChildThreadImpl::StartMojoShellConnection() { | 763 void ChildThreadImpl::StartServiceManagerConnection() { |
761 DCHECK(mojo_shell_connection_); | 764 DCHECK(service_manager_connection_); |
762 mojo_shell_connection_->Start(); | 765 service_manager_connection_->Start(); |
763 } | 766 } |
764 | 767 |
765 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 768 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
766 return false; | 769 return false; |
767 } | 770 } |
768 | 771 |
769 void ChildThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 772 void ChildThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
770 // Set timer slack to maximum on main thread when in background. | 773 // Set timer slack to maximum on main thread when in background. |
771 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 774 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
772 if (backgrounded) | 775 if (backgrounded) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 Listener* route = router_.GetRoute(routing_id); | 864 Listener* route = router_.GetRoute(routing_id); |
862 if (route) | 865 if (route) |
863 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); | 866 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); |
864 } | 867 } |
865 | 868 |
866 bool ChildThreadImpl::IsInBrowserProcess() const { | 869 bool ChildThreadImpl::IsInBrowserProcess() const { |
867 return static_cast<bool>(browser_process_io_runner_); | 870 return static_cast<bool>(browser_process_io_runner_); |
868 } | 871 } |
869 | 872 |
870 } // namespace content | 873 } // namespace content |
OLD | NEW |