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