| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/public/common/content_switches.h" | 56 #include "content/public/common/content_switches.h" |
| 57 #include "content/public/common/mojo_channel_switches.h" | 57 #include "content/public/common/mojo_channel_switches.h" |
| 58 #include "content/public/common/mojo_shell_connection.h" | 58 #include "content/public/common/mojo_shell_connection.h" |
| 59 #include "ipc/attachment_broker.h" | |
| 60 #include "ipc/attachment_broker_unprivileged.h" | |
| 61 #include "ipc/ipc_channel_mojo.h" | 59 #include "ipc/ipc_channel_mojo.h" |
| 62 #include "ipc/ipc_logging.h" | 60 #include "ipc/ipc_logging.h" |
| 63 #include "ipc/ipc_platform_file.h" | 61 #include "ipc/ipc_platform_file.h" |
| 64 #include "ipc/ipc_switches.h" | 62 #include "ipc/ipc_switches.h" |
| 65 #include "ipc/ipc_sync_channel.h" | 63 #include "ipc/ipc_sync_channel.h" |
| 66 #include "ipc/ipc_sync_message_filter.h" | 64 #include "ipc/ipc_sync_message_filter.h" |
| 67 #include "mojo/edk/embedder/embedder.h" | 65 #include "mojo/edk/embedder/embedder.h" |
| 68 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 66 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 69 #include "mojo/edk/embedder/platform_channel_pair.h" | 67 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 70 #include "mojo/edk/embedder/scoped_ipc_support.h" | 68 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 g_lazy_tls.Pointer()->Set(this); | 392 g_lazy_tls.Pointer()->Set(this); |
| 395 on_channel_error_called_ = false; | 393 on_channel_error_called_ = false; |
| 396 message_loop_ = base::MessageLoop::current(); | 394 message_loop_ = base::MessageLoop::current(); |
| 397 #ifdef IPC_MESSAGE_LOG_ENABLED | 395 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 398 // We must make sure to instantiate the IPC Logger *before* we create the | 396 // We must make sure to instantiate the IPC Logger *before* we create the |
| 399 // channel, otherwise we can get a callback on the IO thread which creates | 397 // channel, otherwise we can get a callback on the IO thread which creates |
| 400 // the logger, and the logger does not like being created on the IO thread. | 398 // the logger, and the logger does not like being created on the IO thread. |
| 401 IPC::Logging::GetInstance(); | 399 IPC::Logging::GetInstance(); |
| 402 #endif | 400 #endif |
| 403 | 401 |
| 404 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | |
| 405 | |
| 406 channel_ = | 402 channel_ = |
| 407 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 403 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
| 408 ChildProcess::current()->GetShutDownEvent()); | 404 ChildProcess::current()->GetShutDownEvent()); |
| 409 #ifdef IPC_MESSAGE_LOG_ENABLED | 405 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 410 if (!IsInBrowserProcess()) | 406 if (!IsInBrowserProcess()) |
| 411 IPC::Logging::GetInstance()->SetIPCSender(this); | 407 IPC::Logging::GetInstance()->SetIPCSender(this); |
| 412 #endif | 408 #endif |
| 413 | 409 |
| 414 if (!IsInBrowserProcess()) { | 410 if (!IsInBrowserProcess()) { |
| 415 // Don't double-initialize IPC support in single-process mode. | 411 // Don't double-initialize IPC support in single-process mode. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // and single-process mode. | 497 // and single-process mode. |
| 502 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 498 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
| 503 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 499 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
| 504 #endif | 500 #endif |
| 505 | 501 |
| 506 // Add filters passed here via options. | 502 // Add filters passed here via options. |
| 507 for (auto startup_filter : options.startup_filters) { | 503 for (auto startup_filter : options.startup_filters) { |
| 508 channel_->AddFilter(startup_filter); | 504 channel_->AddFilter(startup_filter); |
| 509 } | 505 } |
| 510 | 506 |
| 511 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | |
| 512 if (broker && !broker->IsPrivilegedBroker()) | |
| 513 broker->RegisterBrokerCommunicationChannel(channel_.get()); | |
| 514 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); | 507 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); |
| 515 | 508 |
| 516 int connection_timeout = kConnectionTimeoutS; | 509 int connection_timeout = kConnectionTimeoutS; |
| 517 std::string connection_override = | 510 std::string connection_override = |
| 518 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 511 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 519 switches::kIPCConnectionTimeout); | 512 switches::kIPCConnectionTimeout); |
| 520 if (!connection_override.empty()) { | 513 if (!connection_override.empty()) { |
| 521 int temp; | 514 int temp; |
| 522 if (base::StringToInt(connection_override, &temp)) | 515 if (base::StringToInt(connection_override, &temp)) |
| 523 connection_timeout = temp; | 516 connection_timeout = temp; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 540 | 533 |
| 541 discardable_shared_memory_manager_.reset( | 534 discardable_shared_memory_manager_.reset( |
| 542 new ChildDiscardableSharedMemoryManager(thread_safe_sender())); | 535 new ChildDiscardableSharedMemoryManager(thread_safe_sender())); |
| 543 } | 536 } |
| 544 | 537 |
| 545 ChildThreadImpl::~ChildThreadImpl() { | 538 ChildThreadImpl::~ChildThreadImpl() { |
| 546 #ifdef IPC_MESSAGE_LOG_ENABLED | 539 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 547 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 540 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
| 548 #endif | 541 #endif |
| 549 | 542 |
| 550 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | |
| 551 if (broker && !broker->IsPrivilegedBroker()) | |
| 552 broker->DeregisterBrokerCommunicationChannel(channel_.get()); | |
| 553 | |
| 554 channel_->RemoveFilter(histogram_message_filter_.get()); | 543 channel_->RemoveFilter(histogram_message_filter_.get()); |
| 555 channel_->RemoveFilter(sync_message_filter_.get()); | 544 channel_->RemoveFilter(sync_message_filter_.get()); |
| 556 | 545 |
| 557 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 546 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
| 558 // reset it as it's not guaranteed to outlive this object. | 547 // reset it as it's not guaranteed to outlive this object. |
| 559 // NOTE: this also has the side-effect of not closing the main IPC channel to | 548 // NOTE: this also has the side-effect of not closing the main IPC channel to |
| 560 // the browser process. This is needed because this is the signal that the | 549 // the browser process. This is needed because this is the signal that the |
| 561 // browser uses to know that this process has died, so we need it to be alive | 550 // browser uses to know that this process has died, so we need it to be alive |
| 562 // until this process is shut down, and the OS closes the handle | 551 // until this process is shut down, and the OS closes the handle |
| 563 // automatically. We used to watch the object handle on Windows to do this, | 552 // automatically. We used to watch the object handle on Windows to do this, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 void ChildThreadImpl::EnsureConnected() { | 775 void ChildThreadImpl::EnsureConnected() { |
| 787 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 776 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
| 788 base::Process::Current().Terminate(0, false); | 777 base::Process::Current().Terminate(0, false); |
| 789 } | 778 } |
| 790 | 779 |
| 791 bool ChildThreadImpl::IsInBrowserProcess() const { | 780 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 792 return static_cast<bool>(browser_process_io_runner_); | 781 return static_cast<bool>(browser_process_io_runner_); |
| 793 } | 782 } |
| 794 | 783 |
| 795 } // namespace content | 784 } // namespace content |
| OLD | NEW |