Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 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_PROCESS_H__ |
michael@0 | 6 | #define CHROME_COMMON_CHILD_PROCESS_H__ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | #include <vector> |
michael@0 | 10 | #include "base/basictypes.h" |
michael@0 | 11 | #include "base/message_loop.h" |
michael@0 | 12 | #include "base/scoped_ptr.h" |
michael@0 | 13 | #include "base/waitable_event.h" |
michael@0 | 14 | |
michael@0 | 15 | class ChildThread; |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | // Base class for child processes of the browser process (i.e. renderer and |
michael@0 | 19 | // plugin host). This is a singleton object for each child process. |
michael@0 | 20 | class ChildProcess { |
michael@0 | 21 | public: |
michael@0 | 22 | // Child processes should have an object that derives from this class. The |
michael@0 | 23 | // constructor will return once ChildThread has started. |
michael@0 | 24 | ChildProcess(ChildThread* child_thread); |
michael@0 | 25 | virtual ~ChildProcess(); |
michael@0 | 26 | |
michael@0 | 27 | // Getter for this process' main thread. |
michael@0 | 28 | ChildThread* child_thread() { return child_thread_.get(); } |
michael@0 | 29 | |
michael@0 | 30 | // A global event object that is signalled when the main thread's message |
michael@0 | 31 | // loop exits. This gives background threads a way to observe the main |
michael@0 | 32 | // thread shutting down. This can be useful when a background thread is |
michael@0 | 33 | // waiting for some information from the browser process. If the browser |
michael@0 | 34 | // process goes away prematurely, the background thread can at least notice |
michael@0 | 35 | // the child processes's main thread exiting to determine that it should give |
michael@0 | 36 | // up waiting. |
michael@0 | 37 | // For example, see the renderer code used to implement |
michael@0 | 38 | // webkit_glue::GetCookies. |
michael@0 | 39 | base::WaitableEvent* GetShutDownEvent(); |
michael@0 | 40 | |
michael@0 | 41 | // These are used for ref-counting the child process. The process shuts |
michael@0 | 42 | // itself down when the ref count reaches 0. |
michael@0 | 43 | // For example, in the renderer process, generally each tab managed by this |
michael@0 | 44 | // process will hold a reference to the process, and release when closed. |
michael@0 | 45 | void AddRefProcess(); |
michael@0 | 46 | void ReleaseProcess(); |
michael@0 | 47 | |
michael@0 | 48 | // Getter for the one ChildProcess object for this process. |
michael@0 | 49 | static ChildProcess* current() { return child_process_; } |
michael@0 | 50 | |
michael@0 | 51 | private: |
michael@0 | 52 | // NOTE: make sure that child_thread_ is listed before shutdown_event_, since |
michael@0 | 53 | // it depends on it (indirectly through IPC::SyncChannel). |
michael@0 | 54 | scoped_ptr<ChildThread> child_thread_; |
michael@0 | 55 | |
michael@0 | 56 | int ref_count_; |
michael@0 | 57 | |
michael@0 | 58 | // An event that will be signalled when we shutdown. |
michael@0 | 59 | base::WaitableEvent shutdown_event_; |
michael@0 | 60 | |
michael@0 | 61 | // The singleton instance for this process. |
michael@0 | 62 | static ChildProcess* child_process_; |
michael@0 | 63 | |
michael@0 | 64 | DISALLOW_EVIL_CONSTRUCTORS(ChildProcess); |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | #endif // CHROME_COMMON_CHILD_PROCESS_H__ |