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