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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_CHILD_PROCESS_H_
6 #define CONTENT_COMMON_CHILD_PROCESS_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "content/common/content_export.h"
17 // Base class for child processes of the browser process (i.e. renderer and
18 // plugin host). This is a singleton object for each child process.
19 class CONTENT_EXPORT ChildProcess
{
21 // Child processes should have an object that derives from this class.
22 // Normally you would immediately call set_main_thread after construction.
24 virtual ~ChildProcess();
26 // May be NULL if the main thread hasn't been set explicitly.
27 ChildThread
* main_thread();
29 // Sets the object associated with the main thread of this process.
30 // Takes ownership of the pointer.
31 void set_main_thread(ChildThread
* thread
);
33 MessageLoop
* io_message_loop() { return io_thread_
.message_loop(); }
34 base::MessageLoopProxy
* io_message_loop_proxy() {
35 return io_thread_
.message_loop_proxy();
38 // A global event object that is signalled when the main thread's message
39 // loop exits. This gives background threads a way to observe the main
40 // thread shutting down. This can be useful when a background thread is
41 // waiting for some information from the browser process. If the browser
42 // process goes away prematurely, the background thread can at least notice
43 // the child processes's main thread exiting to determine that it should give
45 // For example, see the renderer code used to implement
46 // webkit_glue::GetCookies.
47 base::WaitableEvent
* GetShutDownEvent();
49 // These are used for ref-counting the child process. The process shuts
50 // itself down when the ref count reaches 0.
51 // For example, in the renderer process, generally each tab managed by this
52 // process will hold a reference to the process, and release when closed.
54 void ReleaseProcess();
56 // Getter for the one ChildProcess object for this process.
57 static ChildProcess
* current() { return child_process_
; }
59 static void WaitForDebugger(const std::string
& label
);
63 // An event that will be signalled when we shutdown.
64 base::WaitableEvent shutdown_event_
;
66 // The thread that handles IO events.
67 base::Thread io_thread_
;
69 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since
70 // it depends on it (indirectly through IPC::SyncChannel). Same for
72 scoped_ptr
<ChildThread
> main_thread_
;
74 // The singleton instance for this process.
75 static ChildProcess
* child_process_
;
77 DISALLOW_COPY_AND_ASSIGN(ChildProcess
);
80 } // namespace content
82 #endif // CONTENT_COMMON_CHILD_PROCESS_H_