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