IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / browser_child_process_host_impl.h
blob67ce9e2a7f282ba69f092b74e7c8805d0bec3485
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 namespace content {
22 class BrowserChildProcessHostIterator;
23 class BrowserChildProcessObserver;
24 class BrowserMessageFilter;
26 // Plugins/workers and other child processes that live on the IO thread use this
27 // class. RenderProcessHostImpl is the main exception that doesn't use this
28 /// class because it lives on the UI thread.
29 class CONTENT_EXPORT BrowserChildProcessHostImpl
30 : public BrowserChildProcessHost,
31 public NON_EXPORTED_BASE(ChildProcessHostDelegate),
32 public ChildProcessLauncher::Client {
33 public:
34 BrowserChildProcessHostImpl(
35 int process_type,
36 BrowserChildProcessHostDelegate* delegate);
37 virtual ~BrowserChildProcessHostImpl();
39 // Terminates all child processes and deletes each BrowserChildProcessHost
40 // instance.
41 static void TerminateAll();
43 // BrowserChildProcessHost implementation:
44 virtual bool Send(IPC::Message* message) OVERRIDE;
45 virtual void Launch(
46 #if defined(OS_WIN)
47 SandboxedProcessLauncherDelegate* delegate,
48 #elif defined(OS_POSIX)
49 bool use_zygote,
50 const base::EnvironmentMap& environ,
51 #endif
52 CommandLine* cmd_line) OVERRIDE;
53 virtual const ChildProcessData& GetData() const OVERRIDE;
54 virtual ChildProcessHost* GetHost() const OVERRIDE;
55 virtual base::TerminationStatus GetTerminationStatus(
56 bool known_dead, int* exit_code) OVERRIDE;
57 virtual void SetNaClDebugStubPort(int port) OVERRIDE;
58 virtual void SetName(const base::string16& name) OVERRIDE;
59 virtual void SetHandle(base::ProcessHandle handle) OVERRIDE;
61 // 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.
63 base::ProcessHandle GetHandle() const;
65 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown
66 void ForceShutdown();
68 // Callers can reduce the BrowserChildProcess' priority.
69 void SetBackgrounded(bool backgrounded);
71 // Controls whether the child process should be terminated on browser
72 // shutdown. Default is to always terminate.
73 void SetTerminateChildOnShutdown(bool terminate_on_shutdown);
75 // Adds an IPC message filter.
76 void AddFilter(BrowserMessageFilter* filter);
78 // Called when an instance of a particular child is created in a page.
79 static void NotifyProcessInstanceCreated(const ChildProcessData& data);
81 BrowserChildProcessHostDelegate* delegate() const { return delegate_; }
83 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
84 private:
85 friend class BrowserChildProcessHostIterator;
86 friend class BrowserChildProcessObserver;
88 static BrowserChildProcessList* GetIterator();
90 static void AddObserver(BrowserChildProcessObserver* observer);
91 static void RemoveObserver(BrowserChildProcessObserver* observer);
93 // ChildProcessHostDelegate implementation:
94 virtual bool CanShutdown() OVERRIDE;
95 virtual void OnChildDisconnected() OVERRIDE;
96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
97 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
98 virtual void OnChannelError() OVERRIDE;
100 // ChildProcessLauncher::Client implementation.
101 virtual void OnProcessLaunched() OVERRIDE;
103 #if defined(OS_WIN)
104 void DeleteProcessWaitableEvent(base::WaitableEvent* event);
105 void OnProcessExitedEarly(base::WaitableEvent* event);
106 #endif
108 ChildProcessData data_;
109 BrowserChildProcessHostDelegate* delegate_;
110 scoped_ptr<ChildProcessHost> child_process_host_;
112 scoped_ptr<ChildProcessLauncher> child_process_;
114 PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_;
116 #if defined(OS_WIN)
117 // Watches to see if the child process exits before the IPC channel has
118 // been connected. Thereafter, its exit is determined by an error on the
119 // IPC channel.
120 base::WaitableEventWatcher early_exit_watcher_;
121 #endif
124 } // namespace content
126 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_