[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 5 | #ifndef CHROME_RENDERER_RENDER_THREAD_H_ |
| 6 | #define CHROME_RENDERER_RENDER_THREAD_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 8 | #include <string> |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 11 | #include "base/gfx/native_widget_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/shared_memory.h" |
| 13 | #include "base/task.h" |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 15 | #include "chrome/common/child_thread.h" |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame^] | 16 | #include "chrome/common/css_colors.h" |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 17 | #include "chrome/renderer/renderer_histogram_snapshots.h" |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 18 | #include "chrome/renderer/visitedlink_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 20 | class AppCacheDispatcher; |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 21 | class DBMessageFilter; |
[email protected] | a862471 | 2009-04-17 00:51:35 | [diff] [blame] | 22 | class DevToolsAgentFilter; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 23 | class FilePath; |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 24 | class ListValue; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 25 | |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 26 | class RenderDnsMaster; |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 27 | class RendererHistogram; |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 28 | class RendererWebKitClientImpl; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 29 | class SkBitmap; |
[email protected] | 4d395d09 | 2009-02-11 21:40:40 | [diff] [blame] | 30 | class UserScriptSlave; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 31 | struct ModalDialogEvent; |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 32 | struct RendererPreferences; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 33 | struct WebPreferences; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 35 | // The RenderThreadBase is the minimal interface that a RenderView/Widget |
| 36 | // expects from a render thread. The interface basically abstracts a way to send |
| 37 | // and receive messages. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 38 | class RenderThreadBase { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 39 | public: |
| 40 | virtual ~RenderThreadBase() {} |
| 41 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 42 | virtual bool Send(IPC::Message* msg) = 0; |
| 43 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 44 | // Called to add or remove a listener for a particular message routing ID. |
| 45 | // These methods normally get delegated to a MessageRouter. |
| 46 | virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0; |
| 47 | virtual void RemoveRoute(int32 routing_id) = 0; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 48 | |
| 49 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; |
| 50 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 51 | }; |
| 52 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | // The RenderThread class represents a background thread where RenderView |
| 54 | // instances live. The RenderThread supports an API that is used by its |
| 55 | // consumer to talk indirectly to the RenderViews and supporting objects. |
| 56 | // Likewise, it provides an API for the RenderViews to talk back to the main |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 57 | // process (i.e., their corresponding TabContents). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | // |
| 59 | // Most of the communication occurs in the form of IPC messages. They are |
| 60 | // routed to the RenderThread according to the routing IDs of the messages. |
| 61 | // The routing IDs correspond to RenderView instances. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 62 | class RenderThread : public RenderThreadBase, |
| 63 | public ChildThread { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | public: |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 65 | // Grabs the IPC channel name from the command line. |
| 66 | RenderThread(); |
| 67 | // Constructor that's used when running in single process mode. |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 68 | RenderThread(const std::string& channel_name); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 69 | virtual ~RenderThread(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 71 | // Returns the one render thread for this process. Note that this should only |
| 72 | // be accessed when running on the render thread itself |
| 73 | static RenderThread* current(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 75 | // Overridden from RenderThreadBase. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 76 | virtual bool Send(IPC::Message* msg) { |
| 77 | return ChildThread::Send(msg); |
| 78 | } |
| 79 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 80 | virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) { |
| 81 | return ChildThread::AddRoute(routing_id, listener); |
| 82 | } |
| 83 | virtual void RemoveRoute(int32 routing_id) { |
| 84 | return ChildThread::RemoveRoute(routing_id); |
| 85 | } |
| 86 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 87 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 88 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 89 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 90 | VisitedLinkSlave* visited_link_slave() const { |
| 91 | return visited_link_slave_.get(); |
| 92 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 94 | UserScriptSlave* user_script_slave() const { |
| 95 | return user_script_slave_.get(); |
| 96 | } |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 97 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 98 | bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; } |
| 99 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | // Do DNS prefetch resolution of a hostname. |
| 101 | void Resolve(const char* name, size_t length); |
| 102 | |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 103 | // Send all the Histogram data to browser. |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 104 | void SendHistograms(int sequence_number); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 105 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | // Invokes InformHostOfCacheStats after a short delay. Used to move this |
| 107 | // bookkeeping operation off the critical latency path. |
| 108 | void InformHostOfCacheStatsLater(); |
| 109 | |
[email protected] | b07f2909 | 2009-06-05 07:33:21 | [diff] [blame] | 110 | // Sends a message to the browser to close all idle connections. |
| 111 | void CloseIdleConnections(); |
| 112 | |
| 113 | // Sends a message to the browser to enable or disable the disk cache. |
| 114 | void SetCacheMode(bool enabled); |
| 115 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 116 | private: |
| 117 | virtual void OnControlMessageReceived(const IPC::Message& msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 119 | void Init(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 121 | void OnUpdateVisitedLinks(base::SharedMemoryHandle table); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 122 | void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints); |
| 123 | void OnResetVisitedLinks(); |
| 124 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 125 | void OnUpdateUserScripts(base::SharedMemoryHandle table); |
[email protected] | 703e807a | 2009-03-28 19:56:51 | [diff] [blame] | 126 | void OnSetExtensionFunctionNames(const std::vector<std::string>& names); |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 127 | void OnPageActionsUpdated(const std::string& extension_id, |
| 128 | const std::vector<std::string>& page_actions); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | void OnSetNextPageID(int32 next_page_id); |
[email protected] | b9ab10c | 2009-08-07 18:09:55 | [diff] [blame^] | 130 | void OnSetCSSColors(const std::vector<CSSColors::CSSColorMapping>& colors); |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 131 | void OnCreateNewView(gfx::NativeViewId parent_hwnd, |
| 132 | ModalDialogEvent modal_dialog_event, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 133 | const RendererPreferences& renderer_prefs, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | const WebPreferences& webkit_prefs, |
| 135 | int32 view_id); |
| 136 | void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); |
| 137 | void OnSetCacheCapacities(size_t min_dead_capacity, |
| 138 | size_t max_dead_capacity, |
| 139 | size_t capacity); |
| 140 | void OnGetCacheResourceStats(); |
| 141 | |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 142 | // Send all histograms to browser. |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 143 | void OnGetRendererHistograms(int sequence_number); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 144 | |
[email protected] | dfcb62a | 2009-06-17 19:32:43 | [diff] [blame] | 145 | void OnExtensionMessageInvoke(const std::string& function_name, |
| 146 | const ListValue& args); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 147 | void OnPurgePluginListCache(); |
[email protected] | 75e5a87 | 2009-04-02 23:56:11 | [diff] [blame] | 148 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 149 | // Gather usage statistics from the in-memory cache and inform our host. |
| 150 | // These functions should be call periodically so that the host can make |
| 151 | // decisions about how to allocation resources using current information. |
| 152 | void InformHostOfCacheStats(); |
| 153 | |
[email protected] | 90a3fbb1 | 2009-02-28 01:13:47 | [diff] [blame] | 154 | // We initialize WebKit as late as possible. |
| 155 | void EnsureWebKitInitialized(); |
| 156 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | // These objects live solely on the render thread. |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 158 | scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 159 | scoped_ptr<VisitedLinkSlave> visited_link_slave_; |
| 160 | scoped_ptr<UserScriptSlave> user_script_slave_; |
| 161 | scoped_ptr<RenderDnsMaster> dns_master_; |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 162 | scoped_ptr<AppCacheDispatcher> app_cache_dispatcher_; |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 163 | scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_; |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 164 | scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_; |
| 165 | scoped_ptr<RendererWebKitClientImpl> webkit_client_; |
[email protected] | 9291ed1 | 2009-07-23 17:33:22 | [diff] [blame] | 166 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 167 | scoped_refptr<DBMessageFilter> db_message_filter_; |
| 168 | |
[email protected] | 5fa1c54 | 2009-05-05 20:36:07 | [diff] [blame] | 169 | #if defined(OS_POSIX) |
| 170 | scoped_refptr<IPC::ChannelProxy::MessageFilter> |
| 171 | suicide_on_channel_error_filter_; |
| 172 | #endif |
| 173 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 174 | // If true, then a GetPlugins call is allowed to rescan the disk. |
| 175 | bool plugin_refresh_allowed_; |
| 176 | |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(RenderThread); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 178 | }; |
| 179 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 180 | #endif // CHROME_RENDERER_RENDER_THREAD_H_ |