Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / browser_child_process_host_impl.h
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.
4
5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_
6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_
7
8 #include <list>
9
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"
19
20 #if defined(OS_WIN)
21 #include "base/win/object_watcher.h"
22 #endif
23
24 namespace base {
25 class CommandLine;
26 }
27
28 namespace content {
29
30 class BrowserChildProcessHostIterator;
31 class BrowserChildProcessObserver;
32 class BrowserMessageFilter;
33
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(
46       int process_type,
47       BrowserChildProcessHostDelegate* delegate);
48   ~BrowserChildProcessHostImpl() override;
49
50   // Terminates all child processes and deletes each BrowserChildProcessHost
51   // instance.
52   static void TerminateAll();
53
54   // BrowserChildProcessHost implementation:
55   bool Send(IPC::Message* message) override;
56   void Launch(SandboxedProcessLauncherDelegate* delegate,
57               base::CommandLine* cmd_line) 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;
64
65   // ChildProcessHostDelegate implementation:
66   bool CanShutdown() override;
67   void OnChildDisconnected() override;
68   base::ProcessHandle GetHandle() 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;
73
74   // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown
75   void ForceShutdown();
76
77   // Callers can reduce the BrowserChildProcess' priority.
78   void SetBackgrounded(bool backgrounded);
79
80   // Controls whether the child process should be terminated on browser
81   // shutdown. Default is to always terminate.
82   void SetTerminateChildOnShutdown(bool terminate_on_shutdown);
83
84   // Adds an IPC message filter.
85   void AddFilter(BrowserMessageFilter* filter);
86
87   // Called when an instance of a particular child is created in a page.
88   static void NotifyProcessInstanceCreated(const ChildProcessData& data);
89
90   static void HistogramBadMessageTerminated(int process_type);
91
92   BrowserChildProcessHostDelegate* delegate() const { return delegate_; }
93
94   typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList;
95  private:
96   friend class BrowserChildProcessHostIterator;
97   friend class BrowserChildProcessObserver;
98
99   static BrowserChildProcessList* GetIterator();
100
101   static void AddObserver(BrowserChildProcessObserver* observer);
102   static void RemoveObserver(BrowserChildProcessObserver* observer);
103
104   // ChildProcessLauncher::Client implementation.
105   void OnProcessLaunched() override;
106   void OnProcessLaunchFailed() override;
107
108 #if defined(OS_WIN)
109   // ObjectWatcher::Delegate implementation.
110   void OnObjectSignaled(HANDLE object) override;
111 #endif
112
113   ChildProcessData data_;
114   BrowserChildProcessHostDelegate* delegate_;
115   scoped_ptr<ChildProcessHost> child_process_host_;
116
117   scoped_ptr<ChildProcessLauncher> child_process_;
118
119   PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_;
120
121 #if defined(OS_WIN)
122   // Watches to see if the child process exits before the IPC channel has
123   // been connected. Thereafter, its exit is determined by an error on the
124   // IPC channel.
125   base::win::ObjectWatcher early_exit_watcher_;
126 #endif
127 };
128
129 }  // namespace content
130
131 #endif  // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_