blob: 44dd548e4a5edee7cd80abca6458825ac08e0f21 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
[email protected]1d97d2e2008-12-18 23:39:025#ifndef CHROME_RENDERER_RENDER_THREAD_H_
6#define CHROME_RENDERER_RENDER_THREAD_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]1bc83062009-02-06 00:16:378#include <vector>
9
[email protected]18bcc3c2009-01-27 21:39:1510#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/shared_memory.h"
12#include "base/task.h"
13#include "base/thread.h"
[email protected]037fce02009-01-22 01:42:1514#include "build/build_config.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/common/ipc_sync_channel.h"
16#include "chrome/common/message_router.h"
17
[email protected]39008c02009-02-11 23:59:2518class FilePath;
[email protected]4d395d092009-02-11 21:40:4019class NotificationService;
[email protected]39008c02009-02-11 23:59:2520class RenderDnsMaster;
21class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4022class UserScriptSlave;
[email protected]39008c02009-02-11 23:59:2523class VisitedLinkSlave;
24struct ModalDialogEvent;
25struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2926
[email protected]81a34412009-01-05 19:17:2427// The RenderThreadBase is the minimal interface that a RenderView/Widget
28// expects from a render thread. The interface basically abstracts a way to send
29// and receive messages.
[email protected]8085dbc82008-09-26 22:53:4430class RenderThreadBase : public IPC::Message::Sender {
31 public:
32 virtual ~RenderThreadBase() {}
33
34 // True if currently sending a message.
35 virtual bool InSend() const = 0;
36
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]81a34412009-01-05 19:17:2441
42 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
43 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]8085dbc82008-09-26 22:53:4444};
45
initial.commit09911bf2008-07-26 23:55:2946// 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.
initial.commit09911bf2008-07-26 23:55:2955class RenderThread : public IPC::Channel::Listener,
[email protected]8085dbc82008-09-26 22:53:4456 public RenderThreadBase,
[email protected]ab820df2008-08-26 05:55:1057 public base::Thread {
initial.commit09911bf2008-07-26 23:55:2958 public:
[email protected]1bc83062009-02-06 00:16:3759 explicit RenderThread(const std::wstring& channel_name);
[email protected]8085dbc82008-09-26 22:53:4460 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2961
62 // IPC::Channel::Listener implementation:
63 virtual void OnMessageReceived(const IPC::Message& msg);
64 virtual void OnChannelError();
65
66 // IPC::Message::Sender implementation:
67 virtual bool Send(IPC::Message* msg);
68
[email protected]81a34412009-01-05 19:17:2469 // Overridded from RenderThreadBase.
70 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
71 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2972
[email protected]1e0f70402008-10-16 23:57:4773 // Gets the VisitedLinkSlave instance for this thread
initial.commit09911bf2008-07-26 23:55:2974 VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; }
75
[email protected]0938d3c2009-01-09 20:37:3576 // Gets the UserScriptSlave instance for this thread
77 UserScriptSlave* user_script_slave() const { return user_script_slave_; }
[email protected]1e0f70402008-10-16 23:57:4778
initial.commit09911bf2008-07-26 23:55:2979 // Do DNS prefetch resolution of a hostname.
80 void Resolve(const char* name, size_t length);
81
82 // See documentation on MessageRouter for AddRoute and RemoveRoute
[email protected]8085dbc82008-09-26 22:53:4483 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
84 virtual void RemoveRoute(int32 routing_id);
initial.commit09911bf2008-07-26 23:55:2985
86 // Invokes InformHostOfCacheStats after a short delay. Used to move this
87 // bookkeeping operation off the critical latency path.
88 void InformHostOfCacheStatsLater();
89
90 MessageLoop* owner_loop() { return owner_loop_; }
91
92 // Indicates if RenderThread::Send() is on the call stack.
[email protected]8085dbc82008-09-26 22:53:4493 virtual bool InSend() const { return in_send_ != 0; }
initial.commit09911bf2008-07-26 23:55:2994
95 protected:
96 // Called by the thread base class
97 virtual void Init();
98 virtual void CleanUp();
99
100 private:
[email protected]176aa482008-11-14 03:25:15101 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]0938d3c2009-01-09 20:37:35102 void OnUpdateUserScripts(base::SharedMemoryHandle table);
initial.commit09911bf2008-07-26 23:55:29103
[email protected]690a99c2009-01-06 16:48:45104 void OnPluginMessage(const FilePath& plugin_path,
[email protected]a9f4d902008-09-15 23:43:42105 const std::vector<uint8>& data);
initial.commit09911bf2008-07-26 23:55:29106 void OnSetNextPageID(int32 next_page_id);
[email protected]18bcc3c2009-01-27 21:39:15107 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
108 ModalDialogEvent modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29109 const WebPreferences& webkit_prefs,
110 int32 view_id);
111 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
112 void OnSetCacheCapacities(size_t min_dead_capacity,
113 size_t max_dead_capacity,
114 size_t capacity);
115 void OnGetCacheResourceStats();
116
117 // Gather usage statistics from the in-memory cache and inform our host.
118 // These functions should be call periodically so that the host can make
119 // decisions about how to allocation resources using current information.
120 void InformHostOfCacheStats();
121
initial.commit09911bf2008-07-26 23:55:29122 // The message loop used to run tasks on the thread that started this thread.
123 MessageLoop* owner_loop_;
124
125 // Used only on the background render thread to implement message routing
126 // functionality to the consumers of the RenderThread.
127 MessageRouter router_;
128
129 std::wstring channel_name_;
130 scoped_ptr<IPC::SyncChannel> channel_;
131
132 // These objects live solely on the render thread.
133 VisitedLinkSlave* visited_link_slave_;
[email protected]0938d3c2009-01-09 20:37:35134 UserScriptSlave* user_script_slave_;
initial.commit09911bf2008-07-26 23:55:29135
136 scoped_ptr<RenderDnsMaster> render_dns_master_;
137
138 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
139
[email protected]173de1b2008-08-15 18:36:46140 scoped_ptr<NotificationService> notification_service_;
141
initial.commit09911bf2008-07-26 23:55:29142 int in_send_;
143
[email protected]1bc83062009-02-06 00:16:37144 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29145};
146
[email protected]1d97d2e2008-12-18 23:39:02147// The global RenderThread object for this process. Note that this should only
148// be accessed when running on the render thread itself.
149extern RenderThread* g_render_thread;
license.botbf09a502008-08-24 00:55:55150
[email protected]1d97d2e2008-12-18 23:39:02151#endif // CHROME_RENDERER_RENDER_THREAD_H_