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_RENDERER_RENDER_THREAD_H_ | |
6 #define CONTENT_RENDERER_RENDER_THREAD_H_ | |
7 #pragma once | |
8 | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/observer_list.h" | |
14 #include "base/shared_memory.h" | |
15 #include "base/time.h" | |
16 #include "base/timer.h" | |
17 #include "build/build_config.h" | |
18 #include "content/common/child_thread.h" | |
19 #include "content/common/content_export.h" | |
20 #include "content/common/css_colors.h" | |
21 #include "content/common/gpu/gpu_process_launch_causes.h" | |
22 #include "content/public/renderer/render_thread.h" | |
23 #include "ipc/ipc_channel_proxy.h" | |
24 #include "ui/gfx/native_widget_types.h" | |
25 | |
26 class AppCacheDispatcher; | |
27 class AudioInputMessageFilter; | |
28 class AudioMessageFilter; | |
29 class CompositorThread; | |
30 class DBMessageFilter; | |
31 class DevToolsAgentFilter; | |
32 class FilePath; | |
33 class GpuChannelHost; | |
34 class IndexedDBDispatcher; | |
35 class RendererHistogram; | |
36 class RendererHistogramSnapshots; | |
37 class RendererNetPredictor; | |
38 class RendererWebKitPlatformSupportImpl; | |
39 class SkBitmap; | |
40 class VideoCaptureImplManager; | |
41 class WebDatabaseObserverImpl; | |
42 | |
43 struct RendererPreferences; | |
44 struct DOMStorageMsg_Event_Params; | |
45 struct GPUInfo; | |
46 struct ViewMsg_New_Params; | |
47 struct WebPreferences; | |
48 | |
49 namespace IPC { | |
50 struct ChannelHandle; | |
51 } | |
52 | |
53 namespace WebKit { | |
54 class WebStorageEventDispatcher; | |
55 } | |
56 | |
57 namespace base { | |
58 class MessageLoopProxy; | |
59 class Thread; | |
60 } | |
61 | |
62 namespace content { | |
63 class RenderProcessObserver; | |
64 } | |
65 | |
66 namespace v8 { | |
67 class Extension; | |
68 } | |
69 | |
70 // The RenderThread class represents a background thread where RenderView | |
71 // instances live. The RenderThread supports an API that is used by its | |
72 // consumer to talk indirectly to the RenderViews and supporting objects. | |
73 // Likewise, it provides an API for the RenderViews to talk back to the main | |
74 // process (i.e., their corresponding TabContents). | |
75 // | |
76 // Most of the communication occurs in the form of IPC messages. They are | |
77 // routed to the RenderThread according to the routing IDs of the messages. | |
78 // The routing IDs correspond to RenderView instances. | |
79 class CONTENT_EXPORT RenderThread : public content::RenderThread, | |
80 public ChildThread { | |
81 public: | |
82 static RenderThread* current(); | |
83 | |
84 RenderThread(); | |
85 // Constructor that's used when running in single process mode. | |
86 explicit RenderThread(const std::string& channel_name); | |
87 virtual ~RenderThread(); | |
88 | |
89 // Returns the routing ID of the RenderWidget containing the current script | |
90 // execution context (corresponding to WebFrame::frameForCurrentContext). | |
91 static int32 RoutingIDForCurrentContext(); | |
92 | |
93 // content::RenderThread implementation: | |
94 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
95 virtual MessageLoop* GetMessageLoop() OVERRIDE; | |
96 virtual IPC::SyncChannel* GetChannel() OVERRIDE; | |
97 virtual ResourceDispatcher* GetResourceDispatcher() OVERRIDE; | |
98 virtual std::string GetLocale() OVERRIDE; | |
99 virtual void AddRoute(int32 routing_id, | |
100 IPC::Channel::Listener* listener) OVERRIDE; | |
101 virtual void RemoveRoute(int32 routing_id) OVERRIDE; | |
102 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; | |
103 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; | |
104 virtual void SetOutgoingMessageFilter( | |
105 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE; | |
106 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE; | |
107 virtual void RemoveObserver( | |
108 content::RenderProcessObserver* observer) OVERRIDE; | |
109 virtual void WidgetHidden() OVERRIDE; | |
110 virtual void WidgetRestored() OVERRIDE; | |
111 virtual void EnsureWebKitInitialized() OVERRIDE; | |
112 virtual void RecordUserMetrics(const std::string& action) OVERRIDE; | |
113 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE; | |
114 virtual bool IsRegisteredExtension( | |
115 const std::string& v8_extension_name) const OVERRIDE; | |
116 virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE; | |
117 virtual void IdleHandler() OVERRIDE; | |
118 virtual double GetIdleNotificationDelayInS() const OVERRIDE; | |
119 virtual void SetIdleNotificationDelayInS( | |
120 double idle_notification_delay_in_s) OVERRIDE; | |
121 #if defined(OS_WIN) | |
122 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE; | |
123 virtual void ReleaseCachedFonts() OVERRIDE; | |
124 #endif | |
125 | |
126 // These methods modify how the next message is sent. Normally, when sending | |
127 // a synchronous message that runs a nested message loop, we need to suspend | |
128 // callbacks into WebKit. This involves disabling timers and deferring | |
129 // resource loads. However, there are exceptions when we need to customize | |
130 // the behavior. | |
131 void DoNotSuspendWebKitSharedTimer(); | |
132 void DoNotNotifyWebKitOfModalLoop(); | |
133 | |
134 CompositorThread* compositor_thread() const { | |
135 return compositor_thread_.get(); | |
136 } | |
137 | |
138 AppCacheDispatcher* appcache_dispatcher() const { | |
139 return appcache_dispatcher_.get(); | |
140 } | |
141 | |
142 IndexedDBDispatcher* indexed_db_dispatcher() const { | |
143 return indexed_db_dispatcher_.get(); | |
144 } | |
145 | |
146 AudioInputMessageFilter* audio_input_message_filter() { | |
147 return audio_input_message_filter_.get(); | |
148 } | |
149 | |
150 AudioMessageFilter* audio_message_filter() { | |
151 return audio_message_filter_.get(); | |
152 } | |
153 | |
154 VideoCaptureImplManager* video_capture_impl_manager() const { | |
155 return vc_manager_.get(); | |
156 } | |
157 | |
158 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; } | |
159 | |
160 // Synchronously establish a channel to the GPU plugin if not previously | |
161 // established or if it has been lost (for example if the GPU plugin crashed). | |
162 // If there is a pending asynchronous request, it will be completed by the | |
163 // time this routine returns. | |
164 GpuChannelHost* EstablishGpuChannelSync(content::CauseForGpuLaunch); | |
165 | |
166 // Get the GPU channel. Returns NULL if the channel is not established or | |
167 // has been lost. | |
168 GpuChannelHost* GetGpuChannel(); | |
169 | |
170 // Returns a MessageLoopProxy instance corresponding to the message loop | |
171 // of the thread on which file operations should be run. Must be called | |
172 // on the renderer's main thread. | |
173 scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); | |
174 | |
175 private: | |
176 virtual bool OnControlMessageReceived(const IPC::Message& msg); | |
177 | |
178 void Init(); | |
179 | |
180 void OnSetZoomLevelForCurrentURL(const GURL& url, double zoom_level); | |
181 void OnDOMStorageEvent(const DOMStorageMsg_Event_Params& params); | |
182 void OnSetNextPageID(int32 next_page_id); | |
183 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors); | |
184 void OnCreateNewView(const ViewMsg_New_Params& params); | |
185 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); | |
186 void OnPurgePluginListCache(bool reload_pages); | |
187 void OnNetworkStateChanged(bool online); | |
188 void OnGetAccessibilityTree(); | |
189 | |
190 // These objects live solely on the render thread. | |
191 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_; | |
192 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_; | |
193 scoped_ptr<IndexedDBDispatcher> indexed_db_dispatcher_; | |
194 scoped_ptr<RendererWebKitPlatformSupportImpl> webkit_platform_support_; | |
195 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_; | |
196 | |
197 // Used on the renderer and IPC threads. | |
198 scoped_refptr<DBMessageFilter> db_message_filter_; | |
199 scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_; | |
200 scoped_refptr<AudioMessageFilter> audio_message_filter_; | |
201 scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_; | |
202 | |
203 // Used on multiple threads. | |
204 scoped_refptr<VideoCaptureImplManager> vc_manager_; | |
205 | |
206 // Used on multiple script execution context threads. | |
207 scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; | |
208 | |
209 // If true, then a GetPlugins call is allowed to rescan the disk. | |
210 bool plugin_refresh_allowed_; | |
211 | |
212 // The count of RenderWidgets running through this thread. | |
213 int widget_count_; | |
214 | |
215 // The count of hidden RenderWidgets running through this thread. | |
216 int hidden_widget_count_; | |
217 | |
218 // The current value of the idle notification timer delay. | |
219 double idle_notification_delay_in_s_; | |
220 | |
221 bool suspend_webkit_shared_timer_; | |
222 bool notify_webkit_of_modal_loop_; | |
223 | |
224 // Timer that periodically calls IdleHandler. | |
225 base::RepeatingTimer<RenderThread> idle_timer_; | |
226 | |
227 // The channel from the renderer process to the GPU process. | |
228 scoped_refptr<GpuChannelHost> gpu_channel_; | |
229 | |
230 // A lazily initiated thread on which file operations are run. | |
231 scoped_ptr<base::Thread> file_thread_; | |
232 | |
233 // Map of registered v8 extensions. The key is the extension name. | |
234 std::set<std::string> v8_extensions_; | |
235 | |
236 scoped_ptr<CompositorThread> compositor_thread_; | |
237 | |
238 ObserverList<content::RenderProcessObserver> observers_; | |
239 | |
240 DISALLOW_COPY_AND_ASSIGN(RenderThread); | |
241 }; | |
242 | |
243 #endif // CONTENT_RENDERER_RENDER_THREAD_H_ | |
OLD | NEW |