Add ICU message format support
[chromium-blink-merge.git] / content / browser / browser_child_process_host_impl.h
blob0157db9873f45edb06cf173cee52cfd15fdd3b26
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;
33 class ServiceRegistry;
35 // Plugins/workers and other child processes that live on the IO thread use this
36 // class. RenderProcessHostImpl is the main exception that doesn't use this
37 /// class because it lives on the UI thread.
38 class CONTENT_EXPORT BrowserChildProcessHostImpl
39 : public BrowserChildProcessHost,
40 public NON_EXPORTED_BASE(ChildProcessHostDelegate),
41 #if defined(OS_WIN)
42 public base::win::ObjectWatcher::Delegate,
43 #endif
44 public ChildProcessLauncher::Client {
45 public:
46 BrowserChildProcessHostImpl(content::ProcessType process_type,
47 BrowserChildProcessHostDelegate* delegate);
48 ~BrowserChildProcessHostImpl() override;
50 // Terminates all child processes and deletes each BrowserChildProcessHost
51 // instance.
52 static void TerminateAll();
54 // BrowserChildProcessHost implementation:
55 bool Send(IPC::Message* message) override;
56 void Launch(SandboxedProcessLauncherDelegate* delegate,
57 base::CommandLine* cmd_line,
58 bool terminate_on_shutdown) override;
59 const ChildProcessData& GetData() const override;
60 ChildProcessHost* GetHost() const override;
61 base::TerminationStatus GetTerminationStatus(bool known_dead,
62 int* exit_code) override;
63 void SetName(const base::string16& name) override;
64 void SetHandle(base::ProcessHandle handle) override;
65 ServiceRegistry* GetServiceRegistry() override;
67 // ChildProcessHostDelegate implementation:
68 bool CanShutdown() override;
69 void OnChildDisconnected() override;
70 const base::Process& GetProcess() const override;
71 bool OnMessageReceived(const IPC::Message& message) override;
72 void OnChannelConnected(int32 peer_pid) override;
73 void OnChannelError() override;
74 void OnBadMessageReceived(const IPC::Message& message) override;
76 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown
77 void ForceShutdown();
79 // Callers can reduce the BrowserChildProcess' priority.
80 void SetBackgrounded(bool backgrounded);
82 // Adds an IPC message filter.
83 void AddFilter(BrowserMessageFilter* filter);
85 // Called when an instance of a particular child is created in a page.
86 static void NotifyProcessInstanceCreated(const ChildProcessData& data);
88 static void HistogramBadMessageTerminated(int process_type);
90 BrowserChildProcessHostDelegate* delegate() const { return delegate_; }
92 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
93 private:
94 friend class BrowserChildProcessHostIterator;
95 friend class BrowserChildProcessObserver;
97 static BrowserChildProcessList* GetIterator();
99 static void AddObserver(BrowserChildProcessObserver* observer);
100 static void RemoveObserver(BrowserChildProcessObserver* observer);
102 // ChildProcessLauncher::Client implementation.
103 void OnProcessLaunched() override;
104 void OnProcessLaunchFailed() override;
106 #if defined(OS_WIN)
107 // ObjectWatcher::Delegate implementation.
108 void OnObjectSignaled(HANDLE object) override;
109 #endif
111 ChildProcessData data_;
112 BrowserChildProcessHostDelegate* delegate_;
113 scoped_ptr<ChildProcessHost> child_process_host_;
115 scoped_ptr<ChildProcessLauncher> child_process_;
117 PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_;
119 #if defined(OS_WIN)
120 // Watches to see if the child process exits before the IPC channel has
121 // been connected. Thereafter, its exit is determined by an error on the
122 // IPC channel.
123 base::win::ObjectWatcher early_exit_watcher_;
124 #endif
127 } // namespace content
129 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_