blob: 2d1c198b26056490e6ba61b2e91dcc1944d0a06b [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
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.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;
initial.commit09911bf2008-07-26 23:55:2921
[email protected]8085dbc82008-09-26 22:53:4422// 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.
25class 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.commit09911bf2008-07-26 23:55:2938// 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.commit09911bf2008-07-26 23:55:2947class RenderThread : public IPC::Channel::Listener,
[email protected]8085dbc82008-09-26 22:53:4448 public RenderThreadBase,
[email protected]ab820df2008-08-26 05:55:1049 public base::Thread {
initial.commit09911bf2008-07-26 23:55:2950 public:
51 RenderThread(const std::wstring& channel_name);
[email protected]8085dbc82008-09-26 22:53:4452 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2953
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]f886b7bf2008-09-10 10:54:0665 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2966
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]8085dbc82008-09-26 22:53:4473 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
74 virtual void RemoveRoute(int32 routing_id);
initial.commit09911bf2008-07-26 23:55:2975
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]8085dbc82008-09-26 22:53:4483 virtual bool InSend() const { return in_send_ != 0; }
initial.commit09911bf2008-07-26 23:55:2984
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]a9f4d902008-09-15 23:43:4293 void OnPluginMessage(const std::wstring& dll_path,
94 const std::vector<uint8>& data);
initial.commit09911bf2008-07-26 23:55:2995 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.commit09911bf2008-07-26 23:55:29111 // 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]173de1b2008-08-15 18:36:46128 scoped_ptr<NotificationService> notification_service_;
129
initial.commit09911bf2008-07-26 23:55:29130 int in_send_;
131
132 DISALLOW_EVIL_CONSTRUCTORS(RenderThread);
133};
134
135#endif // CHROME_RENDERER_RENDER_THREAD_H__
license.botbf09a502008-08-24 00:55:55136