blob: 0d5da09f7ef7408f7749b72dcd6f1f7dc74057d0 [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"
[email protected]037fce02009-01-22 01:42:1513#include "build/build_config.h"
[email protected]8930d472009-02-21 08:05:2814#include "chrome/common/child_thread.h"
[email protected]55e57d42009-02-25 06:10:1715#include "chrome/renderer/renderer_histogram_snapshots.h"
initial.commit09911bf2008-07-26 23:55:2916
[email protected]1edc16b82009-04-07 17:45:5417class AppCacheDispatcher;
[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;
[email protected]55e57d42009-02-25 06:10:1721class RendererHistogram;
[email protected]8d86fce2009-02-26 23:37:5522class RendererWebKitClientImpl;
[email protected]39008c02009-02-11 23:59:2523class SkBitmap;
[email protected]4d395d092009-02-11 21:40:4024class UserScriptSlave;
[email protected]39008c02009-02-11 23:59:2525class VisitedLinkSlave;
26struct ModalDialogEvent;
27struct WebPreferences;
initial.commit09911bf2008-07-26 23:55:2928
[email protected]81a34412009-01-05 19:17:2429// The RenderThreadBase is the minimal interface that a RenderView/Widget
30// expects from a render thread. The interface basically abstracts a way to send
31// and receive messages.
[email protected]8930d472009-02-21 08:05:2832class RenderThreadBase {
[email protected]8085dbc82008-09-26 22:53:4433 public:
34 virtual ~RenderThreadBase() {}
35
[email protected]8930d472009-02-21 08:05:2836 virtual bool Send(IPC::Message* msg) = 0;
37
[email protected]8085dbc82008-09-26 22:53:4438 // Called to add or remove a listener for a particular message routing ID.
39 // These methods normally get delegated to a MessageRouter.
40 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) = 0;
41 virtual void RemoveRoute(int32 routing_id) = 0;
[email protected]81a34412009-01-05 19:17:2442
43 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
44 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
[email protected]8085dbc82008-09-26 22:53:4445};
46
initial.commit09911bf2008-07-26 23:55:2947// The RenderThread class represents a background thread where RenderView
48// instances live. The RenderThread supports an API that is used by its
49// consumer to talk indirectly to the RenderViews and supporting objects.
50// Likewise, it provides an API for the RenderViews to talk back to the main
51// process (i.e., their corresponding WebContents).
52//
53// Most of the communication occurs in the form of IPC messages. They are
54// routed to the RenderThread according to the routing IDs of the messages.
55// The routing IDs correspond to RenderView instances.
[email protected]8930d472009-02-21 08:05:2856class RenderThread : public RenderThreadBase,
57 public ChildThread {
initial.commit09911bf2008-07-26 23:55:2958 public:
[email protected]8930d472009-02-21 08:05:2859 // Grabs the IPC channel name from the command line.
60 RenderThread();
61 // Constructor that's used when running in single process mode.
62 RenderThread(const std::wstring& channel_name);
[email protected]8085dbc82008-09-26 22:53:4463 virtual ~RenderThread();
initial.commit09911bf2008-07-26 23:55:2964
[email protected]8930d472009-02-21 08:05:2865 // Returns the one render thread for this process. Note that this should only
66 // be accessed when running on the render thread itself
67 static RenderThread* current();
initial.commit09911bf2008-07-26 23:55:2968
[email protected]81a34412009-01-05 19:17:2469 // Overridded from RenderThreadBase.
[email protected]8930d472009-02-21 08:05:2870 virtual bool Send(IPC::Message* msg) {
71 return ChildThread::Send(msg);
72 }
73
[email protected]8930d472009-02-21 08:05:2874 virtual void AddRoute(int32 routing_id, IPC::Channel::Listener* listener) {
75 return ChildThread::AddRoute(routing_id, listener);
76 }
77 virtual void RemoveRoute(int32 routing_id) {
78 return ChildThread::RemoveRoute(routing_id);
79 }
80
[email protected]81a34412009-01-05 19:17:2481 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
82 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
initial.commit09911bf2008-07-26 23:55:2983
[email protected]8d86fce2009-02-26 23:37:5584 VisitedLinkSlave* visited_link_slave() const {
85 return visited_link_slave_.get();
86 }
initial.commit09911bf2008-07-26 23:55:2987
[email protected]8d86fce2009-02-26 23:37:5588 UserScriptSlave* user_script_slave() const {
89 return user_script_slave_.get();
90 }
[email protected]1e0f70402008-10-16 23:57:4791
initial.commit09911bf2008-07-26 23:55:2992 // Do DNS prefetch resolution of a hostname.
93 void Resolve(const char* name, size_t length);
94
[email protected]55e57d42009-02-25 06:10:1795 // Send all the Histogram data to browser.
96 void SendHistograms();
97
initial.commit09911bf2008-07-26 23:55:2998 // Invokes InformHostOfCacheStats after a short delay. Used to move this
99 // bookkeeping operation off the critical latency path.
100 void InformHostOfCacheStatsLater();
101
[email protected]8930d472009-02-21 08:05:28102 private:
103 virtual void OnControlMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:29104
initial.commit09911bf2008-07-26 23:55:29105 // Called by the thread base class
106 virtual void Init();
107 virtual void CleanUp();
108
[email protected]176aa482008-11-14 03:25:15109 void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
[email protected]0938d3c2009-01-09 20:37:35110 void OnUpdateUserScripts(base::SharedMemoryHandle table);
[email protected]703e807a2009-03-28 19:56:51111 void OnSetExtensionFunctionNames(const std::vector<std::string>& names);
initial.commit09911bf2008-07-26 23:55:29112 void OnSetNextPageID(int32 next_page_id);
[email protected]18bcc3c2009-01-27 21:39:15113 void OnCreateNewView(gfx::NativeViewId parent_hwnd,
114 ModalDialogEvent modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29115 const WebPreferences& webkit_prefs,
116 int32 view_id);
117 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
118 void OnSetCacheCapacities(size_t min_dead_capacity,
119 size_t max_dead_capacity,
120 size_t capacity);
121 void OnGetCacheResourceStats();
122
[email protected]55e57d42009-02-25 06:10:17123 // Send all histograms to browser.
124 void OnGetRendererHistograms();
125
[email protected]75e5a872009-04-02 23:56:11126 void OnExtensionHandleConnect(int channel_id);
127 void OnExtensionHandleMessage(const std::string& message, int channel_id);
128
initial.commit09911bf2008-07-26 23:55:29129 // Gather usage statistics from the in-memory cache and inform our host.
130 // These functions should be call periodically so that the host can make
131 // decisions about how to allocation resources using current information.
132 void InformHostOfCacheStats();
133
[email protected]90a3fbb12009-02-28 01:13:47134 // We initialize WebKit as late as possible.
135 void EnsureWebKitInitialized();
136
initial.commit09911bf2008-07-26 23:55:29137 // These objects live solely on the render thread.
[email protected]8d86fce2009-02-26 23:37:55138 scoped_ptr<VisitedLinkSlave> visited_link_slave_;
initial.commit09911bf2008-07-26 23:55:29139
[email protected]8d86fce2009-02-26 23:37:55140 scoped_ptr<UserScriptSlave> user_script_slave_;
initial.commit09911bf2008-07-26 23:55:29141
[email protected]8d86fce2009-02-26 23:37:55142 scoped_ptr<RenderDnsMaster> dns_master_;
143
144 scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
[email protected]55e57d42009-02-25 06:10:17145
initial.commit09911bf2008-07-26 23:55:29146 scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
147
[email protected]173de1b2008-08-15 18:36:46148 scoped_ptr<NotificationService> notification_service_;
149
[email protected]90a3fbb12009-02-28 01:13:47150 scoped_ptr<RendererWebKitClientImpl> webkit_client_;
[email protected]c62ce3e2009-02-26 00:15:20151
[email protected]1edc16b82009-04-07 17:45:54152 scoped_ptr<AppCacheDispatcher> app_cache_dispatcher_;
153
[email protected]1bc83062009-02-06 00:16:37154 DISALLOW_COPY_AND_ASSIGN(RenderThread);
initial.commit09911bf2008-07-26 23:55:29155};
156
[email protected]1d97d2e2008-12-18 23:39:02157#endif // CHROME_RENDERER_RENDER_THREAD_H_