| OLD | NEW | 
|   1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |   1 // Copyright (c) 2006-2008 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 <string> |   8 #include <string> | 
|   9 #include <vector> |   9 #include <vector> | 
|  10 #include "base/basictypes.h" |  10 #include "base/basictypes.h" | 
|  11 #include "base/message_loop.h" |  11 #include "base/message_loop.h" | 
|  12  |  12  | 
 |  13 namespace base { | 
 |  14   class WaitableEvent; | 
 |  15 }; | 
|  13  |  16  | 
|  14 class ChildProcess; |  17 class ChildProcess; | 
|  15  |  18  | 
|  16 class ChildProcessFactoryInterface { |  19 class ChildProcessFactoryInterface { | 
|  17  public: |  20  public: | 
|  18   virtual ChildProcess* Create(const std::wstring& channel_name) = 0; |  21   virtual ChildProcess* Create(const std::wstring& channel_name) = 0; | 
|  19 }; |  22 }; | 
|  20  |  23  | 
|  21 template<class T> |  24 template<class T> | 
|  22 class ChildProcessFactory : public ChildProcessFactoryInterface { |  25 class ChildProcessFactory : public ChildProcessFactoryInterface { | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  46  |  49  | 
|  47   // 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 | 
|  48   // 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 | 
|  49   // 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 | 
|  50   // waiting for some information from the browser process.  If the browser |  53   // waiting for some information from the browser process.  If the browser | 
|  51   // process goes away prematurely, the background thread can at least notice |  54   // process goes away prematurely, the background thread can at least notice | 
|  52   // the child processes's main thread exiting to determine that it should give |  55   // the child processes's main thread exiting to determine that it should give | 
|  53   // up waiting. |  56   // up waiting. | 
|  54   // For example, see the renderer code used to implement |  57   // For example, see the renderer code used to implement | 
|  55   // webkit_glue::GetCookies. |  58   // webkit_glue::GetCookies. | 
|  56   static HANDLE GetShutDownEvent(); |  59   static base::WaitableEvent* GetShutDownEvent(); | 
|  57  |  60  | 
|  58   // You must call Init after creating this object before it will be valid |  61   // You must call Init after creating this object before it will be valid | 
|  59   ChildProcess(); |  62   ChildProcess(); | 
|  60   virtual ~ChildProcess(); |  63   virtual ~ChildProcess(); | 
|  61  |  64  | 
|  62  protected: |  65  protected: | 
|  63   static bool GlobalInit(const std::wstring& channel_name, |  66   static bool GlobalInit(const std::wstring& channel_name, | 
|  64                          ChildProcessFactoryInterface* factory); |  67                          ChildProcessFactoryInterface* factory); | 
|  65  |  68  | 
|  66   static bool ProcessRefCountIsZero(); |  69   static bool ProcessRefCountIsZero(); | 
|  67  |  70  | 
|  68   // The singleton instance for this process. |  71   // The singleton instance for this process. | 
|  69   static ChildProcess* child_process_; |  72   static ChildProcess* child_process_; | 
|  70  |  73  | 
|  71   static MessageLoop* main_thread_loop_; |  74   static MessageLoop* main_thread_loop_; | 
|  72  |  75  | 
|  73   // Derived classes can override this to alter the behavior when the ref count |  76   // Derived classes can override this to alter the behavior when the ref count | 
|  74   // reaches 0. The default implementation calls Quit on the main message loop |  77   // reaches 0. The default implementation calls Quit on the main message loop | 
|  75   // which causes the process to shutdown. Note, this can be called on any |  78   // which causes the process to shutdown. Note, this can be called on any | 
|  76   // thread. (See ReleaseProcess) |  79   // thread. (See ReleaseProcess) | 
|  77   virtual void OnFinalRelease(); |  80   virtual void OnFinalRelease(); | 
|  78  |  81  | 
|  79  private: |  82  private: | 
|  80   // Derived classes can override this to handle any cleanup, called by |  83   // Derived classes can override this to handle any cleanup, called by | 
|  81   // GlobalCleanup. |  84   // GlobalCleanup. | 
|  82   virtual void Cleanup() {} |  85   virtual void Cleanup() {} | 
|  83   static HANDLE shutdown_event_; |  86   static base::WaitableEvent* shutdown_event_; | 
|  84  |  87  | 
|  85   DISALLOW_EVIL_CONSTRUCTORS(ChildProcess); |  88   DISALLOW_EVIL_CONSTRUCTORS(ChildProcess); | 
|  86 }; |  89 }; | 
|  87  |  90  | 
|  88 #endif  // CHROME_COMMON_CHILD_PROCESS_H__ |  91 #endif  // CHROME_COMMON_CHILD_PROCESS_H__ | 
|  89  |  92  | 
| OLD | NEW |