OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 | 10 |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/process.h" |
12 #include "base/synchronization/waitable_event_watcher.h" | 13 #include "base/synchronization/waitable_event_watcher.h" |
13 #include "content/browser/child_process_launcher.h" | 14 #include "content/browser/child_process_launcher.h" |
14 #include "content/common/child_process_host.h" | 15 #include "content/common/child_process_host.h" |
15 #include "content/common/child_process_info.h" | |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/public/common/process_type.h" | 17 #include "content/public/browser/child_process_data.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class WaitableEvent; | 20 class WaitableEvent; |
21 } | 21 } |
22 | 22 |
23 // Plugins/workers and other child processes that live on the IO thread should | 23 // Plugins/workers and other child processes that live on the IO thread should |
24 // derive from this class. | 24 // derive from this class. |
25 // | 25 // |
26 // [Browser]RenderProcessHost is the main exception that doesn't derive from | 26 // [Browser]RenderProcessHost is the main exception that doesn't derive from |
27 // this class. That project lives on the UI thread. | 27 // this class. That project lives on the UI thread. |
28 class CONTENT_EXPORT BrowserChildProcessHost : | 28 class CONTENT_EXPORT BrowserChildProcessHost : |
29 public ChildProcessHost, | 29 public ChildProcessHost, |
30 public ChildProcessInfo, | |
31 public ChildProcessLauncher::Client, | 30 public ChildProcessLauncher::Client, |
32 public base::WaitableEventWatcher::Delegate { | 31 public base::WaitableEventWatcher::Delegate { |
33 public: | 32 public: |
34 virtual ~BrowserChildProcessHost(); | 33 virtual ~BrowserChildProcessHost(); |
35 | 34 |
36 virtual void OnWaitableEventSignaled( | 35 virtual void OnWaitableEventSignaled( |
37 base::WaitableEvent* waitable_event) OVERRIDE; | 36 base::WaitableEvent* waitable_event) OVERRIDE; |
38 | 37 |
39 // Terminates all child processes and deletes each ChildProcessHost instance. | 38 // Terminates all child processes and deletes each ChildProcessHost instance. |
40 static void TerminateAll(); | 39 static void TerminateAll(); |
(...skipping 11 matching lines...) Expand all Loading... |
52 BrowserChildProcessHost* operator*() { return *iterator_; } | 51 BrowserChildProcessHost* operator*() { return *iterator_; } |
53 BrowserChildProcessHost* operator++(); | 52 BrowserChildProcessHost* operator++(); |
54 bool Done(); | 53 bool Done(); |
55 | 54 |
56 private: | 55 private: |
57 bool all_; | 56 bool all_; |
58 content::ProcessType type_; | 57 content::ProcessType type_; |
59 std::list<BrowserChildProcessHost*>::iterator iterator_; | 58 std::list<BrowserChildProcessHost*>::iterator iterator_; |
60 }; | 59 }; |
61 | 60 |
| 61 const content::ChildProcessData& data() const { return data_; } |
| 62 content::ProcessType type() const { return data_.type; } |
| 63 const string16& name() const { return data_.name; } |
| 64 base::ProcessHandle handle() const { return data_.handle; } |
| 65 int id() const { return data_.id; } |
| 66 |
62 protected: | 67 protected: |
63 explicit BrowserChildProcessHost(content::ProcessType type); | 68 explicit BrowserChildProcessHost(content::ProcessType type); |
64 | 69 |
65 // Derived classes call this to launch the child process asynchronously. | 70 // Derived classes call this to launch the child process asynchronously. |
66 void Launch( | 71 void Launch( |
67 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
68 const FilePath& exposed_dir, | 73 const FilePath& exposed_dir, |
69 #elif defined(OS_POSIX) | 74 #elif defined(OS_POSIX) |
70 bool use_zygote, | 75 bool use_zygote, |
71 const base::environment_vector& environ, | 76 const base::environment_vector& environ, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // the host list. Calls ChildProcessHost::ForceShutdown | 110 // the host list. Calls ChildProcessHost::ForceShutdown |
106 virtual void ForceShutdown() OVERRIDE; | 111 virtual void ForceShutdown() OVERRIDE; |
107 | 112 |
108 // Controls whether the child process should be terminated on browser | 113 // Controls whether the child process should be terminated on browser |
109 // shutdown. Default is to always terminate. | 114 // shutdown. Default is to always terminate. |
110 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 115 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); |
111 | 116 |
112 // Sends the given notification on the UI thread. | 117 // Sends the given notification on the UI thread. |
113 void Notify(int type); | 118 void Notify(int type); |
114 | 119 |
| 120 void set_name(const string16& name) { data_.name = name; } |
| 121 void set_handle(base::ProcessHandle handle) { data_.handle = handle; } |
| 122 |
115 private: | 123 private: |
116 // By using an internal class as the ChildProcessLauncher::Client, we can | 124 // By using an internal class as the ChildProcessLauncher::Client, we can |
117 // intercept OnProcessLaunched and do our own processing before | 125 // intercept OnProcessLaunched and do our own processing before |
118 // calling the subclass' implementation. | 126 // calling the subclass' implementation. |
119 class ClientHook : public ChildProcessLauncher::Client { | 127 class ClientHook : public ChildProcessLauncher::Client { |
120 public: | 128 public: |
121 explicit ClientHook(BrowserChildProcessHost* host); | 129 explicit ClientHook(BrowserChildProcessHost* host); |
122 virtual void OnProcessLaunched() OVERRIDE; | 130 virtual void OnProcessLaunched() OVERRIDE; |
123 private: | 131 private: |
124 BrowserChildProcessHost* host_; | 132 BrowserChildProcessHost* host_; |
125 }; | 133 }; |
126 | 134 |
| 135 content::ChildProcessData data_; |
| 136 |
127 ClientHook client_; | 137 ClientHook client_; |
128 scoped_ptr<ChildProcessLauncher> child_process_; | 138 scoped_ptr<ChildProcessLauncher> child_process_; |
129 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
130 base::WaitableEventWatcher child_watcher_; | 140 base::WaitableEventWatcher child_watcher_; |
131 #else | 141 #else |
132 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_; | 142 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_; |
133 #endif | 143 #endif |
134 bool disconnect_was_alive_; | 144 bool disconnect_was_alive_; |
135 }; | 145 }; |
136 | 146 |
137 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ | 147 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
OLD | NEW |