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_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <queue> | |
11 #include <string> | |
12 | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/process.h" | |
15 #include "base/synchronization/waitable_event_watcher.h" | |
16 #include "base/timer.h" | |
17 #include "content/browser/child_process_launcher.h" | |
18 #include "content/common/content_export.h" | |
19 #include "content/browser/renderer_host/render_process_host.h" | |
20 #include "ui/gfx/surface/transport_dib.h" | |
21 | |
22 class CommandLine; | |
23 class RendererMainThread; | |
24 class RenderWidgetHelper; | |
25 | |
26 namespace base { | |
27 class WaitableEvent; | |
28 } | |
29 | |
30 // Implements a concrete RenderProcessHost for the browser process for talking | |
31 // to actual renderer processes (as opposed to mocks). | |
32 // | |
33 // Represents the browser side of the browser <--> renderer communication | |
34 // channel. There will be one RenderProcessHost per renderer process. | |
35 // | |
36 // This object is refcounted so that it can release its resources when all | |
37 // hosts using it go away. | |
38 // | |
39 // This object communicates back and forth with the RenderProcess object | |
40 // running in the renderer process. Each RenderProcessHost and RenderProcess | |
41 // keeps a list of RenderView (renderer) and TabContents (browser) which | |
42 // are correlated with IDs. This way, the Views and the corresponding ViewHosts | |
43 // communicate through the two process objects. | |
44 class CONTENT_EXPORT BrowserRenderProcessHost | |
45 : public RenderProcessHost, | |
46 public ChildProcessLauncher::Client, | |
47 public base::WaitableEventWatcher::Delegate { | |
48 public: | |
49 explicit BrowserRenderProcessHost(content::BrowserContext* browser_context); | |
50 virtual ~BrowserRenderProcessHost(); | |
51 | |
52 // RenderProcessHost implementation (public portion). | |
53 virtual void EnableSendQueue(); | |
54 virtual bool Init(bool is_accessibility_enabled); | |
55 virtual int GetNextRoutingID(); | |
56 virtual void CancelResourceRequests(int render_widget_id); | |
57 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params); | |
58 virtual bool WaitForUpdateMsg(int render_widget_id, | |
59 const base::TimeDelta& max_delay, | |
60 IPC::Message* msg); | |
61 virtual void ReceivedBadMessage(); | |
62 virtual void WidgetRestored(); | |
63 virtual void WidgetHidden(); | |
64 virtual int VisibleWidgetCount() const; | |
65 virtual bool FastShutdownIfPossible(); | |
66 virtual void DumpHandles(); | |
67 virtual base::ProcessHandle GetHandle(); | |
68 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); | |
69 virtual void SetCompositingSurface( | |
70 int render_widget_id, | |
71 gfx::PluginWindowHandle compositing_surface); | |
72 | |
73 // IPC::Channel::Sender via RenderProcessHost. | |
74 virtual bool Send(IPC::Message* msg); | |
75 | |
76 // IPC::Channel::Listener via RenderProcessHost. | |
77 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
79 virtual void OnChannelError() OVERRIDE; | |
80 | |
81 // ChildProcessLauncher::Client implementation. | |
82 virtual void OnProcessLaunched(); | |
83 | |
84 // base::WaitableEventWatcher::Delegate implementation. | |
85 virtual void OnWaitableEventSignaled( | |
86 base::WaitableEvent* waitable_event) OVERRIDE; | |
87 | |
88 private: | |
89 friend class VisitRelayingRenderProcessHost; | |
90 | |
91 // Creates and adds the IO thread message filters. | |
92 void CreateMessageFilters(); | |
93 | |
94 // Control message handlers. | |
95 void OnShutdownRequest(); | |
96 void OnDumpHandlesDone(); | |
97 void SuddenTerminationChanged(bool enabled); | |
98 void OnUserMetricsRecordAction(const std::string& action); | |
99 void OnRevealFolderInOS(const FilePath& path); | |
100 void OnSavedPageAsMHTML(int job_id, int64 mhtml_file_size); | |
101 | |
102 // Generates a command line to be used to spawn a renderer and appends the | |
103 // results to |*command_line|. | |
104 void AppendRendererCommandLine(CommandLine* command_line) const; | |
105 | |
106 // Copies applicable command line switches from the given |browser_cmd| line | |
107 // flags to the output |renderer_cmd| line flags. Not all switches will be | |
108 // copied over. | |
109 void PropagateBrowserCommandLineToRenderer(const CommandLine& browser_cmd, | |
110 CommandLine* renderer_cmd) const; | |
111 | |
112 // Callers can reduce the RenderProcess' priority. | |
113 void SetBackgrounded(bool backgrounded); | |
114 | |
115 // Handle termination of our process. |was_alive| indicates that when we | |
116 // tried to retrieve the exit code the process had not finished yet. | |
117 void ProcessDied(base::ProcessHandle handle, | |
118 base::TerminationStatus status, | |
119 int exit_code, | |
120 bool was_alive); | |
121 | |
122 // The count of currently visible widgets. Since the host can be a container | |
123 // for multiple widgets, it uses this count to determine when it should be | |
124 // backgrounded. | |
125 int32 visible_widgets_; | |
126 | |
127 // Does this process have backgrounded priority. | |
128 bool backgrounded_; | |
129 | |
130 // Used to allow a RenderWidgetHost to intercept various messages on the | |
131 // IO thread. | |
132 scoped_refptr<RenderWidgetHelper> widget_helper_; | |
133 | |
134 // A map of transport DIB ids to cached TransportDIBs | |
135 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_; | |
136 enum { | |
137 // This is the maximum size of |cached_dibs_| | |
138 MAX_MAPPED_TRANSPORT_DIBS = 3, | |
139 }; | |
140 | |
141 // Map a transport DIB from its Id and return it. Returns NULL on error. | |
142 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); | |
143 | |
144 void ClearTransportDIBCache(); | |
145 // This is used to clear our cache five seconds after the last use. | |
146 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_; | |
147 | |
148 // Used in single-process mode. | |
149 scoped_ptr<RendererMainThread> in_process_renderer_; | |
150 | |
151 // True if this prcoess should have accessibility enabled; | |
152 bool accessibility_enabled_; | |
153 | |
154 // True after Init() has been called. We can't just check channel_ because we | |
155 // also reset that in the case of process termination. | |
156 bool is_initialized_; | |
157 | |
158 // Used to launch and terminate the process without blocking the UI thread. | |
159 scoped_ptr<ChildProcessLauncher> child_process_launcher_; | |
160 | |
161 // Messages we queue while waiting for the process handle. We queue them here | |
162 // instead of in the channel so that we ensure they're sent after init related | |
163 // messages that are sent once the process handle is available. This is | |
164 // because the queued messages may have dependencies on the init messages. | |
165 std::queue<IPC::Message*> queued_messages_; | |
166 | |
167 #if defined(OS_WIN) | |
168 // Used to wait until the renderer dies to get an accurrate exit code. | |
169 base::WaitableEventWatcher child_process_watcher_; | |
170 #endif | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); | |
173 }; | |
174 | |
175 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | |
OLD | NEW |