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