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() OVERRIDE; | |
54 virtual bool Init(bool is_accessibility_enabled) OVERRIDE; | |
55 virtual int GetNextRoutingID() OVERRIDE; | |
56 virtual void CancelResourceRequests(int render_widget_id) OVERRIDE; | |
57 virtual void CrossSiteSwapOutACK( | |
58 const ViewMsg_SwapOut_Params& params) OVERRIDE; | |
59 virtual bool WaitForUpdateMsg(int render_widget_id, | |
60 const base::TimeDelta& max_delay, | |
61 IPC::Message* msg) OVERRIDE; | |
62 virtual void ReceivedBadMessage() OVERRIDE; | |
63 virtual void WidgetRestored() OVERRIDE; | |
64 virtual void WidgetHidden() OVERRIDE; | |
65 virtual int VisibleWidgetCount() const OVERRIDE; | |
66 virtual bool FastShutdownIfPossible() OVERRIDE; | |
67 virtual void DumpHandles() OVERRIDE; | |
68 virtual base::ProcessHandle GetHandle() OVERRIDE; | |
69 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id) OVERRIDE; | |
70 virtual void SetCompositingSurface( | |
71 int render_widget_id, | |
72 gfx::PluginWindowHandle compositing_surface) OVERRIDE; | |
73 | |
74 // IPC::Channel::Sender via RenderProcessHost. | |
75 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
76 | |
77 // IPC::Channel::Listener via RenderProcessHost. | |
78 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
79 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
80 virtual void OnChannelError() OVERRIDE; | |
81 | |
82 // ChildProcessLauncher::Client implementation. | |
83 virtual void OnProcessLaunched() OVERRIDE; | |
84 | |
85 // base::WaitableEventWatcher::Delegate implementation. | |
86 virtual void OnWaitableEventSignaled( | |
87 base::WaitableEvent* waitable_event) OVERRIDE; | |
88 | |
89 private: | |
90 friend class VisitRelayingRenderProcessHost; | |
91 | |
92 // Creates and adds the IO thread message filters. | |
93 void CreateMessageFilters(); | |
94 | |
95 // Control message handlers. | |
96 void OnShutdownRequest(); | |
97 void OnDumpHandlesDone(); | |
98 void SuddenTerminationChanged(bool enabled); | |
99 void OnUserMetricsRecordAction(const std::string& action); | |
100 void OnRevealFolderInOS(const FilePath& path); | |
101 void OnSavedPageAsMHTML(int job_id, int64 mhtml_file_size); | |
102 | |
103 // Generates a command line to be used to spawn a renderer and appends the | |
104 // results to |*command_line|. | |
105 void AppendRendererCommandLine(CommandLine* command_line) const; | |
106 | |
107 // Copies applicable command line switches from the given |browser_cmd| line | |
108 // flags to the output |renderer_cmd| line flags. Not all switches will be | |
109 // copied over. | |
110 void PropagateBrowserCommandLineToRenderer(const CommandLine& browser_cmd, | |
111 CommandLine* renderer_cmd) const; | |
112 | |
113 // Callers can reduce the RenderProcess' priority. | |
114 void SetBackgrounded(bool backgrounded); | |
115 | |
116 // Handle termination of our process. |was_alive| indicates that when we | |
117 // tried to retrieve the exit code the process had not finished yet. | |
118 void ProcessDied(base::ProcessHandle handle, | |
119 base::TerminationStatus status, | |
120 int exit_code, | |
121 bool was_alive); | |
122 | |
123 // The count of currently visible widgets. Since the host can be a container | |
124 // for multiple widgets, it uses this count to determine when it should be | |
125 // backgrounded. | |
126 int32 visible_widgets_; | |
127 | |
128 // Does this process have backgrounded priority. | |
129 bool backgrounded_; | |
130 | |
131 // Used to allow a RenderWidgetHost to intercept various messages on the | |
132 // IO thread. | |
133 scoped_refptr<RenderWidgetHelper> widget_helper_; | |
134 | |
135 // A map of transport DIB ids to cached TransportDIBs | |
136 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_; | |
137 enum { | |
138 // This is the maximum size of |cached_dibs_| | |
139 MAX_MAPPED_TRANSPORT_DIBS = 3, | |
140 }; | |
141 | |
142 // Map a transport DIB from its Id and return it. Returns NULL on error. | |
143 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); | |
144 | |
145 void ClearTransportDIBCache(); | |
146 // This is used to clear our cache five seconds after the last use. | |
147 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_; | |
148 | |
149 // Used in single-process mode. | |
150 scoped_ptr<RendererMainThread> in_process_renderer_; | |
151 | |
152 // True if this prcoess should have accessibility enabled; | |
153 bool accessibility_enabled_; | |
154 | |
155 // True after Init() has been called. We can't just check channel_ because we | |
156 // also reset that in the case of process termination. | |
157 bool is_initialized_; | |
158 | |
159 // Used to launch and terminate the process without blocking the UI thread. | |
160 scoped_ptr<ChildProcessLauncher> child_process_launcher_; | |
161 | |
162 // Messages we queue while waiting for the process handle. We queue them here | |
163 // instead of in the channel so that we ensure they're sent after init related | |
164 // messages that are sent once the process handle is available. This is | |
165 // because the queued messages may have dependencies on the init messages. | |
166 std::queue<IPC::Message*> queued_messages_; | |
167 | |
168 #if defined(OS_WIN) | |
169 // Used to wait until the renderer dies to get an accurrate exit code. | |
170 base::WaitableEventWatcher child_process_watcher_; | |
171 #endif | |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); | |
174 }; | |
175 | |
176 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | |
OLD | NEW |