blob: 8a376aad982939e865c143ad0156851b1026cff0 [file] [log] [blame]
[email protected]45776222009-07-15 20:21:581// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]1d97d2e2008-12-18 23:39:025#ifndef CHROME_RENDERER_RENDER_THREAD_H_
6#define CHROME_RENDERER_RENDER_THREAD_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]b68d5ed2009-04-16 02:41:288#include <string>
[email protected]1bc83062009-02-06 00:16:379#include <vector>
10
[email protected]010ea08a2009-10-11 20:21:3211#include "app/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/shared_memory.h"
[email protected]85c55dc2009-11-06 03:05:4613#include "base/string16.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/task.h"
[email protected]71d6d852009-12-07 22:12:3615#include "base/time.h"
16#include "base/timer.h"
[email protected]037fce02009-01-22 01:42:1517#include "build/build_config.h"
[email protected]8930d472009-02-21 08:05:2818#include "chrome/common/child_thread.h"
[email protected]b9ab10c2009-08-07 18:09:5519#include "chrome/common/css_colors.h"
[email protected]b7c7bcf2009-10-03 07:07:3420#include "chrome/common/dom_storage_type.h"
[email protected]55e57d42009-02-25 06:10:1721#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]3e90d4a2009-07-03 17:38:3922#include "chrome/renderer/visitedlink_slave.h"
[email protected]cb6037d2009-11-16 22:55:1723#include "ipc/ipc_platform_file.h"
initial.commit09911bf2008-07-26 23:55:2924
[email protected]1edc16b82009-04-07 17:45:5425class AppCacheDispatcher;
[email protected]017022b2009-07-27 23:06:3426class DBMessageFilter;
[email protected]a8624712009-04-17 00:51:3527class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2528class FilePath;
[email protected]dfcb62a2009-06-17 19:32:4329class ListValue;
[email protected]b7c7bcf2009-10-03 07:07:3430class NullableString16;
[email protected]39008c02009-02-11 23:59:2531class RenderDnsMaster;
[email protected]55e57d42009-02-25 06:10:1732class RendererHistogram;
[email protected]e2b2d4a2009-10-24 03:32:5933class RendererWebDatabaseObserver;
[email protected]8d86fce2009-02-26 23:37:5534class RendererWebKitClientImpl;
[email protected]85c55dc2009-11-06 03:05:4635class SpellCheck;
[email protected]39008c02009-02-11 23:59:2536class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4037class UserScriptSlave;
[email protected]cccf90932009-08-23 17:56:2538class URLPattern;
39
[email protected]9b6f40e2009-06-11 15:54:2640struct RendererPreferences;
[email protected]c61cc652009-11-04 05:44:4041struct ViewMsg_DOMStorageEvent_Params;
[email protected]39008c02009-02-11 23:59:2542struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2943
[email protected]b7c7bcf2009-10-03 07:07:3444namespace WebKit {
45class WebStorageEventDispatcher;
46}
47
[email protected]81a34412009-01-05 19:17:2448// The RenderThreadBase is the minimal interface that a RenderView/Widget
49// expects from a render thread. The interface basically abstracts a way to send
50// and receive messages.
[email protected]8930d472009-02-21 08:05:2851class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4452 public:
53 virtual ~RenderThreadBase() {}
54
[email protected]8930d472009-02-21 08:05:2855 virtual bool Send(IPC::Message* msg) = 0;
56
[email protected]8085dbc82008-09-26 22:53:4457 // Called to add or remove a listener for a particular message routing ID.
58 // These methods normally get delegated to a MessageRouter.
59 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
60 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2461
62 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
63 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]bee16aab2009-08-26 15:55:0364
65 // Called by a RenderWidget when it is hidden or restored.
66 virtual void WidgetHidden() = 0;
67 virtual void WidgetRestored() = 0;
[email protected]8085dbc82008-09-26 22:53:4468};
69
initial.commit09911bf2008-07-26 23:55:2970// 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
[email protected]57c6a652009-05-04 07:58:3474// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2975//
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.
[email protected]8930d472009-02-21 08:05:2879class RenderThread : public RenderThreadBase,
80 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2981 public:
[email protected]8930d472009-02-21 08:05:2882 // Grabs the IPC channel name from the command line.
83 RenderThread();
84 // Constructor that's used when running in single process mode.
[email protected]11f4857282009-11-13 19:56:1785 explicit RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:4486 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2987
[email protected]8930d472009-02-21 08:05:2888 // Returns the one render thread for this process. Note that this should only
89 // be accessed when running on the render thread itself
90 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2991
[email protected]45776222009-07-15 20:21:5892 // Overridden from RenderThreadBase.
[email protected]8930d472009-02-21 08:05:2893 virtual bool Send(IPC::Message* msg) {
94 return ChildThread::Send(msg);
95 }
96
[email protected]8930d472009-02-21 08:05:2897 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) {
[email protected]bee16aab2009-08-26 15:55:0398 widget_count_++;
[email protected]8930d472009-02-21 08:05:2899 return ChildThread::AddRoute(routing_id, listener);
100 }
101 virtual void RemoveRoute(int32 routing_id) {
[email protected]bee16aab2009-08-26 15:55:03102 widget_count_--;
[email protected]8930d472009-02-21 08:05:28103 return ChildThread::RemoveRoute(routing_id);
104 }
105
[email protected]81a34412009-01-05 19:17:24106 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
107 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:29108
[email protected]bee16aab2009-08-26 15:55:03109 virtual void WidgetHidden();
110 virtual void WidgetRestored();
111
[email protected]8d86fce2009-02-26 23:37:55112 VisitedLinkSlave* visited_link_slave() const {
113 return visited_link_slave_.get();
114 }
initial.commit09911bf2008-07-26 23:55:29115
[email protected]8d86fce2009-02-26 23:37:55116 UserScriptSlave* user_script_slave() const {
117 return user_script_slave_.get();
118 }
[email protected]1e0f70402008-10-16 23:57:47119
[email protected]f430b5712009-08-21 21:46:31120 AppCacheDispatcher* appcache_dispatcher() const {
121 return appcache_dispatcher_.get();
122 }
123
[email protected]85c55dc2009-11-06 03:05:46124 SpellCheck* spellchecker() const {
125 return spellchecker_.get();
126 }
[email protected]85c55dc2009-11-06 03:05:46127
[email protected]b547fd42009-04-23 23:16:27128 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
129
[email protected]71d6d852009-12-07 22:12:36130 bool is_extension_process() const { return is_extension_process_; }
131
initial.commit09911bf2008-07-26 23:55:29132 // Do DNS prefetch resolution of a hostname.
133 void Resolve(const char* name, size_t length);
134
[email protected]55e57d42009-02-25 06:10:17135 // Send all the Histogram data to browser.
[email protected]c9a3ef82009-05-28 22:02:46136 void SendHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17137
initial.commit09911bf2008-07-26 23:55:29138 // Invokes InformHostOfCacheStats after a short delay. Used to move this
139 // bookkeeping operation off the critical latency path.
140 void InformHostOfCacheStatsLater();
141
[email protected]b07f29092009-06-05 07:33:21142 // Sends a message to the browser to close all idle connections.
143 void CloseIdleConnections();
144
145 // Sends a message to the browser to enable or disable the disk cache.
146 void SetCacheMode(bool enabled);
147
[email protected]8930d472009-02-21 08:05:28148 private:
149 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29150
[email protected]42f1d7822009-07-23 18:17:55151 void Init();
initial.commit09911bf2008-07-26 23:55:29152
[email protected]176aa482008-11-14 03:25:15153 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]3e90d4a2009-07-03 17:38:39154 void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
155 void OnResetVisitedLinks();
[email protected]40bd6582009-12-04 23:49:51156 void OnSetZoomLevelForCurrentHost(const std::string& host, int zoom_level);
[email protected]0938d3c2009-01-09 20:37:35157 void OnUpdateUserScripts(base::SharedMemoryHandle table);
[email protected]703e807a2009-03-28 19:56:51158 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
[email protected]45776222009-07-15 20:21:58159 void OnPageActionsUpdated(const std::string& extension_id,
[email protected]b7c7bcf2009-10-03 07:07:34160 const std::vector<std::string>& page_actions);
[email protected]c61cc652009-11-04 05:44:40161 void OnDOMStorageEvent(const ViewMsg_DOMStorageEvent_Params& params);
[email protected]75e126b932009-09-28 19:38:49162 void OnExtensionSetAPIPermissions(
163 const std::string& extension_id,
164 const std::vector<std::string>& permissions);
165 void OnExtensionSetHostPermissions(
166 const GURL& extension_url,
167 const std::vector<URLPattern>& permissions);
168 void OnExtensionSetL10nMessages(
169 const std::string& extension_id,
170 const std::map<std::string, std::string>& l10n_messages);
initial.commit09911bf2008-07-26 23:55:29171 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55172 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]18bcc3c2009-01-27 21:39:15173 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
[email protected]80d96fa2009-06-10 22:34:51174 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29175 const WebPreferences& webkit_prefs,
176 int32 view_id);
177 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
178 void OnSetCacheCapacities(size_t min_dead_capacity,
179 size_t max_dead_capacity,
180 size_t capacity);
181 void OnGetCacheResourceStats();
182
[email protected]55e57d42009-02-25 06:10:17183 // Send all histograms to browser.
[email protected]c9a3ef82009-05-28 22:02:46184 void OnGetRendererHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17185
[email protected]d41041092009-10-08 06:56:57186 // Send tcmalloc info to browser.
187 void OnGetRendererTcmalloc();
[email protected]38b48a82009-11-11 01:51:32188 void OnGetV8HeapStats();
[email protected]d41041092009-10-08 06:56:57189
[email protected]dfcb62a2009-06-17 19:32:43190 void OnExtensionMessageInvoke(const std::string& function_name,
191 const ListValue& args);
[email protected]fede6ca12009-10-08 18:24:26192 void OnPurgeMemory();
[email protected]b78e168b2009-09-21 22:05:45193 void OnPurgePluginListCache(bool reload_pages);
[email protected]75e5a872009-04-02 23:56:11194
[email protected]cb6037d2009-11-16 22:55:17195 void OnInitSpellChecker(IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:46196 const std::vector<std::string>& custom_words,
197 const std::string& language,
198 bool auto_spell_correct);
199 void OnSpellCheckWordAdded(const std::string& word);
200 void OnSpellCheckEnableAutoSpellCorrect(bool enable);
[email protected]85c55dc2009-11-06 03:05:46201
initial.commit09911bf2008-07-26 23:55:29202 // Gather usage statistics from the in-memory cache and inform our host.
203 // These functions should be call periodically so that the host can make
204 // decisions about how to allocation resources using current information.
205 void InformHostOfCacheStats();
206
[email protected]90a3fbb12009-02-28 01:13:47207 // We initialize WebKit as late as possible.
208 void EnsureWebKitInitialized();
209
[email protected]bee16aab2009-08-26 15:55:03210 // A task we invoke periodically to assist with idle cleanup.
211 void IdleHandler();
212
[email protected]71d6d852009-12-07 22:12:36213 // Schedule a call to IdleHandler with the given initial delay.
214 void ScheduleIdleHandler(double initial_delay_s);
215
initial.commit09911bf2008-07-26 23:55:29216 // These objects live solely on the render thread.
[email protected]bee16aab2009-08-26 15:55:03217 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_;
[email protected]42f1d7822009-07-23 18:17:55218 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
219 scoped_ptr<UserScriptSlave> user_script_slave_;
220 scoped_ptr<RenderDnsMaster> dns_master_;
[email protected]f430b5712009-08-21 21:46:31221 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22222 scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
[email protected]42f1d7822009-07-23 18:17:55223 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
224 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]b7c7bcf2009-10-03 07:07:34225 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]e2b2d4a2009-10-24 03:32:59226 scoped_ptr<RendererWebDatabaseObserver> renderer_web_database_observer_;
[email protected]85c55dc2009-11-06 03:05:46227 scoped_ptr<SpellCheck> spellchecker_;
[email protected]9291ed12009-07-23 17:33:22228
[email protected]e2b2d4a2009-10-24 03:32:59229 // Used on the renderer and IPC threads.
[email protected]017022b2009-07-27 23:06:34230 scoped_refptr<DBMessageFilter> db_message_filter_;
231
[email protected]5fa1c542009-05-05 20:36:07232#if defined(OS_POSIX)
233 scoped_refptr<IPC::ChannelProxy::MessageFilter>
234 suicide_on_channel_error_filter_;
235#endif
236
[email protected]b547fd42009-04-23 23:16:27237 // If true, then a GetPlugins call is allowed to rescan the disk.
238 bool plugin_refresh_allowed_;
239
[email protected]bee16aab2009-08-26 15:55:03240 // Is there a pending task for doing CacheStats.
241 bool cache_stats_task_pending_;
242
243 // The count of RenderWidgets running through this thread.
244 int widget_count_;
245
246 // The count of hidden RenderWidgets running through this thread.
247 int hidden_widget_count_;
248
249 // The current value of the idle notification timer delay.
250 double idle_notification_delay_in_s_;
251
[email protected]71d6d852009-12-07 22:12:36252 // True if this renderer is running extensions.
253 bool is_extension_process_;
254
255 // Timer that periodically calls IdleHandler.
256 base::RepeatingTimer<RenderThread> idle_timer_;
257
258 // Same as above, but on a longer timer and will run even if the process is
259 // not idle, to ensure that IdleHandle gets called eventually.
260 base::RepeatingTimer<RenderThread> forced_idle_timer_;
261
[email protected]1bc83062009-02-06 00:16:37262 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29263};
264
[email protected]1d97d2e2008-12-18 23:39:02265#endif // CHROME_RENDERER_RENDER_THREAD_H_