| 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_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/process.h" | 12 #include "base/process.h" |
| 13 #include "content/browser/child_process_launcher.h" | 13 #include "content/browser/child_process_launcher.h" |
| 14 #include "content/public/browser/browser_child_process_host.h" | 14 #include "content/public/browser/browser_child_process_host.h" |
| 15 #include "content/public/browser/child_process_data.h" | 15 #include "content/public/browser/child_process_data.h" |
| 16 #include "content/public/common/child_process_host_delegate.h" | 16 #include "content/public/common/child_process_host_delegate.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class BrowserChildProcessHostIterator; | 19 class BrowserChildProcessHostIterator; |
| 20 } | |
| 21 | 20 |
| 22 // Plugins/workers and other child processes that live on the IO thread use this | 21 // Plugins/workers and other child processes that live on the IO thread use this |
| 23 // class. RenderProcessHostImpl is the main exception that doesn't use this | 22 // class. RenderProcessHostImpl is the main exception that doesn't use this |
| 24 /// class because it lives on the UI thread. | 23 /// class because it lives on the UI thread. |
| 25 class CONTENT_EXPORT BrowserChildProcessHostImpl | 24 class CONTENT_EXPORT BrowserChildProcessHostImpl |
| 26 : public content::BrowserChildProcessHost, | 25 : public BrowserChildProcessHost, |
| 27 public NON_EXPORTED_BASE(content::ChildProcessHostDelegate), | 26 public NON_EXPORTED_BASE(ChildProcessHostDelegate), |
| 28 public ChildProcessLauncher::Client { | 27 public ChildProcessLauncher::Client { |
| 29 public: | 28 public: |
| 30 BrowserChildProcessHostImpl( | 29 BrowserChildProcessHostImpl( |
| 31 content::ProcessType type, | 30 ProcessType type, |
| 32 content::BrowserChildProcessHostDelegate* delegate); | 31 BrowserChildProcessHostDelegate* delegate); |
| 33 virtual ~BrowserChildProcessHostImpl(); | 32 virtual ~BrowserChildProcessHostImpl(); |
| 34 | 33 |
| 35 // Terminates all child processes and deletes each BrowserChildProcessHost | 34 // Terminates all child processes and deletes each BrowserChildProcessHost |
| 36 // instance. | 35 // instance. |
| 37 static void TerminateAll(); | 36 static void TerminateAll(); |
| 38 | 37 |
| 39 // BrowserChildProcessHost implementation: | 38 // BrowserChildProcessHost implementation: |
| 40 virtual bool Send(IPC::Message* message) OVERRIDE; | 39 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 41 virtual void Launch( | 40 virtual void Launch( |
| 42 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| 43 const FilePath& exposed_dir, | 42 const FilePath& exposed_dir, |
| 44 #elif defined(OS_POSIX) | 43 #elif defined(OS_POSIX) |
| 45 bool use_zygote, | 44 bool use_zygote, |
| 46 const base::EnvironmentVector& environ, | 45 const base::EnvironmentVector& environ, |
| 47 #endif | 46 #endif |
| 48 CommandLine* cmd_line) OVERRIDE; | 47 CommandLine* cmd_line) OVERRIDE; |
| 49 virtual const content::ChildProcessData& GetData() const OVERRIDE; | 48 virtual const ChildProcessData& GetData() const OVERRIDE; |
| 50 virtual content::ChildProcessHost* GetHost() const OVERRIDE; | 49 virtual ChildProcessHost* GetHost() const OVERRIDE; |
| 51 virtual base::TerminationStatus GetTerminationStatus(int* exit_code) OVERRIDE; | 50 virtual base::TerminationStatus GetTerminationStatus(int* exit_code) OVERRIDE; |
| 52 virtual void SetName(const string16& name) OVERRIDE; | 51 virtual void SetName(const string16& name) OVERRIDE; |
| 53 virtual void SetHandle(base::ProcessHandle handle) OVERRIDE; | 52 virtual void SetHandle(base::ProcessHandle handle) OVERRIDE; |
| 54 | 53 |
| 55 // Returns the handle of the child process. This can be called only after | 54 // Returns the handle of the child process. This can be called only after |
| 56 // OnProcessLaunched is called or it will be invalid and may crash. | 55 // OnProcessLaunched is called or it will be invalid and may crash. |
| 57 base::ProcessHandle GetHandle() const; | 56 base::ProcessHandle GetHandle() const; |
| 58 | 57 |
| 59 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown | 58 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown |
| 60 void ForceShutdown(); | 59 void ForceShutdown(); |
| 61 | 60 |
| 62 // Controls whether the child process should be terminated on browser | 61 // Controls whether the child process should be terminated on browser |
| 63 // shutdown. Default is to always terminate. | 62 // shutdown. Default is to always terminate. |
| 64 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 63 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); |
| 65 | 64 |
| 66 // Sends the given notification on the UI thread. | 65 // Sends the given notification on the UI thread. |
| 67 void Notify(int type); | 66 void Notify(int type); |
| 68 | 67 |
| 69 content::BrowserChildProcessHostDelegate* delegate() const { | 68 BrowserChildProcessHostDelegate* delegate() const { return delegate_; |
| 70 return delegate_; | |
| 71 } | 69 } |
| 72 | 70 |
| 73 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList; | 71 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList; |
| 74 private: | 72 private: |
| 75 friend class content::BrowserChildProcessHostIterator; | 73 friend class BrowserChildProcessHostIterator; |
| 76 | 74 |
| 77 static BrowserChildProcessList* GetIterator(); | 75 static BrowserChildProcessList* GetIterator(); |
| 78 | 76 |
| 79 // ChildProcessHostDelegate implementation: | 77 // ChildProcessHostDelegate implementation: |
| 80 virtual bool CanShutdown() OVERRIDE; | 78 virtual bool CanShutdown() OVERRIDE; |
| 81 virtual void OnChildDisconnected() OVERRIDE; | 79 virtual void OnChildDisconnected() OVERRIDE; |
| 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 83 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 81 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 84 virtual void OnChannelError() OVERRIDE; | 82 virtual void OnChannelError() OVERRIDE; |
| 85 | 83 |
| 86 // ChildProcessLauncher::Client implementation. | 84 // ChildProcessLauncher::Client implementation. |
| 87 virtual void OnProcessLaunched() OVERRIDE; | 85 virtual void OnProcessLaunched() OVERRIDE; |
| 88 | 86 |
| 89 content::ChildProcessData data_; | 87 ChildProcessData data_; |
| 90 content::BrowserChildProcessHostDelegate* delegate_; | 88 BrowserChildProcessHostDelegate* delegate_; |
| 91 scoped_ptr<content::ChildProcessHost> child_process_host_; | 89 scoped_ptr<ChildProcessHost> child_process_host_; |
| 92 | 90 |
| 93 scoped_ptr<ChildProcessLauncher> child_process_; | 91 scoped_ptr<ChildProcessLauncher> child_process_; |
| 94 }; | 92 }; |
| 95 | 93 |
| 94 } // namespace content |
| 95 |
| 96 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 96 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| OLD | NEW |