OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_COMMON_CHILD_PROCESS_H__ | 5 #ifndef CHROME_COMMON_CHILD_PROCESS_H__ |
6 #define CHROME_COMMON_CHILD_PROCESS_H__ | 6 #define CHROME_COMMON_CHILD_PROCESS_H__ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/mp/mp_child_process.h" |
10 #include "base/thread.h" | |
11 #include "base/waitable_event.h" | |
12 #include "chrome/common/child_thread.h" | |
13 | 10 |
14 // Base class for child processes of the browser process (i.e. renderer and | 11 // Base class for child processes of the browser process (i.e. renderer and |
15 // plugin host). This is a singleton object for each child process. | 12 // plugin host). This is a singleton object for each child process. |
16 class ChildProcess { | 13 class ChildProcess : public base::MpChildProcess { |
17 public: | 14 public: |
18 // Child processes should have an object that derives from this class. | 15 // Child processes should have an object that derives from this class. |
19 ChildProcess(); | 16 ChildProcess(); |
20 virtual ~ChildProcess(); | 17 virtual ~ChildProcess(); |
21 | 18 |
22 // Getter for the child process' main thread. | 19 virtual base::Thread* GetIOThread(){ return &io_thread_; } |
23 ChildThread* main_thread() { return main_thread_.get(); } | |
24 void set_main_thread(ChildThread* thread) { main_thread_.reset(thread); } | |
25 | |
26 MessageLoop* io_message_loop() { return io_thread_.message_loop(); } | |
27 | |
28 // A global event object that is signalled when the main thread's message | |
29 // loop exits. This gives background threads a way to observe the main | |
30 // thread shutting down. This can be useful when a background thread is | |
31 // waiting for some information from the browser process. If the browser | |
32 // process goes away prematurely, the background thread can at least notice | |
33 // the child processes's main thread exiting to determine that it should give | |
34 // up waiting. | |
35 // For example, see the renderer code used to implement | |
36 // webkit_glue::GetCookies. | |
37 base::WaitableEvent* GetShutDownEvent(); | |
38 | |
39 // These are used for ref-counting the child process. The process shuts | |
40 // itself down when the ref count reaches 0. | |
41 // For example, in the renderer process, generally each tab managed by this | |
42 // process will hold a reference to the process, and release when closed. | |
43 void AddRefProcess(); | |
44 void ReleaseProcess(); | |
45 | |
46 // Getter for the one ChildProcess object for this process. | |
47 static ChildProcess* current() { return child_process_; } | |
48 | 20 |
49 static void WaitForDebugger(const std::wstring& label); | 21 static void WaitForDebugger(const std::wstring& label); |
50 private: | 22 private: |
51 int ref_count_; | |
52 | |
53 // An event that will be signalled when we shutdown. | |
54 base::WaitableEvent shutdown_event_; | |
55 | 23 |
56 // The thread that handles IO events. | 24 // The thread that handles IO events. |
57 base::Thread io_thread_; | 25 base::Thread io_thread_; |
58 | 26 |
59 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since | |
60 // it depends on it (indirectly through IPC::SyncChannel). Same for | |
61 // io_thread_. | |
62 scoped_ptr<ChildThread> main_thread_; | |
63 | |
64 // The singleton instance for this process. | |
65 static ChildProcess* child_process_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(ChildProcess); | 27 DISALLOW_COPY_AND_ASSIGN(ChildProcess); |
68 }; | 28 }; |
69 | 29 |
70 #endif // CHROME_COMMON_CHILD_PROCESS_H__ | 30 #endif // CHROME_COMMON_CHILD_PROCESS_H__ |
OLD | NEW |