Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "chrome/common/child_thread.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/string_util.h" |
michael@0 | 8 | #include "base/command_line.h" |
michael@0 | 9 | #include "chrome/common/child_process.h" |
michael@0 | 10 | #include "chrome/common/chrome_switches.h" |
michael@0 | 11 | #include "chrome/common/ipc_logging.h" |
michael@0 | 12 | |
michael@0 | 13 | // V8 needs a 1MB stack size. |
michael@0 | 14 | const size_t ChildThread::kV8StackSize = 1024 * 1024; |
michael@0 | 15 | |
michael@0 | 16 | ChildThread::ChildThread(Thread::Options options) |
michael@0 | 17 | : Thread("Chrome_ChildThread"), |
michael@0 | 18 | owner_loop_(MessageLoop::current()), |
michael@0 | 19 | options_(options), |
michael@0 | 20 | check_with_browser_before_shutdown_(false) { |
michael@0 | 21 | DCHECK(owner_loop_); |
michael@0 | 22 | channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValue( |
michael@0 | 23 | switches::kProcessChannelID); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | ChildThread::~ChildThread() { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | #ifdef MOZ_NUWA_PROCESS |
michael@0 | 30 | #include "ipc/Nuwa.h" |
michael@0 | 31 | #endif |
michael@0 | 32 | |
michael@0 | 33 | bool ChildThread::Run() { |
michael@0 | 34 | bool r = StartWithOptions(options_); |
michael@0 | 35 | #ifdef MOZ_NUWA_PROCESS |
michael@0 | 36 | NS_ASSERTION(NuwaMarkCurrentThread, "NuwaMarkCurrentThread is not defined!"); |
michael@0 | 37 | if (IsNuwaProcess()) { |
michael@0 | 38 | message_loop()->PostTask(FROM_HERE, |
michael@0 | 39 | NewRunnableFunction(&ChildThread::MarkThread)); |
michael@0 | 40 | } |
michael@0 | 41 | #endif |
michael@0 | 42 | return r; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void ChildThread::OnChannelError() { |
michael@0 | 46 | owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | #ifdef MOZ_NUWA_PROCESS |
michael@0 | 50 | void ChildThread::MarkThread() { |
michael@0 | 51 | NuwaMarkCurrentThread(nullptr, nullptr); |
michael@0 | 52 | if (!NuwaCheckpointCurrentThread()) { |
michael@0 | 53 | NS_RUNTIMEABORT("Should not be here!"); |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | #endif |
michael@0 | 57 | |
michael@0 | 58 | bool ChildThread::Send(IPC::Message* msg) { |
michael@0 | 59 | if (!channel_.get()) { |
michael@0 | 60 | delete msg; |
michael@0 | 61 | return false; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | return channel_->Send(msg); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | void ChildThread::AddRoute(int32_t routing_id, IPC::Channel::Listener* listener) { |
michael@0 | 68 | DCHECK(MessageLoop::current() == message_loop()); |
michael@0 | 69 | |
michael@0 | 70 | router_.AddRoute(routing_id, listener); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void ChildThread::RemoveRoute(int32_t routing_id) { |
michael@0 | 74 | DCHECK(MessageLoop::current() == message_loop()); |
michael@0 | 75 | |
michael@0 | 76 | router_.RemoveRoute(routing_id); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void ChildThread::OnMessageReceived(const IPC::Message& msg) { |
michael@0 | 80 | if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
michael@0 | 81 | OnControlMessageReceived(msg); |
michael@0 | 82 | } else { |
michael@0 | 83 | router_.OnMessageReceived(msg); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | ChildThread* ChildThread::current() { |
michael@0 | 88 | return ChildProcess::current()->child_thread(); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | void ChildThread::Init() { |
michael@0 | 92 | channel_.reset(new IPC::Channel(channel_name_, |
michael@0 | 93 | IPC::Channel::MODE_CLIENT, |
michael@0 | 94 | this)); |
michael@0 | 95 | |
michael@0 | 96 | #ifdef IPC_MESSAGE_LOG_ENABLED |
michael@0 | 97 | IPC::Logging::current()->SetIPCSender(this); |
michael@0 | 98 | #endif |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | void ChildThread::CleanUp() { |
michael@0 | 102 | #ifdef IPC_MESSAGE_LOG_ENABLED |
michael@0 | 103 | IPC::Logging::current()->SetIPCSender(NULL); |
michael@0 | 104 | #endif |
michael@0 | 105 | // Need to destruct the SyncChannel to the browser before we go away because |
michael@0 | 106 | // it caches a pointer to this thread. |
michael@0 | 107 | channel_.reset(); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | void ChildThread::OnProcessFinalRelease() { |
michael@0 | 111 | if (!check_with_browser_before_shutdown_) { |
michael@0 | 112 | owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
michael@0 | 113 | return; |
michael@0 | 114 | } |
michael@0 | 115 | } |