blob: d2a1fcd3c4f090786c8de737a7b614d3e6e1db37 [file] [log] [blame]
[email protected]45776222009-07-15 20:21:581// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// 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]b68d5ed2009-04-16 02:41:288#include <string>
[email protected]1bc83062009-02-06 00:16:379#include <vector>
10
[email protected]18bcc3c2009-01-27 21:39:1511#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/shared_memory.h"
13#include "base/task.h"
[email protected]037fce02009-01-22 01:42:1514#include "build/build_config.h"
[email protected]8930d472009-02-21 08:05:2815#include "chrome/common/child_thread.h"
[email protected]55e57d42009-02-25 06:10:1716#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]3e90d4a2009-07-03 17:38:3917#include "chrome/renderer/visitedlink_slave.h"
initial.commit09911bf2008-07-26 23:55:2918
[email protected]1edc16b82009-04-07 17:45:5419class AppCacheDispatcher;
[email protected]a8624712009-04-17 00:51:3520class DevToolsAgentFilter;
[email protected]39008c02009-02-11 23:59:2521class FilePath;
[email protected]dfcb62a2009-06-17 19:32:4322class ListValue;
[email protected]42f1d7822009-07-23 18:17:5523
[email protected]39008c02009-02-11 23:59:2524class RenderDnsMaster;
[email protected]55e57d42009-02-25 06:10:1725class RendererHistogram;
[email protected]8d86fce2009-02-26 23:37:5526class RendererWebKitClientImpl;
[email protected]39008c02009-02-11 23:59:2527class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4028class UserScriptSlave;
[email protected]39008c02009-02-11 23:59:2529struct ModalDialogEvent;
[email protected]9b6f40e2009-06-11 15:54:2630struct RendererPreferences;
[email protected]39008c02009-02-11 23:59:2531struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2932
[email protected]81a34412009-01-05 19:17:2433// The RenderThreadBase is the minimal interface that a RenderView/Widget
34// expects from a render thread. The interface basically abstracts a way to send
35// and receive messages.
[email protected]8930d472009-02-21 08:05:2836class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4437 public:
38 virtual ~RenderThreadBase() {}
39
[email protected]8930d472009-02-21 08:05:2840 virtual bool Send(IPC::Message* msg) = 0;
41
[email protected]8085dbc82008-09-26 22:53:4442 // Called to add or remove a listener for a particular message routing ID.
43 // These methods normally get delegated to a MessageRouter.
44 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
45 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2446
47 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
48 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]8085dbc82008-09-26 22:53:4449};
50
initial.commit09911bf2008-07-26 23:55:2951// The RenderThread class represents a background thread where RenderView
52// instances live. The RenderThread supports an API that is used by its
53// consumer to talk indirectly to the RenderViews and supporting objects.
54// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]57c6a652009-05-04 07:58:3455// process (i.e., their corresponding TabContents).
initial.commit09911bf2008-07-26 23:55:2956//
57// Most of the communication occurs in the form of IPC messages. They are
58// routed to the RenderThread according to the routing IDs of the messages.
59// The routing IDs correspond to RenderView instances.
[email protected]8930d472009-02-21 08:05:2860class RenderThread : public RenderThreadBase,
61 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2962 public:
[email protected]8930d472009-02-21 08:05:2863 // Grabs the IPC channel name from the command line.
64 RenderThread();
65 // Constructor that's used when running in single process mode.
[email protected]9a3a293b2009-06-04 22:28:1666 RenderThread(const std::string& channel_name);
[email protected]8085dbc82008-09-26 22:53:4467 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2968
[email protected]8930d472009-02-21 08:05:2869 // Returns the one render thread for this process. Note that this should only
70 // be accessed when running on the render thread itself
71 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2972
[email protected]45776222009-07-15 20:21:5873 // Overridden from RenderThreadBase.
[email protected]8930d472009-02-21 08:05:2874 virtual bool Send(IPC::Message* msg) {
75 return ChildThread::Send(msg);
76 }
77
[email protected]8930d472009-02-21 08:05:2878 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) {
79 return ChildThread::AddRoute(routing_id, listener);
80 }
81 virtual void RemoveRoute(int32 routing_id) {
82 return ChildThread::RemoveRoute(routing_id);
83 }
84
[email protected]81a34412009-01-05 19:17:2485 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
86 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2987
[email protected]8d86fce2009-02-26 23:37:5588 VisitedLinkSlave* visited_link_slave() const {
89 return visited_link_slave_.get();
90 }
initial.commit09911bf2008-07-26 23:55:2991
[email protected]8d86fce2009-02-26 23:37:5592 UserScriptSlave* user_script_slave() const {
93 return user_script_slave_.get();
94 }
[email protected]1e0f70402008-10-16 23:57:4795
[email protected]b547fd42009-04-23 23:16:2796 bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
97
initial.commit09911bf2008-07-26 23:55:2998 // Do DNS prefetch resolution of a hostname.
99 void Resolve(const char* name, size_t length);
100
[email protected]55e57d42009-02-25 06:10:17101 // Send all the Histogram data to browser.
[email protected]c9a3ef82009-05-28 22:02:46102 void SendHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17103
initial.commit09911bf2008-07-26 23:55:29104 // Invokes InformHostOfCacheStats after a short delay. Used to move this
105 // bookkeeping operation off the critical latency path.
106 void InformHostOfCacheStatsLater();
107
[email protected]b07f29092009-06-05 07:33:21108 // Sends a message to the browser to close all idle connections.
109 void CloseIdleConnections();
110
111 // Sends a message to the browser to enable or disable the disk cache.
112 void SetCacheMode(bool enabled);
113
[email protected]8930d472009-02-21 08:05:28114 private:
115 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29116
[email protected]42f1d7822009-07-23 18:17:55117 void Init();
initial.commit09911bf2008-07-26 23:55:29118
[email protected]176aa482008-11-14 03:25:15119 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]3e90d4a2009-07-03 17:38:39120 void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
121 void OnResetVisitedLinks();
122
[email protected]0938d3c2009-01-09 20:37:35123 void OnUpdateUserScripts(base::SharedMemoryHandle table);
[email protected]703e807a2009-03-28 19:56:51124 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
[email protected]45776222009-07-15 20:21:58125 void OnPageActionsUpdated(const std::string& extension_id,
126 const std::vector<std::string>& page_actions);
initial.commit09911bf2008-07-26 23:55:29127 void OnSetNextPageID(int32 next_page_id);
[email protected]18bcc3c2009-01-27 21:39:15128 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
129 ModalDialogEvent modal_dialog_event,
[email protected]80d96fa2009-06-10 22:34:51130 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29131 const WebPreferences& webkit_prefs,
132 int32 view_id);
133 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
134 void OnSetCacheCapacities(size_t min_dead_capacity,
135 size_t max_dead_capacity,
136 size_t capacity);
137 void OnGetCacheResourceStats();
138
[email protected]55e57d42009-02-25 06:10:17139 // Send all histograms to browser.
[email protected]c9a3ef82009-05-28 22:02:46140 void OnGetRendererHistograms(int sequence_number);
[email protected]55e57d42009-02-25 06:10:17141
[email protected]dfcb62a2009-06-17 19:32:43142 void OnExtensionMessageInvoke(const std::string& function_name,
143 const ListValue& args);
[email protected]b547fd42009-04-23 23:16:27144 void OnPurgePluginListCache();
[email protected]75e5a872009-04-02 23:56:11145
initial.commit09911bf2008-07-26 23:55:29146 // Gather usage statistics from the in-memory cache and inform our host.
147 // These functions should be call periodically so that the host can make
148 // decisions about how to allocation resources using current information.
149 void InformHostOfCacheStats();
150
[email protected]90a3fbb12009-02-28 01:13:47151 // We initialize WebKit as late as possible.
152 void EnsureWebKitInitialized();
153
initial.commit09911bf2008-07-26 23:55:29154 // These objects live solely on the render thread.
[email protected]9291ed12009-07-23 17:33:22155 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
[email protected]42f1d7822009-07-23 18:17:55156 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
157 scoped_ptr<UserScriptSlave> user_script_slave_;
158 scoped_ptr<RenderDnsMaster> dns_master_;
[email protected]9291ed12009-07-23 17:33:22159 scoped_ptr<AppCacheDispatcher> app_cache_dispatcher_;
[email protected]9291ed12009-07-23 17:33:22160 scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
[email protected]42f1d7822009-07-23 18:17:55161 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
162 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]9291ed12009-07-23 17:33:22163
[email protected]5fa1c542009-05-05 20:36:07164#if defined(OS_POSIX)
165 scoped_refptr<IPC::ChannelProxy::MessageFilter>
166 suicide_on_channel_error_filter_;
167#endif
168
[email protected]b547fd42009-04-23 23:16:27169 // If true, then a GetPlugins call is allowed to rescan the disk.
170 bool plugin_refresh_allowed_;
171
[email protected]1bc83062009-02-06 00:16:37172 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29173};
174
[email protected]1d97d2e2008-12-18 23:39:02175#endif // CHROME_RENDERER_RENDER_THREAD_H_