blob: ae94815fafefa4852c1c6b8ceaf37d355a926eac [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
8#include "base/ref_counted.h"
9#include "base/shared_memory.h"
10#include "base/task.h"
11#include "base/thread.h"
initial.commit09911bf2008-07-26 23:55:2912#include "chrome/common/ipc_sync_channel.h"
13#include "chrome/common/message_router.h"
14
15class SkBitmap;
16class Task;
17class VisitedLinkSlave;
18struct WebPreferences;
19class RenderDnsMaster;
[email protected]173de1b2008-08-15 18:36:4620class NotificationService;
[email protected]1e0f70402008-10-16 23:57:4721class GreasemonkeySlave;
initial.commit09911bf2008-07-26 23:55:2922
[email protected]81a34412009-01-05 19:17:2423// 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]8085dbc82008-09-26 22:53:4426class 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]81a34412009-01-05 19:17:2437
38 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
39 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]8085dbc82008-09-26 22:53:4440};
41
initial.commit09911bf2008-07-26 23:55:2942// 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.commit09911bf2008-07-26 23:55:2951class RenderThread : public IPC::Channel::Listener,
[email protected]8085dbc82008-09-26 22:53:4452 public RenderThreadBase,
[email protected]ab820df2008-08-26 05:55:1053 public base::Thread {
initial.commit09911bf2008-07-26 23:55:2954 public:
55 RenderThread(const std::wstring& channel_name);
[email protected]8085dbc82008-09-26 22:53:4456 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2957
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]81a34412009-01-05 19:17:2465 // Overridded from RenderThreadBase.
66 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
67 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2968
[email protected]1e0f70402008-10-16 23:57:4769 // Gets the VisitedLinkSlave instance for this thread
initial.commit09911bf2008-07-26 23:55:2970 VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; }
71
[email protected]1e0f70402008-10-16 23:57:4772 // Gets the GreasemonkeySlave instance for this thread
73 GreasemonkeySlave* greasemonkey_slave() const { return greasemonkey_slave_; }
74
initial.commit09911bf2008-07-26 23:55:2975 // 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]8085dbc82008-09-26 22:53:4479 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
80 virtual void RemoveRoute(int32 routing_id);
initial.commit09911bf2008-07-26 23:55:2981
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]8085dbc82008-09-26 22:53:4489 virtual bool InSend() const { return in_send_ != 0; }
initial.commit09911bf2008-07-26 23:55:2990
91 protected:
92 // Called by the thread base class
93 virtual void Init();
94 virtual void CleanUp();
95
96 private:
[email protected]176aa482008-11-14 03:25:1597 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
98 void OnUpdateGreasemonkeyScripts(base::SharedMemoryHandle table);
initial.commit09911bf2008-07-26 23:55:2999
[email protected]a9f4d902008-09-15 23:43:42100 void OnPluginMessage(const std::wstring& dll_path,
101 const std::vector<uint8>& data);
initial.commit09911bf2008-07-26 23:55:29102 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.commit09911bf2008-07-26 23:55:29118 // 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]1e0f70402008-10-16 23:57:47130 GreasemonkeySlave* greasemonkey_slave_;
initial.commit09911bf2008-07-26 23:55:29131
132 scoped_ptr<RenderDnsMaster> render_dns_master_;
133
134 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
135
[email protected]173de1b2008-08-15 18:36:46136 scoped_ptr<NotificationService> notification_service_;
137
initial.commit09911bf2008-07-26 23:55:29138 int in_send_;
139
140 DISALLOW_EVIL_CONSTRUCTORS(RenderThread);
141};
142
[email protected]1d97d2e2008-12-18 23:39:02143// The global RenderThread object for this process. Note that this should only
144// be accessed when running on the render thread itself.
145extern RenderThread* g_render_thread;
license.botbf09a502008-08-24 00:55:55146
[email protected]1d97d2e2008-12-18 23:39:02147#endif // CHROME_RENDERER_RENDER_THREAD_H_