OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_CHILD_CHILD_PROCESS_H_ | 5 #ifndef CONTENT_CHILD_CHILD_PROCESS_H_ |
6 #define CONTENT_CHILD_CHILD_PROCESS_H_ | 6 #define CONTENT_CHILD_CHILD_PROCESS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 class ChildThread; | 15 class ChildThreadImpl; |
16 | 16 |
17 // Base class for child processes of the browser process (i.e. renderer and | 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. | 18 // plugin host). This is a singleton object for each child process. |
19 // | 19 // |
20 // During process shutdown the following sequence of actions happens in | 20 // During process shutdown the following sequence of actions happens in |
21 // order. | 21 // order. |
22 // | 22 // |
23 // 1. ChildProcess::~ChildProcess() is called. | 23 // 1. ChildProcess::~ChildProcess() is called. |
24 // 2. Shutdown event is fired. Background threads should stop. | 24 // 2. Shutdown event is fired. Background threads should stop. |
25 // 3. ChildThread::Shutdown() is called. ChildThread is also deleted. | 25 // 3. ChildThreadImpl::Shutdown() is called. ChildThread is also deleted. |
26 // 4. IO thread is stopped. | 26 // 4. IO thread is stopped. |
27 // 5. Main message loop exits. | 27 // 5. Main message loop exits. |
28 // 6. Child process is now fully stopped. | 28 // 6. Child process is now fully stopped. |
29 // | 29 // |
30 // Note: IO thread outlives the ChildThread object. | 30 // Note: IO thread outlives the ChildThreadImpl object. |
31 class CONTENT_EXPORT ChildProcess { | 31 class CONTENT_EXPORT ChildProcess { |
32 public: | 32 public: |
33 // Child processes should have an object that derives from this class. | 33 // Child processes should have an object that derives from this class. |
34 // Normally you would immediately call set_main_thread after construction. | 34 // Normally you would immediately call set_main_thread after construction. |
35 ChildProcess(); | 35 ChildProcess(); |
36 virtual ~ChildProcess(); | 36 virtual ~ChildProcess(); |
37 | 37 |
38 // May be NULL if the main thread hasn't been set explicitly. | 38 // May be NULL if the main thread hasn't been set explicitly. |
39 ChildThread* main_thread(); | 39 ChildThreadImpl* main_thread(); |
40 | 40 |
41 // Sets the object associated with the main thread of this process. | 41 // Sets the object associated with the main thread of this process. |
42 // Takes ownership of the pointer. | 42 // Takes ownership of the pointer. |
43 void set_main_thread(ChildThread* thread); | 43 void set_main_thread(ChildThreadImpl* thread); |
44 | 44 |
45 base::MessageLoop* io_message_loop() { return io_thread_.message_loop(); } | 45 base::MessageLoop* io_message_loop() { return io_thread_.message_loop(); } |
46 base::MessageLoopProxy* io_message_loop_proxy() { | 46 base::MessageLoopProxy* io_message_loop_proxy() { |
47 return io_thread_.message_loop_proxy().get(); | 47 return io_thread_.message_loop_proxy().get(); |
48 } | 48 } |
49 | 49 |
50 // A global event object that is signalled when the main thread's message | 50 // A global event object that is signalled when the main thread's message |
51 // loop exits. This gives background threads a way to observe the main | 51 // loop exits. This gives background threads a way to observe the main |
52 // thread shutting down. This can be useful when a background thread is | 52 // thread shutting down. This can be useful when a background thread is |
53 // waiting for some information from the browser process. If the browser | 53 // waiting for some information from the browser process. If the browser |
(...skipping 20 matching lines...) Expand all Loading... |
74 | 74 |
75 // An event that will be signalled when we shutdown. | 75 // An event that will be signalled when we shutdown. |
76 base::WaitableEvent shutdown_event_; | 76 base::WaitableEvent shutdown_event_; |
77 | 77 |
78 // The thread that handles IO events. | 78 // The thread that handles IO events. |
79 base::Thread io_thread_; | 79 base::Thread io_thread_; |
80 | 80 |
81 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since | 81 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since |
82 // it depends on it (indirectly through IPC::SyncChannel). Same for | 82 // it depends on it (indirectly through IPC::SyncChannel). Same for |
83 // io_thread_. | 83 // io_thread_. |
84 scoped_ptr<ChildThread> main_thread_; | 84 scoped_ptr<ChildThreadImpl> main_thread_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(ChildProcess); | 86 DISALLOW_COPY_AND_ASSIGN(ChildProcess); |
87 }; | 87 }; |
88 | 88 |
89 } // namespace content | 89 } // namespace content |
90 | 90 |
91 #endif // CONTENT_CHILD_CHILD_PROCESS_H_ | 91 #endif // CONTENT_CHILD_CHILD_PROCESS_H_ |
OLD | NEW |