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] | 4d395d09 | 2009-02-11 21:40:40 | [diff] [blame^] | 10 | #include "base/file_path.h" |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 11 | #include "base/gfx/native_widget_types.h" |
[email protected] | 4d395d09 | 2009-02-11 21:40:40 | [diff] [blame^] | 12 | #include "base/ref_counted.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/shared_memory.h" |
| 14 | #include "base/task.h" |
| 15 | #include "base/thread.h" |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 16 | #include "build/build_config.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "chrome/common/ipc_sync_channel.h" |
| 18 | #include "chrome/common/message_router.h" |
[email protected] | 4d395d09 | 2009-02-11 21:40:40 | [diff] [blame^] | 19 | #include "chrome/common/modal_dialog_event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | |
[email protected] | 216974c | 2009-02-11 21:23:55 | [diff] [blame] | 21 | class SkBitmap; |
[email protected] | 216974c | 2009-02-11 21:23:55 | [diff] [blame] | 22 | class VisitedLinkSlave; |
[email protected] | 216974c | 2009-02-11 21:23:55 | [diff] [blame] | 23 | struct WebPreferences; |
[email protected] | 4d395d09 | 2009-02-11 21:40:40 | [diff] [blame^] | 24 | class RenderDnsMaster; |
| 25 | class NotificationService; |
| 26 | class UserScriptSlave; |
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] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 31 | class RenderThreadBase : public IPC::Message::Sender { |
| 32 | public: |
| 33 | virtual ~RenderThreadBase() {} |
| 34 | |
| 35 | // True if currently sending a message. |
| 36 | virtual bool InSend() const = 0; |
| 37 | |
| 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. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | class RenderThread : public IPC::Channel::Listener, |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 57 | public RenderThreadBase, |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 58 | public base::Thread { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | public: |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 60 | explicit RenderThread(const std::wstring& channel_name); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 61 | virtual ~RenderThread(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | |
| 63 | // IPC::Channel::Listener implementation: |
| 64 | virtual void OnMessageReceived(const IPC::Message& msg); |
| 65 | virtual void OnChannelError(); |
| 66 | |
| 67 | // IPC::Message::Sender implementation: |
| 68 | virtual bool Send(IPC::Message* msg); |
| 69 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 70 | // Overridded from RenderThreadBase. |
| 71 | virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 72 | virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 73 | |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 74 | // Gets the VisitedLinkSlave instance for this thread |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; } |
| 76 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 77 | // Gets the UserScriptSlave instance for this thread |
| 78 | UserScriptSlave* user_script_slave() const { return user_script_slave_; } |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 79 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | // Do DNS prefetch resolution of a hostname. |
| 81 | void Resolve(const char* name, size_t length); |
| 82 | |
| 83 | // See documentation on MessageRouter for AddRoute and RemoveRoute |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 84 | virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); |
| 85 | virtual void RemoveRoute(int32 routing_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | |
| 87 | // Invokes InformHostOfCacheStats after a short delay. Used to move this |
| 88 | // bookkeeping operation off the critical latency path. |
| 89 | void InformHostOfCacheStatsLater(); |
| 90 | |
| 91 | MessageLoop* owner_loop() { return owner_loop_; } |
| 92 | |
| 93 | // Indicates if RenderThread::Send() is on the call stack. |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 94 | virtual bool InSend() const { return in_send_ != 0; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 95 | |
| 96 | protected: |
| 97 | // Called by the thread base class |
| 98 | virtual void Init(); |
| 99 | virtual void CleanUp(); |
| 100 | |
| 101 | private: |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 102 | void OnUpdateVisitedLinks(base::SharedMemoryHandle table); |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 103 | void OnUpdateUserScripts(base::SharedMemoryHandle table); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 104 | |
[email protected] | 690a99c | 2009-01-06 16:48:45 | [diff] [blame] | 105 | void OnPluginMessage(const FilePath& plugin_path, |
[email protected] | a9f4d90 | 2008-09-15 23:43:42 | [diff] [blame] | 106 | const std::vector<uint8>& data); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | void OnSetNextPageID(int32 next_page_id); |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 108 | void OnCreateNewView(gfx::NativeViewId parent_hwnd, |
| 109 | ModalDialogEvent modal_dialog_event, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | const WebPreferences& webkit_prefs, |
| 111 | int32 view_id); |
| 112 | void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); |
| 113 | void OnSetCacheCapacities(size_t min_dead_capacity, |
| 114 | size_t max_dead_capacity, |
| 115 | size_t capacity); |
| 116 | void OnGetCacheResourceStats(); |
| 117 | |
| 118 | // Gather usage statistics from the in-memory cache and inform our host. |
| 119 | // These functions should be call periodically so that the host can make |
| 120 | // decisions about how to allocation resources using current information. |
| 121 | void InformHostOfCacheStats(); |
| 122 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | // The message loop used to run tasks on the thread that started this thread. |
| 124 | MessageLoop* owner_loop_; |
| 125 | |
| 126 | // Used only on the background render thread to implement message routing |
| 127 | // functionality to the consumers of the RenderThread. |
| 128 | MessageRouter router_; |
| 129 | |
| 130 | std::wstring channel_name_; |
| 131 | scoped_ptr<IPC::SyncChannel> channel_; |
| 132 | |
| 133 | // These objects live solely on the render thread. |
| 134 | VisitedLinkSlave* visited_link_slave_; |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 135 | UserScriptSlave* user_script_slave_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | |
| 137 | scoped_ptr<RenderDnsMaster> render_dns_master_; |
| 138 | |
| 139 | scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_; |
| 140 | |
[email protected] | 173de1b | 2008-08-15 18:36:46 | [diff] [blame] | 141 | scoped_ptr<NotificationService> notification_service_; |
| 142 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | int in_send_; |
| 144 | |
[email protected] | 1bc8306 | 2009-02-06 00:16:37 | [diff] [blame] | 145 | DISALLOW_COPY_AND_ASSIGN(RenderThread); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | }; |
| 147 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 148 | // The global RenderThread object for this process. Note that this should only |
| 149 | // be accessed when running on the render thread itself. |
| 150 | extern RenderThread* g_render_thread; |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 151 | |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 152 | #endif // CHROME_RENDERER_RENDER_THREAD_H_ |