blob: 0df9eb3fb8c72a689c433b4f74afd9f05021d893 [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#include "content/renderer/render_thread_impl.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]da00a2882009-03-09 17:51:197#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:088#include <limits>
[email protected]75e126b932009-09-28 19:38:499#include <map>
dcheng07945f632015-12-26 07:59:3210#include <utility>
[email protected]da00a2882009-03-09 17:51:1911#include <vector>
12
[email protected]237a14852012-04-28 02:56:3813#include "base/allocator/allocator_extension.h"
harakenbbfdd9f02017-01-12 07:14:0414#include "base/at_exit.h"
[email protected]06533c0b2009-03-05 21:39:1115#include "base/command_line.h"
[email protected]94f9a0f682009-06-15 18:30:3016#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0317#include "base/logging.h"
avi1023d012015-12-25 02:39:1418#include "base/macros.h"
reveman1af05cb32015-03-17 23:18:1619#include "base/memory/discardable_memory_allocator.h"
hajimehoshi7bb39582016-10-12 04:30:5720#include "base/memory/memory_coordinator_client_registry.h"
dchengcedca5612016-04-09 01:40:1521#include "base/memory/ptr_util.h"
[email protected]8bac37b2013-07-18 19:13:5622#include "base/memory/shared_memory.h"
gabf64a25e2017-05-12 19:42:5623#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3824#include "base/metrics/field_trial.h"
tasaka27961a2017-05-24 07:33:2525#include "base/metrics/histogram_functions.h"
asvitkine8d51e9d2016-09-02 23:55:4326#include "base/metrics/histogram_macros.h"
[email protected]433df472012-03-07 20:33:3927#include "base/path_service.h"
tasakb46626a2016-10-18 05:54:4428#include "base/process/process_metrics.h"
fdoray2df4a9e2016-07-18 23:47:1629#include "base/run_loop.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string16.h"
[email protected]1e1d1e12014-01-17 16:14:2931#include "base/strings/string_number_conversions.h"
hablichd6a4f122015-10-28 11:34:4932#include "base/strings/string_split.h"
ccameron6728bae32015-01-09 20:18:0633#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
fdoray50a38342016-11-21 20:46:0435#include "base/threading/sequenced_worker_pool.h"
reveman34b7a1522015-03-23 20:27:4736#include "base/threading/simple_thread.h"
[email protected]1357c322010-12-30 22:18:5637#include "base/threading/thread_local.h"
[email protected]d293572a2013-05-23 18:50:4538#include "base/threading/thread_restrictions.h"
gab30f26df2016-05-11 19:37:5539#include "base/threading/thread_task_runner_handle.h"
ccameron9c48d1d42016-09-22 01:46:0140#include "base/trace_event/memory_dump_manager.h"
primiano9e38d552015-01-28 04:18:0141#include "base/trace_event/trace_event.h"
[email protected]7a4de7a62010-08-17 18:38:2442#include "base/values.h"
avi1023d012015-12-25 02:39:1443#include "build/build_config.h"
jbroman0d302162015-09-05 05:46:2344#include "cc/base/histograms.h"
[email protected]d72493152014-01-08 17:37:4545#include "cc/base/switches.h"
[email protected]38564622014-08-19 02:47:1846#include "cc/blink/web_layer_impl.h"
danakj920156852015-05-18 20:22:2947#include "cc/raster/task_graph_runner.h"
danakjba65a0912017-09-21 16:38:4248#include "cc/trees/layer_tree_frame_sink.h"
vollick1050cc62015-12-03 07:04:5449#include "cc/trees/layer_tree_host_common.h"
loysoa6edaaff2015-05-25 03:26:4450#include "cc/trees/layer_tree_settings.h"
penghuangd81c1a62016-11-02 20:06:0651#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
dalecurtis4a9839a2017-05-04 23:40:4752#include "components/metrics/public/interfaces/single_sample_metrics.mojom.h"
53#include "components/metrics/single_sample_metrics.h"
danakjc7afae52017-06-20 21:12:4154#include "components/viz/client/client_layer_tree_frame_sink.h"
danakj92429852017-06-29 00:19:0355#include "components/viz/client/client_shared_bitmap_manager.h"
Valery Arkhangorodsky513ac8fd2017-08-02 23:09:2356#include "components/viz/client/hit_test_data_provider.h"
samans7e6675cc2017-06-05 20:16:0857#include "components/viz/client/local_surface_id_provider.h"
Fady Samuel343a74952017-11-30 14:19:2058#include "components/viz/common/features.h"
danakjf20f4502017-09-26 17:13:3159#include "components/viz/common/frame_sinks/copy_output_request.h"
Alex Zhang1f159572017-08-23 20:14:2060#include "components/viz/common/gpu/vulkan_in_process_context_provider.h"
bashia6264042016-09-15 04:49:5161#include "content/child/memory/child_memory_coordinator_impl.h"
[email protected]643255da2013-06-12 20:55:1362#include "content/child/runtime_features.h"
[email protected]57cf97882013-06-26 20:39:0163#include "content/child/thread_safe_sender.h"
[email protected]89c36f82013-07-17 06:23:2764#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4165#include "content/common/dom_storage/dom_storage_messages.h"
thakis18e426412017-03-15 12:06:3766#include "content/common/features.h"
[email protected]82307f6b2014-08-07 03:30:1267#include "content/common/frame_messages.h"
raymesbba82b32016-07-19 00:41:3868#include "content/common/frame_owner_properties.h"
sunnyps8f9139e2017-05-12 17:53:2569#include "content/common/gpu_stream_constants.h"
[email protected]778574e2011-03-21 22:03:5070#include "content/common/view_messages.h"
[email protected]a458504b2012-07-23 19:57:0671#include "content/public/common/content_constants.h"
bashia6264042016-09-15 04:49:5172#include "content/public/common/content_features.h"
[email protected]433df472012-03-07 20:33:3973#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2974#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3175#include "content/public/common/renderer_preferences.h"
benbd9dc802017-04-19 01:37:4376#include "content/public/common/service_manager_connection.h"
ben649b3edd2017-03-23 00:32:0277#include "content/public/common/service_names.mojom.h"
benbd9dc802017-04-19 01:37:4378#include "content/public/common/simple_connection_filter.h"
[email protected]58436a12012-03-21 17:10:2679#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3480#include "content/public/renderer/content_renderer_client.h"
tyoshino832a58a2016-04-18 08:14:0881#include "content/public/renderer/render_thread_observer.h"
[email protected]64ffa0442011-10-03 22:08:3682#include "content/public/renderer/render_view_visitor.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4183#include "content/renderer/appcache/appcache_dispatcher.h"
84#include "content/renderer/appcache/appcache_frontend_impl.h"
fsamuel6c1dfeb2014-12-18 19:21:3385#include "content/renderer/browser_plugin/browser_plugin_manager.h"
jsbell279efb42015-03-31 17:02:4686#include "content/renderer/cache_storage/cache_storage_dispatcher.h"
87#include "content/renderer/cache_storage/cache_storage_message_filter.h"
prashant.nfad657e2016-06-01 07:52:1788#include "content/renderer/categorized_worker_pool.h"
[email protected]1910fe82012-05-10 00:04:1089#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
90#include "content/renderer/dom_storage/webstoragearea_impl.h"
91#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
tbansalb612c5d2017-05-25 18:53:0692#include "content/renderer/effective_connection_type_helper.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4193#include "content/renderer/fileapi/file_system_dispatcher.h"
94#include "content/renderer/fileapi/webfilesystem_impl.h"
simonhonga7e3ac42014-11-11 20:50:2295#include "content/renderer/gpu/compositor_external_begin_frame_source.h"
96#include "content/renderer/gpu/compositor_forwarding_message_filter.h"
danakj83066a32016-06-21 02:34:4997#include "content/renderer/gpu/frame_swap_message_queue.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4198#include "content/renderer/indexed_db/indexed_db_dispatcher.h"
[email protected]7a72d452013-12-13 10:01:1399#include "content/renderer/input/input_event_filter.h"
100#include "content/renderer/input/input_handler_manager.h"
jdduke691dd572014-12-02 20:47:52101#include "content/renderer/input/main_thread_input_event_filter.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:46102#include "content/renderer/loader/resource_dispatcher.h"
Scott Violet1098538e2017-10-05 19:23:33103#include "content/renderer/mash_util.h"
[email protected]f7eb0a392011-07-12 10:19:51104#include "content/renderer/media/audio_input_message_filter.h"
105#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:41106#include "content/renderer/media/audio_renderer_mixer_manager.h"
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:59107#include "content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h"
[email protected]d8cd8372012-03-09 10:49:51108#include "content/renderer/media/media_stream_center.h"
[email protected]a9875152013-06-22 04:03:03109#include "content/renderer/media/midi_message_filter.h"
xhwang194acae2014-11-12 22:46:33110#include "content/renderer/media/render_media_client.h"
[email protected]80b161a2011-06-27 17:42:11111#include "content/renderer/media/video_capture_impl_manager.h"
Stuart Langley849079a2017-08-28 02:02:50112#include "content/renderer/mus/render_widget_window_tree_client_factory.h"
113#include "content/renderer/mus/renderer_window_tree_client.h"
[email protected]d7ff5fb2014-05-29 19:50:25114#include "content/renderer/net_info_helper.h"
John Abd-El-Malekf9f86c12017-10-21 07:22:23115#include "content/renderer/notifications/notification_dispatcher.h"
[email protected]4761cf12012-09-12 10:37:55116#include "content/renderer/p2p/socket_dispatcher.h"
John Abd-El-Malekf75a3192017-10-22 14:23:20117#include "content/renderer/quota_dispatcher.h"
[email protected]82307f6b2014-08-07 03:30:12118#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:05119#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:28120#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:09121#include "content/renderer/renderer_blink_platform_impl.h"
shimazu5de409e42016-09-29 08:45:28122#include "content/renderer/service_worker/embedded_worker_instance_client_impl.h"
mek27c9d742015-07-16 18:30:18123#include "content/renderer/service_worker/service_worker_context_client.h"
kinuko5af4ffe2015-06-09 03:38:46124#include "content/renderer/service_worker/service_worker_context_message_filter.h"
John Abd-El-Maleke1d4de32017-10-21 16:14:29125#include "content/renderer/service_worker/service_worker_message_filter.h"
[email protected]0ec90d522014-03-12 16:28:19126#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
Darin Fisherbcc33632017-09-26 00:57:16127#include "content/renderer/shared_worker/shared_worker_factory_impl.h"
John Abd-El-Malekf75a3192017-10-22 14:23:20128#include "content/renderer/web_database_observer_impl.h"
129#include "content/renderer/worker_thread_registry.h"
juncai2f298a82017-04-18 03:51:39130#include "device/gamepad/public/cpp/gamepads.h"
chunyang.daibe874c52014-11-14 06:45:05131#include "gin/public/debug.h"
dongseong.hwang72183b02014-12-08 10:41:55132#include "gpu/GLES2/gl2extchromium.h"
Victor Miura3a4ad4f82017-12-13 06:03:45133#include "gpu/command_buffer/client/gles2_interface.h"
134#include "gpu/command_buffer/client/raster_interface.h"
danakj6f4e1e22016-04-20 03:27:34135#include "gpu/command_buffer/client/shared_memory_limits.h"
Adrienne Walker436a7752017-08-28 23:33:09136#include "gpu/config/gpu_switches.h"
danakj870925d42016-05-03 20:07:38137#include "gpu/ipc/client/command_buffer_proxy_impl.h"
penghuang346a46f92016-03-31 21:37:52138#include "gpu/ipc/client/gpu_channel_host.h"
[email protected]46f36a492010-07-28 19:36:41139#include "ipc/ipc_channel_handle.h"
amistryd4aa70d2016-06-23 07:52:37140#include "ipc/ipc_channel_mojo.h"
[email protected]cb6037d2009-11-16 22:55:17141#include "ipc/ipc_platform_file.h"
[email protected]433df472012-03-07 20:33:39142#include "media/base/media.h"
chcunningham9a285ed2017-03-08 21:48:56143#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46144#include "media/media_features.h"
Dale Curtis863022e2017-08-19 02:05:34145#include "media/video/gpu_video_accelerator_factories.h"
rockot85dce0862015-11-13 01:33:59146#include "mojo/public/cpp/bindings/strong_binding.h"
Yuki Yamada68992b02017-07-31 06:13:45147#include "mojo/public/cpp/system/message_pipe.h"
[email protected]620161e2011-03-07 18:05:26148#include "net/base/net_errors.h"
eroman9ab64842015-07-21 05:07:52149#include "net/base/port_util.h"
hablichd6a4f122015-10-28 11:34:49150#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
tfarina7a4a7fd2016-01-20 14:23:44151#include "net/base/url_util.h"
brettw4b461082016-11-19 18:55:16152#include "ppapi/features/features.h"
Khushal3e96e662017-10-30 23:16:50153#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
penghuangd6843e42016-12-17 13:57:20154#include "services/service_manager/public/cpp/connector.h"
rockot734fb662016-10-15 16:41:30155#include "services/service_manager/public/cpp/interface_provider.h"
sadrul85cc5d82016-12-20 03:37:41156#include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
Stuart Langley849079a2017-08-28 02:02:50157#include "services/ui/public/cpp/gpu/gpu.h"
penghuangd6843e42016-12-17 13:57:20158#include "services/ui/public/interfaces/constants.mojom.h"
[email protected]b48c53ad2014-02-05 21:59:18159#include "skia/ext/event_tracer_impl.h"
ssid59c969162015-07-28 13:02:58160#include "skia/ext/skia_memory_dump_provider.h"
kinukoed1ed1d2017-02-08 09:13:43161#include "third_party/WebKit/public/platform/WebCache.h"
reed6e5a72222015-08-06 20:37:16162#include "third_party/WebKit/public/platform/WebImageGenerator.h"
bashi5f4c78922016-08-18 23:06:08163#include "third_party/WebKit/public/platform/WebMemoryCoordinator.h"
kinukofbfee762017-03-08 04:01:06164#include "third_party/WebKit/public/platform/WebNetworkStateNotifier.h"
nverne61d2da872017-05-24 10:15:30165#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]89c36f82013-07-17 06:23:27166#include "third_party/WebKit/public/platform/WebString.h"
skyostil457b0a12014-09-09 10:12:07167#include "third_party/WebKit/public/platform/WebThread.h"
altiminc7369bf2017-04-11 14:29:15168#include "third_party/WebKit/public/platform/scheduler/child/webthread_base.h"
skyostil529caa292016-08-10 17:44:51169#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]2255a9332013-06-17 05:12:31170#include "third_party/WebKit/public/web/WebDocument.h"
171#include "third_party/WebKit/public/web/WebFrame.h"
172#include "third_party/WebKit/public/web/WebKit.h"
[email protected]2255a9332013-06-17 05:12:31173#include "third_party/WebKit/public/web/WebScriptController.h"
174#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31175#include "third_party/WebKit/public/web/WebView.h"
David Benjaminb946811c2017-06-26 23:34:29176#include "third_party/boringssl/src/include/openssl/evp.h"
[email protected]ddbb53342014-01-06 10:59:47177#include "third_party/skia/include/core/SkGraphics.h"
[email protected]c49201a2012-05-24 11:04:57178#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:32179#include "ui/base/ui_base_switches.h"
Sadrul Habib Chowdhuryeeb5a942017-11-28 21:17:23180#include "ui/base/ui_base_switches_util.h"
mlamouri7c149652017-03-24 00:00:09181#include "ui/display/display_switches.h"
ennee292bdc2016-09-15 19:57:15182#include "ui/gl/gl_switches.h"
[email protected]2c62b562009-01-27 19:04:50183
[email protected]33b02992014-03-01 01:06:29184#if defined(OS_ANDROID)
185#include <cpu-features.h>
boliubee541f42015-11-05 00:52:53186#include "content/renderer/android/synchronous_compositor_filter.h"
danakjc7afae52017-06-20 21:12:41187#include "content/renderer/android/synchronous_layer_tree_frame_sink.h"
boliue81d16132016-04-26 00:54:41188#include "content/renderer/media/android/stream_texture_factory.h"
dalecurtis88af3932016-02-20 00:12:20189#include "media/base/android/media_codec_util.h"
[email protected]33b02992014-03-01 01:06:29190#endif
191
192#if defined(OS_MACOSX)
ccamerona7644752014-12-30 01:16:31193#include "base/mac/mac_util.h"
rsesek1efb3c32015-09-29 15:39:50194#include "content/renderer/theme_helper_mac.h"
[email protected]33b02992014-03-01 01:06:29195#include "content/renderer/webscrollbarbehavior_impl_mac.h"
196#endif
197
[email protected]da00a2882009-03-09 17:51:19198#if defined(OS_WIN)
199#include <windows.h>
200#include <objbase.h>
201#endif
202
Brett Wilson0748bf412016-11-22 17:55:46203#if BUILDFLAG(ENABLE_WEBRTC)
liushouqun517b1292016-09-14 05:58:59204#include "content/renderer/media/aec_dump_message_filter.h"
[email protected]22fe91d2014-08-12 17:07:12205#include "content/renderer/media/peer_connection_tracker.h"
206#include "content/renderer/media/rtc_peer_connection_handler.h"
207#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]22fe91d2014-08-12 17:07:12208#endif
209
chunyang.daibe874c52014-11-14 06:45:05210#ifdef ENABLE_VTUNE_JIT_INTERFACE
211#include "v8/src/third_party/vtune/v8-vtune.h"
212#endif
213
ochangdd89a1e2016-06-08 16:39:01214#if defined(ENABLE_IPC_FUZZER)
215#include "content/common/external_ipc_dumper.h"
216#endif
217
tasakb46626a2016-10-18 05:54:44218#if defined(OS_MACOSX)
219#include <malloc/malloc.h>
220#else
221#include <malloc.h>
222#endif
223
[email protected]d293572a2013-05-23 18:50:45224using base::ThreadRestrictions;
[email protected]180ef242013-11-07 06:50:46225using blink::WebDocument;
226using blink::WebFrame;
227using blink::WebNetworkStateNotifier;
228using blink::WebRuntimeFeatures;
229using blink::WebScriptController;
230using blink::WebSecurityPolicy;
231using blink::WebString;
232using blink::WebView;
[email protected]e9ff79c2012-10-19 21:31:26233
234namespace content {
initial.commit09911bf2008-07-26 23:55:29235
[email protected]42f1d7822009-07-23 18:17:55236namespace {
[email protected]da9ccfb2012-01-28 00:34:40237
avi1023d012015-12-25 02:39:14238const int64_t kInitialIdleHandlerDelayMs = 1000;
239const int64_t kLongIdleHandlerDelayMs = 30 * 1000;
[email protected]bee16aab2009-08-26 15:55:03240
[email protected]dd2c1022014-07-22 23:13:57241// Maximum allocation size allowed for image scaling filters that
242// require pre-scaling. Skia will fallback to a filter that doesn't
243// require pre-scaling if the default filter would require an
244// allocation that exceeds this limit.
245const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
246
samans2040988b2017-04-11 23:58:35247#if defined(OS_ANDROID)
danakj83066a32016-06-21 02:34:49248// Unique identifier for each output surface created.
danakjc7afae52017-06-20 21:12:41249uint32_t g_next_layer_tree_frame_sink_id = 1;
samans2040988b2017-04-11 23:58:35250#endif
danakj83066a32016-06-21 02:34:49251
rockot5c478a72016-09-28 23:14:18252// An implementation of mojom::RenderMessageFilter which can be mocked out
253// for tests which may indirectly send messages over this interface.
254mojom::RenderMessageFilter* g_render_message_filter_for_testing;
255
olegmax045f7fb12017-05-19 07:58:55256// An implementation of RendererBlinkPlatformImpl which can be mocked out
257// for tests.
258RendererBlinkPlatformImpl* g_current_blink_platform_impl_for_testing;
259
[email protected]f1a29a02011-10-06 23:08:44260// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16261// incorrectly from the wrong thread.
scottmg5e65e3a2017-03-08 08:48:46262base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit
[email protected]6de0fd1d2011-11-15 13:31:49263 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54264
John Abd-El-Malekd4882642017-12-04 21:45:19265base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>::
266 DestructorAtExit g_main_task_runner = LAZY_INSTANCE_INITIALIZER;
267
hong.zhengb28b5332016-05-11 02:33:39268// v8::MemoryPressureLevel should correspond to base::MemoryPressureListener.
269static_assert(static_cast<v8::MemoryPressureLevel>(
270 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
271 v8::MemoryPressureLevel::kNone, "none level not align");
272static_assert(static_cast<v8::MemoryPressureLevel>(
273 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
274 v8::MemoryPressureLevel::kModerate, "moderate level not align");
275static_assert(static_cast<v8::MemoryPressureLevel>(
276 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
277 v8::MemoryPressureLevel::kCritical, "critical level not align");
278
hong.zheng2e296f822016-06-29 02:47:44279// WebMemoryPressureLevel should correspond to base::MemoryPressureListener.
280static_assert(static_cast<blink::WebMemoryPressureLevel>(
Blink Reformat1c4d759e2017-04-09 16:34:54281 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
282 blink::kWebMemoryPressureLevelNone,
283 "blink::WebMemoryPressureLevelNone not align");
284static_assert(
285 static_cast<blink::WebMemoryPressureLevel>(
286 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
287 blink::kWebMemoryPressureLevelModerate,
288 "blink::WebMemoryPressureLevelModerate not align");
289static_assert(
290 static_cast<blink::WebMemoryPressureLevel>(
291 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
292 blink::kWebMemoryPressureLevelCritical,
293 "blink::WebMemoryPressureLevelCritical not align");
hong.zheng2e296f822016-06-29 02:47:44294
[email protected]b2d98762012-09-03 17:04:06295void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13296 const char *name, int min, int max, size_t buckets) {
297 if (min <= 0)
298 min = 1;
[email protected]b2d98762012-09-03 17:04:06299 std::string histogram_name;
300 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
301 if (render_thread_impl) { // Can be null in tests.
302 histogram_name = render_thread_impl->
303 histogram_customizer()->ConvertToCustomHistogramName(name);
304 } else {
305 histogram_name = std::string(name);
306 }
[email protected]de415552013-01-23 04:12:17307 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06308 histogram_name, min, max, buckets,
309 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13310 return histogram;
311}
312
[email protected]b2d98762012-09-03 17:04:06313void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13314 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
315 histogram->Add(sample);
316}
317
ben76f52b242016-06-18 05:42:48318class FrameFactoryImpl : public mojom::FrameFactory {
rockotf8fdd9b2015-12-16 22:22:35319 public:
benf28ce882017-05-02 16:15:49320 explicit FrameFactoryImpl(const service_manager::BindSourceInfo& source_info)
321 : source_info_(source_info), routing_id_highmark_(-1) {}
rockotf8fdd9b2015-12-16 22:22:35322
ben76f52b242016-06-18 05:42:48323 private:
324 // mojom::FrameFactory:
Balazs Engedyba034e72017-10-27 22:26:28325 void CreateFrame(int32_t frame_routing_id,
326 mojom::FrameRequest frame_request) override {
rockotf8fdd9b2015-12-16 22:22:35327 // TODO(morrita): This is for investigating http://crbug.com/415059 and
328 // should be removed once it is fixed.
329 CHECK_LT(routing_id_highmark_, frame_routing_id);
330 routing_id_highmark_ = frame_routing_id;
331
332 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id);
333 // We can receive a GetServiceProviderForFrame message for a frame not yet
rockot067ca55f2016-09-30 22:00:15334 // created due to a race between the message and a
335 // mojom::Renderer::CreateView IPC that triggers creation of the RenderFrame
336 // we want.
rockotf8fdd9b2015-12-16 22:22:35337 if (!frame) {
ben76f52b242016-06-18 05:42:48338 RenderThreadImpl::current()->RegisterPendingFrameCreate(
Balazs Engedyba034e72017-10-27 22:26:28339 source_info_, frame_routing_id, std::move(frame_request));
rockotf8fdd9b2015-12-16 22:22:35340 return;
341 }
342
Balazs Engedyba034e72017-10-27 22:26:28343 frame->BindFrame(source_info_, std::move(frame_request));
rockotf8fdd9b2015-12-16 22:22:35344 }
345
346 private:
benf28ce882017-05-02 16:15:49347 service_manager::BindSourceInfo source_info_;
rockotf8fdd9b2015-12-16 22:22:35348 int32_t routing_id_highmark_;
rockotf8fdd9b2015-12-16 22:22:35349};
350
Ben Goodger21ada1e2017-07-19 14:53:01351void CreateFrameFactory(mojom::FrameFactoryRequest request,
352 const service_manager::BindSourceInfo& source_info) {
Jeremy Roman04f27c372017-10-27 15:20:55353 mojo::MakeStrongBinding(std::make_unique<FrameFactoryImpl>(source_info),
rockot8e66a08d2016-09-13 00:48:21354 std::move(request));
rockotf8fdd9b2015-12-16 22:22:35355}
356
sadrul85cc5d82016-12-20 03:37:41357scoped_refptr<ui::ContextProviderCommandBuffer> CreateOffscreenContext(
danakjc3983552016-05-03 00:04:35358 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
Antoine Labour5ac65db2017-12-19 18:02:58359 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
danakj0dd9e1e2016-05-11 22:15:09360 const gpu::SharedMemoryLimits& limits,
danakj9a04adc2016-05-16 22:45:07361 bool support_locking,
Victor Miura3a4ad4f82017-12-13 06:03:45362 bool support_gles2_interface,
363 bool support_raster_interface,
Adrienne Walker436a7752017-08-28 23:33:09364 bool support_oop_rasterization,
sadrul85cc5d82016-12-20 03:37:41365 ui::command_buffer_metrics::ContextType type,
sunnypsd8ce1c22016-05-10 18:02:40366 int32_t stream_id,
sunnyps8f9139e2017-05-12 17:53:25367 gpu::SchedulingPriority stream_priority) {
danakje8ec797e2016-04-19 04:08:43368 DCHECK(gpu_channel_host);
369 // This is used to create a few different offscreen contexts:
Victor Miura3a4ad4f82017-12-13 06:03:45370 // - The shared main thread context, used by blink for 2D Canvas.
371 // - The compositor worker context, used for GPU raster.
372 // - The media context, used for accelerated video decoding.
danakje8ec797e2016-04-19 04:08:43373 // This is for an offscreen context, so the default framebuffer doesn't need
374 // alpha, depth, stencil, antialiasing.
Antoine Labourfeab2392017-12-21 20:28:39375 gpu::ContextCreationAttribs attributes;
danakje8ec797e2016-04-19 04:08:43376 attributes.alpha_size = -1;
377 attributes.depth_size = 0;
378 attributes.stencil_size = 0;
379 attributes.samples = 0;
380 attributes.sample_buffers = 0;
381 attributes.bind_generates_resource = false;
382 attributes.lose_context_when_out_of_memory = true;
Victor Miura3a4ad4f82017-12-13 06:03:45383 attributes.enable_gles2_interface = support_gles2_interface;
384 attributes.enable_raster_interface = support_raster_interface;
Adrienne Walker436a7752017-08-28 23:33:09385 attributes.enable_oop_rasterization = support_oop_rasterization;
386
sunnypsd8ce1c22016-05-10 18:02:40387 const bool automatic_flushes = false;
kylechar96f3eba2017-09-25 20:23:56388 return base::MakeRefCounted<ui::ContextProviderCommandBuffer>(
Antoine Labour5ac65db2017-12-19 18:02:58389 std::move(gpu_channel_host), gpu_memory_buffer_manager, stream_id,
390 stream_priority, gpu::kNullSurfaceHandle,
zmo09ea813b2017-01-20 23:38:36391 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext/" +
392 ui::command_buffer_metrics::ContextTypeToString(type)),
Victor Miuraff6488612017-12-21 04:16:15393 automatic_flushes, support_locking, limits, attributes,
394 nullptr /* share_context */, type);
danakje8ec797e2016-04-19 04:08:43395}
396
dalecurtis4a9839a2017-05-04 23:40:47397// Hook that allows single-sample metric code from //components/metrics to
398// connect from the renderer process to the browser process.
399void CreateSingleSampleMetricsProvider(
400 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
401 service_manager::Connector* connector,
402 metrics::mojom::SingleSampleMetricsProviderRequest request) {
403 if (task_runner->BelongsToCurrentThread()) {
404 connector->BindInterface(mojom::kBrowserServiceName, std::move(request));
405 return;
406 }
407
408 task_runner->PostTask(
409 FROM_HERE,
tzikff2a81a2017-09-15 05:10:06410 base::BindOnce(&CreateSingleSampleMetricsProvider, std::move(task_runner),
411 connector, base::Passed(&request)));
dalecurtis4a9839a2017-05-04 23:40:47412}
413
samans7e6675cc2017-06-05 20:16:08414class RendererLocalSurfaceIdProvider : public viz::LocalSurfaceIdProvider {
415 public:
Fady Samueld5c26182017-07-12 02:43:33416 const viz::LocalSurfaceId& GetLocalSurfaceIdForFrame(
danakj5e0a12b2017-09-25 17:26:49417 const viz::CompositorFrame& frame) override {
samans7e6675cc2017-06-05 20:16:08418 auto new_surface_properties =
419 RenderWidgetSurfaceProperties::FromCompositorFrame(frame);
420 if (!local_surface_id_.is_valid() ||
421 new_surface_properties != surface_properties_) {
Chris Blumeefd8f242017-12-08 00:24:27422 local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
samans7e6675cc2017-06-05 20:16:08423 surface_properties_ = new_surface_properties;
424 }
425 return local_surface_id_;
426 }
427
428 private:
Chris Blumeefd8f242017-12-08 00:24:27429 viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
Fady Samueld5c26182017-07-12 02:43:33430 viz::LocalSurfaceId local_surface_id_;
samans7e6675cc2017-06-05 20:16:08431 RenderWidgetSurfaceProperties surface_properties_;
432};
433
Khushal3e96e662017-10-30 23:16:50434// This factory is used to defer binding of the InterfacePtr to the compositor
435// thread.
436class UkmRecorderFactoryImpl : public cc::UkmRecorderFactory {
437 public:
Lukasz Anforowiczbb0cfd5e2017-12-14 22:39:46438 explicit UkmRecorderFactoryImpl(
439 std::unique_ptr<service_manager::Connector> connector)
Khushalda50f8152017-12-01 09:04:40440 : connector_(std::move(connector)) {
441 DCHECK(connector_);
Khushal3e96e662017-10-30 23:16:50442 }
443 ~UkmRecorderFactoryImpl() override = default;
444
445 std::unique_ptr<ukm::UkmRecorder> CreateRecorder() override {
Khushalda50f8152017-12-01 09:04:40446 return ukm::MojoUkmRecorder::Create(connector_.get());
Khushal3e96e662017-10-30 23:16:50447 }
448
449 private:
Khushalda50f8152017-12-01 09:04:40450 std::unique_ptr<service_manager::Connector> connector_;
Khushal3e96e662017-10-30 23:16:50451};
452
[email protected]b2d98762012-09-03 17:04:06453} // namespace
454
[email protected]b2d98762012-09-03 17:04:06455RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
456 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
457 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
458 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
hablich4598ddc2015-11-07 18:37:28459 custom_histograms_.insert("V8.MemoryHeapUsed");
460 custom_histograms_.insert("V8.MemoryHeapCommitted");
[email protected]b2d98762012-09-03 17:04:06461}
462
463RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
464
465void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
466 const std::string& host, size_t view_count) {
avi83883c82014-12-23 00:08:49467 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
468 switches::kDisableHistogramCustomizer)) {
[email protected]9baee832012-12-10 11:07:15469 return;
470 }
[email protected]b2d98762012-09-03 17:04:06471 // Check if all RenderViews are displaying a page from the same host. If there
472 // is only one RenderView, the common host is this view's host. If there are
473 // many, check if this one shares the common host of the other
474 // RenderViews. It's ok to not detect some cases where the RenderViews share a
475 // common host. This information is only used for producing custom histograms.
476 if (view_count == 1)
477 SetCommonHost(host);
478 else if (host != common_host_)
479 SetCommonHost(std::string());
480}
481
482std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
483 const char* histogram_name) const {
484 std::string name(histogram_name);
485 if (!common_host_histogram_suffix_.empty() &&
486 custom_histograms_.find(name) != custom_histograms_.end())
487 name += common_host_histogram_suffix_;
488 return name;
489}
490
491void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
492 const std::string& host) {
493 if (host != common_host_) {
494 common_host_ = host;
495 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
Blink Reformat1c4d759e2017-04-09 16:34:54496 blink::MainThreadIsolate()->SetCreateHistogramFunction(CreateHistogram);
[email protected]b2d98762012-09-03 17:04:06497 }
498}
499
hablichd6a4f122015-10-28 11:34:49500std::string RenderThreadImpl::HistogramCustomizer::HostToCustomHistogramSuffix(
501 const std::string& host) {
502 if (host == "mail.google.com")
503 return ".gmail";
504 if (host == "docs.google.com" || host == "drive.google.com")
505 return ".docs";
506 if (host == "plus.google.com")
507 return ".plus";
508 if (host == "inbox.google.com")
509 return ".inbox";
hpayerdd4def052016-02-06 19:06:10510 if (host == "calendar.google.com")
511 return ".calendar";
hablichd6a4f122015-10-28 11:34:49512 if (host == "www.youtube.com")
513 return ".youtube";
514 if (IsAlexaTop10NonGoogleSite(host))
515 return ".top10";
516
517 return std::string();
518}
519
520bool RenderThreadImpl::HistogramCustomizer::IsAlexaTop10NonGoogleSite(
521 const std::string& host) {
522 // The Top10 sites have different TLD and/or subdomains depending on the
523 // localization.
524 if (host == "sina.com.cn")
525 return true;
526
527 std::string sanitized_host =
528 net::registry_controlled_domains::GetDomainAndRegistry(
529 host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
530
531 if (sanitized_host == "facebook.com")
532 return true;
533 if (sanitized_host == "baidu.com")
534 return true;
535 if (sanitized_host == "qq.com")
536 return true;
537 if (sanitized_host == "twitter.com")
538 return true;
539 if (sanitized_host == "taobao.com")
540 return true;
541 if (sanitized_host == "live.com")
542 return true;
543
544 if (!sanitized_host.empty()) {
545 std::vector<base::StringPiece> host_tokens = base::SplitStringPiece(
546 sanitized_host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
547
548 if (host_tokens.size() >= 2) {
549 if ((host_tokens[0] == "yahoo") || (host_tokens[0] == "amazon") ||
550 (host_tokens[0] == "wikipedia")) {
551 return true;
552 }
553 }
554 }
555 return false;
556}
557
leon.han2c0f9f12015-07-11 02:01:19558// static
559RenderThreadImpl* RenderThreadImpl::Create(
560 const InProcessChildThreadParams& params) {
Dmitry Skibaa2476cb92017-12-15 23:44:39561 TRACE_EVENT0("startup", "RenderThreadImpl::Create");
skyostil529caa292016-08-10 17:44:51562 std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler =
563 blink::scheduler::RendererScheduler::Create();
jam75c44222016-03-23 05:34:24564 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
565 return new RenderThreadImpl(
566 params, std::move(renderer_scheduler), test_task_counter);
leon.han2c0f9f12015-07-11 02:01:19567}
568
569// static
570RenderThreadImpl* RenderThreadImpl::Create(
dchengcedca5612016-04-09 01:40:15571 std::unique_ptr<base::MessageLoop> main_message_loop,
skyostil529caa292016-08-10 17:44:51572 std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler) {
Dmitry Skibaa2476cb92017-12-15 23:44:39573 TRACE_EVENT0("startup", "RenderThreadImpl::Create");
dcheng07945f632015-12-26 07:59:32574 return new RenderThreadImpl(std::move(main_message_loop),
575 std::move(renderer_scheduler));
leon.han2c0f9f12015-07-11 02:01:19576}
577
rockot5c478a72016-09-28 23:14:18578// static
[email protected]f1a29a02011-10-06 23:08:44579RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06580 return lazy_tls.Pointer()->Get();
581}
582
rockot5c478a72016-09-28 23:14:18583// static
584mojom::RenderMessageFilter* RenderThreadImpl::current_render_message_filter() {
585 if (g_render_message_filter_for_testing)
586 return g_render_message_filter_for_testing;
587 DCHECK(current());
588 return current()->render_message_filter();
589}
590
591// static
olegmax045f7fb12017-05-19 07:58:55592RendererBlinkPlatformImpl* RenderThreadImpl::current_blink_platform_impl() {
593 if (g_current_blink_platform_impl_for_testing)
594 return g_current_blink_platform_impl_for_testing;
595 DCHECK(current());
596 return current()->blink_platform_impl();
597}
598
599// static
rockot5c478a72016-09-28 23:14:18600void RenderThreadImpl::SetRenderMessageFilterForTesting(
601 mojom::RenderMessageFilter* render_message_filter) {
602 g_render_message_filter_for_testing = render_message_filter;
603}
604
olegmax045f7fb12017-05-19 07:58:55605// static
606void RenderThreadImpl::SetRendererBlinkPlatformImplForTesting(
607 RendererBlinkPlatformImpl* blink_platform_impl) {
608 g_current_blink_platform_impl_for_testing = blink_platform_impl;
609}
610
John Abd-El-Malekd4882642017-12-04 21:45:19611// static
612scoped_refptr<base::SingleThreadTaskRunner>
Hajime Hoshi20578c62018-01-12 09:43:26613RenderThreadImpl::DeprecatedGetMainTaskRunner() {
John Abd-El-Malekd4882642017-12-04 21:45:19614 return g_main_task_runner.Get();
615}
616
staraz067f58242016-11-07 21:06:41617// In single-process mode used for debugging, we don't pass a renderer client
618// ID via command line because RenderThreadImpl lives in the same process as
619// the browser
leon.han2c0f9f12015-07-11 02:01:19620RenderThreadImpl::RenderThreadImpl(
621 const InProcessChildThreadParams& params,
skyostil529caa292016-08-10 17:44:51622 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler,
rockot97a86832016-12-10 04:53:06623 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue)
Hajime Hoshife11b132017-11-13 10:16:07624 : ChildThreadImpl(
625 Options::Builder()
626 .InBrowserProcess(params)
627 .AutoStartServiceManagerConnection(false)
628 .ConnectToBrowser(true)
629 .IPCTaskRunner(scheduler ? scheduler->IPCTaskRunner() : nullptr)
630 .Build()),
dcheng07945f632015-12-26 07:59:32631 renderer_scheduler_(std::move(scheduler)),
rockot067ca55f2016-09-30 22:00:15632 categorized_worker_pool_(new CategorizedWorkerPool()),
staraz067f58242016-11-07 21:06:41633 renderer_binding_(this),
danakjab9ef4d2017-10-31 23:38:33634 client_id_(1),
635 compositing_mode_watcher_binding_(this) {
jam75c44222016-03-23 05:34:24636 Init(resource_task_queue);
morritac6238ab2015-03-18 01:48:29637}
638
[email protected]42f1d7822009-07-23 18:17:55639// When we run plugins in process, we actually run them on the render thread,
640// which means that we need to make the render thread pump UI events.
haraken53f081d2014-11-11 01:03:40641RenderThreadImpl::RenderThreadImpl(
dchengcedca5612016-04-09 01:40:15642 std::unique_ptr<base::MessageLoop> main_message_loop,
skyostil529caa292016-08-10 17:44:51643 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler)
Hajime Hoshia1626932017-11-30 09:50:59644 : ChildThreadImpl(
645 Options::Builder()
646 .AutoStartServiceManagerConnection(false)
647 .ConnectToBrowser(true)
648 .IPCTaskRunner(scheduler ? scheduler->IPCTaskRunner() : nullptr)
649 .Build()),
dcheng07945f632015-12-26 07:59:32650 renderer_scheduler_(std::move(scheduler)),
651 main_message_loop_(std::move(main_message_loop)),
rockot067ca55f2016-09-30 22:00:15652 categorized_worker_pool_(new CategorizedWorkerPool()),
wjmaclean1d970622017-01-21 22:28:24653 is_scroll_animator_enabled_(false),
danakjab9ef4d2017-10-31 23:38:33654 renderer_binding_(this),
655 compositing_mode_watcher_binding_(this) {
jam75c44222016-03-23 05:34:24656 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
staraz067f58242016-11-07 21:06:41657 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
658 switches::kRendererClientId));
659 base::StringToInt(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
660 switches::kRendererClientId),
661 &client_id_);
jam75c44222016-03-23 05:34:24662 Init(test_task_counter);
haraken53f081d2014-11-11 01:03:40663}
664
jam75c44222016-03-23 05:34:24665void RenderThreadImpl::Init(
rockot97a86832016-12-10 04:53:06666 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) {
fdorayf6d86242015-10-08 16:49:53667 TRACE_EVENT0("startup", "RenderThreadImpl::Init");
[email protected]a872ea1f2010-08-11 04:45:33668
ssidb2e3ece2015-02-09 16:02:20669 base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex(
[email protected]91a2aea2013-07-08 23:14:39670 base::PlatformThread::CurrentId(),
671 kTraceEventRendererMainThreadSortIndex);
672
thakis18e426412017-03-15 12:06:37673#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
sievers9dff72052015-11-16 18:35:57674 // On Mac and Android Java UI, the select popups are rendered by the browser.
Blink Reformat1c4d759e2017-04-09 16:34:54675 blink::WebView::SetUseExternalPopupMenus(true);
[email protected]53c607c2011-03-21 23:19:04676#endif
677
[email protected]94f9a0f682009-06-15 18:30:30678 lazy_tls.Pointer()->Set(this);
John Abd-El-Malekd4882642017-12-04 21:45:19679 g_main_task_runner.Get() = base::MessageLoop::current()->task_runner();
[email protected]b3e83de2012-02-07 03:33:28680
[email protected]06c694d2012-02-01 22:26:16681 // Register this object as the main thread.
682 ChildProcess::current()->set_main_thread(this);
683
dalecurtis4a9839a2017-05-04 23:40:47684 metrics::InitializeSingleSampleMetricsFactory(
685 base::BindRepeating(&CreateSingleSampleMetricsProvider,
686 message_loop()->task_runner(), GetConnector()));
687
Sadrul Habib Chowdhuryeeb5a942017-11-28 21:17:23688 gpu_ =
689 ui::Gpu::Create(GetConnector(),
690 switches::IsMusHostingViz() ? ui::mojom::kServiceName
691 : mojom::kBrowserServiceName,
692 GetIOTaskRunner());
penghuange1d86512016-07-08 18:15:00693
Gary Klassenb78686272017-08-11 22:38:13694 viz::mojom::SharedBitmapAllocationNotifierPtr
danakj92429852017-06-29 00:19:03695 shared_bitmap_allocation_notifier_ptr;
Saman Sami9b768542017-07-14 20:42:34696 GetConnector()->BindInterface(
697 mojom::kBrowserServiceName,
danakj92429852017-06-29 00:19:03698 mojo::MakeRequest(&shared_bitmap_allocation_notifier_ptr));
Jeremy Roman04f27c372017-10-27 15:20:55699 shared_bitmap_manager_ = std::make_unique<viz::ClientSharedBitmapManager>(
Gary Klassenb78686272017-08-11 22:38:13700 viz::mojom::ThreadSafeSharedBitmapAllocationNotifierPtr::Create(
danakj92429852017-06-29 00:19:03701 shared_bitmap_allocation_notifier_ptr.PassInterface(),
702 GetChannel()->ipc_task_runner_refptr()));
jcivelli0f21bd52016-12-07 21:21:33703
John Abd-El-Malekf9f86c12017-10-21 07:22:23704 notification_dispatcher_ =
705 new NotificationDispatcher(thread_safe_sender());
706 AddFilter(notification_dispatcher_->GetFilter());
707
Hajime Hoshi1711b522018-01-19 10:29:20708 resource_dispatcher_.reset(new ResourceDispatcher());
Sasha Bermeister9a3f9da2017-11-29 03:30:28709 quota_dispatcher_.reset(new QuotaDispatcher(message_loop()->task_runner()));
Yuzhu Shenfe5f3a52018-01-11 21:24:13710 url_loader_throttle_provider_ =
711 GetContentClient()->renderer()->CreateURLLoaderThrottleProvider(
712 URLLoaderThrottleProviderType::kFrame);
John Abd-El-Malek6b56ef712017-10-21 22:52:46713
Stuart Langley7b8dc772017-10-31 03:55:20714 auto registry = std::make_unique<service_manager::BinderRegistry>();
Ken Rockot510c5972017-12-05 16:37:04715 InitializeWebKit(resource_task_queue, registry.get());
Makoto Shimazu7af43ee2017-08-25 10:20:40716 blink_initialized_time_ = base::TimeTicks::Now();
jam75c44222016-03-23 05:34:24717
[email protected]31f87132010-04-21 23:36:21718 // In single process the single process is all there is.
Alexander Timin4b6152232017-10-17 20:34:06719 webkit_shared_timer_suspended_ = false;
[email protected]bee16aab2009-08-26 15:55:03720 widget_count_ = 0;
721 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44722 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48723 idle_notifications_to_skip_ = 0;
[email protected]8d86fce2009-02-26 23:37:55724
[email protected]d5b2fdf2013-06-05 09:36:55725 appcache_dispatcher_.reset(
Nicholas Verne07e9c6452017-12-13 04:12:55726 new AppCacheDispatcher(new AppCacheFrontendImpl()));
727 registry->AddInterface(
728 base::BindRepeating(&AppCacheDispatcher::Bind,
729 base::Unretained(appcache_dispatcher())),
Hajime Hoshi20578c62018-01-12 09:43:26730 GetRendererScheduler()->IPCTaskRunner());
[email protected]1910fe82012-05-10 00:04:10731 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
reillyg39fb4662016-11-22 20:27:17732 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
jsbellabadb9b2015-03-23 21:03:44733 main_thread_cache_storage_dispatcher_.reset(
jsbell279efb42015-03-31 17:02:46734 new CacheStorageDispatcher(thread_safe_sender()));
John Abd-El-Malekdcf1d1372017-10-22 06:39:41735 file_system_dispatcher_.reset(new FileSystemDispatcher());
[email protected]dd9241932010-02-24 19:23:13736
[email protected]45048072014-01-14 13:51:29737 vc_manager_.reset(new VideoCaptureImplManager());
[email protected]c9c43a02013-12-17 08:59:54738
fsamuel6c1dfeb2014-12-18 19:21:33739 browser_plugin_manager_.reset(new BrowserPluginManager());
740 AddObserver(browser_plugin_manager_.get());
741
Brett Wilson0748bf412016-11-22 17:55:46742#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]af089972013-01-10 04:04:40743 peer_connection_tracker_.reset(new PeerConnectionTracker());
744 AddObserver(peer_connection_tracker_.get());
745
thestig529ad8a2016-07-08 20:30:12746 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOTaskRunner().get());
[email protected]fc72bb12013-06-02 21:13:46747 AddFilter(p2p_socket_dispatcher_.get());
[email protected]921480f62013-07-20 03:42:57748
ivocadd54f0d2015-12-18 23:17:05749 peer_connection_factory_.reset(
750 new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get()));
751
skyostil2d3b5bd2015-05-27 15:40:59752 aec_dump_message_filter_ = new AecDumpMessageFilter(
thestig529ad8a2016-07-08 20:30:12753 GetIOTaskRunner(), message_loop()->task_runner());
ivocadd54f0d2015-12-18 23:17:05754
[email protected]da9f30a2014-06-18 19:39:04755 AddFilter(aec_dump_message_filter_.get());
756
Brett Wilson0748bf412016-11-22 17:55:46757#endif // BUILDFLAG(ENABLE_WEBRTC)
Max Morin3d464a42018-01-15 11:17:00758 {
759 scoped_refptr<AudioInputMessageFilter> audio_input_message_filter;
760 if (!base::FeatureList::IsEnabled(
761 features::kUseMojoAudioInputStreamFactory)) {
762 // In case we shouldn't use mojo factories, we need to create an
763 // AudioInputMessageFilter which |audio_input_ipc_factory_| can use for
764 // IPC.
765 audio_input_message_filter =
766 base::MakeRefCounted<AudioInputMessageFilter>(GetIOTaskRunner());
767 AddFilter(audio_input_message_filter.get());
768 }
[email protected]e25f4d72011-06-08 20:58:46769
Max Morin3d464a42018-01-15 11:17:00770 audio_input_ipc_factory_.emplace(std::move(audio_input_message_filter),
771 message_loop()->task_runner(),
772 GetIOTaskRunner());
Max Morind4c4887d2017-06-08 07:41:34773 }
774
Max Morin3d464a42018-01-15 11:17:00775 {
776 scoped_refptr<AudioMessageFilter> audio_output_message_filter;
777 if (!base::FeatureList::IsEnabled(
778 features::kUseMojoAudioOutputStreamFactory)) {
779 // In case we shouldn't use mojo factories, we need to create an
780 // AudioMessageFilter which |audio_output_ipc_factory_| can use for IPC.
781 audio_output_message_filter =
782 base::MakeRefCounted<AudioMessageFilter>(GetIOTaskRunner());
783 AddFilter(audio_output_message_filter.get());
784 }
785
786 audio_output_ipc_factory_.emplace(std::move(audio_output_message_filter),
787 GetIOTaskRunner());
788 }
[email protected]f7eb0a392011-07-12 10:19:51789
thestig529ad8a2016-07-08 20:30:12790 midi_message_filter_ = new MidiMessageFilter(GetIOTaskRunner());
[email protected]a9875152013-06-22 04:03:03791 AddFilter(midi_message_filter_.get());
792
jsbellabadb9b2015-03-23 21:03:44793 AddFilter((new CacheStorageMessageFilter(thread_safe_sender()))->GetFilter());
794
kinuko5af4ffe2015-06-09 03:38:46795 AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter());
[email protected]ddbb53342014-01-06 10:59:47796
Darin Fisherbcc33632017-09-26 00:57:16797// Register exported services:
798
sadrul943e3b32016-08-04 18:22:59799#if defined(USE_AURA)
Scott Violet30daff62017-12-01 07:04:52800 if (IsRunningWithMus())
bend32292b2016-10-07 00:21:58801 CreateRenderWidgetWindowTreeClientFactory(GetServiceManagerConnection());
rockotcef38272016-07-15 22:47:47802#endif
803
Stuart Langley7b8dc772017-10-31 03:55:20804 registry->AddInterface(base::Bind(&SharedWorkerFactoryImpl::Create),
805 base::ThreadTaskRunnerHandle::Get());
806 GetServiceManagerConnection()->AddConnectionFilter(
807 std::make_unique<SimpleConnectionFilter>(std::move(registry)));
Stuart Langley6771c902017-09-01 11:23:30808
Darin Fisherbcc33632017-09-26 00:57:16809 {
810 auto registry_with_source_info =
Jeremy Roman04f27c372017-10-27 15:20:55811 std::make_unique<service_manager::BinderRegistryWithArgs<
Darin Fisherbcc33632017-09-26 00:57:16812 const service_manager::BindSourceInfo&>>();
813 registry_with_source_info->AddInterface(
814 base::Bind(&CreateFrameFactory), base::ThreadTaskRunnerHandle::Get());
815 GetServiceManagerConnection()->AddConnectionFilter(
Jeremy Roman04f27c372017-10-27 15:20:55816 std::make_unique<SimpleConnectionFilterWithSourceInfo>(
Darin Fisherbcc33632017-09-26 00:57:16817 std::move(registry_with_source_info)));
818 }
rockotcef38272016-07-15 22:47:47819
[email protected]e9ff79c2012-10-19 21:31:26820 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24821
benbd9dc802017-04-19 01:37:43822 StartServiceManagerConnection();
823
rockot067ca55f2016-09-30 22:00:15824 GetAssociatedInterfaceRegistry()->AddInterface(
825 base::Bind(&RenderThreadImpl::OnRendererInterfaceRequest,
826 base::Unretained(this)));
827
[email protected]b48c53ad2014-02-05 21:59:18828 InitSkiaEventTracer();
ssid59c969162015-07-28 13:02:58829 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
primiano186d6bfe2015-10-30 13:21:40830 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr);
[email protected]b48c53ad2014-02-05 21:59:18831
avi83883c82014-12-23 00:08:49832 const base::CommandLine& command_line =
833 *base::CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01834
ochangdd89a1e2016-06-08 16:39:01835#if defined(ENABLE_IPC_FUZZER)
836 if (command_line.HasSwitch(switches::kIpcDumpDirectory)) {
837 base::FilePath dump_directory =
838 command_line.GetSwitchValuePath(switches::kIpcDumpDirectory);
839 IPC::ChannelProxy::OutgoingMessageFilter* filter =
840 LoadExternalIPCDumper(dump_directory);
841 GetChannel()->set_outgoing_message_filter(filter);
842 }
843#endif
844
jbroman0d302162015-09-05 05:46:23845 cc::SetClientNameForMetrics("Renderer");
loysoa6edaaff2015-05-25 03:26:44846
loyso65c93c602015-08-11 05:15:57847 is_threaded_animation_enabled_ =
848 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
849
reveman91a0a872014-11-04 03:40:32850 is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy);
ericrk1d17f752015-10-20 03:03:07851 is_partial_raster_enabled_ =
dongseong.hwang23db47f2016-03-08 07:50:02852 !command_line.HasSwitch(switches::kDisablePartialRaster);
ccameronc7fcd132015-11-03 20:14:31853 is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch(
854 switches::kEnableGpuMemoryBufferCompositorResources);
[email protected]a23530d2014-03-11 06:04:14855
Greg Kerra7b943b2017-07-24 23:17:17856// On macOS this value is adjusted in `UpdateScrollbarTheme()`,
857// but the system default is true.
858#if defined(OS_MACOSX)
859 is_elastic_overscroll_enabled_ = true;
ccamerona7644752014-12-30 01:16:31860#else
861 is_elastic_overscroll_enabled_ = false;
862#endif
863
[email protected]a23530d2014-03-11 06:04:14864 if (command_line.HasSwitch(switches::kDisableLCDText)) {
865 is_lcd_text_enabled_ = false;
866 } else if (command_line.HasSwitch(switches::kEnableLCDText)) {
867 is_lcd_text_enabled_ = true;
868 } else {
869#if defined(OS_ANDROID)
870 is_lcd_text_enabled_ = false;
871#else
872 is_lcd_text_enabled_ = true;
873#endif
874 }
875
danakjab9ef4d2017-10-31 23:38:33876 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
877 is_gpu_compositing_disabled_ = true;
878
[email protected]b8d82c22014-03-31 20:12:46879 is_gpu_rasterization_forced_ =
880 command_line.HasSwitch(switches::kForceGpuRasterization);
[email protected]a23530d2014-03-11 06:04:14881
senorblancob60ba952015-01-27 19:12:36882 if (command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) {
883 std::string string_value = command_line.GetSwitchValueASCII(
884 switches::kGpuRasterizationMSAASampleCount);
885 bool parsed_msaa_sample_count =
886 base::StringToInt(string_value, &gpu_rasterization_msaa_sample_count_);
887 DCHECK(parsed_msaa_sample_count) << string_value;
888 DCHECK_GE(gpu_rasterization_msaa_sample_count_, 0);
889 } else {
senorblanco2a5b0e12015-08-14 21:55:37890 gpu_rasterization_msaa_sample_count_ = -1;
senorblancob60ba952015-01-27 19:12:36891 }
892
[email protected]b242b142014-05-07 14:48:49893 if (command_line.HasSwitch(switches::kDisableDistanceFieldText)) {
894 is_distance_field_text_enabled_ = false;
895 } else if (command_line.HasSwitch(switches::kEnableDistanceFieldText)) {
896 is_distance_field_text_enabled_ = true;
897 } else {
898 is_distance_field_text_enabled_ = false;
899 }
900
Khushalfdacdc92017-09-22 22:40:52901 WebRuntimeFeatures::EnableCompositorImageAnimations(
902 command_line.HasSwitch(switches::kEnableCompositorImageAnimations));
903
[email protected]433df472012-03-07 20:33:39904 // Note that under Linux, the media library will normally already have
905 // been initialized by the Zygote before this instance became a Renderer.
chcunninghamfd11b3c2015-06-09 02:09:42906 media::InitializeMediaLibrary();
[email protected]433df472012-03-07 20:33:39907
dalecurtis88af3932016-02-20 00:12:20908#if defined(OS_ANDROID)
909 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
910 media::MediaCodecUtil::IsMediaCodecAvailable()) {
911 media::EnablePlatformDecoderSupport();
912 }
913#endif
914
bashi296ebda2017-03-28 03:27:09915 memory_pressure_listener_.reset(new base::MemoryPressureListener(
916 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
917 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
918 base::Unretained(this))));
919
920 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
921 // Disable MemoryPressureListener when memory coordinator is enabled.
922 base::MemoryPressureListener::SetNotificationsSuppressed(true);
923
924 // TODO(bashi): Revisit how to manage the lifetime of
925 // ChildMemoryCoordinatorImpl.
926 // https://codereview.chromium.org/2094583002/#msg52
927 mojom::MemoryCoordinatorHandlePtr parent_coordinator;
928 GetConnector()->BindInterface(mojom::kBrowserServiceName,
929 mojo::MakeRequest(&parent_coordinator));
930 memory_coordinator_ = CreateChildMemoryCoordinator(
931 std::move(parent_coordinator), this);
932 }
933
danakj16275d4c2015-06-11 19:23:51934 int num_raster_threads = 0;
935 std::string string_value =
936 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
937 bool parsed_num_raster_threads =
938 base::StringToInt(string_value, &num_raster_threads);
939 DCHECK(parsed_num_raster_threads) << string_value;
940 DCHECK_GT(num_raster_threads, 0);
vmiura78b69282015-02-14 00:01:17941
prashant.nfad657e2016-06-01 07:52:17942 categorized_worker_pool_->Start(num_raster_threads);
[email protected]1e1d1e12014-01-17 16:14:29943
penghuang342762b2016-12-02 21:04:58944 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr;
Sadrul Habib Chowdhury1dbe3b42017-11-18 02:27:43945 if (IsRunningWithMus()) {
penghuangd6843e42016-12-17 13:57:20946#if defined(USE_AURA)
benbd3c2482017-01-07 05:48:21947 GetServiceManagerConnection()->GetConnector()->BindInterface(
penghuangd6843e42016-12-17 13:57:20948 ui::mojom::kServiceName, &manager_ptr);
949#else
950 NOTREACHED();
951#endif
952 } else {
ben649b3edd2017-03-23 00:32:02953 ChildThread::Get()->GetConnector()->BindInterface(
954 mojom::kBrowserServiceName, mojo::MakeRequest(&manager_ptr));
penghuangd6843e42016-12-17 13:57:20955 }
956
Jeremy Roman04f27c372017-10-27 15:20:55957 discardable_shared_memory_manager_ = std::make_unique<
penghuang342762b2016-12-02 21:04:58958 discardable_memory::ClientDiscardableSharedMemoryManager>(
959 std::move(manager_ptr), GetIOTaskRunner());
960
boliu9760e212015-06-23 22:49:06961 // TODO(boliu): In single process, browser main loop should set up the
962 // discardable memory manager, and should skip this if kSingleProcess.
963 // See crbug.com/503724.
964 base::DiscardableMemoryAllocator::SetInstance(
penghuang342762b2016-12-02 21:04:58965 discardable_shared_memory_manager_.get());
revemancb5a66af2014-10-25 00:34:39966
ben649b3edd2017-03-23 00:32:02967 GetConnector()->BindInterface(mojom::kBrowserServiceName,
968 mojo::MakeRequest(&storage_partition_service_));
hajimehoshi69093272016-05-13 08:30:58969
reveman7b97c322016-09-20 02:10:58970#if defined(OS_LINUX)
Nicholas Verne84dc55e2017-11-23 01:02:38971 render_message_filter()->SetThreadPriority(
972 ChildProcess::current()->io_thread_id(), base::ThreadPriority::DISPLAY);
973 render_message_filter()->SetThreadPriority(
lukasza6710dbd2017-04-07 20:58:03974 categorized_worker_pool_->background_worker_thread_id(),
reveman7b97c322016-09-20 02:10:58975 base::ThreadPriority::BACKGROUND);
976#endif
977
tasakbb0640b2017-05-15 09:02:26978 process_foregrounded_count_ = 0;
tasakb95dbb50c2017-02-08 18:07:50979 needs_to_record_first_active_paint_ = false;
Takashi SAKAMOTO870f6262017-08-22 04:08:27980 was_backgrounded_time_ = base::TimeTicks::Min();
hajimehoshi7bb39582016-10-12 04:30:57981
982 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
fdoray50a38342016-11-21 20:46:04983
984 // If this renderer doesn't run inside the browser process, enable
985 // SequencedWorkerPool. Otherwise, it should already have been enabled.
986 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler
987 // redirection experiment concludes https://crbug.com/622400.
988 if (!command_line.HasSwitch(switches::kSingleProcess))
989 base::SequencedWorkerPool::EnableForProcess();
samans2040988b2017-04-11 23:58:35990
991 GetConnector()->BindInterface(mojom::kBrowserServiceName,
992 mojo::MakeRequest(&frame_sink_provider_));
danakjab9ef4d2017-10-31 23:38:33993
994 if (!is_gpu_compositing_disabled_) {
995 GetConnector()->BindInterface(
996 mojom::kBrowserServiceName,
997 mojo::MakeRequest(&compositing_mode_reporter_));
998
999 // Make |this| a CompositingModeWatcher for the
1000 // |compositing_mode_reporter_|.
1001 viz::mojom::CompositingModeWatcherPtr watcher_ptr;
1002 compositing_mode_watcher_binding_.Bind(mojo::MakeRequest(&watcher_ptr));
1003 compositing_mode_reporter_->AddCompositingModeWatcher(
1004 std::move(watcher_ptr));
1005 }
initial.commit09911bf2008-07-26 23:55:291006}
1007
John Abd-El-Malekd4882642017-12-04 21:45:191008RenderThreadImpl::~RenderThreadImpl() {
1009 g_main_task_runner.Get() = nullptr;
1010}
[email protected]ce79d8512013-04-22 22:44:411011
Nicholas Verne5420564d2017-10-27 07:37:541012void RenderThreadImpl::Shutdown() {
John Abd-El-Malekdcf1d1372017-10-22 06:39:411013 ChildThreadImpl::Shutdown();
John Abd-El-Malekf75a3192017-10-22 14:23:201014 quota_dispatcher_.reset();
John Abd-El-Malekdcf1d1372017-10-22 06:39:411015 file_system_dispatcher_.reset();
1016 WebFileSystemImpl::DeleteThreadSpecificInstance();
harakenbbfdd9f02017-01-12 07:14:041017 // In a multi-process mode, we immediately exit the renderer.
1018 // Historically we had a graceful shutdown sequence here but it was
1019 // 1) a waste of performance and 2) a source of lots of complicated
1020 // crashes caused by shutdown ordering. Immediate exit eliminates
1021 // those problems.
cbrunia3f655b2017-03-20 11:36:411022
1023 // Give the V8 isolate a chance to dump internal stats useful for performance
1024 // evaluation and debugging.
Blink Reformat1c4d759e2017-04-09 16:34:541025 blink::MainThreadIsolate()->DumpAndResetStats();
cbrunia3f655b2017-03-20 11:36:411026
Adithya Srinivasandf421e82017-06-01 14:36:111027 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1028 switches::kDumpBlinkRuntimeCallStats))
1029 blink::LogRuntimeCallStats();
1030
harakenbbfdd9f02017-01-12 07:14:041031 // In a single-process mode, we cannot call _exit(0) in Shutdown() because
1032 // it will exit the process before the browser side is ready to exit.
1033 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1034 switches::kSingleProcess))
haraken940efb92017-02-08 05:58:151035 base::Process::TerminateCurrentProcessImmediately(0);
harakenbbfdd9f02017-01-12 07:14:041036}
[email protected]1223d6ef2011-03-28 16:47:501037
harakenbbfdd9f02017-01-12 07:14:041038bool RenderThreadImpl::ShouldBeDestroyed() {
1039 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1040 switches::kSingleProcess));
1041 // In a single-process mode, it is unsafe to destruct this renderer thread
1042 // because we haven't run the shutdown sequence. Hence we leak the render
1043 // thread.
1044 //
1045 // In this case, we also need to disable at-exit callbacks because some of
1046 // the at-exit callbacks are expected to run after the renderer thread
1047 // has been destructed.
1048 base::AtExitManager::DisableAllAtExitManagers();
1049 return false;
initial.commit09911bf2008-07-26 23:55:291050}
1051
[email protected]f1a29a02011-10-06 23:08:441052bool RenderThreadImpl::Send(IPC::Message* msg) {
changwan6ed4d432016-05-19 22:03:541053 // There are cases where we want to pump asynchronous messages while waiting
1054 // synchronously for the replies to the message to be sent here. However, this
1055 // may create an opportunity for re-entrancy into WebKit and other subsystems,
1056 // so we need to take care to disable callbacks, timers, and pending network
1057 // loads that could trigger such callbacks.
[email protected]38b592902011-04-16 02:08:421058 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:501059 if (msg->is_sync()) {
1060 if (msg->is_caller_pumping_messages()) {
1061 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:501062 }
[email protected]c1f50aa2010-02-18 03:46:571063 }
1064
Yoland Yan25439ba2017-10-11 19:45:551065 std::unique_ptr<blink::scheduler::RendererScheduler::RendererPauseHandle>
1066 renderer_paused_handle;
1067
[email protected]c1f50aa2010-02-18 03:46:571068 if (pumping_events) {
Yoland Yan25439ba2017-10-11 19:45:551069 renderer_paused_handle = renderer_scheduler_->PauseRenderer();
Blink Reformat1c4d759e2017-04-09 16:34:541070 WebView::WillEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571071 }
1072
jam8a021512a2015-02-03 18:16:081073 bool rv = ChildThreadImpl::Send(msg);
[email protected]c1f50aa2010-02-18 03:46:571074
Yoland Yan25439ba2017-10-11 19:45:551075 if (pumping_events)
Blink Reformat1c4d759e2017-04-09 16:34:541076 WebView::DidExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571077
1078 return rv;
1079}
1080
[email protected]f1a29a02011-10-06 23:08:441081IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:061082 return channel();
1083}
1084
[email protected]f1a29a02011-10-06 23:08:441085std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:061086 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:021087 // --lang command line flag.
avi83883c82014-12-23 00:08:491088 const base::CommandLine& parsed_command_line =
1089 *base::CommandLine::ForCurrentProcess();
[email protected]526476902011-10-06 20:34:061090 const std::string& lang =
1091 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:021092 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:061093 return lang;
1094}
1095
[email protected]07bb6332012-01-21 01:07:571096IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
1097 return sync_message_filter();
1098}
1099
avi1023d012015-12-25 02:39:141100void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) {
jam8a021512a2015-02-03 18:16:081101 ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener);
ben76f52b242016-06-18 05:42:481102 auto it = pending_frame_creates_.find(routing_id);
1103 if (it == pending_frame_creates_.end())
rockotf8fdd9b2015-12-16 22:22:351104 return;
1105
1106 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
1107 if (!frame)
1108 return;
1109
ben76f52b242016-06-18 05:42:481110 scoped_refptr<PendingFrameCreate> create(it->second);
Balazs Engedyba034e72017-10-27 22:26:281111 frame->BindFrame(it->second->browser_info(), it->second->TakeFrameRequest());
ben76f52b242016-06-18 05:42:481112 pending_frame_creates_.erase(it);
[email protected]c1f50aa2010-02-18 03:46:571113}
1114
avi1023d012015-12-25 02:39:141115void RenderThreadImpl::RemoveRoute(int32_t routing_id) {
jam8a021512a2015-02-03 18:16:081116 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id);
[email protected]c1f50aa2010-02-18 03:46:571117}
[email protected]0ec90d522014-03-12 16:28:191118
ben76f52b242016-06-18 05:42:481119void RenderThreadImpl::RegisterPendingFrameCreate(
benf28ce882017-05-02 16:15:491120 const service_manager::BindSourceInfo& browser_info,
rockotf8fdd9b2015-12-16 22:22:351121 int routing_id,
Balazs Engedyba034e72017-10-27 22:26:281122 mojom::FrameRequest frame_request) {
ben76f52b242016-06-18 05:42:481123 std::pair<PendingFrameCreateMap::iterator, bool> result =
1124 pending_frame_creates_.insert(std::make_pair(
kylechar96f3eba2017-09-25 20:23:561125 routing_id, base::MakeRefCounted<PendingFrameCreate>(
Balazs Engedyba034e72017-10-27 22:26:281126 browser_info, routing_id, std::move(frame_request))));
rockotf8fdd9b2015-12-16 22:22:351127 CHECK(result.second) << "Inserting a duplicate item.";
1128}
1129
leon.han06e55662016-03-26 17:19:421130mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() {
jamc912ca32016-02-24 20:17:311131 return storage_partition_service_.get();
1132}
1133
jam188f19f2017-06-07 03:56:241134mojom::RendererHost* RenderThreadImpl::GetRendererHost() {
Nicholas Verne06de8122017-11-16 04:47:381135 if (!renderer_host_) {
Joel Hockey3146d142017-11-15 22:27:401136 GetChannel()->GetRemoteAssociatedInterface(&renderer_host_);
Nicholas Verne06de8122017-11-16 04:47:381137 }
jam188f19f2017-06-07 03:56:241138 return renderer_host_.get();
1139}
1140
[email protected]77fc9b92011-10-15 16:20:371141int RenderThreadImpl::GenerateRoutingID() {
rockote261d2112016-09-21 22:22:231142 int32_t routing_id = MSG_ROUTING_NONE;
1143 render_message_filter()->GenerateRoutingID(&routing_id);
[email protected]77fc9b92011-10-15 16:20:371144 return routing_id;
1145}
1146
[email protected]74122042014-04-25 00:07:301147void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551148 channel()->AddFilter(filter);
1149}
1150
[email protected]74122042014-04-25 00:07:301151void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551152 channel()->RemoveFilter(filter);
1153}
1154
tyoshino832a58a2016-04-18 08:14:081155void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) {
[email protected]526476902011-10-06 20:34:061156 observers_.AddObserver(observer);
nigeltao7cd8d5582016-12-12 06:05:281157 observer->RegisterMojoInterfaces(&associated_interfaces_);
[email protected]526476902011-10-06 20:34:061158}
1159
tyoshino832a58a2016-04-18 08:14:081160void RenderThreadImpl::RemoveObserver(RenderThreadObserver* observer) {
nigeltao7cd8d5582016-12-12 06:05:281161 observer->UnregisterMojoInterfaces(&associated_interfaces_);
[email protected]526476902011-10-06 20:34:061162 observers_.RemoveObserver(observer);
1163}
1164
[email protected]359dfa32011-10-12 01:10:151165void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:261166 ResourceDispatcherDelegate* delegate) {
John Abd-El-Malek6b56ef712017-10-21 22:52:461167 resource_dispatcher_->set_delegate(delegate);
[email protected]359dfa32011-10-12 01:10:151168}
1169
vollick1050cc62015-12-03 07:04:541170void RenderThreadImpl::InitializeCompositorThread() {
boliu66024c62016-04-20 04:00:411171 base::Thread::Options options;
vollick1050cc62015-12-03 07:04:541172#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:411173 options.priority = base::ThreadPriority::DISPLAY;
vollick1050cc62015-12-03 07:04:541174#endif
altiminc7369bf2017-04-11 14:29:151175 compositor_thread_ =
1176 blink::scheduler::WebThreadBase::CreateCompositorThread(options);
boliu66024c62016-04-20 04:00:411177 blink_platform_impl_->SetCompositorThread(compositor_thread_.get());
Siddhartha5ac59e62018-01-03 00:08:141178 compositor_task_runner_ = compositor_thread_->GetSingleThreadTaskRunner();
boliu66024c62016-04-20 04:00:411179 compositor_task_runner_->PostTask(
1180 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061181 base::BindOnce(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
1182 false));
reveman7b97c322016-09-20 02:10:581183#if defined(OS_LINUX)
Nicholas Verne84dc55e2017-11-23 01:02:381184 render_message_filter()->SetThreadPriority(compositor_thread_->ThreadId(),
1185 base::ThreadPriority::DISPLAY);
reveman7b97c322016-09-20 02:10:581186#endif
vollick1050cc62015-12-03 07:04:541187
Dave Tapuska525eb15e2017-08-17 21:05:501188 if (!base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
1189 SynchronousInputHandlerProxyClient* synchronous_input_handler_proxy_client =
1190 nullptr;
vollick1050cc62015-12-03 07:04:541191#if defined(OS_ANDROID)
Dave Tapuska525eb15e2017-08-17 21:05:501192 if (GetContentClient()->UsingSynchronousCompositing()) {
1193 sync_compositor_message_filter_ =
1194 new SynchronousCompositorFilter(compositor_task_runner_);
1195 AddFilter(sync_compositor_message_filter_.get());
1196 synchronous_input_handler_proxy_client =
1197 sync_compositor_message_filter_.get();
1198 }
vollick1050cc62015-12-03 07:04:541199#endif
Dave Tapuska525eb15e2017-08-17 21:05:501200 scoped_refptr<InputEventFilter> compositor_input_event_filter(
1201 new InputEventFilter(main_input_callback_.callback(),
1202 main_thread_compositor_task_runner_,
1203 compositor_task_runner_));
1204 InputHandlerManagerClient* input_handler_manager_client =
1205 compositor_input_event_filter.get();
1206 input_event_filter_ = compositor_input_event_filter;
1207 input_handler_manager_.reset(new InputHandlerManager(
1208 compositor_task_runner_, input_handler_manager_client,
1209 synchronous_input_handler_proxy_client, renderer_scheduler_.get()));
1210 } else {
1211#if defined(OS_ANDROID)
1212 // TODO(dtapuska): Implement a mojo channel for the synchronous
1213 // compositor android webview uses.
1214 DCHECK(!GetContentClient()->UsingSynchronousCompositing());
1215#endif
1216 }
vollick1050cc62015-12-03 07:04:541217}
1218
jam75c44222016-03-23 05:34:241219void RenderThreadImpl::InitializeWebKit(
Stuart Langley7b8dc772017-10-31 03:55:201220 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue,
Ken Rockot510c5972017-12-05 16:37:041221 service_manager::BinderRegistry* registry) {
jam75c44222016-03-23 05:34:241222 DCHECK(!blink_platform_impl_);
[email protected]d1b8fccc2011-08-03 01:20:131223
avi83883c82014-12-23 00:08:491224 const base::CommandLine& command_line =
1225 *base::CommandLine::ForCurrentProcess();
chunyang.daibe874c52014-11-14 06:45:051226
1227#ifdef ENABLE_VTUNE_JIT_INTERFACE
1228 if (command_line.HasSwitch(switches::kEnableVtune))
1229 gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler());
1230#endif
1231
Reilly Grant9944f162017-08-29 01:22:411232 blink_platform_impl_.reset(
1233 new RendererBlinkPlatformImpl(renderer_scheduler_.get()));
rmcilroy4073ae12015-01-08 13:08:101234 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line);
hlopko852ffcf2016-09-16 16:50:591235 GetContentClient()
1236 ->renderer()
1237 ->SetRuntimeFeaturesDefaultsBeforeBlinkInitialization();
Ken Rockot510c5972017-12-05 16:37:041238 blink::Initialize(blink_platform_impl_.get(), registry);
[email protected]d1b8fccc2011-08-03 01:20:131239
Blink Reformat1c4d759e2017-04-09 16:34:541240 v8::Isolate* isolate = blink::MainThreadIsolate();
[email protected]4b5340282014-07-08 11:37:341241 isolate->SetCreateHistogramFunction(CreateHistogram);
1242 isolate->SetAddHistogramSampleFunction(AddHistogramSample);
skyostila37c2a72016-06-29 17:30:071243 renderer_scheduler_->SetRAILModeObserver(this);
[email protected]4b5340282014-07-08 11:37:341244
rmcilroy321f924d2014-11-06 00:56:001245 main_thread_compositor_task_runner_ =
danakj6e3bf8012014-12-16 18:27:531246 renderer_scheduler_->CompositorTaskRunner();
skyostilc30aa402014-10-10 13:49:091247
jdduke691dd572014-12-02 20:47:521248 main_input_callback_.Reset(
1249 base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived),
1250 base::Unretained(this)));
1251
khushalsagard7178e42017-01-20 01:31:491252 if (!command_line.HasSwitch(switches::kDisableThreadedCompositing))
vollick1050cc62015-12-03 07:04:541253 InitializeCompositorThread();
[email protected]a9fb30aa2011-10-06 06:58:461254
jdduke691dd572014-12-02 20:47:521255 if (!input_event_filter_.get()) {
1256 // Always provide an input event filter implementation to ensure consistent
1257 // input event scheduling and prioritization.
1258 // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and
1259 // MainThreadInputEventFilter, crbug.com/436057.
1260 input_event_filter_ = new MainThreadInputEventFilter(
1261 main_input_callback_.callback(), main_thread_compositor_task_runner_);
1262 }
1263 AddFilter(input_event_filter_.get());
1264
skyostil2d3b5bd2015-05-27 15:40:591265 scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner;
vollick1050cc62015-12-03 07:04:541266 if (compositor_task_runner_)
skyostil2d3b5bd2015-05-27 15:40:591267 compositor_impl_side_task_runner = compositor_task_runner_;
[email protected]7f1f63f2013-03-07 06:07:291268 else
skyostil2d3b5bd2015-05-27 15:40:591269 compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get();
[email protected]1842fe22012-08-13 23:24:351270
simonhonga7e3ac42014-11-11 20:50:221271 compositor_message_filter_ = new CompositorForwardingMessageFilter(
skyostil2d3b5bd2015-05-27 15:40:591272 compositor_impl_side_task_runner.get());
simonhonga7e3ac42014-11-11 20:50:221273 AddFilter(compositor_message_filter_.get());
[email protected]1842fe22012-08-13 23:24:351274
[email protected]58436a12012-03-21 17:10:261275 RenderThreadImpl::RegisterSchemes();
1276
xhwang194acae2014-11-12 22:46:331277 RenderMediaClient::Initialize();
1278
ulan4a385192015-11-11 10:59:181279 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]1784b2f2011-11-24 10:53:481280 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
ulan4a385192015-11-11 10:59:181281 } else {
1282 // If we do not track widget visibility, then assume conservatively that
1283 // the isolate is in background. This reduces memory usage.
1284 isolate->IsolateInBackgroundNotification();
1285 }
[email protected]2541d1a2013-07-10 07:33:271286
John Abd-El-Maleke1d4de32017-10-21 16:14:291287 service_worker_message_filter_ =
1288 new ServiceWorkerMessageFilter(thread_safe_sender());
1289 AddFilter(service_worker_message_filter_->GetFilter());
1290
Shubhie Panicker11a8e6a2017-09-19 09:29:231291 renderer_scheduler_->SetStoppingWhenBackgroundedEnabled(
1292 GetContentClient()->renderer()->AllowStoppingWhenProcessBackgrounded());
jdduke73220f02015-09-04 17:03:511293
reedccf98c52014-10-03 16:40:381294 SkGraphics::SetResourceCacheSingleAllocationByteLimit(
[email protected]dd2c1022014-07-22 23:13:571295 kImageCacheSingleAllocationByteLimit);
1296
reed6e5a72222015-08-06 20:37:161297 // Hook up blink's codecs so skia can call them
reed08cd16372017-02-21 22:11:411298 SkGraphics::SetImageGeneratorFromEncodedDataFactory(
Vladimir Levin325831d2017-08-30 15:03:221299 blink::WebImageGenerator::CreateAsSkImageGenerator);
reed6e5a72222015-08-06 20:37:161300
paritosh.in7e30c902015-04-15 17:04:071301 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) {
1302 std::string allowed_ports =
1303 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts);
1304 net::SetExplicitlyAllowedPorts(allowed_ports);
1305 }
[email protected]d1b8fccc2011-08-03 01:20:131306}
1307
[email protected]58436a12012-03-21 17:10:261308void RenderThreadImpl::RegisterSchemes() {
mkwst8e94fb32015-05-20 05:05:141309 // chrome:
Blink Reformat1c4d759e2017-04-09 16:34:541310 WebString chrome_scheme(WebString::FromASCII(kChromeUIScheme));
1311 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(chrome_scheme);
1312 WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(
mkwst8e94fb32015-05-20 05:05:141313 chrome_scheme);
mkwst8e94fb32015-05-20 05:05:141314
1315 // chrome-devtools:
Blink Reformat1c4d759e2017-04-09 16:34:541316 WebString devtools_scheme(WebString::FromASCII(kChromeDevToolsScheme));
1317 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(devtools_scheme);
meacerce6b66032016-06-02 20:56:051318
1319 // view-source:
Blink Reformat1c4d759e2017-04-09 16:34:541320 WebString view_source_scheme(WebString::FromASCII(kViewSourceScheme));
1321 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(view_source_scheme);
Alex Moshchuk71f485592017-08-16 16:20:001322
1323 // chrome-error:
1324 WebString error_scheme(WebString::FromASCII(kChromeErrorScheme));
1325 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(error_scheme);
1326 WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(error_scheme);
[email protected]58436a12012-03-21 17:10:261327}
1328
[email protected]e6e30ac2014-01-13 21:24:391329void RenderThreadImpl::RecordAction(const base::UserMetricsAction& action) {
[email protected]97880c82013-12-04 07:09:211330 Send(new ViewHostMsg_UserMetricsRecordAction(action.str_));
1331}
1332
1333void RenderThreadImpl::RecordComputedAction(const std::string& action) {
[email protected]526476902011-10-06 20:34:061334 Send(new ViewHostMsg_UserMetricsRecordAction(action));
1335}
1336
dchengcedca5612016-04-09 01:40:151337std::unique_ptr<base::SharedMemory>
1338RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
sadrulee3ff1f2016-12-09 04:22:011339 return ChildThreadImpl::AllocateSharedMemory(size);
[email protected]00614a82011-10-07 22:39:311340}
1341
Fady Samuel4b5f9862017-07-11 05:27:201342viz::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() {
jbauman2f5c1942014-12-06 03:28:241343 return shared_bitmap_manager();
1344}
1345
[email protected]f1a29a02011-10-06 23:08:441346void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
Blink Reformat1c4d759e2017-04-09 16:34:541347 WebScriptController::RegisterExtension(extension);
[email protected]526476902011-10-06 20:34:061348}
1349
avi1023d012015-12-25 02:39:141350void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) {
[email protected]6593ae12011-11-14 12:09:441351 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:061352 idle_timer_.Stop();
1353 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:441354 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:441355 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:061356}
1357
[email protected]f1a29a02011-10-06 23:08:441358void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:481359 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:261360 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:481361 RunIdleHandlerWhenWidgetsHidden();
1362 if (run_in_foreground_tab) {
jochen5a32aaf2014-09-26 20:37:431363 if (idle_notifications_to_skip_ > 0) {
1364 --idle_notifications_to_skip_;
1365 } else {
ssid0603ca9f2015-06-09 16:48:081366 ReleaseFreeMemory();
jochen5a32aaf2014-09-26 20:37:431367 }
1368 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]1784b2f2011-11-24 10:53:481369 return;
1370 }
[email protected]237a14852012-04-28 02:56:381371
ssid0603ca9f2015-06-09 16:48:081372 ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:061373
[email protected]26e82322014-01-20 14:18:221374 // Continue the idle timer if the webkit shared timer is not suspended or
1375 // something is left to do.
Alexander Timin4b6152232017-10-17 20:34:061376 bool continue_timer = !webkit_shared_timer_suspended_;
[email protected]26e82322014-01-20 14:18:221377
sullivancd45a3e2014-09-19 14:39:181378 // Schedule next invocation. When the tab is originally hidden, an invocation
1379 // is scheduled for kInitialIdleHandlerDelayMs in
1380 // RenderThreadImpl::WidgetHidden in order to race to a minimal heap.
1381 // After that, idle calls can be much less frequent, so run at a maximum of
1382 // once every kLongIdleHandlerDelayMs.
[email protected]6593ae12011-11-14 12:09:441383 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:061384 // delay = delay + 1 / (delay + 2)
1385 // Using floor(delay) has a dampening effect such as:
sullivancd45a3e2014-09-19 14:39:181386 // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ...
[email protected]6593ae12011-11-14 12:09:441387 // If the delay is in milliseconds, the above formula is equivalent to:
1388 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
1389 // which is equivalent to
1390 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
[email protected]26e82322014-01-20 14:18:221391 if (continue_timer) {
sullivancd45a3e2014-09-19 14:39:181392 ScheduleIdleHandler(
1393 std::max(kLongIdleHandlerDelayMs,
1394 idle_notification_delay_in_ms_ +
1395 1000000 / (idle_notification_delay_in_ms_ + 2000)));
[email protected]26e82322014-01-20 14:18:221396
1397 } else {
1398 idle_timer_.Stop();
1399 }
[email protected]526476902011-10-06 20:34:061400
ericwilligers88e69742016-10-17 19:29:551401 for (auto& observer : observers_)
1402 observer.IdleNotification();
[email protected]526476902011-10-06 20:34:061403}
1404
avi1023d012015-12-25 02:39:141405int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const {
[email protected]6593ae12011-11-14 12:09:441406 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:061407}
1408
[email protected]6593ae12011-11-14 12:09:441409void RenderThreadImpl::SetIdleNotificationDelayInMs(
avi1023d012015-12-25 02:39:141410 int64_t idle_notification_delay_in_ms) {
[email protected]6593ae12011-11-14 12:09:441411 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:081412}
1413
[email protected]5b18406362013-06-18 18:46:431414int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) {
kinukoef647412015-12-23 06:10:431415 return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure);
[email protected]a9bd323d2013-06-17 20:27:561416}
1417
[email protected]b02f5902012-12-19 07:33:001418bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
1419 bool result = false;
1420 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
1421 return result;
1422}
1423
[email protected]1784b2f2011-11-24 10:53:481424void RenderThreadImpl::PostponeIdleNotification() {
1425 idle_notifications_to_skip_ = 2;
1426}
1427
dcastagna7f45dada2015-10-19 20:17:351428media::GpuVideoAcceleratorFactories* RenderThreadImpl::GetGpuFactories() {
[email protected]3bb8bb32013-07-11 13:13:031429 DCHECK(IsMainThread());
1430
dcastagna09bd6b32016-02-01 21:54:281431 if (!gpu_factories_.empty()) {
sadrul85cc5d82016-12-20 03:37:411432 scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider =
dcastagna09bd6b32016-02-01 21:54:281433 gpu_factories_.back()->ContextProviderMainThread();
1434 if (shared_context_provider) {
Xu Xing32549162017-07-17 22:25:431435 viz::ContextProvider::ScopedContextLock lock(
dcastagna09bd6b32016-02-01 21:54:281436 shared_context_provider.get());
Miguel Casas5e1018052018-01-09 19:17:361437 if (lock.ContextGL()->GetGraphicsResetStatusKHR() == GL_NO_ERROR)
leon.han21e0e482017-02-23 04:13:321438 return gpu_factories_.back().get();
Miguel Casas5e1018052018-01-09 19:17:361439
1440 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1441 GetMediaThreadTaskRunner();
1442 media_task_runner->PostTask(
1443 FROM_HERE,
1444 base::BindOnce(
1445 base::IgnoreResult(
1446 &GpuVideoAcceleratorFactoriesImpl::CheckContextLost),
1447 base::Unretained(gpu_factories_.back().get())));
dcastagna09bd6b32016-02-01 21:54:281448 }
1449 }
dcastagna7f45dada2015-10-19 20:17:351450
tobiasjsca238b3b2015-06-24 22:53:541451 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1452
danakj0b4b94e32016-05-10 22:33:011453 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
sadrul6d310fa2016-08-04 02:12:161454 EstablishGpuChannelSync();
danakj0b4b94e32016-05-10 22:33:011455 if (!gpu_channel_host)
1456 return nullptr;
danakj0dd9e1e2016-05-11 22:15:091457 // This context is only used to create textures and mailbox them, so
1458 // use lower limits than the default.
1459 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
danakj9a04adc2016-05-16 22:45:071460 bool support_locking = true;
Victor Miura3a4ad4f82017-12-13 06:03:451461 bool support_gles2_interface = true;
1462 bool support_raster_interface = false;
Adrienne Walker436a7752017-08-28 23:33:091463 bool support_oop_rasterization = false;
sadrul85cc5d82016-12-20 03:37:411464 scoped_refptr<ui::ContextProviderCommandBuffer> media_context_provider =
Antoine Labour5ac65db2017-12-19 18:02:581465 CreateOffscreenContext(
1466 gpu_channel_host, GetGpuMemoryBufferManager(), limits,
1467 support_locking, support_gles2_interface, support_raster_interface,
1468 support_oop_rasterization, ui::command_buffer_metrics::MEDIA_CONTEXT,
1469 kGpuStreamIdDefault, kGpuStreamPriorityDefault);
danakj45cfd232017-10-18 19:31:311470 auto result = media_context_provider->BindToCurrentThread();
1471 if (result != gpu::ContextResult::kSuccess)
danakj0b4b94e32016-05-10 22:33:011472 return nullptr;
danakj0b4b94e32016-05-10 22:33:011473
acolwellb4034942014-08-28 15:42:431474 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1475 GetMediaThreadTaskRunner();
danakj0b4b94e32016-05-10 22:33:011476 const bool enable_video_accelerator =
Zhenyao Mo16d39b82017-12-15 22:48:041477 !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
1478 (gpu_channel_host->gpu_feature_info()
1479 .status_values[gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE] ==
1480 gpu::kGpuFeatureStatusEnabled);
danakj0b4b94e32016-05-10 22:33:011481 const bool enable_gpu_memory_buffer_video_frames =
danakjab9ef4d2017-10-31 23:38:331482 !is_gpu_compositing_disabled_ &&
dcastagna43c3a86a2016-02-02 21:16:381483#if defined(OS_MACOSX) || defined(OS_LINUX)
danakjab9ef4d2017-10-31 23:38:331484 !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames);
jbaumana0bb8982017-05-05 19:50:531485#elif defined(OS_WIN)
1486 !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) &&
jbaumana0bb8982017-05-05 19:50:531487 (cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames) ||
1488 gpu_channel_host->gpu_info().supports_overlays);
dcastagnab65e6072015-09-05 07:18:421489#else
danakj0b4b94e32016-05-10 22:33:011490 cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames);
dcastagnab65e6072015-09-05 07:18:421491#endif
dcastagna5077d6d2016-01-27 00:07:051492
Miguel Casas-Sanchez7d464702017-07-29 14:19:211493 media::mojom::VideoEncodeAcceleratorProviderPtr vea_provider;
1494 gpu_->CreateVideoEncodeAcceleratorProvider(mojo::MakeRequest(&vea_provider));
Miguel Casas-Sanchezdaca32562017-07-11 08:05:451495
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:591496 gpu_factories_.push_back(GpuVideoAcceleratorFactoriesImpl::Create(
danakj0b4b94e32016-05-10 22:33:011497 std::move(gpu_channel_host), base::ThreadTaskRunnerHandle::Get(),
1498 media_task_runner, std::move(media_context_provider),
Victor Miuracabdfac2018-01-05 02:18:181499 enable_gpu_memory_buffer_video_frames, enable_video_accelerator,
1500 vea_provider.PassInterface()));
Miguel Casas5e1018052018-01-09 19:17:361501 gpu_factories_.back()->SetRenderingColorSpace(rendering_color_space_);
leon.han21e0e482017-02-23 04:13:321502 return gpu_factories_.back().get();
[email protected]3bb8bb32013-07-11 13:13:031503}
1504
sadrul85cc5d82016-12-20 03:37:411505scoped_refptr<ui::ContextProviderCommandBuffer>
[email protected]f10dc472013-09-27 03:31:591506RenderThreadImpl::SharedMainThreadContextProvider() {
[email protected]e06e1122013-03-15 17:12:381507 DCHECK(IsMainThread());
danakje8ec797e2016-04-19 04:08:431508 if (shared_main_thread_contexts_ &&
1509 shared_main_thread_contexts_->ContextGL()->GetGraphicsResetStatusKHR() ==
1510 GL_NO_ERROR)
1511 return shared_main_thread_contexts_;
1512
sadrul6d310fa2016-08-04 02:12:161513 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
1514 EstablishGpuChannelSync());
danakje8ec797e2016-04-19 04:08:431515 if (!gpu_channel_host) {
1516 shared_main_thread_contexts_ = nullptr;
1517 return nullptr;
[email protected]c29b7ff2013-03-06 03:51:041518 }
danakje8ec797e2016-04-19 04:08:431519
danakj9a04adc2016-05-16 22:45:071520 bool support_locking = false;
Victor Miura3a4ad4f82017-12-13 06:03:451521 bool support_gles2_interface = true;
Khushal60916ba2018-01-19 19:47:471522 bool support_raster_interface = true;
Adrienne Walker436a7752017-08-28 23:33:091523 bool support_oop_rasterization = false;
danakjc3983552016-05-03 00:04:351524 shared_main_thread_contexts_ = CreateOffscreenContext(
Antoine Labour5ac65db2017-12-19 18:02:581525 std::move(gpu_channel_host), GetGpuMemoryBufferManager(),
1526 gpu::SharedMemoryLimits(), support_locking, support_gles2_interface,
1527 support_raster_interface, support_oop_rasterization,
sadrul85cc5d82016-12-20 03:37:411528 ui::command_buffer_metrics::RENDERER_MAINTHREAD_CONTEXT,
sunnyps8f9139e2017-05-12 17:53:251529 kGpuStreamIdDefault, kGpuStreamPriorityDefault);
danakj45cfd232017-10-18 19:31:311530 auto result = shared_main_thread_contexts_->BindToCurrentThread();
1531 if (result != gpu::ContextResult::kSuccess)
danakje8ec797e2016-04-19 04:08:431532 shared_main_thread_contexts_ = nullptr;
[email protected]f10dc472013-09-27 03:31:591533 return shared_main_thread_contexts_;
[email protected]c29b7ff2013-03-06 03:51:041534}
1535
siva.gunturi5d4feb052015-11-15 16:15:311536#if defined(OS_ANDROID)
boliuf8753bf62016-02-11 20:09:421537
siva.gunturi5d4feb052015-11-15 16:15:311538scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() {
1539 DCHECK(IsMainThread());
boliu30f1b262016-04-19 00:12:331540 if (!stream_texture_factory_.get() ||
1541 stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() !=
1542 GL_NO_ERROR) {
sadrul85cc5d82016-12-20 03:37:411543 scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider =
piman9fc22f32016-05-02 22:21:221544 SharedMainThreadContextProvider();
1545 if (!shared_context_provider) {
penghuange1d86512016-07-08 18:15:001546 stream_texture_factory_ = nullptr;
1547 return nullptr;
siva.gunturi5d4feb052015-11-15 16:15:311548 }
piman9fc22f32016-05-02 22:21:221549 DCHECK(shared_context_provider->GetCommandBufferProxy());
1550 DCHECK(shared_context_provider->GetCommandBufferProxy()->channel());
1551 stream_texture_factory_ =
1552 StreamTextureFactory::Create(std::move(shared_context_provider));
siva.gunturi5d4feb052015-11-15 16:15:311553 }
1554 return stream_texture_factory_;
1555}
boliuf8753bf62016-02-11 20:09:421556
1557bool RenderThreadImpl::EnableStreamTextureCopy() {
boliu30f1b262016-04-19 00:12:331558 return sync_compositor_message_filter_.get();
boliuf8753bf62016-02-11 20:09:421559}
1560
siva.gunturi5d4feb052015-11-15 16:15:311561#endif
1562
[email protected]e9ff79c2012-10-19 21:31:261563AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]59383c782013-04-17 16:43:271564 if (!audio_renderer_mixer_manager_) {
olka7a4679392016-05-27 15:32:581565 audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create();
[email protected]3958e972012-07-17 00:25:411566 }
1567
1568 return audio_renderer_mixer_manager_.get();
1569}
1570
[email protected]73429ca2014-03-06 06:07:471571base::WaitableEvent* RenderThreadImpl::GetShutdownEvent() {
1572 return ChildProcess::current()->GetShutDownEvent();
1573}
1574
staraz067f58242016-11-07 21:06:411575int32_t RenderThreadImpl::GetClientId() {
1576 return client_id_;
1577}
1578
Karan Bhatiac89897f2017-08-10 01:06:401579void RenderThreadImpl::SetRendererProcessType(
1580 blink::scheduler::RendererProcessType type) {
1581 renderer_scheduler_->SetRendererProcessType(type);
1582}
1583
John Abd-El-Malek6b56ef712017-10-21 22:52:461584bool RenderThreadImpl::OnMessageReceived(const IPC::Message& msg) {
John Abd-El-Malekdcf1d1372017-10-22 06:39:411585 if (file_system_dispatcher_->OnMessageReceived(msg))
1586 return true;
John Abd-El-Malek6b56ef712017-10-21 22:52:461587 return ChildThreadImpl::OnMessageReceived(msg);
1588}
1589
rockot067ca55f2016-09-30 22:00:151590void RenderThreadImpl::OnAssociatedInterfaceRequest(
1591 const std::string& name,
1592 mojo::ScopedInterfaceEndpointHandle handle) {
rockot70bbb59492017-01-25 00:56:511593 if (associated_interfaces_.CanBindRequest(name))
1594 associated_interfaces_.BindRequest(name, std::move(handle));
1595 else
1596 ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle));
rockot067ca55f2016-09-30 22:00:151597}
1598
weilifabbf7572017-05-22 19:05:161599scoped_refptr<base::SingleThreadTaskRunner>
1600RenderThreadImpl::GetIOTaskRunner() {
1601 return ChildProcess::current()->io_task_runner();
1602}
1603
danakj6e3bf8012014-12-16 18:27:531604bool RenderThreadImpl::IsGpuRasterizationForced() {
1605 return is_gpu_rasterization_forced_;
1606}
1607
senorblancob60ba952015-01-27 19:12:361608int RenderThreadImpl::GetGpuRasterizationMSAASampleCount() {
1609 return gpu_rasterization_msaa_sample_count_;
1610}
1611
danakj6e3bf8012014-12-16 18:27:531612bool RenderThreadImpl::IsLcdTextEnabled() {
1613 return is_lcd_text_enabled_;
1614}
1615
1616bool RenderThreadImpl::IsDistanceFieldTextEnabled() {
1617 return is_distance_field_text_enabled_;
1618}
1619
1620bool RenderThreadImpl::IsZeroCopyEnabled() {
1621 return is_zero_copy_enabled_;
1622}
1623
ericrk1d17f752015-10-20 03:03:071624bool RenderThreadImpl::IsPartialRasterEnabled() {
1625 return is_partial_raster_enabled_;
jbroman5f7f71932015-08-18 16:24:461626}
1627
ccameronc7fcd132015-11-03 20:14:311628bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() {
1629 return is_gpu_memory_buffer_compositor_resources_enabled_;
1630}
1631
ccamerona7644752014-12-30 01:16:311632bool RenderThreadImpl::IsElasticOverscrollEnabled() {
1633 return is_elastic_overscroll_enabled_;
1634}
1635
danakj6e3bf8012014-12-16 18:27:531636scoped_refptr<base::SingleThreadTaskRunner>
1637RenderThreadImpl::GetCompositorMainThreadTaskRunner() {
1638 return main_thread_compositor_task_runner_;
1639}
1640
1641scoped_refptr<base::SingleThreadTaskRunner>
1642RenderThreadImpl::GetCompositorImplThreadTaskRunner() {
skyostil2d3b5bd2015-05-27 15:40:591643 return compositor_task_runner_;
danakj6e3bf8012014-12-16 18:27:531644}
1645
1646gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() {
sadrul53546592016-12-17 01:44:211647 return gpu_->gpu_memory_buffer_manager();
danakj6e3bf8012014-12-16 18:27:531648}
1649
skyostil529caa292016-08-10 17:44:511650blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() {
danakj6e3bf8012014-12-16 18:27:531651 return renderer_scheduler_.get();
1652}
1653
Fady Samuelc645ffe2017-07-24 17:28:201654std::unique_ptr<viz::BeginFrameSource>
danakj6e3bf8012014-12-16 18:27:531655RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) {
Jeremy Roman04f27c372017-10-27 15:20:551656 return std::make_unique<CompositorExternalBeginFrameSource>(
ricea29649b92016-08-31 09:30:211657 compositor_message_filter_.get(), sync_message_filter(), routing_id);
danakj6e3bf8012014-12-16 18:27:531658}
1659
Fady Samuelc645ffe2017-07-24 17:28:201660std::unique_ptr<viz::SyntheticBeginFrameSource>
samans09812d32017-03-27 19:51:501661RenderThreadImpl::CreateSyntheticBeginFrameSource() {
1662 base::SingleThreadTaskRunner* compositor_impl_side_task_runner =
1663 compositor_task_runner_ ? compositor_task_runner_.get()
1664 : base::ThreadTaskRunnerHandle::Get().get();
Jeremy Roman04f27c372017-10-27 15:20:551665 return std::make_unique<viz::BackToBackBeginFrameSource>(
1666 std::make_unique<viz::DelayBasedTimeSource>(
samans09812d32017-03-27 19:51:501667 compositor_impl_side_task_runner));
1668}
1669
reveman34b7a1522015-03-23 20:27:471670cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() {
prashant.nfad657e2016-06-01 07:52:171671 return categorized_worker_pool_->GetTaskGraphRunner();
reveman34b7a1522015-03-23 20:27:471672}
1673
loyso65c93c602015-08-11 05:15:571674bool RenderThreadImpl::IsThreadedAnimationEnabled() {
1675 return is_threaded_animation_enabled_;
1676}
1677
wjmaclean1d970622017-01-21 22:28:241678bool RenderThreadImpl::IsScrollAnimatorEnabled() {
1679 return is_scroll_animator_enabled_;
1680}
1681
Khushal3e96e662017-10-30 23:16:501682std::unique_ptr<cc::UkmRecorderFactory>
1683RenderThreadImpl::CreateUkmRecorderFactory() {
Khushalda50f8152017-12-01 09:04:401684 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1685 switches::kDisableCompositorUkmForTests)) {
1686 return nullptr;
1687 }
1688
1689 return std::make_unique<UkmRecorderFactoryImpl>(GetConnector()->Clone());
Khushal3e96e662017-10-30 23:16:501690}
1691
skyostila37c2a72016-06-29 17:30:071692void RenderThreadImpl::OnRAILModeChanged(v8::RAILMode rail_mode) {
Blink Reformat1c4d759e2017-04-09 16:34:541693 blink::MainThreadIsolate()->SetRAILMode(rail_mode);
1694 blink::SetRAILModeOnWorkerThreadIsolates(rail_mode);
skyostila37c2a72016-06-29 17:30:071695}
1696
[email protected]b3e83de2012-02-07 03:33:281697bool RenderThreadImpl::IsMainThread() {
1698 return !!current();
1699}
1700
torne88b66452016-05-03 13:22:141701void RenderThreadImpl::OnChannelError() {
1702 // In single-process mode, the renderer can't be restarted after shutdown.
1703 // So, if we get a channel error, crash the whole process right now to get a
1704 // more informative stack, since we will otherwise just crash later when we
1705 // try to restart it.
1706 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
1707 switches::kSingleProcess));
1708 ChildThreadImpl::OnChannelError();
1709}
1710
Nicholas Verne06de8122017-11-16 04:47:381711void RenderThreadImpl::OnProcessFinalRelease() {
1712 if (on_channel_error_called())
1713 return;
1714 // The child process shutdown sequence is a request response based mechanism,
1715 // where we send out an initial feeler request to the child process host
1716 // instance in the browser to verify if it's ok to shutdown the child process.
1717 // The browser then sends back a response if it's ok to shutdown. This avoids
1718 // race conditions if the process refcount is 0 but there's an IPC message
1719 // inflight that would addref it.
1720 GetRendererHost()->ShutdownRequest();
1721}
1722
[email protected]f1a29a02011-10-06 23:08:441723bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
dchenga2d442c22016-10-13 15:39:211724 for (auto& observer : observers_) {
1725 if (observer.OnControlMessageReceived(msg))
[email protected]1223d6ef2011-03-28 16:47:501726 return true;
1727 }
1728
[email protected]70c19a932010-05-14 12:59:111729 // Some messages are handled by delegates.
Nicholas Verne07e9c6452017-12-13 04:12:551730 if (dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281731 return true;
[email protected]1910fe82012-05-10 00:04:101732 }
Darin Fisherbcc33632017-09-26 00:57:161733 return false;
initial.commit09911bf2008-07-26 23:55:291734}
1735
Nicholas Verne5420564d2017-10-27 07:37:541736void RenderThreadImpl::SetProcessBackgrounded(bool backgrounded) {
1737 // Set timer slack to maximum on main thread when in background.
1738 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE;
1739 if (backgrounded)
1740 timer_slack = base::TIMER_SLACK_MAXIMUM;
1741 base::MessageLoop::current()->SetTimerSlack(timer_slack);
jdduke73220f02015-09-04 17:03:511742
Alexander Timin771b3372017-06-15 13:26:471743 renderer_scheduler_->SetRendererBackgrounded(backgrounded);
hajimehoshi69093272016-05-13 08:30:581744 if (backgrounded) {
tasakb95dbb50c2017-02-08 18:07:501745 needs_to_record_first_active_paint_ = false;
tasak335a1872017-06-14 09:50:231746 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1747 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061748 base::BindOnce(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1749 base::Unretained(this), "5min",
1750 process_foregrounded_count_),
tasak335a1872017-06-14 09:50:231751 base::TimeDelta::FromMinutes(5));
1752 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1753 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061754 base::BindOnce(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1755 base::Unretained(this), "10min",
1756 process_foregrounded_count_),
tasak335a1872017-06-14 09:50:231757 base::TimeDelta::FromMinutes(10));
1758 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1759 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061760 base::BindOnce(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1761 base::Unretained(this), "15min",
1762 process_foregrounded_count_),
tasak335a1872017-06-14 09:50:231763 base::TimeDelta::FromMinutes(15));
Takashi SAKAMOTO870f6262017-08-22 04:08:271764 was_backgrounded_time_ = base::TimeTicks::Now();
hajimehoshi69093272016-05-13 08:30:581765 } else {
tasakbb0640b2017-05-15 09:02:261766 process_foregrounded_count_++;
hajimehoshi69093272016-05-13 08:30:581767 }
1768}
1769
Nicholas Verne5420564d2017-10-27 07:37:541770void RenderThreadImpl::ProcessPurgeAndSuspend() {
tasak6ff44032016-11-07 06:45:251771 if (!RendererIsHidden())
hajimehoshi69093272016-05-13 08:30:581772 return;
tasakff1e62422016-12-22 04:53:551773
tasakc4de4672017-04-26 02:37:361774 if (!base::FeatureList::IsEnabled(features::kPurgeAndSuspend))
1775 return;
1776
1777 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
tasakb95dbb50c2017-02-08 18:07:501778 needs_to_record_first_active_paint_ = true;
tasakc4de4672017-04-26 02:37:361779
1780 RendererMemoryMetrics memory_metrics;
1781 if (!GetRendererMemoryMetrics(&memory_metrics))
1782 return;
1783
1784 purge_and_suspend_memory_metrics_ = memory_metrics;
tasaka27961a2017-05-24 07:33:251785 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1786 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061787 base::BindOnce(
1788 &RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1789 base::Unretained(this), "30min", process_foregrounded_count_),
tasaka27961a2017-05-24 07:33:251790 base::TimeDelta::FromMinutes(30));
1791 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1792 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061793 base::BindOnce(
1794 &RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1795 base::Unretained(this), "60min", process_foregrounded_count_),
tasaka27961a2017-05-24 07:33:251796 base::TimeDelta::FromMinutes(60));
1797 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1798 FROM_HERE,
tzikff2a81a2017-09-15 05:10:061799 base::BindOnce(
1800 &RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1801 base::Unretained(this), "90min", process_foregrounded_count_),
tasaka27961a2017-05-24 07:33:251802 base::TimeDelta::FromMinutes(90));
tasakb46626a2016-10-18 05:54:441803}
1804
bashia0ba0d42017-04-03 08:11:061805bool RenderThreadImpl::GetRendererMemoryMetrics(
keishi51ed0d52017-01-12 10:04:461806 RendererMemoryMetrics* memory_metrics) const {
1807 DCHECK(memory_metrics);
1808
chrisha05e94f22017-04-05 22:06:041809 // Cache this result, as it can change while this code is running, and is used
1810 // as a divisor below.
1811 size_t render_view_count = RenderView::GetRenderViewCount();
1812
1813 // If there are no render views it doesn't make sense to calculate metrics
1814 // right now.
1815 if (render_view_count == 0)
bashia0ba0d42017-04-03 08:11:061816 return false;
1817
keishi51ed0d52017-01-12 10:04:461818 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get();
1819 memory_metrics->partition_alloc_kb =
Blink Reformat1c4d759e2017-04-09 16:34:541820 blink_stats.partition_alloc_total_allocated_bytes / 1024;
1821 memory_metrics->blink_gc_kb =
1822 blink_stats.blink_gc_total_allocated_bytes / 1024;
keishi12b598b92017-06-20 10:25:261823 std::unique_ptr<base::ProcessMetrics> metric(
1824 base::ProcessMetrics::CreateCurrentProcessMetrics());
1825 size_t malloc_usage = metric->GetMallocUsage();
keishi51ed0d52017-01-12 10:04:461826 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024;
1827
1828 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics
1829 discardable_stats = discardable_shared_memory_manager_->GetStatistics();
1830 size_t discardable_usage =
1831 discardable_stats.total_size - discardable_stats.freelist_size;
1832 memory_metrics->discardable_kb = discardable_usage / 1024;
1833
1834 size_t v8_usage = 0;
Blink Reformat1c4d759e2017-04-09 16:34:541835 if (v8::Isolate* isolate = blink::MainThreadIsolate()) {
keishi51ed0d52017-01-12 10:04:461836 v8::HeapStatistics v8_heap_statistics;
1837 isolate->GetHeapStatistics(&v8_heap_statistics);
1838 v8_usage = v8_heap_statistics.total_heap_size();
1839 }
1840 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is
1841 // reported. We should collect memory usages of all isolates using
1842 // memory-infra.
1843 memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024;
Blink Reformat1c4d759e2017-04-09 16:34:541844 size_t total_allocated = blink_stats.partition_alloc_total_allocated_bytes +
1845 blink_stats.blink_gc_total_allocated_bytes +
keishi51ed0d52017-01-12 10:04:461846 malloc_usage + v8_usage + discardable_usage;
1847 memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024;
1848 memory_metrics->non_discardable_total_allocated_mb =
1849 (total_allocated - discardable_usage) / 1024 / 1024;
1850 memory_metrics->total_allocated_per_render_view_mb =
chrisha05e94f22017-04-05 22:06:041851 total_allocated / render_view_count / 1024 / 1024;
bashia0ba0d42017-04-03 08:11:061852
1853 return true;
keishi51ed0d52017-01-12 10:04:461854}
1855
tasak335a1872017-06-14 09:50:231856static void RecordMemoryUsageAfterBackgroundedMB(const char* basename,
1857 const char* suffix,
1858 int memory_usage) {
1859 std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix);
1860 base::UmaHistogramMemoryLargeMB(histogram_name, memory_usage);
1861}
1862
1863void RenderThreadImpl::RecordMemoryUsageAfterBackgrounded(
1864 const char* suffix,
1865 int foregrounded_count) {
1866 // If this renderer is resumed, we should not update UMA.
1867 if (!RendererIsHidden())
1868 return;
1869 // If this renderer was not kept backgrounded for 5/10/15 minutes,
1870 // we should not record current memory usage.
1871 if (foregrounded_count != process_foregrounded_count_)
1872 return;
1873
1874 RendererMemoryMetrics memory_metrics;
1875 if (!GetRendererMemoryMetrics(&memory_metrics))
1876 return;
1877 RecordMemoryUsageAfterBackgroundedMB(
1878 "Memory.Experimental.Renderer.PartitionAlloc.AfterBackgrounded", suffix,
1879 memory_metrics.partition_alloc_kb / 1024);
1880 RecordMemoryUsageAfterBackgroundedMB(
1881 "Memory.Experimental.Renderer.BlinkGC.AfterBackgrounded", suffix,
1882 memory_metrics.blink_gc_kb / 1024);
1883 RecordMemoryUsageAfterBackgroundedMB(
1884 "Memory.Experimental.Renderer.Malloc.AfterBackgrounded", suffix,
1885 memory_metrics.malloc_mb);
1886 RecordMemoryUsageAfterBackgroundedMB(
1887 "Memory.Experimental.Renderer.Discardable.AfterBackgrounded", suffix,
1888 memory_metrics.discardable_kb / 1024);
1889 RecordMemoryUsageAfterBackgroundedMB(
1890 "Memory.Experimental.Renderer.V8MainThreaIsolate.AfterBackgrounded",
1891 suffix, memory_metrics.v8_main_thread_isolate_mb);
1892 RecordMemoryUsageAfterBackgroundedMB(
1893 "Memory.Experimental.Renderer.TotalAllocated.AfterBackgrounded", suffix,
1894 memory_metrics.total_allocated_mb);
1895}
1896
tasak72f64042017-01-19 14:02:531897#define GET_MEMORY_GROWTH(current, previous, allocator) \
1898 (current.allocator > previous.allocator \
1899 ? current.allocator - previous.allocator \
1900 : 0)
1901
tasaka27961a2017-05-24 07:33:251902static void RecordPurgeAndSuspendMemoryGrowthKB(const char* basename,
1903 const char* suffix,
1904 int memory_usage) {
1905 std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix);
1906 base::UmaHistogramMemoryKB(histogram_name, memory_usage);
1907}
tasakbb0640b2017-05-15 09:02:261908
1909void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics(
1910 const char* suffix,
1911 int foregrounded_count_when_purged) {
tasak72f64042017-01-19 14:02:531912 // If this renderer is resumed, we should not update UMA.
1913 if (!RendererIsHidden())
1914 return;
tasakbb0640b2017-05-15 09:02:261915 if (foregrounded_count_when_purged != process_foregrounded_count_)
1916 return;
tasak72f64042017-01-19 14:02:531917
1918 RendererMemoryMetrics memory_metrics;
bashia0ba0d42017-04-03 08:11:061919 if (!GetRendererMemoryMetrics(&memory_metrics))
1920 return;
1921
tasaka27961a2017-05-24 07:33:251922 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261923 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix,
tasak72f64042017-01-19 14:02:531924 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1925 partition_alloc_kb));
tasaka27961a2017-05-24 07:33:251926 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261927 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix,
tasak72f64042017-01-19 14:02:531928 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1929 blink_gc_kb));
tasaka27961a2017-05-24 07:33:251930 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261931 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix,
tasak72f64042017-01-19 14:02:531932 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261933 malloc_mb) *
1934 1024);
tasaka27961a2017-05-24 07:33:251935 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261936 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix,
tasak72f64042017-01-19 14:02:531937 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1938 discardable_kb));
tasaka27961a2017-05-24 07:33:251939 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261940 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix,
tasak72f64042017-01-19 14:02:531941 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261942 v8_main_thread_isolate_mb) *
1943 1024);
tasaka27961a2017-05-24 07:33:251944 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261945 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix,
tasak72f64042017-01-19 14:02:531946 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261947 total_allocated_mb) *
1948 1024);
jdduke73220f02015-09-04 17:03:511949}
1950
danakjab9ef4d2017-10-31 23:38:331951void RenderThreadImpl::CompositingModeFallbackToSoftware() {
Antoine Labour7fcbc782017-11-14 16:59:581952 gpu_->LoseChannel();
danakjab9ef4d2017-10-31 23:38:331953 is_gpu_compositing_disabled_ = true;
1954}
1955
Bo Liud1ef1c32017-12-08 06:15:501956scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
[email protected]d13f35d2012-05-18 02:28:151957 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1958
Antoine Labour7fcbc782017-11-14 16:59:581959 scoped_refptr<gpu::GpuChannelHost> gpu_channel =
Bo Liud1ef1c32017-12-08 06:15:501960 gpu_->EstablishGpuChannelSync();
Antoine Labour7fcbc782017-11-14 16:59:581961 if (gpu_channel)
1962 GetContentClient()->SetGpuInfo(gpu_channel->gpu_info());
1963 return gpu_channel;
[email protected]3bf4d532010-03-27 00:23:341964}
1965
danakjc7afae52017-06-20 21:12:411966void RenderThreadImpl::RequestNewLayerTreeFrameSink(
danakj83066a32016-06-21 02:34:491967 int routing_id,
1968 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue,
fsamuelcf3002e2017-03-20 23:13:471969 const GURL& url,
danakjc7afae52017-06-20 21:12:411970 const LayerTreeFrameSinkCallback& callback) {
danakj946e3172017-11-06 23:46:511971 // Misconfigured bots (eg. crbug.com/780757) could run layout tests on a
1972 // machine where gpu compositing doesn't work. Don't crash in that case.
1973 if (layout_test_mode() && is_gpu_compositing_disabled_) {
1974 LOG(FATAL) << "Layout tests require gpu compositing, but it is disabled.";
1975 return;
1976 }
1977
danakj83066a32016-06-21 02:34:491978 const base::CommandLine& command_line =
1979 *base::CommandLine::ForCurrentProcess();
Xu Xing48e1b322017-09-25 10:48:011980 viz::ClientLayerTreeFrameSink::InitParams params;
Sunny Sachanandani158d26d2017-12-12 19:44:101981 params.compositor_task_runner = compositor_task_runner_;
Xu Xing48e1b322017-09-25 10:48:011982 params.enable_surface_synchronization =
Fady Samuel343a74952017-11-30 14:19:201983 features::IsSurfaceSynchronizationEnabled();
Xu Xing48e1b322017-09-25 10:48:011984 params.local_surface_id_provider =
Jeremy Roman04f27c372017-10-27 15:20:551985 std::make_unique<RendererLocalSurfaceIdProvider>();
Fady Samuel0c4b4bf2017-08-22 00:06:461986
Eric Seckler8af8c0e52018-01-17 23:45:531987 // The renderer runs animations and layout for animate_only BeginFrames.
1988 params.wants_animate_only_begin_frames = true;
1989
samans09812d32017-03-27 19:51:501990 // In disable gpu vsync mode, also let the renderer tick as fast as it
1991 // can. The top level begin frame source will also be running as a back
1992 // to back begin frame source, but using a synthetic begin frame source
1993 // here reduces latency when in this mode (at least for frames
1994 // starting--it potentially increases it for input on the other hand.)
samans09812d32017-03-27 19:51:501995 if (command_line.HasSwitch(switches::kDisableGpuVsync) &&
1996 command_line.GetSwitchValueASCII(switches::kDisableGpuVsync) != "gpu") {
Xu Xing48e1b322017-09-25 10:48:011997 params.synthetic_begin_frame_source = CreateSyntheticBeginFrameSource();
samans09812d32017-03-27 19:51:501998 }
1999
sadrul943e3b32016-08-04 18:22:592000#if defined(USE_AURA)
Sadrul Habib Chowdhuryeeb5a942017-11-28 21:17:232001 if (switches::IsMusHostingViz()) {
Scott Violet986ac472017-08-10 16:38:342002 if (!RendererWindowTreeClient::Get(routing_id)) {
2003 callback.Run(nullptr);
2004 return;
2005 }
Bo Liud1ef1c32017-12-08 06:15:502006 scoped_refptr<gpu::GpuChannelHost> channel = EstablishGpuChannelSync();
sadrulbe22c4f2017-03-14 06:59:252007 // If the channel could not be established correctly, then return null. This
2008 // would cause the compositor to wait and try again at a later time.
fsamuelcf3002e2017-03-20 23:13:472009 if (!channel) {
2010 callback.Run(nullptr);
2011 return;
2012 }
fsamuel95c974eb2017-03-22 10:00:252013 RendererWindowTreeClient::Get(routing_id)
danakjc7afae52017-06-20 21:12:412014 ->RequestLayerTreeFrameSink(
fsamuel95c974eb2017-03-22 10:00:252015 gpu_->CreateContextProvider(std::move(channel)),
2016 GetGpuMemoryBufferManager(), callback);
fsamuelcf3002e2017-03-20 23:13:472017 return;
danakj83066a32016-06-21 02:34:492018 }
2019#endif
2020
Gary Klassen4d0f0232017-07-27 23:23:122021 viz::mojom::CompositorFrameSinkRequest sink_request =
kylecharb82991b2017-10-04 22:40:082022 mojo::MakeRequest(&params.pipes.compositor_frame_sink_info);
Gary Klassen4d0f0232017-07-27 23:23:122023 viz::mojom::CompositorFrameSinkClientPtr client;
kylecharb82991b2017-10-04 22:40:082024 params.pipes.client_request = mojo::MakeRequest(&client);
samansa61ab212017-05-24 12:11:432025
danakj83066a32016-06-21 02:34:492026 if (command_line.HasSwitch(switches::kEnableVulkan)) {
Alex Zhang1f159572017-08-23 20:14:202027 scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider =
2028 viz::VulkanInProcessContextProvider::Create();
danakj83066a32016-06-21 02:34:492029 if (vulkan_context_provider) {
2030 DCHECK(!layout_test_mode());
samansa61ab212017-05-24 12:11:432031 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
2032 std::move(client));
Jeremy Roman04f27c372017-10-27 15:20:552033 callback.Run(std::make_unique<viz::ClientLayerTreeFrameSink>(
Xu Xing48e1b322017-09-25 10:48:012034 std::move(vulkan_context_provider), &params));
fsamuelcf3002e2017-03-20 23:13:472035 return;
danakj83066a32016-06-21 02:34:492036 }
2037 }
2038
danakjab9ef4d2017-10-31 23:38:332039 if (is_gpu_compositing_disabled_) {
danakj83066a32016-06-21 02:34:492040 DCHECK(!layout_test_mode());
samansa61ab212017-05-24 12:11:432041 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
2042 std::move(client));
Xu Xing48e1b322017-09-25 10:48:012043 params.shared_bitmap_manager = shared_bitmap_manager();
Jeremy Roman04f27c372017-10-27 15:20:552044 callback.Run(std::make_unique<viz::ClientLayerTreeFrameSink>(
Xu Xing48e1b322017-09-25 10:48:012045 nullptr, nullptr, &params));
fsamuelcf3002e2017-03-20 23:13:472046 return;
danakj83066a32016-06-21 02:34:492047 }
2048
danakjab9ef4d2017-10-31 23:38:332049 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
Bo Liud1ef1c32017-12-08 06:15:502050 EstablishGpuChannelSync();
danakjab9ef4d2017-10-31 23:38:332051 if (!gpu_channel_host) {
2052 // Wait and try again. We may hear that the compositing mode has switched
2053 // to software in the meantime.
2054 callback.Run(nullptr);
2055 return;
2056 }
2057
Victor Miuraff6488612017-12-21 04:16:152058 scoped_refptr<viz::RasterContextProvider> worker_context_provider =
danakj83066a32016-06-21 02:34:492059 SharedCompositorWorkerContextProvider();
2060 if (!worker_context_provider) {
2061 // Cause the compositor to wait and try again.
fsamuelcf3002e2017-03-20 23:13:472062 callback.Run(nullptr);
2063 return;
danakj83066a32016-06-21 02:34:492064 }
2065
2066 // The renderer compositor context doesn't do a lot of stuff, so we don't
2067 // expect it to need a lot of space for commands or transfer. Raster and
2068 // uploads happen on the worker context instead.
2069 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
2070
2071 // This is for an offscreen context for the compositor. So the default
2072 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
Antoine Labourfeab2392017-12-21 20:28:392073 gpu::ContextCreationAttribs attributes;
danakj83066a32016-06-21 02:34:492074 attributes.alpha_size = -1;
2075 attributes.depth_size = 0;
2076 attributes.stencil_size = 0;
2077 attributes.samples = 0;
2078 attributes.sample_buffers = 0;
2079 attributes.bind_generates_resource = false;
2080 attributes.lose_context_when_out_of_memory = true;
Victor Miura3a4ad4f82017-12-13 06:03:452081 attributes.enable_gles2_interface = true;
2082 attributes.enable_raster_interface = false;
2083 attributes.enable_oop_rasterization = false;
danakj83066a32016-06-21 02:34:492084
2085 constexpr bool automatic_flushes = false;
2086 constexpr bool support_locking = false;
2087
sadrul85cc5d82016-12-20 03:37:412088 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider(
2089 new ui::ContextProviderCommandBuffer(
Antoine Labour5ac65db2017-12-19 18:02:582090 gpu_channel_host, GetGpuMemoryBufferManager(), kGpuStreamIdDefault,
2091 kGpuStreamPriorityDefault, gpu::kNullSurfaceHandle, url,
Victor Miuraff6488612017-12-21 04:16:152092 automatic_flushes, support_locking, limits, attributes,
2093 nullptr /* share_context */,
sadrul85cc5d82016-12-20 03:37:412094 ui::command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT));
danakj83066a32016-06-21 02:34:492095
danakj83066a32016-06-21 02:34:492096 if (layout_test_deps_) {
danakjc7afae52017-06-20 21:12:412097 callback.Run(layout_test_deps_->CreateLayerTreeFrameSink(
jbroman6ccbc7d472016-07-27 04:45:412098 routing_id, std::move(gpu_channel_host), std::move(context_provider),
fsamuelcf3002e2017-03-20 23:13:472099 std::move(worker_context_provider), GetGpuMemoryBufferManager(), this));
2100 return;
danakj83066a32016-06-21 02:34:492101 }
2102
2103#if defined(OS_ANDROID)
2104 if (sync_compositor_message_filter_) {
Fady Samuelc645ffe2017-07-24 17:28:202105 std::unique_ptr<viz::BeginFrameSource> begin_frame_source =
Xu Xing48e1b322017-09-25 10:48:012106 params.synthetic_begin_frame_source
2107 ? std::move(params.synthetic_begin_frame_source)
samans09812d32017-03-27 19:51:502108 : CreateExternalBeginFrameSource(routing_id);
Jeremy Roman04f27c372017-10-27 15:20:552109 callback.Run(std::make_unique<SynchronousLayerTreeFrameSink>(
danakja40dd4482016-06-28 01:14:102110 std::move(context_provider), std::move(worker_context_provider),
danakja2b002952017-12-14 22:36:222111 compositor_task_runner_, GetGpuMemoryBufferManager(), routing_id,
2112 g_next_layer_tree_frame_sink_id++, std::move(begin_frame_source),
2113 sync_compositor_message_filter_.get(),
fsamuelcf3002e2017-03-20 23:13:472114 std::move(frame_swap_message_queue)));
2115 return;
danakj83066a32016-06-21 02:34:492116 }
2117#endif
samansa61ab212017-05-24 12:11:432118 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
2119 std::move(client));
Xu Xing48e1b322017-09-25 10:48:012120 params.gpu_memory_buffer_manager = GetGpuMemoryBufferManager();
Jeremy Roman04f27c372017-10-27 15:20:552121 callback.Run(std::make_unique<viz::ClientLayerTreeFrameSink>(
samans2040988b2017-04-11 23:58:352122 std::move(context_provider), std::move(worker_context_provider),
Xu Xing48e1b322017-09-25 10:48:012123 &params));
danakj83066a32016-06-21 02:34:492124}
2125
Sam McNally52e50282017-11-29 00:54:022126blink::AssociatedInterfaceRegistry*
rockot067ca55f2016-09-30 22:00:152127RenderThreadImpl::GetAssociatedInterfaceRegistry() {
2128 return &associated_interfaces_;
2129}
2130
jbroman6ccbc7d472016-07-27 04:45:412131std::unique_ptr<cc::SwapPromise>
2132RenderThreadImpl::RequestCopyOfOutputForLayoutTest(
2133 int32_t routing_id,
Fady Samueldfecb7d2017-07-26 11:41:042134 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:412135 DCHECK(layout_test_deps_);
2136 return layout_test_deps_->RequestCopyOfOutput(routing_id, std::move(request));
2137}
2138
altimineb6bd1962017-05-03 14:52:382139std::unique_ptr<blink::WebMediaStreamCenter>
2140RenderThreadImpl::CreateMediaStreamCenter(
[email protected]180ef242013-11-07 06:50:462141 blink::WebMediaStreamCenterClient* client) {
altimineb6bd1962017-05-03 14:52:382142 std::unique_ptr<blink::WebMediaStreamCenter> media_stream_center;
Brett Wilson0748bf412016-11-22 17:55:462143#if BUILDFLAG(ENABLE_WEBRTC)
altimineb6bd1962017-05-03 14:52:382144 if (!media_stream_center) {
Harald Alvestrand4931caa2017-11-08 16:53:352145 media_stream_center = std::make_unique<MediaStreamCenter>(
2146 client, GetPeerConnectionDependencyFactory());
[email protected]68e5fee2013-02-18 10:04:222147 }
[email protected]d8cd8372012-03-09 10:49:512148#endif
altimineb6bd1962017-05-03 14:52:382149 return media_stream_center;
[email protected]d8cd8372012-03-09 10:49:512150}
2151
Brett Wilson0748bf412016-11-22 17:55:462152#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]0107d8a2014-05-16 10:20:342153PeerConnectionDependencyFactory*
2154RenderThreadImpl::GetPeerConnectionDependencyFactory() {
[email protected]83e0a482014-05-22 18:07:182155 return peer_connection_factory_.get();
[email protected]6ee10bd2012-09-13 09:01:532156}
[email protected]22fe91d2014-08-12 17:07:122157#endif
[email protected]6ee10bd2012-09-13 09:01:532158
rockot1587e332016-07-27 17:44:142159mojom::RenderFrameMessageFilter*
2160RenderThreadImpl::render_frame_message_filter() {
2161 if (!render_frame_message_filter_)
2162 GetChannel()->GetRemoteAssociatedInterface(&render_frame_message_filter_);
2163 return render_frame_message_filter_.get();
2164}
2165
rockote261d2112016-09-21 22:22:232166mojom::RenderMessageFilter* RenderThreadImpl::render_message_filter() {
2167 if (!render_message_filter_)
2168 GetChannel()->GetRemoteAssociatedInterface(&render_message_filter_);
2169 return render_message_filter_.get();
2170}
2171
penghuang346a46f92016-03-31 21:37:522172gpu::GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
Antoine Labour7fcbc782017-11-14 16:59:582173 return gpu_->GetGpuChannel().get();
[email protected]6217d392010-03-25 22:08:352174}
2175
rockot067ca55f2016-09-30 22:00:152176void RenderThreadImpl::CreateView(mojom::CreateViewParamsPtr params) {
2177 CompositorDependencies* compositor_deps = this;
wjmaclean1d970622017-01-21 22:28:242178 is_scroll_animator_enabled_ = params->web_preferences.enable_scroll_animator;
rockot067ca55f2016-09-30 22:00:152179 // When bringing in render_view, also bring in webkit's glue and jsbindings.
Balazs Engedyba034e72017-10-27 22:26:282180 RenderViewImpl::Create(compositor_deps, std::move(params),
Hajime Hoshiabb3c8f2017-12-04 18:41:392181 RenderWidget::ShowCallback(),
2182 GetRendererScheduler()->DefaultTaskRunner());
rockot067ca55f2016-09-30 22:00:152183}
2184
rockot53be7caf2016-10-04 20:17:082185void RenderThreadImpl::CreateFrame(mojom::CreateFrameParamsPtr params) {
rockot53be7caf2016-10-04 20:17:082186 CompositorDependencies* compositor_deps = this;
Ken Rockot26efbd62017-11-16 04:39:492187 service_manager::mojom::InterfaceProviderPtr interface_provider(
2188 std::move(params->interface_provider));
rockot53be7caf2016-10-04 20:17:082189 RenderFrameImpl::CreateFrame(
Ken Rockot26efbd62017-11-16 04:39:492190 params->routing_id, std::move(interface_provider),
Balazs Engedyba034e72017-10-27 22:26:282191 params->proxy_routing_id, params->opener_routing_id,
rockot53be7caf2016-10-04 20:17:082192 params->parent_routing_id, params->previous_sibling_routing_id,
Pavel Feldman25234722017-10-11 02:49:062193 params->devtools_frame_token, params->replication_state, compositor_deps,
Daniel Chenge0555e192018-01-18 20:00:052194 *params->widget_params, params->frame_owner_properties,
2195 params->has_committed_real_load);
rockot53be7caf2016-10-04 20:17:082196}
2197
Makoto Shimazu7af43ee2017-08-25 10:20:402198void RenderThreadImpl::SetUpEmbeddedWorkerChannelForServiceWorker(
2199 mojom::EmbeddedWorkerInstanceClientAssociatedRequest client_request) {
2200 EmbeddedWorkerInstanceClientImpl::Create(
2201 blink_initialized_time_, GetIOTaskRunner(), std::move(client_request));
2202}
2203
rockot53be7caf2016-10-04 20:17:082204void RenderThreadImpl::CreateFrameProxy(
2205 int32_t routing_id,
2206 int32_t render_view_routing_id,
2207 int32_t opener_routing_id,
2208 int32_t parent_routing_id,
2209 const FrameReplicationState& replicated_state) {
nick3b5a21f2016-11-22 23:07:112210 RenderFrameProxy::CreateFrameProxy(
2211 routing_id, render_view_routing_id,
2212 RenderFrameImpl::ResolveOpener(opener_routing_id), parent_routing_id,
2213 replicated_state);
rockot53be7caf2016-10-04 20:17:082214}
2215
rockota2db0da2016-10-18 17:39:112216void RenderThreadImpl::OnNetworkConnectionChanged(
2217 net::NetworkChangeNotifier::ConnectionType type,
2218 double max_bandwidth_mbps) {
2219 bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE;
Blink Reformat1c4d759e2017-04-09 16:34:542220 WebNetworkStateNotifier::SetOnLine(online);
rockota2db0da2016-10-18 17:39:112221 for (auto& observer : observers_)
2222 observer.NetworkStateChanged(online);
Blink Reformat1c4d759e2017-04-09 16:34:542223 WebNetworkStateNotifier::SetWebConnection(
rockota2db0da2016-10-18 17:39:112224 NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps);
2225}
2226
tbansal15973c32017-05-10 18:40:442227void RenderThreadImpl::OnNetworkQualityChanged(
tbansalb612c5d2017-05-25 18:53:062228 net::EffectiveConnectionType type,
tbansal99d8aeb2017-05-22 19:12:582229 base::TimeDelta http_rtt,
2230 base::TimeDelta transport_rtt,
tbansal15973c32017-05-10 18:40:442231 double downlink_throughput_kbps) {
2232 UMA_HISTOGRAM_BOOLEAN("NQE.RenderThreadNotified", true);
tbansalb612c5d2017-05-25 18:53:062233 WebNetworkStateNotifier::SetNetworkQuality(
2234 EffectiveConnectionTypeToWebEffectiveConnectionType(type), http_rtt,
2235 transport_rtt, downlink_throughput_kbps);
tbansal15973c32017-05-10 18:40:442236}
2237
rockota2db0da2016-10-18 17:39:112238void RenderThreadImpl::SetWebKitSharedTimersSuspended(bool suspend) {
2239#if defined(OS_ANDROID)
2240 if (suspend) {
Alexander Timin4b6152232017-10-17 20:34:062241 renderer_scheduler_->PauseTimersForAndroidWebView();
rockota2db0da2016-10-18 17:39:112242 } else {
Alexander Timin4b6152232017-10-17 20:34:062243 renderer_scheduler_->ResumeTimersForAndroidWebView();
rockota2db0da2016-10-18 17:39:112244 }
Alexander Timin4b6152232017-10-17 20:34:062245 webkit_shared_timer_suspended_ = suspend;
rockota2db0da2016-10-18 17:39:112246#else
2247 NOTREACHED();
2248#endif
2249}
2250
2251void RenderThreadImpl::UpdateScrollbarTheme(
2252 mojom::UpdateScrollbarThemeParamsPtr params) {
2253#if defined(OS_MACOSX)
2254 static_cast<WebScrollbarBehaviorImpl*>(
Blink Reformat1c4d759e2017-04-09 16:34:542255 blink_platform_impl_->ScrollbarBehavior())
rockota2db0da2016-10-18 17:39:112256 ->set_jump_on_track_click(params->jump_on_track_click);
2257
Blink Reformat1c4d759e2017-04-09 16:34:542258 blink::WebScrollbarTheme::UpdateScrollbarsWithNSDefaults(
rockota2db0da2016-10-18 17:39:112259 params->initial_button_delay, params->autoscroll_button_delay,
2260 params->preferred_scroller_style, params->redraw,
2261 params->button_placement);
Greg Kerra7b943b2017-07-24 23:17:172262
2263 is_elastic_overscroll_enabled_ = params->scroll_view_rubber_banding;
rockota2db0da2016-10-18 17:39:112264#else
2265 NOTREACHED();
2266#endif
2267}
2268
2269void RenderThreadImpl::OnSystemColorsChanged(
2270 int32_t aqua_color_variant,
2271 const std::string& highlight_text_color,
2272 const std::string& highlight_color) {
2273#if defined(OS_MACOSX)
2274 SystemColorsDidChange(aqua_color_variant, highlight_text_color,
2275 highlight_color);
2276#else
2277 NOTREACHED();
2278#endif
2279}
2280
2281void RenderThreadImpl::PurgePluginListCache(bool reload_pages) {
brettw4b461082016-11-19 18:55:162282#if BUILDFLAG(ENABLE_PLUGINS)
rockota2db0da2016-10-18 17:39:112283 // The call below will cause a GetPlugins call with refresh=true, but at this
2284 // point we already know that the browser has refreshed its list, so disable
2285 // refresh temporarily to prevent each renderer process causing the list to be
2286 // regenerated.
2287 blink_platform_impl_->set_plugin_refresh_allowed(false);
Blink Reformat1c4d759e2017-04-09 16:34:542288 blink::ResetPluginCache(reload_pages);
rockota2db0da2016-10-18 17:39:112289 blink_platform_impl_->set_plugin_refresh_allowed(true);
2290
2291 for (auto& observer : observers_)
2292 observer.PluginListChanged();
2293#else
2294 NOTREACHED();
2295#endif
2296}
2297
[email protected]5071cb22013-07-10 02:19:062298void RenderThreadImpl::OnMemoryPressure(
2299 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
kylecharb82991b2017-10-04 22:40:082300 TRACE_EVENT0("memory", "RenderThreadImpl::OnMemoryPressure");
rmcilroy7fbb3bd52015-02-17 19:02:142301 if (blink_platform_impl_) {
Blink Reformat1c4d759e2017-04-09 16:34:542302 blink::WebMemoryCoordinator::OnMemoryPressure(
bashic577bfc2016-01-08 03:42:352303 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
hajimehoshi7bb39582016-10-12 04:30:572304 }
2305 if (memory_pressure_level ==
2306 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
2307 ReleaseFreeMemory();
2308 ClearMemory();
2309 }
2310}
rmcilroyab967c972015-02-17 23:15:002311
hajimehoshi7bb39582016-10-12 04:30:572312void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
hajimehoshi7bb39582016-10-12 04:30:572313 if (blink_platform_impl_) {
Blink Reformat1c4d759e2017-04-09 16:34:542314 blink::WebMemoryCoordinator::OnMemoryStateChange(
hajimehoshi7bb39582016-10-12 04:30:572315 static_cast<blink::MemoryState>(state));
2316 }
bashi233f65e2017-02-09 08:36:032317}
2318
2319void RenderThreadImpl::OnPurgeMemory() {
bashib9058f282017-03-30 01:55:242320 // Record amount of purged memory after 2 seconds. 2 seconds is arbitrary
2321 // but it works most cases.
2322 RendererMemoryMetrics metrics;
bashia0ba0d42017-04-03 08:11:062323 if (!GetRendererMemoryMetrics(&metrics))
2324 return;
2325
bashib9058f282017-03-30 01:55:242326 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
2327 FROM_HERE,
tzikff2a81a2017-09-15 05:10:062328 base::BindOnce(&RenderThreadImpl::RecordPurgeMemory,
2329 base::Unretained(this), std::move(metrics)),
bashib9058f282017-03-30 01:55:242330 base::TimeDelta::FromSeconds(2));
2331
bashi233f65e2017-02-09 08:36:032332 OnTrimMemoryImmediately();
2333 ReleaseFreeMemory();
2334 ClearMemory();
2335 if (blink_platform_impl_)
Blink Reformat1c4d759e2017-04-09 16:34:542336 blink::WebMemoryCoordinator::OnPurgeMemory();
hajimehoshi7bb39582016-10-12 04:30:572337}
2338
bashib9058f282017-03-30 01:55:242339void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
2340 RendererMemoryMetrics after;
bashia0ba0d42017-04-03 08:11:062341 if (!GetRendererMemoryMetrics(&after))
2342 return;
bashib9058f282017-03-30 01:55:242343 int64_t mbytes = static_cast<int64_t>(before.total_allocated_mb) -
2344 static_cast<int64_t>(after.total_allocated_mb);
2345 if (mbytes < 0)
2346 mbytes = 0;
2347 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer.PurgedMemory",
2348 mbytes);
2349}
2350
hajimehoshi7bb39582016-10-12 04:30:572351void RenderThreadImpl::ClearMemory() {
2352 // Do not call into blink if it is not initialized.
2353 if (blink_platform_impl_) {
2354 // Purge Skia font cache, by setting it to 0 and then again to the
2355 // previous limit.
2356 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2357 SkGraphics::SetFontCacheLimit(font_cache_limit);
rmcilroy7fbb3bd52015-02-17 19:02:142358 }
[email protected]5071cb22013-07-10 02:19:062359}
2360
Marijn Kruisselbrink8c276412017-07-29 06:11:212361scoped_refptr<base::TaskRunner> RenderThreadImpl::GetFileThreadTaskRunner() {
2362 return blink_platform_impl_->BaseFileTaskRunner();
[email protected]c6a7b862010-08-20 22:19:382363}
[email protected]e9ff79c2012-10-19 21:31:262364
acolwellb4034942014-08-28 15:42:432365scoped_refptr<base::SingleThreadTaskRunner>
2366RenderThreadImpl::GetMediaThreadTaskRunner() {
fdoraye94d8642016-07-07 19:19:012367 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
[email protected]c1330c82013-06-06 02:23:252368 if (!media_thread_) {
2369 media_thread_.reset(new base::Thread("Media"));
2370 media_thread_->Start();
2371 }
skyostil2d3b5bd2015-05-27 15:40:592372 return media_thread_->task_runner();
[email protected]c1330c82013-06-06 02:23:252373}
2374
dcastagna4517a182015-08-05 19:51:032375base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() {
prashant.nfad657e2016-06-01 07:52:172376 return categorized_worker_pool_.get();
dcastagnab880e8f2015-06-30 20:16:062377}
2378
Victor Miuraff6488612017-12-21 04:16:152379scoped_refptr<viz::RasterContextProvider>
danakj0b4b94e32016-05-10 22:33:012380RenderThreadImpl::SharedCompositorWorkerContextProvider() {
revemand180dfc32015-09-24 00:19:432381 DCHECK(IsMainThread());
2382 // Try to reuse existing shared worker context provider.
revemand180dfc32015-09-24 00:19:432383 if (shared_worker_context_provider_) {
2384 // Note: If context is lost, delete reference after releasing the lock.
Victor Miura29b7ea3d2017-12-19 20:23:592385 viz::RasterContextProvider::ScopedRasterContextLock lock(
boliu11afa7e2016-04-18 18:04:142386 shared_worker_context_provider_.get());
Victor Miura29b7ea3d2017-12-19 20:23:592387 if (lock.RasterInterface()->GetGraphicsResetStatusKHR() == GL_NO_ERROR)
danakje8ec797e2016-04-19 04:08:432388 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432389 }
danakje8ec797e2016-04-19 04:08:432390
sadrul6d310fa2016-08-04 02:12:162391 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
2392 EstablishGpuChannelSync());
danakje8ec797e2016-04-19 04:08:432393 if (!gpu_channel_host) {
2394 shared_worker_context_provider_ = nullptr;
2395 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432396 }
danakje8ec797e2016-04-19 04:08:432397
danakj9a04adc2016-05-16 22:45:072398 bool support_locking = true;
Adrienne Walker436a7752017-08-28 23:33:092399 bool support_oop_rasterization =
2400 base::CommandLine::ForCurrentProcess()->HasSwitch(
2401 switches::kEnableOOPRasterization);
Victor Miuraff6488612017-12-21 04:16:152402 bool support_gles2_interface = false;
Victor Miura3a4ad4f82017-12-13 06:03:452403 bool support_raster_interface = true;
danakj0dd9e1e2016-05-11 22:15:092404 shared_worker_context_provider_ = CreateOffscreenContext(
Antoine Labour5ac65db2017-12-19 18:02:582405 std::move(gpu_channel_host), GetGpuMemoryBufferManager(),
2406 gpu::SharedMemoryLimits(), support_locking, support_gles2_interface,
2407 support_raster_interface, support_oop_rasterization,
Victor Miuraff6488612017-12-21 04:16:152408 ui::command_buffer_metrics::RENDER_WORKER_CONTEXT, kGpuStreamIdWorker,
2409 kGpuStreamPriorityWorker);
danakj45cfd232017-10-18 19:31:312410 auto result = shared_worker_context_provider_->BindToCurrentThread();
2411 if (result != gpu::ContextResult::kSuccess)
danakje8ec797e2016-04-19 04:08:432412 shared_worker_context_provider_ = nullptr;
revemand180dfc32015-09-24 00:19:432413 return shared_worker_context_provider_;
2414}
2415
juncai2f298a82017-04-18 03:51:392416void RenderThreadImpl::SampleGamepads(device::Gamepads* data) {
Blink Reformat1c4d759e2017-04-09 16:34:542417 blink_platform_impl_->SampleGamepads(*data);
[email protected]0ff736562014-05-09 09:09:472418}
2419
rmcilroyaa296052015-04-14 15:35:272420bool RenderThreadImpl::RendererIsHidden() const {
2421 return widget_count_ > 0 && hidden_widget_count_ == widget_count_;
2422}
2423
[email protected]b2db9272014-01-10 17:42:002424void RenderThreadImpl::WidgetCreated() {
rmcilroyaa296052015-04-14 15:35:272425 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002426 widget_count_++;
rmcilroyaa296052015-04-14 15:35:272427 if (renderer_was_hidden)
2428 OnRendererVisible();
[email protected]b2db9272014-01-10 17:42:002429}
2430
2431void RenderThreadImpl::WidgetDestroyed() {
rmcilroyaa296052015-04-14 15:35:272432 // TODO(rmcilroy): Remove the restriction that destroyed widgets must be
2433 // unhidden before WidgetDestroyed is called.
2434 DCHECK_GT(widget_count_, 0);
2435 DCHECK_GT(widget_count_, hidden_widget_count_);
[email protected]b2db9272014-01-10 17:42:002436 widget_count_--;
rmcilroyaa296052015-04-14 15:35:272437 if (RendererIsHidden())
2438 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002439}
2440
2441void RenderThreadImpl::WidgetHidden() {
2442 DCHECK_LT(hidden_widget_count_, widget_count_);
2443 hidden_widget_count_++;
rmcilroyaa296052015-04-14 15:35:272444 if (RendererIsHidden())
2445 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002446}
2447
2448void RenderThreadImpl::WidgetRestored() {
rmcilroyaa296052015-04-14 15:35:272449 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002450 DCHECK_GT(hidden_widget_count_, 0);
2451 hidden_widget_count_--;
rmcilroyaa296052015-04-14 15:35:272452 if (renderer_was_hidden)
2453 OnRendererVisible();
2454}
[email protected]b2db9272014-01-10 17:42:002455
rmcilroyaa296052015-04-14 15:35:272456void RenderThreadImpl::OnRendererHidden() {
Blink Reformat1c4d759e2017-04-09 16:34:542457 blink::MainThreadIsolate()->IsolateInBackgroundNotification();
rmcilroyaa296052015-04-14 15:35:272458 // TODO(rmcilroy): Remove IdleHandler and replace it with an IdleTask
2459 // scheduled by the RendererScheduler - http://crbug.com/469210.
ulan4a385192015-11-11 10:59:182460 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
2461 return;
Alexander Timin771b3372017-06-15 13:26:472462 renderer_scheduler_->SetRendererHidden(true);
ulan4a385192015-11-11 10:59:182463 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
rmcilroyaa296052015-04-14 15:35:272464}
2465
2466void RenderThreadImpl::OnRendererVisible() {
Blink Reformat1c4d759e2017-04-09 16:34:542467 blink::MainThreadIsolate()->IsolateInForegroundNotification();
rmcilroyaa296052015-04-14 15:35:272468 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]b2db9272014-01-10 17:42:002469 return;
Alexander Timin771b3372017-06-15 13:26:472470 renderer_scheduler_->SetRendererHidden(false);
[email protected]b2db9272014-01-10 17:42:002471 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
2472}
2473
ssid0603ca9f2015-06-09 16:48:082474void RenderThreadImpl::ReleaseFreeMemory() {
2475 base::allocator::ReleaseFreeMemory();
penghuang342762b2016-12-02 21:04:582476 discardable_shared_memory_manager_->ReleaseFreeMemory();
ssid0603ca9f2015-06-09 16:48:082477
2478 if (blink_platform_impl_)
Blink Reformat1c4d759e2017-04-09 16:34:542479 blink::DecommitFreeableMemory();
ssid0603ca9f2015-06-09 16:48:082480}
2481
ben76f52b242016-06-18 05:42:482482RenderThreadImpl::PendingFrameCreate::PendingFrameCreate(
benf28ce882017-05-02 16:15:492483 const service_manager::BindSourceInfo& browser_info,
rockotf8fdd9b2015-12-16 22:22:352484 int routing_id,
Balazs Engedyba034e72017-10-27 22:26:282485 mojom::FrameRequest frame_request)
benf28ce882017-05-02 16:15:492486 : browser_info_(browser_info),
2487 routing_id_(routing_id),
Balazs Engedyba034e72017-10-27 22:26:282488 frame_request_(std::move(frame_request)) {}
rockotf8fdd9b2015-12-16 22:22:352489
ben76f52b242016-06-18 05:42:482490RenderThreadImpl::PendingFrameCreate::~PendingFrameCreate() {
rockotf8fdd9b2015-12-16 22:22:352491}
2492
ben76f52b242016-06-18 05:42:482493void RenderThreadImpl::PendingFrameCreate::OnConnectionError() {
rockotf8fdd9b2015-12-16 22:22:352494 size_t erased =
ben76f52b242016-06-18 05:42:482495 RenderThreadImpl::current()->pending_frame_creates_.erase(routing_id_);
rockotf8fdd9b2015-12-16 22:22:352496 DCHECK_EQ(1u, erased);
2497}
2498
hong.zhengb28b5332016-05-11 02:33:392499void RenderThreadImpl::OnSyncMemoryPressure(
2500 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
Blink Reformat1c4d759e2017-04-09 16:34:542501 if (!blink::MainThreadIsolate())
hong.zhengb28b5332016-05-11 02:33:392502 return;
2503
2504 v8::MemoryPressureLevel v8_memory_pressure_level =
2505 static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
2506
Luke Halliwell16136de2017-07-05 21:15:562507#if !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND)
hong.zhengb28b5332016-05-11 02:33:392508 // In order to reduce performance impact, translate critical level to
Luke Halliwell16136de2017-07-05 21:15:562509 // moderate level for foreground renderer.
hong.zhengb28b5332016-05-11 02:33:392510 if (!RendererIsHidden() &&
2511 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
2512 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
Luke Halliwell16136de2017-07-05 21:15:562513#endif // !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND)
hong.zhengb28b5332016-05-11 02:33:392514
Blink Reformat1c4d759e2017-04-09 16:34:542515 blink::MainThreadIsolate()->MemoryPressureNotification(
hong.zhengb28b5332016-05-11 02:33:392516 v8_memory_pressure_level);
2517 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2518 v8_memory_pressure_level);
2519}
2520
bashic4b4afcb2016-08-23 06:37:522521// Note that this would be called only when memory_coordinator is enabled.
2522// OnSyncMemoryPressure() is never called in that case.
2523void RenderThreadImpl::OnTrimMemoryImmediately() {
Blink Reformat1c4d759e2017-04-09 16:34:542524 if (blink::MainThreadIsolate()) {
2525 blink::MainThreadIsolate()->MemoryPressureNotification(
bashic4b4afcb2016-08-23 06:37:522526 v8::MemoryPressureLevel::kCritical);
2527 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2528 v8::MemoryPressureLevel::kCritical);
2529 }
2530}
2531
rockot067ca55f2016-09-30 22:00:152532void RenderThreadImpl::OnRendererInterfaceRequest(
2533 mojom::RendererAssociatedRequest request) {
2534 DCHECK(!renderer_binding_.is_bound());
2535 renderer_binding_.Bind(std::move(request));
2536}
bashic4b4afcb2016-08-23 06:37:522537
Takashi SAKAMOTO870f6262017-08-22 04:08:272538bool RenderThreadImpl::NeedsToRecordFirstActivePaint(
2539 int ttfap_metric_type) const {
2540 if (ttfap_metric_type == RenderWidget::TTFAP_AFTER_PURGED)
2541 return needs_to_record_first_active_paint_;
2542
2543 if (was_backgrounded_time_.is_min())
2544 return false;
2545 base::TimeDelta passed = base::TimeTicks::Now() - was_backgrounded_time_;
2546 return passed.InMinutes() >= 5;
2547}
2548
Miguel Casas5e1018052018-01-09 19:17:362549void RenderThreadImpl::SetRenderingColorSpace(
2550 const gfx::ColorSpace& color_space) {
2551 DCHECK(IsMainThread());
2552 rendering_color_space_ = color_space;
2553
2554 for (const auto& factories : gpu_factories_) {
2555 if (factories)
2556 factories->SetRenderingColorSpace(color_space);
2557 }
2558}
2559
[email protected]e9ff79c2012-10-19 21:31:262560} // namespace content