Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | #ifndef CHROME_COMMON_CHILD_THREAD_H_ |
michael@0 | 6 | #define CHROME_COMMON_CHILD_THREAD_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "base/thread.h" |
michael@0 | 9 | #include "chrome/common/ipc_sync_channel.h" |
michael@0 | 10 | #include "chrome/common/message_router.h" |
michael@0 | 11 | |
michael@0 | 12 | class ResourceDispatcher; |
michael@0 | 13 | |
michael@0 | 14 | // Child processes's background thread should derive from this class. |
michael@0 | 15 | class ChildThread : public IPC::Channel::Listener, |
michael@0 | 16 | public IPC::Message::Sender, |
michael@0 | 17 | public base::Thread { |
michael@0 | 18 | public: |
michael@0 | 19 | // Creates the thread. |
michael@0 | 20 | ChildThread(Thread::Options options); |
michael@0 | 21 | virtual ~ChildThread(); |
michael@0 | 22 | |
michael@0 | 23 | // IPC::Message::Sender implementation: |
michael@0 | 24 | virtual bool Send(IPC::Message* msg); |
michael@0 | 25 | |
michael@0 | 26 | // See documentation on MessageRouter for AddRoute and RemoveRoute |
michael@0 | 27 | void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener); |
michael@0 | 28 | void RemoveRoute(int32_t routing_id); |
michael@0 | 29 | |
michael@0 | 30 | MessageLoop* owner_loop() { return owner_loop_; } |
michael@0 | 31 | |
michael@0 | 32 | protected: |
michael@0 | 33 | friend class ChildProcess; |
michael@0 | 34 | |
michael@0 | 35 | // Starts the thread. |
michael@0 | 36 | bool Run(); |
michael@0 | 37 | |
michael@0 | 38 | // Overrides the channel name. Used for --single-process mode. |
michael@0 | 39 | void SetChannelName(const std::wstring& name) { channel_name_ = name; } |
michael@0 | 40 | |
michael@0 | 41 | // Called when the process refcount is 0. |
michael@0 | 42 | void OnProcessFinalRelease(); |
michael@0 | 43 | |
michael@0 | 44 | protected: |
michael@0 | 45 | // The required stack size if V8 runs on a thread. |
michael@0 | 46 | static const size_t kV8StackSize; |
michael@0 | 47 | |
michael@0 | 48 | virtual void OnControlMessageReceived(const IPC::Message& msg) { } |
michael@0 | 49 | |
michael@0 | 50 | // Returns the one child thread. |
michael@0 | 51 | static ChildThread* current(); |
michael@0 | 52 | |
michael@0 | 53 | IPC::Channel* channel() { return channel_.get(); } |
michael@0 | 54 | |
michael@0 | 55 | // Thread implementation. |
michael@0 | 56 | virtual void Init(); |
michael@0 | 57 | virtual void CleanUp(); |
michael@0 | 58 | |
michael@0 | 59 | private: |
michael@0 | 60 | // IPC::Channel::Listener implementation: |
michael@0 | 61 | virtual void OnMessageReceived(const IPC::Message& msg); |
michael@0 | 62 | virtual void OnChannelError(); |
michael@0 | 63 | |
michael@0 | 64 | #ifdef MOZ_NUWA_PROCESS |
michael@0 | 65 | static void MarkThread(); |
michael@0 | 66 | #endif |
michael@0 | 67 | |
michael@0 | 68 | // The message loop used to run tasks on the thread that started this thread. |
michael@0 | 69 | MessageLoop* owner_loop_; |
michael@0 | 70 | |
michael@0 | 71 | std::wstring channel_name_; |
michael@0 | 72 | scoped_ptr<IPC::Channel> channel_; |
michael@0 | 73 | |
michael@0 | 74 | // Used only on the background render thread to implement message routing |
michael@0 | 75 | // functionality to the consumers of the ChildThread. |
michael@0 | 76 | MessageRouter router_; |
michael@0 | 77 | |
michael@0 | 78 | Thread::Options options_; |
michael@0 | 79 | |
michael@0 | 80 | // If true, checks with the browser process before shutdown. This avoids race |
michael@0 | 81 | // conditions if the process refcount is 0 but there's an IPC message inflight |
michael@0 | 82 | // that would addref it. |
michael@0 | 83 | bool check_with_browser_before_shutdown_; |
michael@0 | 84 | |
michael@0 | 85 | DISALLOW_EVIL_CONSTRUCTORS(ChildThread); |
michael@0 | 86 | }; |
michael@0 | 87 | |
michael@0 | 88 | #endif // CHROME_COMMON_CHILD_THREAD_H_ |