blob: e60c91b198a9c1b9a13f19739eea240e0a562572 [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]18bcc3c2009-01-27 21:39:1511#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/shared_memory.h"
13#include "base/task.h"
[email protected]037fce02009-01-22 01:42:1514#include "build/build_config.h"
[email protected]8930d472009-02-21 08:05:2815#include "chrome/common/child_thread.h"
[email protected]b9ab10c2009-08-07 18:09:5516#include "chrome/common/css_colors.h"
[email protected]b7c7bcf2009-10-03 07:07:3417#include "chrome/common/dom_storage_type.h"
[email protected]55e57d42009-02-25 06:10:1718#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]3e90d4a2009-07-03 17:38:3919#include "chrome/renderer/visitedlink_slave.h"
initial.commit09911bf2008-07-26 23:55:2920
[email protected]1edc16b82009-04-07 17:45:5421class AppCacheDispatcher;
[email protected]017022b2009-07-27 23:06:3422class DBMessageFilter;
[email protected]a8624712009-04-17 00:51:3523class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2524class FilePath;
[email protected]dfcb62a2009-06-17 19:32:4325class ListValue;
[email protected]b7c7bcf2009-10-03 07:07:3426class NullableString16;
[email protected]39008c02009-02-11 23:59:2527class RenderDnsMaster;
[email protected]55e57d42009-02-25 06:10:1728class RendererHistogram;
[email protected]8d86fce2009-02-26 23:37:5529class RendererWebKitClientImpl;
[email protected]39008c02009-02-11 23:59:2530class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4031class UserScriptSlave;
[email protected]cccf90932009-08-23 17:56:2532class URLPattern;
33
[email protected]9b6f40e2009-06-11 15:54:2634struct RendererPreferences;
[email protected]39008c02009-02-11 23:59:2535struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2936
[email protected]b7c7bcf2009-10-03 07:07:3437namespace WebKit {
38class WebStorageEventDispatcher;
39}
40
[email protected]81a34412009-01-05 19:17:2441// The RenderThreadBase is the minimal interface that a RenderView/Widget
42// expects from a render thread. The interface basically abstracts a way to send
43// and receive messages.
[email protected]8930d472009-02-21 08:05:2844class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4445 public:
46 virtual ~RenderThreadBase() {}
47
[email protected]8930d472009-02-21 08:05:2848 virtual bool Send(IPC::Message* msg) = 0;
49
[email protected]8085dbc82008-09-26 22:53:4450 // Called to add or remove a listener for a particular message routing ID.
51 // These methods normally get delegated to a MessageRouter.
52 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
53 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2454
55 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
56 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]bee16aab2009-08-26 15:55:0357
58 // Called by a RenderWidget when it is hidden or restored.
59 virtual void WidgetHidden() = 0;
60 virtual void WidgetRestored() = 0;
[email protected]8085dbc82008-09-26 22:53:4461};
62
initial.commit09911bf2008-07-26 23:55:2963// The RenderThread class represents a background thread where RenderView
64// instances live. The RenderThread supports an API that is used by its
65// consumer to talk indirectly to the RenderViews and supporting objects.
66// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3467// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2968//
69// Most of the communication occurs in the form of IPC messages. They are
70// routed to the RenderThread according to the routing IDs of the messages.
71// The routing IDs correspond to RenderView instances.
[email protected]8930d472009-02-21 08:05:2872class RenderThread : public RenderThreadBase,
73 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2974 public:
[email protected]8930d472009-02-21 08:05:2875 // Grabs the IPC channel name from the command line.
76 RenderThread();
77 // Constructor that's used when running in single process mode.
[email protected]9a3a293b2009-06-04 22:28:1678 RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:4479 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2980
[email protected]8930d472009-02-21 08:05:2881 // Returns the one render thread for this process. Note that this should only
82 // be accessed when running on the render thread itself
83 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2984
[email protected]45776222009-07-15 20:21:5885 // Overridden from RenderThreadBase.
[email protected]8930d472009-02-21 08:05:2886 virtual bool Send(IPC::Message* msg) {
87 return ChildThread::Send(msg);
88 }
89
[email protected]8930d472009-02-21 08:05:2890 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) {
[email protected]bee16aab2009-08-26 15:55:0391 widget_count_++;
[email protected]8930d472009-02-21 08:05:2892 return ChildThread::AddRoute(routing_id, listener);
93 }
94 virtual void RemoveRoute(int32 routing_id) {
[email protected]bee16aab2009-08-26 15:55:0395 widget_count_--;
[email protected]8930d472009-02-21 08:05:2896 return ChildThread::RemoveRoute(routing_id);
97 }
98
[email protected]81a34412009-01-05 19:17:2499 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
100 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:29101
[email protected]bee16aab2009-08-26 15:55:03102 virtual void WidgetHidden();
103 virtual void WidgetRestored();
104
[email protected]8d86fce2009-02-26 23:37:55105 VisitedLinkSlave* visited_link_slave() const {
106 return visited_link_slave_.get();
107 }
initial.commit09911bf2008-07-26 23:55:29108
[email protected]8d86fce2009-02-26 23:37:55109 UserScriptSlave* user_script_slave() const {
110 return user_script_slave_.get();
111 }
[email protected]1e0f70402008-10-16 23:57:47112
[email protected]f430b5712009-08-21 21:46:31113 AppCacheDispatcher* appcache_dispatcher() const {
114 return appcache_dispatcher_.get();
115 }
116
[email protected]b547fd42009-04-23 23:16:27117 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
118
initial.commit09911bf2008-07-26 23:55:29119 // Do DNS prefetch resolution of a hostname.
120 void Resolve(const char* name, size_t length);
121
[email protected]55e57d42009-02-25 06:10:17122 // Send all the Histogram data to browser.
[email protected]c9a3ef82009-05-28 22:02:46123 void SendHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17124
initial.commit09911bf2008-07-26 23:55:29125 // Invokes InformHostOfCacheStats after a short delay. Used to move this
126 // bookkeeping operation off the critical latency path.
127 void InformHostOfCacheStatsLater();
128
[email protected]b07f29092009-06-05 07:33:21129 // Sends a message to the browser to close all idle connections.
130 void CloseIdleConnections();
131
132 // Sends a message to the browser to enable or disable the disk cache.
133 void SetCacheMode(bool enabled);
134
[email protected]8930d472009-02-21 08:05:28135 private:
136 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29137
[email protected]42f1d7822009-07-23 18:17:55138 void Init();
initial.commit09911bf2008-07-26 23:55:29139
[email protected]176aa482008-11-14 03:25:15140 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]3e90d4a2009-07-03 17:38:39141 void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
142 void OnResetVisitedLinks();
143
[email protected]0938d3c2009-01-09 20:37:35144 void OnUpdateUserScripts(base::SharedMemoryHandle table);
[email protected]703e807a2009-03-28 19:56:51145 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
[email protected]45776222009-07-15 20:21:58146 void OnPageActionsUpdated(const std::string& extension_id,
[email protected]b7c7bcf2009-10-03 07:07:34147 const std::vector<std::string>& page_actions);
148 void OnDOMStorageEvent(const string16& key, const NullableString16& old_value,
149 const NullableString16& new_value, const string16& origin,
150 DOMStorageType dom_storage_type);
[email protected]75e126b932009-09-28 19:38:49151 void OnExtensionSetAPIPermissions(
152 const std::string& extension_id,
153 const std::vector<std::string>& permissions);
154 void OnExtensionSetHostPermissions(
155 const GURL& extension_url,
156 const std::vector<URLPattern>& permissions);
157 void OnExtensionSetL10nMessages(
158 const std::string& extension_id,
159 const std::map<std::string, std::string>& l10n_messages);
initial.commit09911bf2008-07-26 23:55:29160 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55161 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]18bcc3c2009-01-27 21:39:15162 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
[email protected]80d96fa2009-06-10 22:34:51163 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29164 const WebPreferences& webkit_prefs,
165 int32 view_id);
166 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
167 void OnSetCacheCapacities(size_t min_dead_capacity,
168 size_t max_dead_capacity,
169 size_t capacity);
170 void OnGetCacheResourceStats();
171
[email protected]55e57d42009-02-25 06:10:17172 // Send all histograms to browser.
[email protected]c9a3ef82009-05-28 22:02:46173 void OnGetRendererHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17174
[email protected]d41041092009-10-08 06:56:57175 // Send tcmalloc info to browser.
176 void OnGetRendererTcmalloc();
177
[email protected]dfcb62a2009-06-17 19:32:43178 void OnExtensionMessageInvoke(const std::string& function_name,
179 const ListValue& args);
[email protected]fede6ca12009-10-08 18:24:26180 void OnPurgeMemory();
[email protected]b78e168b2009-09-21 22:05:45181 void OnPurgePluginListCache(bool reload_pages);
[email protected]75e5a872009-04-02 23:56:11182
initial.commit09911bf2008-07-26 23:55:29183 // Gather usage statistics from the in-memory cache and inform our host.
184 // These functions should be call periodically so that the host can make
185 // decisions about how to allocation resources using current information.
186 void InformHostOfCacheStats();
187
[email protected]90a3fbb12009-02-28 01:13:47188 // We initialize WebKit as late as possible.
189 void EnsureWebKitInitialized();
190
[email protected]bee16aab2009-08-26 15:55:03191 // A task we invoke periodically to assist with idle cleanup.
192 void IdleHandler();
193
initial.commit09911bf2008-07-26 23:55:29194 // These objects live solely on the render thread.
[email protected]bee16aab2009-08-26 15:55:03195 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_;
[email protected]42f1d7822009-07-23 18:17:55196 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
197 scoped_ptr<UserScriptSlave> user_script_slave_;
198 scoped_ptr<RenderDnsMaster> dns_master_;
[email protected]f430b5712009-08-21 21:46:31199 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22200 scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
[email protected]42f1d7822009-07-23 18:17:55201 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
202 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]b7c7bcf2009-10-03 07:07:34203 scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22204
[email protected]017022b2009-07-27 23:06:34205 scoped_refptr<DBMessageFilter> db_message_filter_;
206
[email protected]5fa1c542009-05-05 20:36:07207#if defined(OS_POSIX)
208 scoped_refptr<IPC::ChannelProxy::MessageFilter>
209 suicide_on_channel_error_filter_;
210#endif
211
[email protected]b547fd42009-04-23 23:16:27212 // If true, then a GetPlugins call is allowed to rescan the disk.
213 bool plugin_refresh_allowed_;
214
[email protected]bee16aab2009-08-26 15:55:03215 // Is there a pending task for doing CacheStats.
216 bool cache_stats_task_pending_;
217
218 // The count of RenderWidgets running through this thread.
219 int widget_count_;
220
221 // The count of hidden RenderWidgets running through this thread.
222 int hidden_widget_count_;
223
224 // The current value of the idle notification timer delay.
225 double idle_notification_delay_in_s_;
226
[email protected]1bc83062009-02-06 00:16:37227 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29228};
229
[email protected]1d97d2e2008-12-18 23:39:02230#endif // CHROME_RENDERER_RENDER_THREAD_H_