blob: ab9a0b2a0a03f6c485968b6ed934dac6607a1743 [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]55e57d42009-02-25 06:10:1717#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]3e90d4a2009-07-03 17:38:3918#include "chrome/renderer/visitedlink_slave.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]1edc16b82009-04-07 17:45:5420class AppCacheDispatcher;
[email protected]017022b2009-07-27 23:06:3421class DBMessageFilter;
[email protected]a8624712009-04-17 00:51:3522class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2523class FilePath;
[email protected]dfcb62a2009-06-17 19:32:4324class ListValue;
[email protected]39008c02009-02-11 23:59:2525class RenderDnsMaster;
[email protected]55e57d42009-02-25 06:10:1726class RendererHistogram;
[email protected]8d86fce2009-02-26 23:37:5527class RendererWebKitClientImpl;
[email protected]39008c02009-02-11 23:59:2528class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4029class UserScriptSlave;
[email protected]cccf90932009-08-23 17:56:2530class URLPattern;
31
[email protected]39008c02009-02-11 23:59:2532struct ModalDialogEvent;
[email protected]9b6f40e2009-06-11 15:54:2633struct RendererPreferences;
[email protected]39008c02009-02-11 23:59:2534struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2935
[email protected]81a34412009-01-05 19:17:2436// The RenderThreadBase is the minimal interface that a RenderView/Widget
37// expects from a render thread. The interface basically abstracts a way to send
38// and receive messages.
[email protected]8930d472009-02-21 08:05:2839class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4440 public:
41 virtual ~RenderThreadBase() {}
42
[email protected]8930d472009-02-21 08:05:2843 virtual bool Send(IPC::Message* msg) = 0;
44
[email protected]8085dbc82008-09-26 22:53:4445 // Called to add or remove a listener for a particular message routing ID.
46 // These methods normally get delegated to a MessageRouter.
47 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
48 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2449
50 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
51 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]bee16aab2009-08-26 15:55:0352
53 // Called by a RenderWidget when it is hidden or restored.
54 virtual void WidgetHidden() = 0;
55 virtual void WidgetRestored() = 0;
[email protected]8085dbc82008-09-26 22:53:4456};
57
initial.commit09911bf2008-07-26 23:55:2958// The RenderThread class represents a background thread where RenderView
59// instances live. The RenderThread supports an API that is used by its
60// consumer to talk indirectly to the RenderViews and supporting objects.
61// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3462// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2963//
64// Most of the communication occurs in the form of IPC messages. They are
65// routed to the RenderThread according to the routing IDs of the messages.
66// The routing IDs correspond to RenderView instances.
[email protected]8930d472009-02-21 08:05:2867class RenderThread : public RenderThreadBase,
68 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2969 public:
[email protected]8930d472009-02-21 08:05:2870 // Grabs the IPC channel name from the command line.
71 RenderThread();
72 // Constructor that's used when running in single process mode.
[email protected]9a3a293b2009-06-04 22:28:1673 RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:4474 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2975
[email protected]8930d472009-02-21 08:05:2876 // Returns the one render thread for this process. Note that this should only
77 // be accessed when running on the render thread itself
78 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2979
[email protected]45776222009-07-15 20:21:5880 // Overridden from RenderThreadBase.
[email protected]8930d472009-02-21 08:05:2881 virtual bool Send(IPC::Message* msg) {
82 return ChildThread::Send(msg);
83 }
84
[email protected]8930d472009-02-21 08:05:2885 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) {
[email protected]bee16aab2009-08-26 15:55:0386 widget_count_++;
[email protected]8930d472009-02-21 08:05:2887 return ChildThread::AddRoute(routing_id, listener);
88 }
89 virtual void RemoveRoute(int32 routing_id) {
[email protected]bee16aab2009-08-26 15:55:0390 widget_count_--;
[email protected]8930d472009-02-21 08:05:2891 return ChildThread::RemoveRoute(routing_id);
92 }
93
[email protected]81a34412009-01-05 19:17:2494 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
95 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2996
[email protected]bee16aab2009-08-26 15:55:0397 virtual void WidgetHidden();
98 virtual void WidgetRestored();
99
[email protected]8d86fce2009-02-26 23:37:55100 VisitedLinkSlave* visited_link_slave() const {
101 return visited_link_slave_.get();
102 }
initial.commit09911bf2008-07-26 23:55:29103
[email protected]8d86fce2009-02-26 23:37:55104 UserScriptSlave* user_script_slave() const {
105 return user_script_slave_.get();
106 }
[email protected]1e0f70402008-10-16 23:57:47107
[email protected]f430b5712009-08-21 21:46:31108 AppCacheDispatcher* appcache_dispatcher() const {
109 return appcache_dispatcher_.get();
110 }
111
[email protected]b547fd42009-04-23 23:16:27112 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
113
initial.commit09911bf2008-07-26 23:55:29114 // Do DNS prefetch resolution of a hostname.
115 void Resolve(const char* name, size_t length);
116
[email protected]55e57d42009-02-25 06:10:17117 // Send all the Histogram data to browser.
[email protected]c9a3ef82009-05-28 22:02:46118 void SendHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17119
initial.commit09911bf2008-07-26 23:55:29120 // Invokes InformHostOfCacheStats after a short delay. Used to move this
121 // bookkeeping operation off the critical latency path.
122 void InformHostOfCacheStatsLater();
123
[email protected]b07f29092009-06-05 07:33:21124 // Sends a message to the browser to close all idle connections.
125 void CloseIdleConnections();
126
127 // Sends a message to the browser to enable or disable the disk cache.
128 void SetCacheMode(bool enabled);
129
[email protected]8930d472009-02-21 08:05:28130 private:
131 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29132
[email protected]42f1d7822009-07-23 18:17:55133 void Init();
initial.commit09911bf2008-07-26 23:55:29134
[email protected]176aa482008-11-14 03:25:15135 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]3e90d4a2009-07-03 17:38:39136 void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
137 void OnResetVisitedLinks();
138
[email protected]0938d3c2009-01-09 20:37:35139 void OnUpdateUserScripts(base::SharedMemoryHandle table);
[email protected]703e807a2009-03-28 19:56:51140 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
[email protected]45776222009-07-15 20:21:58141 void OnPageActionsUpdated(const std::string& extension_id,
142 const std::vector<std::string>& page_actions);
[email protected]cccf90932009-08-23 17:56:25143 void OnExtensionSetAPIPermissions(const std::string& extension_id,
144 const std::vector<std::string>& permissions);
145 void OnExtensionSetHostPermissions(const GURL& extension_url,
146 const std::vector<URLPattern>& permissions);
initial.commit09911bf2008-07-26 23:55:29147 void OnSetNextPageID(int32 next_page_id);
[email protected]b9ab10c2009-08-07 18:09:55148 void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors);
[email protected]18bcc3c2009-01-27 21:39:15149 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
150 ModalDialogEvent modal_dialog_event,
[email protected]80d96fa2009-06-10 22:34:51151 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29152 const WebPreferences& webkit_prefs,
153 int32 view_id);
154 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
155 void OnSetCacheCapacities(size_t min_dead_capacity,
156 size_t max_dead_capacity,
157 size_t capacity);
158 void OnGetCacheResourceStats();
159
[email protected]55e57d42009-02-25 06:10:17160 // Send all histograms to browser.
[email protected]c9a3ef82009-05-28 22:02:46161 void OnGetRendererHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17162
[email protected]dfcb62a2009-06-17 19:32:43163 void OnExtensionMessageInvoke(const std::string& function_name,
164 const ListValue& args);
[email protected]b78e168b2009-09-21 22:05:45165 void OnPurgePluginListCache(bool reload_pages);
[email protected]75e5a872009-04-02 23:56:11166
initial.commit09911bf2008-07-26 23:55:29167 // Gather usage statistics from the in-memory cache and inform our host.
168 // These functions should be call periodically so that the host can make
169 // decisions about how to allocation resources using current information.
170 void InformHostOfCacheStats();
171
[email protected]90a3fbb12009-02-28 01:13:47172 // We initialize WebKit as late as possible.
173 void EnsureWebKitInitialized();
174
[email protected]bee16aab2009-08-26 15:55:03175 // A task we invoke periodically to assist with idle cleanup.
176 void IdleHandler();
177
initial.commit09911bf2008-07-26 23:55:29178 // These objects live solely on the render thread.
[email protected]bee16aab2009-08-26 15:55:03179 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > task_factory_;
[email protected]42f1d7822009-07-23 18:17:55180 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
181 scoped_ptr<UserScriptSlave> user_script_slave_;
182 scoped_ptr<RenderDnsMaster> dns_master_;
[email protected]f430b5712009-08-21 21:46:31183 scoped_ptr<AppCacheDispatcher> appcache_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22184 scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
[email protected]42f1d7822009-07-23 18:17:55185 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
186 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]9291ed12009-07-23 17:33:22187
[email protected]017022b2009-07-27 23:06:34188 scoped_refptr<DBMessageFilter> db_message_filter_;
189
[email protected]5fa1c542009-05-05 20:36:07190#if defined(OS_POSIX)
191 scoped_refptr<IPC::ChannelProxy::MessageFilter>
192 suicide_on_channel_error_filter_;
193#endif
194
[email protected]b547fd42009-04-23 23:16:27195 // If true, then a GetPlugins call is allowed to rescan the disk.
196 bool plugin_refresh_allowed_;
197
[email protected]bee16aab2009-08-26 15:55:03198 // Is there a pending task for doing CacheStats.
199 bool cache_stats_task_pending_;
200
201 // The count of RenderWidgets running through this thread.
202 int widget_count_;
203
204 // The count of hidden RenderWidgets running through this thread.
205 int hidden_widget_count_;
206
207 // The current value of the idle notification timer delay.
208 double idle_notification_delay_in_s_;
209
[email protected]1bc83062009-02-06 00:16:37210 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29211};
212
[email protected]1d97d2e2008-12-18 23:39:02213#endif // CHROME_RENDERER_RENDER_THREAD_H_