Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / browser_child_process_host_impl.h
blob08e1b360a1147dec8c9124e9800333585eb3f978
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_
6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_
8 #include <list>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/process/process.h"
13 #include "base/synchronization/waitable_event_watcher.h"
14 #include "content/browser/child_process_launcher.h"
15 #include "content/browser/power_monitor_message_broadcaster.h"
16 #include "content/public/browser/browser_child_process_host.h"
17 #include "content/public/browser/child_process_data.h"
18 #include "content/public/common/child_process_host_delegate.h"
20 #if defined(OS_WIN)
21 #include "base/win/object_watcher.h"
22 #endif
24 namespace base {
25 class CommandLine;
28 namespace content {
30 class BrowserChildProcessHostIterator;
31 class BrowserChildProcessObserver;
32 class BrowserMessageFilter;
34 // Plugins/workers and other child processes that live on the IO thread use this
35 // class. RenderProcessHostImpl is the main exception that doesn't use this
36 /// class because it lives on the UI thread.
37 class CONTENT_EXPORT BrowserChildProcessHostImpl
38 : public BrowserChildProcessHost,
39 public NON_EXPORTED_BASE(ChildProcessHostDelegate),
40 #if defined(OS_WIN)
41 public base::win::ObjectWatcher::Delegate,
42 #endif
43 public ChildProcessLauncher::Client {
44 public:
45 BrowserChildProcessHostImpl(content::ProcessType process_type,
46 BrowserChildProcessHostDelegate* delegate);
47 ~BrowserChildProcessHostImpl() override;
49 // Terminates all child processes and deletes each BrowserChildProcessHost
50 // instance.
51 static void TerminateAll();
53 // BrowserChildProcessHost implementation:
54 bool Send(IPC::Message* message) override;
55 void Launch(SandboxedProcessLauncherDelegate* delegate,
56 base::CommandLine* cmd_line,
57 bool terminate_on_shutdown) override;
58 const ChildProcessData& GetData() const override;
59 ChildProcessHost* GetHost() const override;
60 base::TerminationStatus GetTerminationStatus(bool known_dead,
61 int* exit_code) override;
62 void SetName(const base::string16& name) override;
63 void SetHandle(base::ProcessHandle handle) override;
65 // ChildProcessHostDelegate implementation:
66 bool CanShutdown() override;
67 void OnChildDisconnected() override;
68 const base::Process& GetProcess() const override;
69 bool OnMessageReceived(const IPC::Message& message) override;
70 void OnChannelConnected(int32 peer_pid) override;
71 void OnChannelError() override;
72 void OnBadMessageReceived(const IPC::Message& message) override;
74 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown
75 void ForceShutdown();
77 // Callers can reduce the BrowserChildProcess' priority.
78 void SetBackgrounded(bool backgrounded);
80 // Adds an IPC message filter.
81 void AddFilter(BrowserMessageFilter* filter);
83 // Called when an instance of a particular child is created in a page.
84 static void NotifyProcessInstanceCreated(const ChildProcessData& data);
86 static void HistogramBadMessageTerminated(int process_type);
88 BrowserChildProcessHostDelegate* delegate() const { return delegate_; }
90 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
91 private:
92 friend class BrowserChildProcessHostIterator;
93 friend class BrowserChildProcessObserver;
95 static BrowserChildProcessList* GetIterator();
97 static void AddObserver(BrowserChildProcessObserver* observer);
98 static void RemoveObserver(BrowserChildProcessObserver* observer);
100 // ChildProcessLauncher::Client implementation.
101 void OnProcessLaunched() override;
102 void OnProcessLaunchFailed() override;
104 #if defined(OS_WIN)
105 // ObjectWatcher::Delegate implementation.
106 void OnObjectSignaled(HANDLE object) override;
107 #endif
109 ChildProcessData data_;
110 BrowserChildProcessHostDelegate* delegate_;
111 scoped_ptr<ChildProcessHost> child_process_host_;
113 scoped_ptr<ChildProcessLauncher> child_process_;
115 PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_;
117 #if defined(OS_WIN)
118 // Watches to see if the child process exits before the IPC channel has
119 // been connected. Thereafter, its exit is determined by an error on the
120 // IPC channel.
121 base::win::ObjectWatcher early_exit_watcher_;
122 #endif
125 } // namespace content
127 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_