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