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