michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef CHROME_COMMON_CHILD_PROCESS_H__ michael@0: #define CHROME_COMMON_CHILD_PROCESS_H__ michael@0: michael@0: #include michael@0: #include michael@0: #include "base/basictypes.h" michael@0: #include "base/message_loop.h" michael@0: #include "base/scoped_ptr.h" michael@0: #include "base/waitable_event.h" michael@0: michael@0: class ChildThread; michael@0: michael@0: michael@0: // Base class for child processes of the browser process (i.e. renderer and michael@0: // plugin host). This is a singleton object for each child process. michael@0: class ChildProcess { michael@0: public: michael@0: // Child processes should have an object that derives from this class. The michael@0: // constructor will return once ChildThread has started. michael@0: ChildProcess(ChildThread* child_thread); michael@0: virtual ~ChildProcess(); michael@0: michael@0: // Getter for this process' main thread. michael@0: ChildThread* child_thread() { return child_thread_.get(); } michael@0: michael@0: // A global event object that is signalled when the main thread's message michael@0: // loop exits. This gives background threads a way to observe the main michael@0: // thread shutting down. This can be useful when a background thread is michael@0: // waiting for some information from the browser process. If the browser michael@0: // process goes away prematurely, the background thread can at least notice michael@0: // the child processes's main thread exiting to determine that it should give michael@0: // up waiting. michael@0: // For example, see the renderer code used to implement michael@0: // webkit_glue::GetCookies. michael@0: base::WaitableEvent* GetShutDownEvent(); michael@0: michael@0: // These are used for ref-counting the child process. The process shuts michael@0: // itself down when the ref count reaches 0. michael@0: // For example, in the renderer process, generally each tab managed by this michael@0: // process will hold a reference to the process, and release when closed. michael@0: void AddRefProcess(); michael@0: void ReleaseProcess(); michael@0: michael@0: // Getter for the one ChildProcess object for this process. michael@0: static ChildProcess* current() { return child_process_; } michael@0: michael@0: private: michael@0: // NOTE: make sure that child_thread_ is listed before shutdown_event_, since michael@0: // it depends on it (indirectly through IPC::SyncChannel). michael@0: scoped_ptr child_thread_; michael@0: michael@0: int ref_count_; michael@0: michael@0: // An event that will be signalled when we shutdown. michael@0: base::WaitableEvent shutdown_event_; michael@0: michael@0: // The singleton instance for this process. michael@0: static ChildProcess* child_process_; michael@0: michael@0: DISALLOW_EVIL_CONSTRUCTORS(ChildProcess); michael@0: }; michael@0: michael@0: #endif // CHROME_COMMON_CHILD_PROCESS_H__