blob: 840dbba52908c082863f5939b2ab213446b71198 [file] [log] [blame]
[email protected]d3d6325d2012-01-03 21:17:361// Copyright (c) 2012 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]f1a29a02011-10-06 23:08:445#ifndef CONTENT_RENDERER_RENDER_THREAD_IMPL_H_
6#define CONTENT_RENDERER_RENDER_THREAD_IMPL_H_
initial.commit09911bf2008-07-26 23:55:297
avi1023d012015-12-25 02:39:148#include <stddef.h>
9#include <stdint.h>
10
maxmorin017ba8c62017-06-02 10:23:0911#include <map>
leon.han21e0e482017-02-23 04:13:3212#include <memory>
[email protected]6779aa12011-03-29 17:32:2413#include <set>
[email protected]b68d5ed2009-04-16 02:41:2814#include <string>
maxmorin017ba8c62017-06-02 10:23:0915#include <utility>
[email protected]1bc83062009-02-06 00:16:3716#include <vector>
17
jdduke691dd572014-12-02 20:47:5218#include "base/cancelable_callback.h"
Sebastien Marchand836d04b32020-04-28 18:10:0319#include "base/clang_profiling_buildflags.h"
Tal Pressmanc951ed92020-09-01 00:24:2320#include "base/containers/unique_ptr_adapters.h"
avi1023d012015-12-25 02:39:1421#include "base/macros.h"
Gordon Guan96c21ee2019-11-06 15:05:3922#include "base/memory/discardable_memory_allocator.h"
[email protected]5071cb22013-07-10 02:19:0623#include "base/memory/memory_pressure_listener.h"
rockot775ce0d2015-01-27 18:35:0124#include "base/memory/ref_counted.h"
[email protected]e6e30ac2014-01-13 21:24:3925#include "base/metrics/user_metrics_action.h"
[email protected]1223d6ef2011-03-28 16:47:5026#include "base/observer_list.h"
maxmorin017ba8c62017-06-02 10:23:0927#include "base/optional.h"
[email protected]21aa99682013-06-11 07:17:0128#include "base/strings/string16.h"
tbansal99d8aeb2017-05-22 19:12:5829#include "base/time/time.h"
[email protected]037fce02009-01-22 01:42:1530#include "build/build_config.h"
Dave Tapuskae9cad0f2020-09-18 14:10:4631#include "cc/mojom/render_frame_metadata.mojom.h"
jam8a021512a2015-02-03 18:16:0832#include "content/child/child_thread_impl.h"
Tal Pressmanc951ed92020-09-01 00:24:2333#include "content/common/agent_scheduling_group.mojom.h"
[email protected]8d128d62011-09-13 22:11:5734#include "content/common/content_export.h"
ben76f52b242016-06-18 05:42:4835#include "content/common/frame.mojom.h"
alexmosbc7eafa2014-12-06 01:38:0936#include "content/common/frame_replication_state.h"
samans2040988b2017-04-11 23:58:3537#include "content/common/frame_sink_provider.mojom.h"
rockote261d2112016-09-21 22:22:2338#include "content/common/render_message_filter.mojom.h"
rockot067ca55f2016-09-30 22:00:1539#include "content/common/renderer.mojom.h"
jam188f19f2017-06-07 03:56:2440#include "content/common/renderer_host.mojom.h"
[email protected]526476902011-10-06 20:34:0641#include "content/public/renderer/render_thread.h"
Yuzhu Shenfe5f3a52018-01-11 21:24:1342#include "content/public/renderer/url_loader_throttle_provider.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1343#include "content/renderer/compositor/compositor_dependencies.h"
Gordon Guan96c21ee2019-11-06 15:05:3944#include "content/renderer/discardable_memory_utils.h"
penghuang346a46f92016-03-31 21:37:5245#include "gpu/ipc/client/gpu_channel_host.h"
Antoine Laboure55c9ef82017-11-10 18:51:2346#include "ipc/ipc_sync_channel.h"
Scott Violeta35f9a42018-03-22 22:00:4447#include "media/media_buildflags.h"
Julie Jeongeun Kim4e77af2622019-09-11 03:36:4548#include "mojo/public/cpp/bindings/associated_receiver.h"
Julie Jeongeun Kimdaa9aa12019-10-24 02:51:5649#include "mojo/public/cpp/bindings/associated_remote.h"
Julie Jeongeun Kim4e77af2622019-09-11 03:36:4550#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim4421c2e2019-09-11 06:34:3951#include "mojo/public/cpp/bindings/pending_receiver.h"
Julie Jeongeun Kim6f4b7e02019-09-11 05:05:4652#include "mojo/public/cpp/bindings/pending_remote.h"
Gyuyoung Kimef648a2e72019-09-17 09:48:3553#include "mojo/public/cpp/bindings/receiver.h"
Mario Sanchez Prada5492c9a2019-09-10 20:58:1154#include "mojo/public/cpp/bindings/remote.h"
[email protected]d7ff5fb2014-05-29 19:50:2555#include "net/base/network_change_notifier.h"
tbansalb612c5d2017-05-25 18:53:0656#include "net/nqe/effective_connection_type.h"
Ken Rockot54311e62018-02-10 19:01:5257#include "services/network/public/mojom/url_loader_factory.mojom.h"
Miyoung Shin99505dd2019-07-27 12:45:3558#include "services/viz/public/mojom/compositing/compositing_mode_watcher.mojom.h"
Ken Rockot26e4e802018-07-31 15:03:3359#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
Mike West6e4cbb32019-02-13 09:40:1760#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
Kent Tamura38fb4342018-07-25 12:47:5361#include "third_party/blink/public/platform/scheduler/web_rail_mode_observer.h"
Daniel Murphy738378c2019-05-31 21:59:2562#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
Blink Reformata30d4232018-04-07 15:31:0663#include "third_party/blink/public/platform/web_connection_type.h"
Blink Reformata30d4232018-04-07 15:31:0664#include "third_party/blink/public/web/web_memory_statistics.h"
[email protected]08397d52011-02-05 01:53:3865#include "ui/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2966
[email protected]39008c02009-02-11 23:59:2567class SkBitmap;
[email protected]46f36a492010-07-28 19:36:4168
[email protected]180ef242013-11-07 06:50:4669namespace blink {
Antonio Gomes925f9b92019-07-30 23:23:2370class WebVideoCaptureImplManager;
[email protected]b7c7bcf2009-10-03 07:07:3471}
72
[email protected]64ffa0442011-10-03 22:08:3673namespace base {
skyostil457b0a12014-09-09 10:12:0774class SingleThreadTaskRunner;
[email protected]64ffa0442011-10-03 22:08:3675class Thread;
76}
77
[email protected]c29b7ff2013-03-06 03:51:0478namespace cc {
reveman34b7a1522015-03-23 20:27:4779class TaskGraphRunner;
[email protected]c29b7ff2013-03-06 03:51:0480}
81
penghuang346a46f92016-03-31 21:37:5282namespace gpu {
83class GpuChannelHost;
84}
85
[email protected]563d665f2013-02-01 04:42:3986namespace media {
[email protected]2329bfc72014-02-28 02:03:2187class GpuVideoAcceleratorFactories;
[email protected]563d665f2013-02-01 04:42:3988}
89
Ken Rockot13051c932019-11-14 20:11:5190namespace mojo {
91class BinderMap;
92}
93
danakj92429852017-06-29 00:19:0394namespace viz {
Scott Violet7e33efc2018-08-29 22:30:1595class ContextProviderCommandBuffer;
96class Gpu;
Scott Violet703b8242019-06-11 19:34:3697class RasterContextProvider;
98class SyntheticBeginFrameSource;
99} // namespace viz
Scott Violet7e33efc2018-08-29 22:30:15100
[email protected]64ffa0442011-10-03 22:08:36101namespace content {
Tal Pressman9780e2c2020-08-26 06:35:09102class AgentSchedulingGroup;
John Abd-El-Maleke1d4de32017-10-21 16:14:29103class CategorizedWorkerPool;
John Abd-El-Maleke1d4de32017-10-21 16:14:29104class GpuVideoAcceleratorFactoriesImpl;
tyoshino832a58a2016-04-18 08:14:08105class RenderThreadObserver;
tfarina556a7232014-10-05 01:02:09106class RendererBlinkPlatformImpl;
John Abd-El-Malek6b56ef712017-10-21 22:52:46107class ResourceDispatcher;
Alex Clarke9fc39b9b2020-01-31 17:29:47108class VariationsRenderThreadObserver;
[email protected]cb25aa12012-08-07 19:13:43109
boliubee541f42015-11-05 00:52:53110#if defined(OS_ANDROID)
siva.gunturi5d4feb052015-11-15 16:15:31111class StreamTextureFactory;
boliubee541f42015-11-05 00:52:53112#endif
113
Matt Falkenhagenef13d782019-05-30 21:02:12114// The RenderThreadImpl class represents the main thread, where RenderView
initial.commit09911bf2008-07-26 23:55:29115// instances live. The RenderThread supports an API that is used by its
116// consumer to talk indirectly to the RenderViews and supporting objects.
117// Likewise, it provides an API for the RenderViews to talk back to the main
[email protected]770005b2012-04-16 15:58:13118// process (i.e., their corresponding WebContentsImpl).
initial.commit09911bf2008-07-26 23:55:29119//
120// Most of the communication occurs in the form of IPC messages. They are
121// routed to the RenderThread according to the routing IDs of the messages.
122// The routing IDs correspond to RenderView instances.
danakj6e3bf8012014-12-16 18:27:53123class CONTENT_EXPORT RenderThreadImpl
124 : public RenderThread,
jam8a021512a2015-02-03 18:16:08125 public ChildThreadImpl,
Nico Weber43ddd7a32017-08-15 19:19:27126 public mojom::Renderer,
danakjab9ef4d2017-10-31 23:38:33127 public viz::mojom::CompositingModeWatcher,
Nico Weber43ddd7a32017-08-15 19:19:27128 public CompositorDependencies {
initial.commit09911bf2008-07-26 23:55:29129 public:
[email protected]f1a29a02011-10-06 23:08:44130 static RenderThreadImpl* current();
rockot5c478a72016-09-28 23:14:18131 static mojom::RenderMessageFilter* current_render_message_filter();
olegmax045f7fb12017-05-19 07:58:55132 static RendererBlinkPlatformImpl* current_blink_platform_impl();
rockot5c478a72016-09-28 23:14:18133
134 static void SetRenderMessageFilterForTesting(
135 mojom::RenderMessageFilter* render_message_filter);
olegmax045f7fb12017-05-19 07:58:55136 static void SetRendererBlinkPlatformImplForTesting(
137 RendererBlinkPlatformImpl* blink_platform_impl);
[email protected]526476902011-10-06 20:34:06138
John Abd-El-Malekd4882642017-12-04 21:45:19139 // Returns the task runner for the main thread where the RenderThread lives.
Hajime Hoshi20578c62018-01-12 09:43:26140 static scoped_refptr<base::SingleThreadTaskRunner>
141 DeprecatedGetMainTaskRunner();
John Abd-El-Malekd4882642017-12-04 21:45:19142
Wez6979109b2018-09-07 17:30:56143 RenderThreadImpl(
144 base::RepeatingClosure quit_closure,
Greg Kraynovf5d60272018-08-10 12:28:51145 std::unique_ptr<blink::scheduler::WebThreadScheduler> scheduler);
146 RenderThreadImpl(
147 const InProcessChildThreadParams& params,
Sunny Sachanandanie3e582502019-10-22 20:10:38148 int32_t client_id,
Greg Kraynovf5d60272018-08-10 12:28:51149 std::unique_ptr<blink::scheduler::WebThreadScheduler> scheduler);
dcheng6d18e402014-10-21 12:32:52150 ~RenderThreadImpl() override;
151 void Shutdown() override;
harakenbbfdd9f02017-01-12 07:14:04152 bool ShouldBeDestroyed() override;
initial.commit09911bf2008-07-26 23:55:29153
[email protected]58436a12012-03-21 17:10:26154 // When initializing WebKit, ensure that any schemes needed for the content
155 // module are registered properly. Static to allow sharing with tests.
156 static void RegisterSchemes();
157
[email protected]e9ff79c2012-10-19 21:31:26158 // RenderThread implementation:
dcheng6d18e402014-10-21 12:32:52159 bool Send(IPC::Message* msg) override;
dcheng6d18e402014-10-21 12:32:52160 IPC::SyncChannel* GetChannel() override;
161 std::string GetLocale() override;
162 IPC::SyncMessageFilter* GetSyncMessageFilter() override;
avi1023d012015-12-25 02:39:14163 void AddRoute(int32_t routing_id, IPC::Listener* listener) override;
164 void RemoveRoute(int32_t routing_id) override;
dcheng6d18e402014-10-21 12:32:52165 int GenerateRoutingID() override;
166 void AddFilter(IPC::MessageFilter* filter) override;
167 void RemoveFilter(IPC::MessageFilter* filter) override;
tyoshino832a58a2016-04-18 08:14:08168 void AddObserver(RenderThreadObserver* observer) override;
169 void RemoveObserver(RenderThreadObserver* observer) override;
dcheng6d18e402014-10-21 12:32:52170 void SetResourceDispatcherDelegate(
mohan.reddyee0b42a2014-10-08 04:53:14171 ResourceDispatcherDelegate* delegate) override;
Clemens Hammacher38b6a762019-02-05 13:07:22172 void RegisterExtension(std::unique_ptr<v8::Extension> extension) override;
danakj710b4c02019-11-28 16:08:45173 int PostTaskToAllWebWorkers(base::RepeatingClosure closure) override;
dcheng6d18e402014-10-21 12:32:52174 bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
175 base::WaitableEvent* GetShutdownEvent() override;
staraz067f58242016-11-07 21:06:41176 int32_t GetClientId() override;
Nasko Oskov3d0d1dc2018-09-25 03:57:13177 bool IsOnline() override;
Karan Bhatiac89897f2017-08-10 01:06:40178 void SetRendererProcessType(
Yuta Kitamura63593502018-11-12 09:27:13179 blink::scheduler::WebRendererProcessType type) override;
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:49180 blink::WebString GetUserAgent() override;
Mike West6e4cbb32019-02-13 09:40:17181 const blink::UserAgentMetadata& GetUserAgentMetadata() override;
Virender Singhdfc6c792019-12-03 05:40:03182 bool IsUseZoomForDSF() override;
[email protected]1223d6ef2011-03-28 16:47:50183
rockot067ca55f2016-09-30 22:00:15184 // IPC::Listener implementation via ChildThreadImpl:
185 void OnAssociatedInterfaceRequest(
186 const std::string& name,
187 mojo::ScopedInterfaceEndpointHandle handle) override;
188
weilifabbf7572017-05-22 19:05:16189 // ChildThread implementation via ChildThreadImpl:
190 scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() override;
191
danakj6e3bf8012014-12-16 18:27:53192 // CompositorDependencies implementation.
danakj6e3bf8012014-12-16 18:27:53193 bool IsLcdTextEnabled() override;
ccamerona7644752014-12-30 01:16:31194 bool IsElasticOverscrollEnabled() override;
danakj4b347212018-07-04 17:55:17195 bool IsUseZoomForDSFEnabled() override;
Dave Tapuska14d816f2020-04-20 16:21:13196 bool IsSingleThreaded() override;
danakjf24dc812019-10-04 19:03:16197 scoped_refptr<base::SingleThreadTaskRunner> GetCleanupTaskRunner() override;
Yuta Kitamuradeb91bb2018-05-29 05:53:20198 blink::scheduler::WebThreadScheduler* GetWebMainThreadScheduler() override;
reveman34b7a1522015-03-23 20:27:47199 cc::TaskGraphRunner* GetTaskGraphRunner() override;
wjmaclean1d970622017-01-21 22:28:24200 bool IsScrollAnimatorEnabled() override;
Khushal3e96e662017-10-30 23:16:50201 std::unique_ptr<cc::UkmRecorderFactory> CreateUkmRecorderFactory() override;
danakj2d2889a2019-04-05 21:22:08202 void RequestNewLayerTreeFrameSink(
Erik Chen450ab562019-10-10 18:58:13203 RenderWidget* render_widget,
danakj2d2889a2019-04-05 21:22:08204 const GURL& url,
205 LayerTreeFrameSinkCallback callback,
danakj2d2889a2019-04-05 21:22:08206 const char* client_name) override;
danakj6e3bf8012014-12-16 18:27:53207
danakje6da4f12018-07-04 17:41:30208 bool IsThreadedAnimationEnabled();
Dave Tapuska14d816f2020-04-20 16:21:13209 scoped_refptr<base::SingleThreadTaskRunner>
210 GetCompositorMainThreadTaskRunner();
danakje6da4f12018-07-04 17:41:30211
danakjab9ef4d2017-10-31 23:38:33212 // viz::mojom::CompositingModeWatcher implementation.
213 void CompositingModeFallbackToSoftware() override;
214
215 // Whether gpu compositing is being used or is disabled for software
216 // compositing. Clients of the compositor should give resources that match
217 // the appropriate mode.
218 bool IsGpuCompositingDisabled() { return is_gpu_compositing_disabled_; }
219
[email protected]b3e83de2012-02-07 03:33:28220 // Synchronously establish a channel to the GPU plugin if not previously
221 // established or if it has been lost (for example if the GPU plugin crashed).
222 // If there is a pending asynchronous request, it will be completed by the
Bo Liud1ef1c32017-12-08 06:15:50223 // time this routine returns.
224 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync();
[email protected]b3e83de2012-02-07 03:33:28225
pimanc44437a22016-10-29 00:09:22226 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager();
227
Sam McNally52e50282017-11-29 00:54:02228 blink::AssociatedInterfaceRegistry* GetAssociatedInterfaceRegistry();
rockot067ca55f2016-09-30 22:00:15229
Gordon Guan96c21ee2019-11-06 15:05:39230 base::DiscardableMemoryAllocator* GetDiscardableMemoryAllocatorForTest()
231 const {
232 return discardable_memory_allocator_.get();
penghuang342762b2016-12-02 21:04:58233 }
234
tfarina556a7232014-10-05 01:02:09235 RendererBlinkPlatformImpl* blink_platform_impl() const {
236 DCHECK(blink_platform_impl_);
237 return blink_platform_impl_.get();
[email protected]078780b2014-06-20 16:57:06238 }
239
Yuta Kitamura4e256bfc2018-09-27 06:32:35240 // Returns the task runner on the compositor thread.
241 //
danakj6e3bf8012014-12-16 18:27:53242 // Will be null if threaded compositing has not been enabled.
skyostil2d3b5bd2015-05-27 15:40:59243 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner() const {
244 return compositor_task_runner_;
[email protected]a9fb30aa2011-10-06 06:58:46245 }
246
John Abd-El-Malek6b56ef712017-10-21 22:52:46247 ResourceDispatcher* resource_dispatcher() const {
248 return resource_dispatcher_.get();
249 }
250
Yuzhu Shenfe5f3a52018-01-11 21:24:13251 URLLoaderThrottleProvider* url_loader_throttle_provider() const {
252 return url_loader_throttle_provider_.get();
253 }
254
[email protected]6ca6a082013-09-22 20:10:05255#if defined(OS_ANDROID)
siva.gunturi5d4feb052015-11-15 16:15:31256 scoped_refptr<StreamTextureFactory> GetStreamTexureFactory();
boliuf8753bf62016-02-11 20:09:42257 bool EnableStreamTextureCopy();
[email protected]6ca6a082013-09-22 20:10:05258#endif
259
Antonio Gomes925f9b92019-07-30 23:23:23260 blink::WebVideoCaptureImplManager* video_capture_impl_manager() const {
[email protected]80b161a2011-06-27 17:42:11261 return vc_manager_.get();
262 }
263
rockote261d2112016-09-21 22:22:23264 mojom::RenderMessageFilter* render_message_filter();
rockot1587e332016-07-27 17:44:14265
[email protected]6217d392010-03-25 22:08:35266 // Get the GPU channel. Returns NULL if the channel is not established or
267 // has been lost.
penghuang346a46f92016-03-31 21:37:52268 gpu::GpuChannelHost* GetGpuChannel();
[email protected]6217d392010-03-25 22:08:35269
skyostil2d3b5bd2015-05-27 15:40:59270 // Returns a SingleThreadTaskRunner instance corresponding to the message loop
[email protected]c1330c82013-06-06 02:23:25271 // of the thread on which media operations should be run. Must be called
272 // on the renderer's main thread.
acolwellb4034942014-08-28 15:42:43273 scoped_refptr<base::SingleThreadTaskRunner> GetMediaThreadTaskRunner();
[email protected]c1330c82013-06-06 02:23:25274
dcastagna4517a182015-08-05 19:51:03275 // A TaskRunner instance that runs tasks on the raster worker pool.
276 base::TaskRunner* GetWorkerTaskRunner();
dcastagnab880e8f2015-06-30 20:16:06277
CJ DiMeglio79f7c91a22018-08-30 22:24:43278 // Creates a ContextProvider if yet created, and returns it to be used for
279 // video frame compositing. The ContextProvider given as an argument is
280 // one that has been lost, and is a hint to the RenderThreadImpl to clear
281 // it's |video_frame_compositor_context_provider_| if it matches.
Sergey Ulanov83f4a152019-02-14 03:54:25282 scoped_refptr<viz::RasterContextProvider>
283 GetVideoFrameCompositorContextProvider(
284 scoped_refptr<viz::RasterContextProvider>);
CJ DiMeglio79f7c91a22018-08-30 22:24:43285
danakj0b4b94e32016-05-10 22:33:01286 // Returns a worker context provider that will be bound on the compositor
287 // thread.
Victor Miuraff6488612017-12-21 04:16:15288 scoped_refptr<viz::RasterContextProvider>
Jonathan Backer8e4f35d2018-10-15 20:56:42289 SharedCompositorWorkerContextProvider(bool try_gpu_rasterization);
revemand180dfc32015-09-24 00:19:43290
dcastagna7f45dada2015-10-19 20:17:35291 media::GpuVideoAcceleratorFactories* GetGpuFactories();
[email protected]3bb8bb32013-07-11 13:13:03292
Scott Violet703b8242019-06-11 19:34:36293 scoped_refptr<viz::ContextProviderCommandBuffer>
sadrul85cc5d82016-12-20 03:37:41294 SharedMainThreadContextProvider();
[email protected]c29b7ff2013-03-06 03:51:04295
Yuzu Saijo9acd7e62019-06-12 10:05:31296 class UnfreezableMessageFilter : public IPC::MessageFilter {
297 public:
298 explicit UnfreezableMessageFilter(RenderThreadImpl* render_thread_impl);
299 bool OnMessageReceived(const IPC::Message& message) override;
300
301 // Adds |unfreezable_task_runner| for the task to be executed later.
302 void AddListenerUnfreezableTaskRunner(
303 int32_t routing_id,
304 scoped_refptr<base::SingleThreadTaskRunner> unfreezable_task_runner);
305
Brook Hongc4ab7a02020-04-02 16:55:54306 // Removes |unfreezable_task_runner| for the task to be executed later.
307 void RemoveListenerUnfreezableTaskRunner(
308 int32_t routing_id);
309
Yuzu Saijo9acd7e62019-06-12 10:05:31310 // Called on the I/O thread.
311 // Returns the unfreezable task runner associated with |routing_id|.
312 scoped_refptr<base::SingleThreadTaskRunner> GetUnfreezableTaskRunner(
313 int32_t routing_id);
314
315 private:
316 ~UnfreezableMessageFilter() override;
317 RenderThreadImpl* render_thread_impl_;
318 base::Lock unfreezable_task_runners_lock_;
319 // Map of routing_id and listener's thread unfreezable task runner.
320 std::map<int32_t, scoped_refptr<base::SingleThreadTaskRunner>>
321 unfreezable_task_runners_ GUARDED_BY(unfreezable_task_runners_lock_);
322 };
323
[email protected]b2d98762012-09-03 17:04:06324 // For producing custom V8 histograms. Custom histograms are produced if all
325 // RenderViews share the same host, and the host is in the pre-specified set
326 // of hosts we want to produce custom diagrams for. The name for a custom
327 // diagram is the name of the corresponding generic diagram plus a
328 // host-specific suffix.
329 class CONTENT_EXPORT HistogramCustomizer {
330 public:
331 HistogramCustomizer();
332 ~HistogramCustomizer();
333
334 // Called when a top frame of a RenderView navigates. This function updates
335 // RenderThreadImpl's information about whether all RenderViews are
336 // displaying a page from the same host. |host| is the host where a
337 // RenderView navigated, and |view_count| is the number of RenderViews in
338 // this process.
339 void RenderViewNavigatedToHost(const std::string& host, size_t view_count);
340
341 // Used for customizing some histograms if all RenderViews share the same
342 // host. Returns the current custom histogram name to use for
343 // |histogram_name|, or |histogram_name| if it shouldn't be customized.
344 std::string ConvertToCustomHistogramName(const char* histogram_name) const;
345
346 private:
hablichd6a4f122015-10-28 11:34:49347 FRIEND_TEST_ALL_PREFIXES(RenderThreadImplUnittest,
348 IdentifyAlexaTop10NonGoogleSite);
[email protected]b2d98762012-09-03 17:04:06349 friend class RenderThreadImplUnittest;
Yuzu Saijo9acd7e62019-06-12 10:05:31350 friend class UnfreezableMessageFilter;
[email protected]b2d98762012-09-03 17:04:06351
hablichd6a4f122015-10-28 11:34:49352 // Converts a host name to a suffix for histograms
353 std::string HostToCustomHistogramSuffix(const std::string& host);
354
355 // Helper function to identify a certain set of top pages
356 bool IsAlexaTop10NonGoogleSite(const std::string& host);
357
[email protected]b2d98762012-09-03 17:04:06358 // Used for updating the information on which is the common host which all
359 // RenderView's share (if any). If there is no common host, this function is
360 // called with an empty string.
361 void SetCommonHost(const std::string& host);
362
363 // The current common host of the RenderViews; empty string if there is no
364 // common host.
365 std::string common_host_;
366 // The corresponding suffix.
367 std::string common_host_histogram_suffix_;
368 // Set of histograms for which we want to produce a custom histogram if
369 // possible.
370 std::set<std::string> custom_histograms_;
371
372 DISALLOW_COPY_AND_ASSIGN(HistogramCustomizer);
373 };
374
375 HistogramCustomizer* histogram_customizer() {
376 return &histogram_customizer_;
377 }
378
benf28ce882017-05-02 16:15:49379 void RegisterPendingFrameCreate(
benf28ce882017-05-02 16:15:49380 int routing_id,
Henrique Ferreiro3a9751c2019-09-30 13:54:07381 mojo::PendingReceiver<mojom::Frame> frame);
rockotf8fdd9b2015-12-16 22:22:35382
jam188f19f2017-06-07 03:56:24383 mojom::RendererHost* GetRendererHost();
jamc912ca32016-02-24 20:17:31384
keishi51ed0d52017-01-12 10:04:46385 struct RendererMemoryMetrics {
386 size_t partition_alloc_kb;
387 size_t blink_gc_kb;
388 size_t malloc_mb;
389 size_t discardable_kb;
390 size_t v8_main_thread_isolate_mb;
391 size_t total_allocated_mb;
392 size_t non_discardable_total_allocated_mb;
393 size_t total_allocated_per_render_view_mb;
394 };
bashia0ba0d42017-04-03 08:11:06395 bool GetRendererMemoryMetrics(RendererMemoryMetrics* memory_metrics) const;
keishi51ed0d52017-01-12 10:04:46396
Takashi SAKAMOTO870f6262017-08-22 04:08:27397 bool NeedsToRecordFirstActivePaint(int metric_type) const;
tasakb95dbb50c2017-02-08 18:07:50398
Aditya Keerthie84331b32019-03-20 15:25:52399 void RecordMetricsForBackgroundedRendererPurge();
400
Miguel Casas5e1018052018-01-09 19:17:36401 // Sets the current pipeline rendering color space.
402 void SetRenderingColorSpace(const gfx::ColorSpace& color_space);
403
CJ DiMeglio79f7c91a22018-08-30 22:24:43404 scoped_refptr<base::SingleThreadTaskRunner>
405 CreateVideoFrameCompositorTaskRunner();
406
CJ DiMegliob6eb9cd2018-11-06 23:44:01407 // In the case of kOnDemand, we wont be using the task_runner created in
408 // CreateVideoFrameCompositorTaskRunner.
409 // TODO(https://crbug/901513): Remove once kOnDemand is removed.
410 void SetVideoFrameCompositorTaskRunner(
411 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
412 video_frame_compositor_task_runner_ = task_runner;
413 }
414
[email protected]8930d472009-02-21 08:05:28415 private:
Aditya Keerthic0d45b42019-02-25 18:53:00416 friend class RenderThreadImplBrowserTest;
Dominic Farolino08c265692020-09-24 06:59:42417 friend class AgentSchedulingGroup;
Aditya Keerthic0d45b42019-02-25 18:53:00418
Nicholas Verne06de8122017-11-16 04:47:38419 void OnProcessFinalRelease() override;
torne88b66452016-05-03 13:22:14420 // IPC::Listener
421 void OnChannelError() override;
422
[email protected]57cf97882013-06-26 20:39:01423 // ChildThread
dcheng6d18e402014-10-21 12:32:52424 bool OnControlMessageReceived(const IPC::Message& msg) override;
liberato3aeeb2c2016-02-25 17:54:38425 void RecordAction(const base::UserMetricsAction& action) override;
426 void RecordComputedAction(const std::string& action) override;
initial.commit09911bf2008-07-26 23:55:29427
sadrul53546592016-12-17 01:44:21428 bool IsMainThread();
[email protected]57cf97882013-06-26 20:39:01429
Greg Kraynovf5d60272018-08-10 12:28:51430 void Init();
vollick1050cc62015-12-03 07:04:54431 void InitializeCompositorThread();
Ken Rockot13051c932019-11-14 20:11:51432 void InitializeWebKit(mojo::BinderMap* binders);
jam75c44222016-03-23 05:34:24433
initial.commit09911bf2008-07-26 23:55:29434 void OnTransferBitmap(const SkBitmap& bitmap, int resource_id);
[email protected]b3df5a42010-05-11 14:31:09435 void OnGetAccessibilityTree();
blundellc00adf442016-09-16 10:43:41436
rockot067ca55f2016-09-30 22:00:15437 // mojom::Renderer:
rockot067ca55f2016-09-30 22:00:15438 void CreateView(mojom::CreateViewParamsPtr params) override;
Erik Chen3433ee02019-08-05 20:14:26439 void DestroyView(int32_t view_id) override;
rockot53be7caf2016-10-04 20:17:08440 void CreateFrame(mojom::CreateFrameParamsPtr params) override;
Tal Pressmanc951ed92020-09-01 00:24:23441 void CreateAgentSchedulingGroup(
442 mojo::PendingRemote<mojom::AgentSchedulingGroupHost>
443 agent_scheduling_group_host,
444 mojo::PendingReceiver<mojom::AgentSchedulingGroup> agent_scheduling_group)
445 override;
Tal Pressman25d1eae2020-09-14 02:35:47446 void CreateAssociatedAgentSchedulingGroup(
447 mojo::PendingAssociatedRemote<mojom::AgentSchedulingGroupHost>
448 agent_scheduling_group_host,
449 mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>
450 agent_scheduling_group) override;
Dmitry Gozman89361212018-02-13 16:10:44451 void CreateFrameProxy(
452 int32_t routing_id,
453 int32_t render_view_routing_id,
Antonio Gomesde8657a452020-05-25 17:14:47454 const base::Optional<base::UnguessableToken>& opener_frame_token,
Dmitry Gozman89361212018-02-13 16:10:44455 int32_t parent_routing_id,
456 const FrameReplicationState& replicated_state,
Dave Tapuska84449382020-05-01 00:39:04457 const base::UnguessableToken& frame_token,
Dmitry Gozman89361212018-02-13 16:10:44458 const base::UnguessableToken& devtools_frame_token) override;
rockota2db0da2016-10-18 17:39:11459 void OnNetworkConnectionChanged(
460 net::NetworkChangeNotifier::ConnectionType type,
461 double max_bandwidth_mbps) override;
tbansalb612c5d2017-05-25 18:53:06462 void OnNetworkQualityChanged(net::EffectiveConnectionType type,
463 base::TimeDelta http_rtt,
tbansal99d8aeb2017-05-22 19:12:58464 base::TimeDelta transport_rtt,
tbansal15973c32017-05-10 18:40:44465 double bandwidth_kbps) override;
rockota2db0da2016-10-18 17:39:11466 void SetWebKitSharedTimersSuspended(bool suspend) override;
Yutaka Hiranob0465f72018-05-17 05:48:25467 void SetUserAgent(const std::string& user_agent) override;
Mike West6e4cbb32019-02-13 09:40:17468 void SetUserAgentMetadata(const blink::UserAgentMetadata& metadata) override;
John Abd-El-Malek4058ad22020-06-03 21:16:04469 void SetCorsExemptHeaderList(const std::vector<std::string>& list) override;
rockota2db0da2016-10-18 17:39:11470 void UpdateScrollbarTheme(
471 mojom::UpdateScrollbarThemeParamsPtr params) override;
472 void OnSystemColorsChanged(int32_t aqua_color_variant,
473 const std::string& highlight_text_color,
474 const std::string& highlight_color) override;
Ionel Popescu237e8e32019-08-07 19:50:54475 void UpdateSystemColorInfo(
476 mojom::UpdateSystemColorInfoParamsPtr params) override;
rockota2db0da2016-10-18 17:39:11477 void PurgePluginListCache(bool reload_pages) override;
John Budorickee1c9512019-10-17 15:32:19478 void SetProcessState(mojom::RenderProcessBackgroundState background_state,
479 mojom::RenderProcessVisibleState visible_state) override;
Shubhie Panicker45ce80a82018-02-01 01:40:19480 void SetSchedulerKeepActive(bool keep_active) override;
Nasko Oskov1c2c0492019-03-14 20:13:39481 void SetIsLockedToSite() override;
Sebastien Marchand836d04b32020-04-28 18:10:03482#if BUILDFLAG(CLANG_PROFILING_INSIDE_SANDBOX)
483 void WriteClangProfilingProfile(
484 WriteClangProfilingProfileCallback callback) override;
485#endif
Yutaka Hirano9881e99a2020-06-22 06:54:05486 void SetIsCrossOriginIsolated(bool value) override;
[email protected]5071cb22013-07-10 02:19:06487 void OnMemoryPressure(
488 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
rockota2db0da2016-10-18 17:39:11489
rmcilroyaa296052015-04-14 15:35:27490 bool RendererIsHidden() const;
491 void OnRendererHidden();
492 void OnRendererVisible();
[email protected]b3df5a42010-05-11 14:31:09493
Aditya Keerthic0d45b42019-02-25 18:53:00494 bool RendererIsBackgrounded() const;
495 void OnRendererBackgrounded();
496 void OnRendererForegrounded();
497
tasak335a1872017-06-14 09:50:23498 void RecordMemoryUsageAfterBackgrounded(const char* suffix,
499 int foregrounded_count);
Aditya Keerthie84331b32019-03-20 15:25:52500 void OnRecordMetricsForBackgroundedRendererPurgeTimerExpired(
tasakbb0640b2017-05-15 09:02:26501 const char* suffix,
502 int foregrounded_count_when_purged);
tasakb46626a2016-10-18 05:54:44503
ssid0603ca9f2015-06-09 16:48:08504 void ReleaseFreeMemory();
505
hong.zhengb28b5332016-05-11 02:33:39506 void OnSyncMemoryPressure(
507 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
508
Fady Samuelc645ffe2017-07-24 17:28:20509 std::unique_ptr<viz::SyntheticBeginFrameSource>
samans09812d32017-03-27 19:51:50510 CreateSyntheticBeginFrameSource();
511
Julie Jeongeun Kim4e77af2622019-09-11 03:36:45512 void OnRendererInterfaceReceiver(
513 mojo::PendingAssociatedReceiver<mojom::Renderer> receiver);
rockot067ca55f2016-09-30 22:00:15514
Tal Pressmanc951ed92020-09-01 00:24:23515 void RemoveAgentSchedulingGroup(
516 const AgentSchedulingGroup* agent_scheduling_group);
517 base::RepeatingCallback<void(const AgentSchedulingGroup*)>
518 remove_agent_scheduling_group_callback_;
519
Thiabaud Engelbrecht75bce0962020-09-21 20:50:58520 std::unique_ptr<discardable_memory::ClientDiscardableSharedMemoryManager>
Gordon Guan96c21ee2019-11-06 15:05:39521 discardable_memory_allocator_;
penghuang342762b2016-12-02 21:04:58522
initial.commit09911bf2008-07-26 23:55:29523 // These objects live solely on the render thread.
Yuta Kitamuradeb91bb2018-05-29 05:53:20524 std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_;
dchengcedca5612016-04-09 01:40:15525 std::unique_ptr<RendererBlinkPlatformImpl> blink_platform_impl_;
John Abd-El-Malek6b56ef712017-10-21 22:52:46526 std::unique_ptr<ResourceDispatcher> resource_dispatcher_;
Yuzhu Shenfe5f3a52018-01-11 21:24:13527 std::unique_ptr<URLLoaderThrottleProvider> url_loader_throttle_provider_;
[email protected]9291ed12009-07-23 17:33:22528
Yuzu Saijo9acd7e62019-06-12 10:05:31529 // Filter out unfreezable messages and pass it to unfreezable task runners.
530 scoped_refptr<UnfreezableMessageFilter> unfreezable_message_filter_;
531
liushouqun517b1292016-09-14 05:58:59532 // Used on the render thread.
Antonio Gomes925f9b92019-07-30 23:23:23533 std::unique_ptr<blink::WebVideoCaptureImplManager> vc_manager_;
[email protected]da9f30a2014-06-18 19:39:04534
Aditya Keerthic0d45b42019-02-25 18:53:00535 // Used to keep track of the renderer's backgrounded and visibility state.
536 // Updated via an IPC from the browser process. If nullopt, the browser
537 // process has yet to send an update and the state is unknown.
John Budorickee1c9512019-10-17 15:32:19538 base::Optional<mojom::RenderProcessBackgroundState> background_state_;
539 base::Optional<mojom::RenderProcessVisibleState> visible_state_;
[email protected]bee16aab2009-08-26 15:55:03540
Yutaka Hiranob0465f72018-05-17 05:48:25541 blink::WebString user_agent_;
Mike West6e4cbb32019-02-13 09:40:17542 blink::UserAgentMetadata user_agent_metadata_;
Yutaka Hiranob0465f72018-05-17 05:48:25543
danakjab9ef4d2017-10-31 23:38:33544 // Sticky once true, indicates that compositing is done without Gpu, so
545 // resources given to the compositor or to the viz service should be
546 // software-based.
547 bool is_gpu_compositing_disabled_ = false;
548
dcastagna7f45dada2015-10-19 20:17:35549 // Utility class to provide GPU functionalities to media.
dcastagna09bd6b32016-02-01 21:54:28550 // TODO(dcastagna): This should be just one scoped_ptr once
551 // http://crbug.com/580386 is fixed.
552 // NOTE(dcastagna): At worst this accumulates a few bytes per context lost.
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:59553 std::vector<std::unique_ptr<GpuVideoAcceleratorFactoriesImpl>> gpu_factories_;
dcastagna7f45dada2015-10-19 20:17:35554
[email protected]c1330c82013-06-06 02:23:25555 // Thread for running multimedia operations (e.g., video decoding).
dchengcedca5612016-04-09 01:40:15556 std::unique_ptr<base::Thread> media_thread_;
[email protected]c1330c82013-06-06 02:23:25557
skyostil2d3b5bd2015-05-27 15:40:59558 // Will point to appropriate task runner after initialization,
[email protected]ea5f70a2013-03-07 12:30:36559 // regardless of whether |compositor_thread_| is overriden.
skyostil2d3b5bd2015-05-27 15:40:59560 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
[email protected]ea5f70a2013-03-07 12:30:36561
CJ DiMeglio79f7c91a22018-08-30 22:24:43562 // Task to run the VideoFrameCompositor on.
563 scoped_refptr<base::SingleThreadTaskRunner>
564 video_frame_compositor_task_runner_;
565
dcastagnab880e8f2015-06-30 20:16:06566 // Pool of workers used for raster operations (e.g., tile rasterization).
prashant.nfad657e2016-06-01 07:52:17567 scoped_refptr<CategorizedWorkerPool> categorized_worker_pool_;
reveman34b7a1522015-03-23 20:27:47568
boliubee541f42015-11-05 00:52:53569#if defined(OS_ANDROID)
siva.gunturi5d4feb052015-11-15 16:15:31570 scoped_refptr<StreamTextureFactory> stream_texture_factory_;
boliubee541f42015-11-05 00:52:53571#endif
572
Scott Violet703b8242019-06-11 19:34:36573 scoped_refptr<viz::ContextProviderCommandBuffer> shared_main_thread_contexts_;
[email protected]c29b7ff2013-03-06 03:51:04574
Trent Apteda250ec3ab2018-08-19 08:52:19575 base::ObserverList<RenderThreadObserver>::Unchecked observers_;
[email protected]1223d6ef2011-03-28 16:47:50576
Sergey Ulanov83f4a152019-02-14 03:54:25577 scoped_refptr<viz::RasterContextProvider>
578 video_frame_compositor_context_provider_;
CJ DiMeglio79f7c91a22018-08-30 22:24:43579
Victor Miuraff6488612017-12-21 04:16:15580 scoped_refptr<viz::RasterContextProvider> shared_worker_context_provider_;
[email protected]3b2afc32012-06-18 21:31:16581
[email protected]b2d98762012-09-03 17:04:06582 HistogramCustomizer histogram_customizer_;
583
dchengcedca5612016-04-09 01:40:15584 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
[email protected]5071cb22013-07-10 02:19:06585
Scott Violet703b8242019-06-11 19:34:36586 std::unique_ptr<viz::Gpu> gpu_;
sadrul9e0bb1d2016-08-04 20:18:39587
Alex Clarke9fc39b9b2020-01-31 17:29:47588 std::unique_ptr<VariationsRenderThreadObserver> variations_observer_;
589
skyostil457b0a12014-09-09 10:12:07590 scoped_refptr<base::SingleThreadTaskRunner>
591 main_thread_compositor_task_runner_;
skyostil457b0a12014-09-09 10:12:07592
danakj6e3bf8012014-12-16 18:27:53593 // Compositor settings.
senorblancob60ba952015-01-27 19:12:36594 int gpu_rasterization_msaa_sample_count_;
[email protected]a23530d2014-03-11 06:04:14595 bool is_lcd_text_enabled_;
[email protected]2cccfef2014-05-01 06:05:16596 bool is_zero_copy_enabled_;
ccameronc7fcd132015-11-03 20:14:31597 bool is_gpu_memory_buffer_compositor_resources_enabled_;
ericrk1d17f752015-10-20 03:03:07598 bool is_partial_raster_enabled_;
ccamerona7644752014-12-30 01:16:31599 bool is_elastic_overscroll_enabled_;
danakj4b347212018-07-04 17:55:17600 bool is_zoom_for_dsf_enabled_;
loyso65c93c602015-08-11 05:15:57601 bool is_threaded_animation_enabled_;
wjmaclean1d970622017-01-21 22:28:24602 bool is_scroll_animator_enabled_;
[email protected]a23530d2014-03-11 06:04:14603
Miguel Casas5e1018052018-01-09 19:17:36604 // Target rendering ColorSpace.
605 gfx::ColorSpace rendering_color_space_;
606
Scott Violet9b2d60dc2020-05-13 04:05:04607 // Used when AddRoute() is called and the RenderFrameImpl hasn't been created
608 // yet.
609 std::map<int, mojo::PendingReceiver<mojom::Frame>> pending_frames_;
rockotf8fdd9b2015-12-16 22:22:35610
Julie Jeongeun Kimdaa9aa12019-10-24 02:51:56611 mojo::AssociatedRemote<mojom::RendererHost> renderer_host_;
jamc912ca32016-02-24 20:17:31612
Ken Rockot26e4e802018-07-31 15:03:33613 blink::AssociatedInterfaceRegistry associated_interfaces_;
rockot067ca55f2016-09-30 22:00:15614
Julie Jeongeun Kim4e77af2622019-09-11 03:36:45615 mojo::AssociatedReceiver<mojom::Renderer> renderer_receiver_{this};
rockot067ca55f2016-09-30 22:00:15616
Julie Jeongeun Kim23966e22019-10-26 02:13:29617 mojo::AssociatedRemote<mojom::RenderMessageFilter> render_message_filter_;
rockot1587e332016-07-27 17:44:14618
Tal Pressmanc951ed92020-09-01 00:24:23619 std::set<std::unique_ptr<AgentSchedulingGroup>, base::UniquePtrComparator>
620 agent_scheduling_groups_;
Tal Pressman9780e2c2020-08-26 06:35:09621
tasak72f64042017-01-19 14:02:53622 RendererMemoryMetrics purge_and_suspend_memory_metrics_;
tasakb95dbb50c2017-02-08 18:07:50623 bool needs_to_record_first_active_paint_;
Takashi SAKAMOTO870f6262017-08-22 04:08:27624 base::TimeTicks was_backgrounded_time_;
tasakbb0640b2017-05-15 09:02:26625 int process_foregrounded_count_;
Nasko Oskov3d0d1dc2018-09-25 03:57:13626 bool online_status_ = true;
hajimehoshi69093272016-05-13 08:30:58627
staraz067f58242016-11-07 21:06:41628 int32_t client_id_;
629
Mario Sanchez Prada5492c9a2019-09-10 20:58:11630 mojo::Remote<mojom::FrameSinkProvider> frame_sink_provider_;
samans2040988b2017-04-11 23:58:35631
danakjab9ef4d2017-10-31 23:38:33632 // A mojo connection to the CompositingModeReporter service.
Gyuyoung Kimc9cf74a2019-11-05 00:54:35633 mojo::Remote<viz::mojom::CompositingModeReporter> compositing_mode_reporter_;
danakjab9ef4d2017-10-31 23:38:33634 // The class is a CompositingModeWatcher, which is bound to mojo through
danakj4ee301c2017-11-29 16:19:43635 // this member.
Gyuyoung Kimef648a2e72019-09-17 09:48:35636 mojo::Receiver<viz::mojom::CompositingModeWatcher>
637 compositing_mode_watcher_receiver_{this};
danakjab9ef4d2017-10-31 23:38:33638
Jeremy Roman3bca4bf2019-07-11 03:41:25639 base::WeakPtrFactory<RenderThreadImpl> weak_factory_{this};
Ben Goodgerf180ce12018-02-09 22:54:01640
[email protected]f1a29a02011-10-06 23:08:44641 DISALLOW_COPY_AND_ASSIGN(RenderThreadImpl);
initial.commit09911bf2008-07-26 23:55:29642};
643
[email protected]e9ff79c2012-10-19 21:31:26644} // namespace content
645
[email protected]f1a29a02011-10-06 23:08:44646#endif // CONTENT_RENDERER_RENDER_THREAD_IMPL_H_