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