blob: 5a2e80a8010fce04b458d0415c9271bfcdd9bd41 [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]690a99c2009-01-06 16:48:458#include "base/file_path.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/ref_counted.h"
10#include "base/shared_memory.h"
11#include "base/task.h"
12#include "base/thread.h"
[email protected]037fce02009-01-22 01:42:1513#include "build/build_config.h"
initial.commit09911bf2008-07-26 23:55:2914#include "chrome/common/ipc_sync_channel.h"
15#include "chrome/common/message_router.h"
16
17class SkBitmap;
18class Task;
19class VisitedLinkSlave;
20struct WebPreferences;
21class RenderDnsMaster;
[email protected]173de1b2008-08-15 18:36:4622class NotificationService;
[email protected]0938d3c2009-01-09 20:37:3523class UserScriptSlave;
initial.commit09911bf2008-07-26 23:55:2924
[email protected]81a34412009-01-05 19:17:2425// The RenderThreadBase is the minimal interface that a RenderView/Widget
26// expects from a render thread. The interface basically abstracts a way to send
27// and receive messages.
[email protected]8085dbc82008-09-26 22:53:4428class RenderThreadBase : public IPC::Message::Sender {
29 public:
30 virtual ~RenderThreadBase() {}
31
32 // True if currently sending a message.
33 virtual bool InSend() const = 0;
34
35 // Called to add or remove a listener for a particular message routing ID.
36 // These methods normally get delegated to a MessageRouter.
37 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
38 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2439
40 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
41 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]8085dbc82008-09-26 22:53:4442};
43
initial.commit09911bf2008-07-26 23:55:2944// The RenderThread class represents a background thread where RenderView
45// instances live. The RenderThread supports an API that is used by its
46// consumer to talk indirectly to the RenderViews and supporting objects.
47// Likewise, it provides an API for the RenderViews to talk back to the main
48// process (i.e., their corresponding WebContents).
49//
50// Most of the communication occurs in the form of IPC messages. They are
51// routed to the RenderThread according to the routing IDs of the messages.
52// The routing IDs correspond to RenderView instances.
initial.commit09911bf2008-07-26 23:55:2953class RenderThread : public IPC::Channel::Listener,
[email protected]8085dbc82008-09-26 22:53:4454 public RenderThreadBase,
[email protected]ab820df2008-08-26 05:55:1055 public base::Thread {
initial.commit09911bf2008-07-26 23:55:2956 public:
57 RenderThread(const std::wstring& channel_name);
[email protected]8085dbc82008-09-26 22:53:4458 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2959
60 // IPC::Channel::Listener implementation:
61 virtual void OnMessageReceived(const IPC::Message& msg);
62 virtual void OnChannelError();
63
64 // IPC::Message::Sender implementation:
65 virtual bool Send(IPC::Message* msg);
66
[email protected]81a34412009-01-05 19:17:2467 // Overridded from RenderThreadBase.
68 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
69 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2970
[email protected]1e0f70402008-10-16 23:57:4771 // Gets the VisitedLinkSlave instance for this thread
initial.commit09911bf2008-07-26 23:55:2972 VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; }
73
[email protected]0938d3c2009-01-09 20:37:3574 // Gets the UserScriptSlave instance for this thread
75 UserScriptSlave* user_script_slave() const { return user_script_slave_; }
[email protected]1e0f70402008-10-16 23:57:4776
initial.commit09911bf2008-07-26 23:55:2977 // Do DNS prefetch resolution of a hostname.
78 void Resolve(const char* name, size_t length);
79
80 // See documentation on MessageRouter for AddRoute and RemoveRoute
[email protected]8085dbc82008-09-26 22:53:4481 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
82 virtual void RemoveRoute(int32 routing_id);
initial.commit09911bf2008-07-26 23:55:2983
84 // Invokes InformHostOfCacheStats after a short delay. Used to move this
85 // bookkeeping operation off the critical latency path.
86 void InformHostOfCacheStatsLater();
87
88 MessageLoop* owner_loop() { return owner_loop_; }
89
90 // Indicates if RenderThread::Send() is on the call stack.
[email protected]8085dbc82008-09-26 22:53:4491 virtual bool InSend() const { return in_send_ != 0; }
initial.commit09911bf2008-07-26 23:55:2992
93 protected:
94 // Called by the thread base class
95 virtual void Init();
96 virtual void CleanUp();
97
98 private:
[email protected]176aa482008-11-14 03:25:1599 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]0938d3c2009-01-09 20:37:35100 void OnUpdateUserScripts(base::SharedMemoryHandle table);
initial.commit09911bf2008-07-26 23:55:29101
[email protected]690a99c2009-01-06 16:48:45102 void OnPluginMessage(const FilePath& plugin_path,
[email protected]a9f4d902008-09-15 23:43:42103 const std::vector<uint8>& data);
initial.commit09911bf2008-07-26 23:55:29104 void OnSetNextPageID(int32 next_page_id);
[email protected]037fce02009-01-22 01:42:15105#if defined(OS_WIN)
106 // TODO(port): we'll need to support that at some point, but it's not clear
107 // if we'll be using the same sort of messages for setting this up
initial.commit09911bf2008-07-26 23:55:29108 void OnCreateNewView(HWND parent_hwnd,
109 HANDLE modal_dialog_event,
110 const WebPreferences& webkit_prefs,
111 int32 view_id);
[email protected]037fce02009-01-22 01:42:15112#endif
initial.commit09911bf2008-07-26 23:55:29113 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
114 void OnSetCacheCapacities(size_t min_dead_capacity,
115 size_t max_dead_capacity,
116 size_t capacity);
117 void OnGetCacheResourceStats();
118
119 // Gather usage statistics from the in-memory cache and inform our host.
120 // These functions should be call periodically so that the host can make
121 // decisions about how to allocation resources using current information.
122 void InformHostOfCacheStats();
123
initial.commit09911bf2008-07-26 23:55:29124 // The message loop used to run tasks on the thread that started this thread.
125 MessageLoop* owner_loop_;
126
127 // Used only on the background render thread to implement message routing
128 // functionality to the consumers of the RenderThread.
129 MessageRouter router_;
130
131 std::wstring channel_name_;
132 scoped_ptr<IPC::SyncChannel> channel_;
133
134 // These objects live solely on the render thread.
135 VisitedLinkSlave* visited_link_slave_;
[email protected]0938d3c2009-01-09 20:37:35136 UserScriptSlave* user_script_slave_;
initial.commit09911bf2008-07-26 23:55:29137
138 scoped_ptr<RenderDnsMaster> render_dns_master_;
139
140 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
141
[email protected]173de1b2008-08-15 18:36:46142 scoped_ptr<NotificationService> notification_service_;
143
initial.commit09911bf2008-07-26 23:55:29144 int in_send_;
145
146 DISALLOW_EVIL_CONSTRUCTORS(RenderThread);
147};
148
[email protected]1d97d2e2008-12-18 23:39:02149// The global RenderThread object for this process. Note that this should only
150// be accessed when running on the render thread itself.
151extern RenderThread* g_render_thread;
license.botbf09a502008-08-24 00:55:55152
[email protected]1d97d2e2008-12-18 23:39:02153#endif // CHROME_RENDERER_RENDER_THREAD_H_