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 | |
| 8 | #include "base/ref_counted.h" |
| 9 | #include "base/shared_memory.h" |
| 10 | #include "base/task.h" |
| 11 | #include "base/thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "chrome/common/ipc_sync_channel.h" |
| 13 | #include "chrome/common/message_router.h" |
| 14 | |
| 15 | class SkBitmap; |
| 16 | class Task; |
| 17 | class VisitedLinkSlave; |
| 18 | struct WebPreferences; |
| 19 | class RenderDnsMaster; |
[email protected] | 173de1b | 2008-08-15 18:36:46 | [diff] [blame] | 20 | class NotificationService; |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 21 | class GreasemonkeySlave; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame^] | 23 | // The RenderThreadBase is the minimal interface that a RenderView/Widget |
| 24 | // expects from a render thread. The interface basically abstracts a way to send |
| 25 | // and receive messages. |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 26 | class RenderThreadBase : public IPC::Message::Sender { |
| 27 | public: |
| 28 | virtual ~RenderThreadBase() {} |
| 29 | |
| 30 | // True if currently sending a message. |
| 31 | virtual bool InSend() const = 0; |
| 32 | |
| 33 | // Called to add or remove a listener for a particular message routing ID. |
| 34 | // These methods normally get delegated to a MessageRouter. |
| 35 | virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0; |
| 36 | virtual void RemoveRoute(int32 routing_id) = 0; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame^] | 37 | |
| 38 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; |
| 39 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 40 | }; |
| 41 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | // The RenderThread class represents a background thread where RenderView |
| 43 | // instances live. The RenderThread supports an API that is used by its |
| 44 | // consumer to talk indirectly to the RenderViews and supporting objects. |
| 45 | // Likewise, it provides an API for the RenderViews to talk back to the main |
| 46 | // process (i.e., their corresponding WebContents). |
| 47 | // |
| 48 | // Most of the communication occurs in the form of IPC messages. They are |
| 49 | // routed to the RenderThread according to the routing IDs of the messages. |
| 50 | // The routing IDs correspond to RenderView instances. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 51 | class RenderThread : public IPC::Channel::Listener, |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 52 | public RenderThreadBase, |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 53 | public base::Thread { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | public: |
| 55 | RenderThread(const std::wstring& channel_name); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 56 | virtual ~RenderThread(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | |
| 58 | // IPC::Channel::Listener implementation: |
| 59 | virtual void OnMessageReceived(const IPC::Message& msg); |
| 60 | virtual void OnChannelError(); |
| 61 | |
| 62 | // IPC::Message::Sender implementation: |
| 63 | virtual bool Send(IPC::Message* msg); |
| 64 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame^] | 65 | // Overridded from RenderThreadBase. |
| 66 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 67 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 69 | // Gets the VisitedLinkSlave instance for this thread |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; } |
| 71 | |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 72 | // Gets the GreasemonkeySlave instance for this thread |
| 73 | GreasemonkeySlave* greasemonkey_slave() const { return greasemonkey_slave_; } |
| 74 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | // Do DNS prefetch resolution of a hostname. |
| 76 | void Resolve(const char* name, size_t length); |
| 77 | |
| 78 | // See documentation on MessageRouter for AddRoute and RemoveRoute |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 79 | virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); |
| 80 | virtual void RemoveRoute(int32 routing_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | |
| 82 | // Invokes InformHostOfCacheStats after a short delay. Used to move this |
| 83 | // bookkeeping operation off the critical latency path. |
| 84 | void InformHostOfCacheStatsLater(); |
| 85 | |
| 86 | MessageLoop* owner_loop() { return owner_loop_; } |
| 87 | |
| 88 | // Indicates if RenderThread::Send() is on the call stack. |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 89 | virtual bool InSend() const { return in_send_ != 0; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | |
| 91 | protected: |
| 92 | // Called by the thread base class |
| 93 | virtual void Init(); |
| 94 | virtual void CleanUp(); |
| 95 | |
| 96 | private: |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 97 | void OnUpdateVisitedLinks(base::SharedMemoryHandle table); |
| 98 | void OnUpdateGreasemonkeyScripts(base::SharedMemoryHandle table); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | |
[email protected] | a9f4d90 | 2008-09-15 23:43:42 | [diff] [blame] | 100 | void OnPluginMessage(const std::wstring& dll_path, |
| 101 | const std::vector<uint8>& data); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | void OnSetNextPageID(int32 next_page_id); |
| 103 | void OnCreateNewView(HWND parent_hwnd, |
| 104 | HANDLE modal_dialog_event, |
| 105 | const WebPreferences& webkit_prefs, |
| 106 | int32 view_id); |
| 107 | void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); |
| 108 | void OnSetCacheCapacities(size_t min_dead_capacity, |
| 109 | size_t max_dead_capacity, |
| 110 | size_t capacity); |
| 111 | void OnGetCacheResourceStats(); |
| 112 | |
| 113 | // Gather usage statistics from the in-memory cache and inform our host. |
| 114 | // These functions should be call periodically so that the host can make |
| 115 | // decisions about how to allocation resources using current information. |
| 116 | void InformHostOfCacheStats(); |
| 117 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | // The message loop used to run tasks on the thread that started this thread. |
| 119 | MessageLoop* owner_loop_; |
| 120 | |
| 121 | // Used only on the background render thread to implement message routing |
| 122 | // functionality to the consumers of the RenderThread. |
| 123 | MessageRouter router_; |
| 124 | |
| 125 | std::wstring channel_name_; |
| 126 | scoped_ptr<IPC::SyncChannel> channel_; |
| 127 | |
| 128 | // These objects live solely on the render thread. |
| 129 | VisitedLinkSlave* visited_link_slave_; |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 130 | GreasemonkeySlave* greasemonkey_slave_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | |
| 132 | scoped_ptr<RenderDnsMaster> render_dns_master_; |
| 133 | |
| 134 | scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_; |
| 135 | |
[email protected] | 173de1b | 2008-08-15 18:36:46 | [diff] [blame] | 136 | scoped_ptr<NotificationService> notification_service_; |
| 137 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 138 | int in_send_; |
| 139 | |
| 140 | DISALLOW_EVIL_CONSTRUCTORS(RenderThread); |
| 141 | }; |
| 142 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 143 | // The global RenderThread object for this process. Note that this should only |
| 144 | // be accessed when running on the render thread itself. |
| 145 | extern RenderThread* g_render_thread; |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 146 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 147 | #endif // CHROME_RENDERER_RENDER_THREAD_H_ |