blob: 2dc38f5d281eed899c5f215bcef2f672d839c384 [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"
creis9f7248b2016-01-27 20:27:3916#include "base/debug/crash_logging.h"
[email protected]94f9a0f682009-06-15 18:30:3017#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0318#include "base/logging.h"
avi1023d012015-12-25 02:39:1419#include "base/macros.h"
reveman1af05cb32015-03-17 23:18:1620#include "base/memory/discardable_memory_allocator.h"
hajimehoshi7bb39582016-10-12 04:30:5721#include "base/memory/memory_coordinator_client_registry.h"
dchengcedca5612016-04-09 01:40:1522#include "base/memory/ptr_util.h"
[email protected]8bac37b2013-07-18 19:13:5623#include "base/memory/shared_memory.h"
gabf64a25e2017-05-12 19:42:5624#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3825#include "base/metrics/field_trial.h"
tasaka27961a2017-05-24 07:33:2526#include "base/metrics/histogram_functions.h"
asvitkine8d51e9d2016-09-02 23:55:4327#include "base/metrics/histogram_macros.h"
[email protected]433df472012-03-07 20:33:3928#include "base/path_service.h"
tasakb46626a2016-10-18 05:54:4429#include "base/process/process_metrics.h"
fdoray2df4a9e2016-07-18 23:47:1630#include "base/run_loop.h"
[email protected]21aa99682013-06-11 07:17:0131#include "base/strings/string16.h"
[email protected]1e1d1e12014-01-17 16:14:2932#include "base/strings/string_number_conversions.h"
hablichd6a4f122015-10-28 11:34:4933#include "base/strings/string_split.h"
ccameron6728bae32015-01-09 20:18:0634#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
fdoray50a38342016-11-21 20:46:0436#include "base/threading/sequenced_worker_pool.h"
reveman34b7a1522015-03-23 20:27:4737#include "base/threading/simple_thread.h"
[email protected]1357c322010-12-30 22:18:5638#include "base/threading/thread_local.h"
[email protected]d293572a2013-05-23 18:50:4539#include "base/threading/thread_restrictions.h"
gab30f26df2016-05-11 19:37:5540#include "base/threading/thread_task_runner_handle.h"
ccameron9c48d1d42016-09-22 01:46:0141#include "base/trace_event/memory_dump_manager.h"
primiano9e38d552015-01-28 04:18:0142#include "base/trace_event/trace_event.h"
[email protected]7a4de7a62010-08-17 18:38:2443#include "base/values.h"
avi1023d012015-12-25 02:39:1444#include "build/build_config.h"
jbroman0d302162015-09-05 05:46:2345#include "cc/base/histograms.h"
[email protected]d72493152014-01-08 17:37:4546#include "cc/base/switches.h"
[email protected]38564622014-08-19 02:47:1847#include "cc/blink/web_layer_impl.h"
danakjc7afae52017-06-20 21:12:4148#include "cc/output/layer_tree_frame_sink.h"
danakj83066a32016-06-21 02:34:4949#include "cc/output/vulkan_in_process_context_provider.h"
danakj920156852015-05-18 20:22:2950#include "cc/raster/task_graph_runner.h"
vollick1050cc62015-12-03 07:04:5451#include "cc/trees/layer_tree_host_common.h"
loysoa6edaaff2015-05-25 03:26:4452#include "cc/trees/layer_tree_settings.h"
penghuangd81c1a62016-11-02 20:06:0653#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
dalecurtis4a9839a2017-05-04 23:40:4754#include "components/metrics/public/interfaces/single_sample_metrics.mojom.h"
55#include "components/metrics/single_sample_metrics.h"
danakjc7afae52017-06-20 21:12:4156#include "components/viz/client/client_layer_tree_frame_sink.h"
danakj92429852017-06-29 00:19:0357#include "components/viz/client/client_shared_bitmap_manager.h"
Valery Arkhangorodsky513ac8fd2017-08-02 23:09:2358#include "components/viz/client/hit_test_data_provider.h"
samans7e6675cc2017-06-05 20:16:0859#include "components/viz/client/local_surface_id_provider.h"
Fady Samueldfecb7d2017-07-26 11:41:0460#include "components/viz/common/quads/copy_output_request.h"
Fady Samuel1d744b22017-07-10 21:23:5561#include "components/viz/common/resources/buffer_to_texture_target_map.h"
[email protected]a8cb3b73b2013-08-12 05:50:5062#include "content/child/appcache/appcache_dispatcher.h"
63#include "content/child/appcache/appcache_frontend_impl.h"
dmurph1fb98482016-03-30 21:14:2664#include "content/child/blob_storage/blob_message_filter.h"
[email protected]10208ea2013-06-06 20:08:0365#include "content/child/child_histogram_message_filter.h"
alexclarke0bc36e8d32014-12-17 17:29:2066#include "content/child/child_resource_message_filter.h"
[email protected]89c36f82013-07-17 06:23:2767#include "content/child/db_message_filter.h"
[email protected]c7199a6e2013-06-04 12:56:0168#include "content/child/indexed_db/indexed_db_dispatcher.h"
bashia6264042016-09-15 04:49:5169#include "content/child/memory/child_memory_coordinator_impl.h"
[email protected]10208ea2013-06-06 20:08:0370#include "content/child/resource_dispatcher.h"
alexclarke0bc36e8d32014-12-17 17:29:2071#include "content/child/resource_scheduling_filter.h"
[email protected]643255da2013-06-12 20:55:1372#include "content/child/runtime_features.h"
[email protected]57cf97882013-06-26 20:39:0173#include "content/child/thread_safe_sender.h"
[email protected]c7199a6e2013-06-04 12:56:0174#include "content/child/web_database_observer_impl.h"
kinukoef647412015-12-23 06:10:4375#include "content/child/worker_thread_registry.h"
[email protected]bdae9812011-10-15 00:33:0376#include "content/common/child_process_messages.h"
[email protected]89c36f82013-07-17 06:23:2777#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4178#include "content/common/dom_storage/dom_storage_messages.h"
thakis18e426412017-03-15 12:06:3779#include "content/common/features.h"
[email protected]82307f6b2014-08-07 03:30:1280#include "content/common/frame_messages.h"
raymesbba82b32016-07-19 00:41:3881#include "content/common/frame_owner_properties.h"
sunnyps8f9139e2017-05-12 17:53:2582#include "content/common/gpu_stream_constants.h"
avia7c3f51c2015-09-16 00:30:3183#include "content/common/render_process_messages.h"
[email protected]94dc971d2011-03-05 19:08:3284#include "content/common/resource_messages.h"
alexmos68734212016-08-27 00:06:3185#include "content/common/site_isolation_policy.h"
[email protected]778574e2011-03-21 22:03:5086#include "content/common/view_messages.h"
[email protected]0ec90d522014-03-12 16:28:1987#include "content/common/worker_messages.h"
[email protected]a458504b2012-07-23 19:57:0688#include "content/public/common/content_constants.h"
bashia6264042016-09-15 04:49:5189#include "content/public/common/content_features.h"
[email protected]433df472012-03-07 20:33:3990#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2991#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3192#include "content/public/common/renderer_preferences.h"
benbd9dc802017-04-19 01:37:4393#include "content/public/common/service_manager_connection.h"
ben649b3edd2017-03-23 00:32:0294#include "content/public/common/service_names.mojom.h"
benbd9dc802017-04-19 01:37:4395#include "content/public/common/simple_connection_filter.h"
[email protected]58436a12012-03-21 17:10:2696#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3497#include "content/public/renderer/content_renderer_client.h"
tyoshino832a58a2016-04-18 08:14:0898#include "content/public/renderer/render_thread_observer.h"
[email protected]64ffa0442011-10-03 22:08:3699#include "content/public/renderer/render_view_visitor.h"
fsamuel6c1dfeb2014-12-18 19:21:33100#include "content/renderer/browser_plugin/browser_plugin_manager.h"
jsbell279efb42015-03-31 17:02:46101#include "content/renderer/cache_storage/cache_storage_dispatcher.h"
102#include "content/renderer/cache_storage/cache_storage_message_filter.h"
prashant.nfad657e2016-06-01 07:52:17103#include "content/renderer/categorized_worker_pool.h"
[email protected]70019152012-12-19 11:44:19104#include "content/renderer/devtools/devtools_agent_filter.h"
[email protected]1910fe82012-05-10 00:04:10105#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
106#include "content/renderer/dom_storage/webstoragearea_impl.h"
107#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
tbansalb612c5d2017-05-25 18:53:06108#include "content/renderer/effective_connection_type_helper.h"
simonhonga7e3ac42014-11-11 20:50:22109#include "content/renderer/gpu/compositor_external_begin_frame_source.h"
110#include "content/renderer/gpu/compositor_forwarding_message_filter.h"
danakj83066a32016-06-21 02:34:49111#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]7a72d452013-12-13 10:01:13112#include "content/renderer/input/input_event_filter.h"
113#include "content/renderer/input/input_handler_manager.h"
jdduke691dd572014-12-02 20:47:52114#include "content/renderer/input/main_thread_input_event_filter.h"
[email protected]f7eb0a392011-07-12 10:19:51115#include "content/renderer/media/audio_input_message_filter.h"
116#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:41117#include "content/renderer/media/audio_renderer_mixer_manager.h"
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:59118#include "content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h"
[email protected]d8cd8372012-03-09 10:49:51119#include "content/renderer/media/media_stream_center.h"
[email protected]a9875152013-06-22 04:03:03120#include "content/renderer/media/midi_message_filter.h"
xhwang194acae2014-11-12 22:46:33121#include "content/renderer/media/render_media_client.h"
[email protected]80b161a2011-06-27 17:42:11122#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]d7ff5fb2014-05-29 19:50:25123#include "content/renderer/net_info_helper.h"
[email protected]4761cf12012-09-12 10:37:55124#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]82307f6b2014-08-07 03:30:12125#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:05126#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:28127#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:09128#include "content/renderer/renderer_blink_platform_impl.h"
jdduke94ae1f32015-02-05 06:27:13129#include "content/renderer/scheduler/resource_dispatch_throttler.h"
shimazu5de409e42016-09-29 08:45:28130#include "content/renderer/service_worker/embedded_worker_instance_client_impl.h"
mek27c9d742015-07-16 18:30:18131#include "content/renderer/service_worker/service_worker_context_client.h"
kinuko5af4ffe2015-06-09 03:38:46132#include "content/renderer/service_worker/service_worker_context_message_filter.h"
[email protected]0ec90d522014-03-12 16:28:19133#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
juncai2f298a82017-04-18 03:51:39134#include "device/gamepad/public/cpp/gamepads.h"
chunyang.daibe874c52014-11-14 06:45:05135#include "gin/public/debug.h"
dongseong.hwang72183b02014-12-08 10:41:55136#include "gpu/GLES2/gl2extchromium.h"
danakj6f4e1e22016-04-20 03:27:34137#include "gpu/command_buffer/client/shared_memory_limits.h"
danakj870925d42016-05-03 20:07:38138#include "gpu/ipc/client/command_buffer_proxy_impl.h"
penghuang346a46f92016-03-31 21:37:52139#include "gpu/ipc/client/gpu_channel_host.h"
[email protected]46f36a492010-07-28 19:36:41140#include "ipc/ipc_channel_handle.h"
amistryd4aa70d2016-06-23 07:52:37141#include "ipc/ipc_channel_mojo.h"
[email protected]cb6037d2009-11-16 22:55:17142#include "ipc/ipc_platform_file.h"
[email protected]433df472012-03-07 20:33:39143#include "media/base/media.h"
chcunningham9a285ed2017-03-08 21:48:56144#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46145#include "media/media_features.h"
servolk8b3b39b2015-03-03 19:08:18146#include "media/renderers/gpu_video_accelerator_factories.h"
rockot85dce0862015-11-13 01:33:59147#include "mojo/public/cpp/bindings/strong_binding.h"
Yuki Yamada68992b02017-07-31 06:13:45148#include "mojo/public/cpp/system/message_pipe.h"
[email protected]620161e2011-03-07 18:05:26149#include "net/base/net_errors.h"
eroman9ab64842015-07-21 05:07:52150#include "net/base/port_util.h"
hablichd6a4f122015-10-28 11:34:49151#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
tfarina7a4a7fd2016-01-20 14:23:44152#include "net/base/url_util.h"
brettw4b461082016-11-19 18:55:16153#include "ppapi/features/features.h"
benbd9dc802017-04-19 01:37:43154#include "services/service_manager/public/cpp/binder_registry.h"
penghuangd6843e42016-12-17 13:57:20155#include "services/service_manager/public/cpp/connector.h"
rockot734fb662016-10-15 16:41:30156#include "services/service_manager/public/cpp/interface_provider.h"
sadrul85cc5d82016-12-20 03:37:41157#include "services/ui/public/cpp/gpu/context_provider_command_buffer.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/WebDatabase.h"
171#include "third_party/WebKit/public/web/WebDocument.h"
172#include "third_party/WebKit/public/web/WebFrame.h"
173#include "third_party/WebKit/public/web/WebKit.h"
[email protected]2255a9332013-06-17 05:12:31174#include "third_party/WebKit/public/web/WebScriptController.h"
175#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31176#include "third_party/WebKit/public/web/WebView.h"
David Benjaminb946811c2017-06-26 23:34:29177#include "third_party/boringssl/src/include/openssl/evp.h"
[email protected]ddbb53342014-01-06 10:59:47178#include "third_party/skia/include/core/SkGraphics.h"
[email protected]c49201a2012-05-24 11:04:57179#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:32180#include "ui/base/ui_base_switches.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"
lgrey023fd362017-06-08 19:20:52194#include "base/process/process.h"
195#include "content/common/mac/app_nap_activity.h"
rsesek1efb3c32015-09-29 15:39:50196#include "content/renderer/theme_helper_mac.h"
[email protected]33b02992014-03-01 01:06:29197#include "content/renderer/webscrollbarbehavior_impl_mac.h"
198#endif
199
[email protected]da00a2882009-03-09 17:51:19200#if defined(OS_WIN)
201#include <windows.h>
202#include <objbase.h>
203#endif
204
Brett Wilson0748bf412016-11-22 17:55:46205#if BUILDFLAG(ENABLE_WEBRTC)
liushouqun517b1292016-09-14 05:58:59206#include "content/renderer/media/aec_dump_message_filter.h"
[email protected]22fe91d2014-08-12 17:07:12207#include "content/renderer/media/peer_connection_tracker.h"
208#include "content/renderer/media/rtc_peer_connection_handler.h"
209#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]22fe91d2014-08-12 17:07:12210#endif
211
chunyang.daibe874c52014-11-14 06:45:05212#ifdef ENABLE_VTUNE_JIT_INTERFACE
213#include "v8/src/third_party/vtune/v8-vtune.h"
214#endif
215
bend32292b2016-10-07 00:21:58216#include "content/public/common/service_manager_connection.h"
fsamuel2545ecc2015-12-05 00:44:46217#include "content/renderer/mus/render_widget_window_tree_client_factory.h"
sadrul602ce1362017-01-26 06:41:10218#include "content/renderer/mus/renderer_window_tree_client.h"
sadrul04cfa892016-12-09 17:53:49219#include "services/ui/public/cpp/gpu/gpu.h"
fsamuel6c6da0232015-11-26 05:13:46220
ochangdd89a1e2016-06-08 16:39:01221#if defined(ENABLE_IPC_FUZZER)
222#include "content/common/external_ipc_dumper.h"
223#endif
224
tasakb46626a2016-10-18 05:54:44225#if defined(OS_MACOSX)
226#include <malloc/malloc.h>
227#else
228#include <malloc.h>
229#endif
230
[email protected]d293572a2013-05-23 18:50:45231using base::ThreadRestrictions;
[email protected]180ef242013-11-07 06:50:46232using blink::WebDocument;
233using blink::WebFrame;
234using blink::WebNetworkStateNotifier;
235using blink::WebRuntimeFeatures;
236using blink::WebScriptController;
237using blink::WebSecurityPolicy;
238using blink::WebString;
239using blink::WebView;
[email protected]e9ff79c2012-10-19 21:31:26240
241namespace content {
initial.commit09911bf2008-07-26 23:55:29242
[email protected]42f1d7822009-07-23 18:17:55243namespace {
[email protected]da9ccfb2012-01-28 00:34:40244
avi1023d012015-12-25 02:39:14245const int64_t kInitialIdleHandlerDelayMs = 1000;
246const int64_t kLongIdleHandlerDelayMs = 30 * 1000;
[email protected]bee16aab2009-08-26 15:55:03247
jdduke94ae1f32015-02-05 06:27:13248#if defined(OS_ANDROID)
249// On Android, resource messages can each take ~1.5ms to dispatch on the browser
250// IO thread. Limiting the message rate to 3/frame at 60hz ensures that the
251// induced work takes but a fraction (~1/4) of the overall frame budget.
252const int kMaxResourceRequestsPerFlushWhenThrottled = 3;
253#else
254const int kMaxResourceRequestsPerFlushWhenThrottled = 8;
255#endif
256const double kThrottledResourceRequestFlushPeriodS = 1. / 60.;
257
[email protected]dd2c1022014-07-22 23:13:57258// Maximum allocation size allowed for image scaling filters that
259// require pre-scaling. Skia will fallback to a filter that doesn't
260// require pre-scaling if the default filter would require an
261// allocation that exceeds this limit.
262const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
263
samans2040988b2017-04-11 23:58:35264#if defined(OS_ANDROID)
danakj83066a32016-06-21 02:34:49265// Unique identifier for each output surface created.
danakjc7afae52017-06-20 21:12:41266uint32_t g_next_layer_tree_frame_sink_id = 1;
samans2040988b2017-04-11 23:58:35267#endif
danakj83066a32016-06-21 02:34:49268
rockot5c478a72016-09-28 23:14:18269// An implementation of mojom::RenderMessageFilter which can be mocked out
270// for tests which may indirectly send messages over this interface.
271mojom::RenderMessageFilter* g_render_message_filter_for_testing;
272
olegmax045f7fb12017-05-19 07:58:55273// An implementation of RendererBlinkPlatformImpl which can be mocked out
274// for tests.
275RendererBlinkPlatformImpl* g_current_blink_platform_impl_for_testing;
276
[email protected]f1a29a02011-10-06 23:08:44277// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16278// incorrectly from the wrong thread.
scottmg5e65e3a2017-03-08 08:48:46279base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit
[email protected]6de0fd1d2011-11-15 13:31:49280 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54281
hong.zhengb28b5332016-05-11 02:33:39282// v8::MemoryPressureLevel should correspond to base::MemoryPressureListener.
283static_assert(static_cast<v8::MemoryPressureLevel>(
284 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
285 v8::MemoryPressureLevel::kNone, "none level not align");
286static_assert(static_cast<v8::MemoryPressureLevel>(
287 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
288 v8::MemoryPressureLevel::kModerate, "moderate level not align");
289static_assert(static_cast<v8::MemoryPressureLevel>(
290 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
291 v8::MemoryPressureLevel::kCritical, "critical level not align");
292
hong.zheng2e296f822016-06-29 02:47:44293// WebMemoryPressureLevel should correspond to base::MemoryPressureListener.
294static_assert(static_cast<blink::WebMemoryPressureLevel>(
Blink Reformat1c4d759e2017-04-09 16:34:54295 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
296 blink::kWebMemoryPressureLevelNone,
297 "blink::WebMemoryPressureLevelNone not align");
298static_assert(
299 static_cast<blink::WebMemoryPressureLevel>(
300 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
301 blink::kWebMemoryPressureLevelModerate,
302 "blink::WebMemoryPressureLevelModerate not align");
303static_assert(
304 static_cast<blink::WebMemoryPressureLevel>(
305 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
306 blink::kWebMemoryPressureLevelCritical,
307 "blink::WebMemoryPressureLevelCritical not align");
hong.zheng2e296f822016-06-29 02:47:44308
[email protected]b2d98762012-09-03 17:04:06309void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13310 const char *name, int min, int max, size_t buckets) {
311 if (min <= 0)
312 min = 1;
[email protected]b2d98762012-09-03 17:04:06313 std::string histogram_name;
314 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
315 if (render_thread_impl) { // Can be null in tests.
316 histogram_name = render_thread_impl->
317 histogram_customizer()->ConvertToCustomHistogramName(name);
318 } else {
319 histogram_name = std::string(name);
320 }
[email protected]de415552013-01-23 04:12:17321 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06322 histogram_name, min, max, buckets,
323 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13324 return histogram;
325}
326
[email protected]b2d98762012-09-03 17:04:06327void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13328 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
329 histogram->Add(sample);
330}
331
ben76f52b242016-06-18 05:42:48332class FrameFactoryImpl : public mojom::FrameFactory {
rockotf8fdd9b2015-12-16 22:22:35333 public:
benf28ce882017-05-02 16:15:49334 explicit FrameFactoryImpl(const service_manager::BindSourceInfo& source_info)
335 : source_info_(source_info), routing_id_highmark_(-1) {}
rockotf8fdd9b2015-12-16 22:22:35336
ben76f52b242016-06-18 05:42:48337 private:
338 // mojom::FrameFactory:
csharrison95f01e922017-04-24 18:52:35339 void CreateFrame(
340 int32_t frame_routing_id,
341 mojom::FrameRequest frame_request,
342 mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker) override {
rockotf8fdd9b2015-12-16 22:22:35343 // TODO(morrita): This is for investigating http://crbug.com/415059 and
344 // should be removed once it is fixed.
345 CHECK_LT(routing_id_highmark_, frame_routing_id);
346 routing_id_highmark_ = frame_routing_id;
347
348 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id);
349 // We can receive a GetServiceProviderForFrame message for a frame not yet
rockot067ca55f2016-09-30 22:00:15350 // created due to a race between the message and a
351 // mojom::Renderer::CreateView IPC that triggers creation of the RenderFrame
352 // we want.
rockotf8fdd9b2015-12-16 22:22:35353 if (!frame) {
ben76f52b242016-06-18 05:42:48354 RenderThreadImpl::current()->RegisterPendingFrameCreate(
benf28ce882017-05-02 16:15:49355 source_info_, frame_routing_id, std::move(frame_request),
csharrison95f01e922017-04-24 18:52:35356 std::move(frame_host_interface_broker));
rockotf8fdd9b2015-12-16 22:22:35357 return;
358 }
359
benf28ce882017-05-02 16:15:49360 frame->BindFrame(source_info_, std::move(frame_request),
csharrison95f01e922017-04-24 18:52:35361 std::move(frame_host_interface_broker));
rockotf8fdd9b2015-12-16 22:22:35362 }
363
364 private:
benf28ce882017-05-02 16:15:49365 service_manager::BindSourceInfo source_info_;
rockotf8fdd9b2015-12-16 22:22:35366 int32_t routing_id_highmark_;
rockotf8fdd9b2015-12-16 22:22:35367};
368
Ben Goodger21ada1e2017-07-19 14:53:01369void CreateFrameFactory(mojom::FrameFactoryRequest request,
370 const service_manager::BindSourceInfo& source_info) {
benf28ce882017-05-02 16:15:49371 mojo::MakeStrongBinding(base::MakeUnique<FrameFactoryImpl>(source_info),
rockot8e66a08d2016-09-13 00:48:21372 std::move(request));
rockotf8fdd9b2015-12-16 22:22:35373}
374
sadrul85cc5d82016-12-20 03:37:41375scoped_refptr<ui::ContextProviderCommandBuffer> CreateOffscreenContext(
danakjc3983552016-05-03 00:04:35376 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
danakj0dd9e1e2016-05-11 22:15:09377 const gpu::SharedMemoryLimits& limits,
danakj9a04adc2016-05-16 22:45:07378 bool support_locking,
sadrul85cc5d82016-12-20 03:37:41379 ui::command_buffer_metrics::ContextType type,
sunnypsd8ce1c22016-05-10 18:02:40380 int32_t stream_id,
sunnyps8f9139e2017-05-12 17:53:25381 gpu::SchedulingPriority stream_priority) {
danakje8ec797e2016-04-19 04:08:43382 DCHECK(gpu_channel_host);
383 // This is used to create a few different offscreen contexts:
384 // - The shared main thread context (offscreen) used by blink for canvas.
385 // - The worker context (offscreen) used for GPU raster and video decoding.
386 // This is for an offscreen context, so the default framebuffer doesn't need
387 // alpha, depth, stencil, antialiasing.
388 gpu::gles2::ContextCreationAttribHelper attributes;
389 attributes.alpha_size = -1;
390 attributes.depth_size = 0;
391 attributes.stencil_size = 0;
392 attributes.samples = 0;
393 attributes.sample_buffers = 0;
394 attributes.bind_generates_resource = false;
395 attributes.lose_context_when_out_of_memory = true;
sunnypsd8ce1c22016-05-10 18:02:40396 const bool automatic_flushes = false;
sadrul85cc5d82016-12-20 03:37:41397 return make_scoped_refptr(new ui::ContextProviderCommandBuffer(
sunnypsd8ce1c22016-05-10 18:02:40398 std::move(gpu_channel_host), stream_id, stream_priority,
399 gpu::kNullSurfaceHandle,
zmo09ea813b2017-01-20 23:38:36400 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext/" +
401 ui::command_buffer_metrics::ContextTypeToString(type)),
pimand488e8b42016-06-30 19:06:59402 automatic_flushes, support_locking, limits, attributes, nullptr, type));
danakje8ec797e2016-04-19 04:08:43403}
404
penghuange1d86512016-07-08 18:15:00405bool IsRunningInMash() {
406 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
407 return cmdline->HasSwitch(switches::kIsRunningInMash);
408}
409
dalecurtis4a9839a2017-05-04 23:40:47410// Hook that allows single-sample metric code from //components/metrics to
411// connect from the renderer process to the browser process.
412void CreateSingleSampleMetricsProvider(
413 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
414 service_manager::Connector* connector,
415 metrics::mojom::SingleSampleMetricsProviderRequest request) {
416 if (task_runner->BelongsToCurrentThread()) {
417 connector->BindInterface(mojom::kBrowserServiceName, std::move(request));
418 return;
419 }
420
421 task_runner->PostTask(
422 FROM_HERE,
423 base::Bind(&CreateSingleSampleMetricsProvider, std::move(task_runner),
424 connector, base::Passed(&request)));
425}
426
samans7e6675cc2017-06-05 20:16:08427class RendererLocalSurfaceIdProvider : public viz::LocalSurfaceIdProvider {
428 public:
Fady Samueld5c26182017-07-12 02:43:33429 const viz::LocalSurfaceId& GetLocalSurfaceIdForFrame(
samans7e6675cc2017-06-05 20:16:08430 const cc::CompositorFrame& frame) override {
431 auto new_surface_properties =
432 RenderWidgetSurfaceProperties::FromCompositorFrame(frame);
433 if (!local_surface_id_.is_valid() ||
434 new_surface_properties != surface_properties_) {
435 local_surface_id_ = local_surface_id_allocator_.GenerateId();
436 surface_properties_ = new_surface_properties;
437 }
438 return local_surface_id_;
439 }
440
441 private:
Fady Samueld5c26182017-07-12 02:43:33442 viz::LocalSurfaceIdAllocator local_surface_id_allocator_;
443 viz::LocalSurfaceId local_surface_id_;
samans7e6675cc2017-06-05 20:16:08444 RenderWidgetSurfaceProperties surface_properties_;
445};
446
[email protected]b2d98762012-09-03 17:04:06447} // namespace
448
[email protected]b2d98762012-09-03 17:04:06449RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
450 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
451 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
452 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
hablich4598ddc2015-11-07 18:37:28453 custom_histograms_.insert("V8.MemoryHeapUsed");
454 custom_histograms_.insert("V8.MemoryHeapCommitted");
[email protected]b2d98762012-09-03 17:04:06455}
456
457RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
458
459void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
460 const std::string& host, size_t view_count) {
avi83883c82014-12-23 00:08:49461 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
462 switches::kDisableHistogramCustomizer)) {
[email protected]9baee832012-12-10 11:07:15463 return;
464 }
[email protected]b2d98762012-09-03 17:04:06465 // Check if all RenderViews are displaying a page from the same host. If there
466 // is only one RenderView, the common host is this view's host. If there are
467 // many, check if this one shares the common host of the other
468 // RenderViews. It's ok to not detect some cases where the RenderViews share a
469 // common host. This information is only used for producing custom histograms.
470 if (view_count == 1)
471 SetCommonHost(host);
472 else if (host != common_host_)
473 SetCommonHost(std::string());
474}
475
476std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
477 const char* histogram_name) const {
478 std::string name(histogram_name);
479 if (!common_host_histogram_suffix_.empty() &&
480 custom_histograms_.find(name) != custom_histograms_.end())
481 name += common_host_histogram_suffix_;
482 return name;
483}
484
485void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
486 const std::string& host) {
487 if (host != common_host_) {
488 common_host_ = host;
489 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
Blink Reformat1c4d759e2017-04-09 16:34:54490 blink::MainThreadIsolate()->SetCreateHistogramFunction(CreateHistogram);
[email protected]b2d98762012-09-03 17:04:06491 }
492}
493
hablichd6a4f122015-10-28 11:34:49494std::string RenderThreadImpl::HistogramCustomizer::HostToCustomHistogramSuffix(
495 const std::string& host) {
496 if (host == "mail.google.com")
497 return ".gmail";
498 if (host == "docs.google.com" || host == "drive.google.com")
499 return ".docs";
500 if (host == "plus.google.com")
501 return ".plus";
502 if (host == "inbox.google.com")
503 return ".inbox";
hpayerdd4def052016-02-06 19:06:10504 if (host == "calendar.google.com")
505 return ".calendar";
hablichd6a4f122015-10-28 11:34:49506 if (host == "www.youtube.com")
507 return ".youtube";
508 if (IsAlexaTop10NonGoogleSite(host))
509 return ".top10";
510
511 return std::string();
512}
513
514bool RenderThreadImpl::HistogramCustomizer::IsAlexaTop10NonGoogleSite(
515 const std::string& host) {
516 // The Top10 sites have different TLD and/or subdomains depending on the
517 // localization.
518 if (host == "sina.com.cn")
519 return true;
520
521 std::string sanitized_host =
522 net::registry_controlled_domains::GetDomainAndRegistry(
523 host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
524
525 if (sanitized_host == "facebook.com")
526 return true;
527 if (sanitized_host == "baidu.com")
528 return true;
529 if (sanitized_host == "qq.com")
530 return true;
531 if (sanitized_host == "twitter.com")
532 return true;
533 if (sanitized_host == "taobao.com")
534 return true;
535 if (sanitized_host == "live.com")
536 return true;
537
538 if (!sanitized_host.empty()) {
539 std::vector<base::StringPiece> host_tokens = base::SplitStringPiece(
540 sanitized_host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
541
542 if (host_tokens.size() >= 2) {
543 if ((host_tokens[0] == "yahoo") || (host_tokens[0] == "amazon") ||
544 (host_tokens[0] == "wikipedia")) {
545 return true;
546 }
547 }
548 }
549 return false;
550}
551
leon.han2c0f9f12015-07-11 02:01:19552// static
553RenderThreadImpl* RenderThreadImpl::Create(
554 const InProcessChildThreadParams& params) {
skyostil529caa292016-08-10 17:44:51555 std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler =
556 blink::scheduler::RendererScheduler::Create();
jam75c44222016-03-23 05:34:24557 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
558 return new RenderThreadImpl(
559 params, std::move(renderer_scheduler), test_task_counter);
leon.han2c0f9f12015-07-11 02:01:19560}
561
562// static
563RenderThreadImpl* RenderThreadImpl::Create(
dchengcedca5612016-04-09 01:40:15564 std::unique_ptr<base::MessageLoop> main_message_loop,
skyostil529caa292016-08-10 17:44:51565 std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler) {
dcheng07945f632015-12-26 07:59:32566 return new RenderThreadImpl(std::move(main_message_loop),
567 std::move(renderer_scheduler));
leon.han2c0f9f12015-07-11 02:01:19568}
569
rockot5c478a72016-09-28 23:14:18570// static
[email protected]f1a29a02011-10-06 23:08:44571RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06572 return lazy_tls.Pointer()->Get();
573}
574
rockot5c478a72016-09-28 23:14:18575// static
576mojom::RenderMessageFilter* RenderThreadImpl::current_render_message_filter() {
577 if (g_render_message_filter_for_testing)
578 return g_render_message_filter_for_testing;
579 DCHECK(current());
580 return current()->render_message_filter();
581}
582
583// static
olegmax045f7fb12017-05-19 07:58:55584RendererBlinkPlatformImpl* RenderThreadImpl::current_blink_platform_impl() {
585 if (g_current_blink_platform_impl_for_testing)
586 return g_current_blink_platform_impl_for_testing;
587 DCHECK(current());
588 return current()->blink_platform_impl();
589}
590
591// static
rockot5c478a72016-09-28 23:14:18592void RenderThreadImpl::SetRenderMessageFilterForTesting(
593 mojom::RenderMessageFilter* render_message_filter) {
594 g_render_message_filter_for_testing = render_message_filter;
595}
596
olegmax045f7fb12017-05-19 07:58:55597// static
598void RenderThreadImpl::SetRendererBlinkPlatformImplForTesting(
599 RendererBlinkPlatformImpl* blink_platform_impl) {
600 g_current_blink_platform_impl_for_testing = blink_platform_impl;
601}
602
staraz067f58242016-11-07 21:06:41603// In single-process mode used for debugging, we don't pass a renderer client
604// ID via command line because RenderThreadImpl lives in the same process as
605// the browser
leon.han2c0f9f12015-07-11 02:01:19606RenderThreadImpl::RenderThreadImpl(
607 const InProcessChildThreadParams& params,
skyostil529caa292016-08-10 17:44:51608 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler,
rockot97a86832016-12-10 04:53:06609 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue)
morritac6238ab2015-03-18 01:48:29610 : ChildThreadImpl(Options::Builder()
prashant.nfad657e2016-06-01 07:52:17611 .InBrowserProcess(params)
bend32292b2016-10-07 00:21:58612 .AutoStartServiceManagerConnection(false)
ben5be0b9132016-08-03 00:17:18613 .ConnectToBrowser(true)
prashant.nfad657e2016-06-01 07:52:17614 .Build()),
dcheng07945f632015-12-26 07:59:32615 renderer_scheduler_(std::move(scheduler)),
rockot067ca55f2016-09-30 22:00:15616 categorized_worker_pool_(new CategorizedWorkerPool()),
staraz067f58242016-11-07 21:06:41617 renderer_binding_(this),
Lukasz Anforowicz5a024122017-07-19 21:31:57618 client_id_(1) {
jam75c44222016-03-23 05:34:24619 Init(resource_task_queue);
morritac6238ab2015-03-18 01:48:29620}
621
[email protected]42f1d7822009-07-23 18:17:55622// When we run plugins in process, we actually run them on the render thread,
623// which means that we need to make the render thread pump UI events.
haraken53f081d2014-11-11 01:03:40624RenderThreadImpl::RenderThreadImpl(
dchengcedca5612016-04-09 01:40:15625 std::unique_ptr<base::MessageLoop> main_message_loop,
skyostil529caa292016-08-10 17:44:51626 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler)
rockotcef38272016-07-15 22:47:47627 : ChildThreadImpl(Options::Builder()
bend32292b2016-10-07 00:21:58628 .AutoStartServiceManagerConnection(false)
ben5be0b9132016-08-03 00:17:18629 .ConnectToBrowser(true)
rockotcef38272016-07-15 22:47:47630 .Build()),
dcheng07945f632015-12-26 07:59:32631 renderer_scheduler_(std::move(scheduler)),
632 main_message_loop_(std::move(main_message_loop)),
rockot067ca55f2016-09-30 22:00:15633 categorized_worker_pool_(new CategorizedWorkerPool()),
wjmaclean1d970622017-01-21 22:28:24634 is_scroll_animator_enabled_(false),
Lukasz Anforowicz5a024122017-07-19 21:31:57635 renderer_binding_(this) {
jam75c44222016-03-23 05:34:24636 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
staraz067f58242016-11-07 21:06:41637 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
638 switches::kRendererClientId));
639 base::StringToInt(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
640 switches::kRendererClientId),
641 &client_id_);
jam75c44222016-03-23 05:34:24642 Init(test_task_counter);
haraken53f081d2014-11-11 01:03:40643}
644
jam75c44222016-03-23 05:34:24645void RenderThreadImpl::Init(
rockot97a86832016-12-10 04:53:06646 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) {
fdorayf6d86242015-10-08 16:49:53647 TRACE_EVENT0("startup", "RenderThreadImpl::Init");
[email protected]a872ea1f2010-08-11 04:45:33648
ssidb2e3ece2015-02-09 16:02:20649 base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex(
[email protected]91a2aea2013-07-08 23:14:39650 base::PlatformThread::CurrentId(),
651 kTraceEventRendererMainThreadSortIndex);
652
thakis18e426412017-03-15 12:06:37653#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
sievers9dff72052015-11-16 18:35:57654 // On Mac and Android Java UI, the select popups are rendered by the browser.
Blink Reformat1c4d759e2017-04-09 16:34:54655 blink::WebView::SetUseExternalPopupMenus(true);
[email protected]53c607c2011-03-21 23:19:04656#endif
657
[email protected]94f9a0f682009-06-15 18:30:30658 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28659
[email protected]06c694d2012-02-01 22:26:16660 // Register this object as the main thread.
661 ChildProcess::current()->set_main_thread(this);
662
dalecurtis4a9839a2017-05-04 23:40:47663 metrics::InitializeSingleSampleMetricsFactory(
664 base::BindRepeating(&CreateSingleSampleMetricsProvider,
665 message_loop()->task_runner(), GetConnector()));
666
ben649b3edd2017-03-23 00:32:02667 gpu_ = ui::Gpu::Create(
668 GetConnector(),
669 IsRunningInMash() ? ui::mojom::kServiceName : mojom::kBrowserServiceName,
670 GetIOTaskRunner());
penghuange1d86512016-07-08 18:15:00671
Gary Klassenb78686272017-08-11 22:38:13672 viz::mojom::SharedBitmapAllocationNotifierPtr
danakj92429852017-06-29 00:19:03673 shared_bitmap_allocation_notifier_ptr;
Saman Sami9b768542017-07-14 20:42:34674 GetConnector()->BindInterface(
675 mojom::kBrowserServiceName,
danakj92429852017-06-29 00:19:03676 mojo::MakeRequest(&shared_bitmap_allocation_notifier_ptr));
677 shared_bitmap_manager_ = base::MakeUnique<viz::ClientSharedBitmapManager>(
Gary Klassenb78686272017-08-11 22:38:13678 viz::mojom::ThreadSafeSharedBitmapAllocationNotifierPtr::Create(
danakj92429852017-06-29 00:19:03679 shared_bitmap_allocation_notifier_ptr.PassInterface(),
680 GetChannel()->ipc_task_runner_refptr()));
jcivelli0f21bd52016-12-07 21:21:33681
jam75c44222016-03-23 05:34:24682 InitializeWebKit(resource_task_queue);
683
[email protected]31f87132010-04-21 23:36:21684 // In single process the single process is all there is.
[email protected]26e82322014-01-20 14:18:22685 webkit_shared_timer_suspended_ = false;
[email protected]bee16aab2009-08-26 15:55:03686 widget_count_ = 0;
687 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44688 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48689 idle_notifications_to_skip_ = 0;
[email protected]8d86fce2009-02-26 23:37:55690
[email protected]d5b2fdf2013-06-05 09:36:55691 appcache_dispatcher_.reset(
[email protected]a8cb3b73b2013-08-12 05:50:50692 new AppCacheDispatcher(Get(), new AppCacheFrontendImpl()));
[email protected]1910fe82012-05-10 00:04:10693 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
reillyg39fb4662016-11-22 20:27:17694 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
jsbellabadb9b2015-03-23 21:03:44695 main_thread_cache_storage_dispatcher_.reset(
jsbell279efb42015-03-31 17:02:46696 new CacheStorageDispatcher(thread_safe_sender()));
[email protected]dd9241932010-02-24 19:23:13697
jdduke94ae1f32015-02-05 06:27:13698 // Note: This may reorder messages from the ResourceDispatcher with respect to
699 // other subsystems.
700 resource_dispatch_throttler_.reset(new ResourceDispatchThrottler(
701 static_cast<RenderThread*>(this), renderer_scheduler_.get(),
702 base::TimeDelta::FromSecondsD(kThrottledResourceRequestFlushPeriodS),
703 kMaxResourceRequestsPerFlushWhenThrottled));
704 resource_dispatcher()->set_message_sender(resource_dispatch_throttler_.get());
705
thestig529ad8a2016-07-08 20:30:12706 blob_message_filter_ = new BlobMessageFilter(GetFileThreadTaskRunner());
dmurph1fb98482016-03-30 21:14:26707 AddFilter(blob_message_filter_.get());
[email protected]017022b2009-07-27 23:06:34708 db_message_filter_ = new DBMessageFilter();
709 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13710
[email protected]45048072014-01-14 13:51:29711 vc_manager_.reset(new VideoCaptureImplManager());
[email protected]c9c43a02013-12-17 08:59:54712
fsamuel6c1dfeb2014-12-18 19:21:33713 browser_plugin_manager_.reset(new BrowserPluginManager());
714 AddObserver(browser_plugin_manager_.get());
715
Brett Wilson0748bf412016-11-22 17:55:46716#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]af089972013-01-10 04:04:40717 peer_connection_tracker_.reset(new PeerConnectionTracker());
718 AddObserver(peer_connection_tracker_.get());
719
thestig529ad8a2016-07-08 20:30:12720 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOTaskRunner().get());
[email protected]fc72bb12013-06-02 21:13:46721 AddFilter(p2p_socket_dispatcher_.get());
[email protected]921480f62013-07-20 03:42:57722
ivocadd54f0d2015-12-18 23:17:05723 peer_connection_factory_.reset(
724 new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get()));
725
skyostil2d3b5bd2015-05-27 15:40:59726 aec_dump_message_filter_ = new AecDumpMessageFilter(
thestig529ad8a2016-07-08 20:30:12727 GetIOTaskRunner(), message_loop()->task_runner());
ivocadd54f0d2015-12-18 23:17:05728
[email protected]da9f30a2014-06-18 19:39:04729 AddFilter(aec_dump_message_filter_.get());
730
Brett Wilson0748bf412016-11-22 17:55:46731#endif // BUILDFLAG(ENABLE_WEBRTC)
[email protected]e25f4d72011-06-08 20:58:46732
thestig529ad8a2016-07-08 20:30:12733 audio_input_message_filter_ = new AudioInputMessageFilter(GetIOTaskRunner());
[email protected]f7eb0a392011-07-12 10:19:51734 AddFilter(audio_input_message_filter_.get());
735
Max Morind4c4887d2017-06-08 07:41:34736 scoped_refptr<AudioMessageFilter> audio_message_filter;
737 if (!base::FeatureList::IsEnabled(
738 features::kUseMojoAudioOutputStreamFactory)) {
739 // In case we shouldn't use mojo factories, we need to create an
740 // AudioMessageFilter which |audio_ipc_factory_| can use for IPC.
741 audio_message_filter =
742 base::MakeRefCounted<AudioMessageFilter>(GetIOTaskRunner());
743 AddFilter(audio_message_filter.get());
744 }
745
maxmorin017ba8c62017-06-02 10:23:09746 audio_ipc_factory_.emplace(std::move(audio_message_filter),
747 GetIOTaskRunner());
[email protected]f7eb0a392011-07-12 10:19:51748
thestig529ad8a2016-07-08 20:30:12749 midi_message_filter_ = new MidiMessageFilter(GetIOTaskRunner());
[email protected]a9875152013-06-22 04:03:03750 AddFilter(midi_message_filter_.get());
751
jsbellabadb9b2015-03-23 21:03:44752 AddFilter((new CacheStorageMessageFilter(thread_safe_sender()))->GetFilter());
753
kinuko5af4ffe2015-06-09 03:38:46754 AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter());
[email protected]ddbb53342014-01-06 10:59:47755
sadrul943e3b32016-08-04 18:22:59756#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14757 if (IsRunningInMash()) {
bend32292b2016-10-07 00:21:58758 CreateRenderWidgetWindowTreeClientFactory(GetServiceManagerConnection());
rockotcef38272016-07-15 22:47:47759 }
760#endif
761
Ben Goodger21ada1e2017-07-19 14:53:01762 auto registry = base::MakeUnique<service_manager::BinderRegistryWithArgs<
763 const service_manager::BindSourceInfo&>>();
benbd9dc802017-04-19 01:37:43764 registry->AddInterface(base::Bind(&CreateFrameFactory),
765 base::ThreadTaskRunnerHandle::Get());
Matt Falkenhagen38ab68b2017-06-28 08:33:23766 registry->AddInterface(base::Bind(&EmbeddedWorkerInstanceClientImpl::Create,
Makoto Shimazu166906a2017-07-12 06:04:01767 base::TimeTicks::Now(), GetIOTaskRunner()),
benbd9dc802017-04-19 01:37:43768 base::ThreadTaskRunnerHandle::Get());
769 GetServiceManagerConnection()->AddConnectionFilter(
Ben Goodger21ada1e2017-07-19 14:53:01770 base::MakeUnique<SimpleConnectionFilterWithSourceInfo>(
771 std::move(registry)));
rockotcef38272016-07-15 22:47:47772
[email protected]e9ff79c2012-10-19 21:31:26773 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24774
benbd9dc802017-04-19 01:37:43775 StartServiceManagerConnection();
776
rockot067ca55f2016-09-30 22:00:15777 GetAssociatedInterfaceRegistry()->AddInterface(
778 base::Bind(&RenderThreadImpl::OnRendererInterfaceRequest,
779 base::Unretained(this)));
780
[email protected]b48c53ad2014-02-05 21:59:18781 InitSkiaEventTracer();
ssid59c969162015-07-28 13:02:58782 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
primiano186d6bfe2015-10-30 13:21:40783 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr);
[email protected]b48c53ad2014-02-05 21:59:18784
avi83883c82014-12-23 00:08:49785 const base::CommandLine& command_line =
786 *base::CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01787
ochangdd89a1e2016-06-08 16:39:01788#if defined(ENABLE_IPC_FUZZER)
789 if (command_line.HasSwitch(switches::kIpcDumpDirectory)) {
790 base::FilePath dump_directory =
791 command_line.GetSwitchValuePath(switches::kIpcDumpDirectory);
792 IPC::ChannelProxy::OutgoingMessageFilter* filter =
793 LoadExternalIPCDumper(dump_directory);
794 GetChannel()->set_outgoing_message_filter(filter);
795 }
796#endif
797
jbroman0d302162015-09-05 05:46:23798 cc::SetClientNameForMetrics("Renderer");
loysoa6edaaff2015-05-25 03:26:44799
loyso65c93c602015-08-11 05:15:57800 is_threaded_animation_enabled_ =
801 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
802
reveman91a0a872014-11-04 03:40:32803 is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy);
ericrk1d17f752015-10-20 03:03:07804 is_partial_raster_enabled_ =
dongseong.hwang23db47f2016-03-08 07:50:02805 !command_line.HasSwitch(switches::kDisablePartialRaster);
ccameronc7fcd132015-11-03 20:14:31806 is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch(
807 switches::kEnableGpuMemoryBufferCompositorResources);
[email protected]a23530d2014-03-11 06:04:14808
jame1f453c2016-03-21 15:51:34809#if defined(OS_MACOSX)
lgrey023fd362017-06-08 19:20:52810 if (base::Process::IsAppNapEnabled()) {
811 AppNapActivity::InitializeAppNapSupport();
812 }
Greg Kerra7b943b2017-07-24 23:17:17813#endif
814
815// On macOS this value is adjusted in `UpdateScrollbarTheme()`,
816// but the system default is true.
817#if defined(OS_MACOSX)
818 is_elastic_overscroll_enabled_ = true;
ccamerona7644752014-12-30 01:16:31819#else
820 is_elastic_overscroll_enabled_ = false;
821#endif
822
danakje6eb185c2015-02-27 23:52:05823 std::string image_texture_target_string =
dcastagna7f2f7192015-06-16 18:44:35824 command_line.GetSwitchValueASCII(switches::kContentImageTextureTarget);
ericrk9151705c2016-07-26 19:53:16825 buffer_to_texture_target_map_ =
Fady Samuel1d744b22017-07-10 21:23:55826 viz::StringToBufferToTextureTargetMap(image_texture_target_string);
reveman44b807f12014-11-26 02:44:50827
[email protected]a23530d2014-03-11 06:04:14828 if (command_line.HasSwitch(switches::kDisableLCDText)) {
829 is_lcd_text_enabled_ = false;
830 } else if (command_line.HasSwitch(switches::kEnableLCDText)) {
831 is_lcd_text_enabled_ = true;
832 } else {
833#if defined(OS_ANDROID)
834 is_lcd_text_enabled_ = false;
835#else
836 is_lcd_text_enabled_ = true;
837#endif
838 }
839
[email protected]b8d82c22014-03-31 20:12:46840 is_gpu_rasterization_forced_ =
841 command_line.HasSwitch(switches::kForceGpuRasterization);
sunnypsd8ce1c22016-05-10 18:02:40842 is_async_worker_context_enabled_ =
843 command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext);
[email protected]a23530d2014-03-11 06:04:14844
senorblancob60ba952015-01-27 19:12:36845 if (command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) {
846 std::string string_value = command_line.GetSwitchValueASCII(
847 switches::kGpuRasterizationMSAASampleCount);
848 bool parsed_msaa_sample_count =
849 base::StringToInt(string_value, &gpu_rasterization_msaa_sample_count_);
850 DCHECK(parsed_msaa_sample_count) << string_value;
851 DCHECK_GE(gpu_rasterization_msaa_sample_count_, 0);
852 } else {
senorblanco2a5b0e12015-08-14 21:55:37853 gpu_rasterization_msaa_sample_count_ = -1;
senorblancob60ba952015-01-27 19:12:36854 }
855
[email protected]b242b142014-05-07 14:48:49856 if (command_line.HasSwitch(switches::kDisableDistanceFieldText)) {
857 is_distance_field_text_enabled_ = false;
858 } else if (command_line.HasSwitch(switches::kEnableDistanceFieldText)) {
859 is_distance_field_text_enabled_ = true;
860 } else {
861 is_distance_field_text_enabled_ = false;
862 }
863
[email protected]433df472012-03-07 20:33:39864 // Note that under Linux, the media library will normally already have
865 // been initialized by the Zygote before this instance became a Renderer.
chcunninghamfd11b3c2015-06-09 02:09:42866 media::InitializeMediaLibrary();
[email protected]433df472012-03-07 20:33:39867
dalecurtis88af3932016-02-20 00:12:20868#if defined(OS_ANDROID)
869 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
870 media::MediaCodecUtil::IsMediaCodecAvailable()) {
871 media::EnablePlatformDecoderSupport();
872 }
873#endif
874
bashi296ebda2017-03-28 03:27:09875 memory_pressure_listener_.reset(new base::MemoryPressureListener(
876 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
877 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
878 base::Unretained(this))));
879
880 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
881 // Disable MemoryPressureListener when memory coordinator is enabled.
882 base::MemoryPressureListener::SetNotificationsSuppressed(true);
883
884 // TODO(bashi): Revisit how to manage the lifetime of
885 // ChildMemoryCoordinatorImpl.
886 // https://codereview.chromium.org/2094583002/#msg52
887 mojom::MemoryCoordinatorHandlePtr parent_coordinator;
888 GetConnector()->BindInterface(mojom::kBrowserServiceName,
889 mojo::MakeRequest(&parent_coordinator));
890 memory_coordinator_ = CreateChildMemoryCoordinator(
891 std::move(parent_coordinator), this);
892 }
893
danakj16275d4c2015-06-11 19:23:51894 int num_raster_threads = 0;
895 std::string string_value =
896 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
897 bool parsed_num_raster_threads =
898 base::StringToInt(string_value, &num_raster_threads);
899 DCHECK(parsed_num_raster_threads) << string_value;
900 DCHECK_GT(num_raster_threads, 0);
vmiura78b69282015-02-14 00:01:17901
prashant.nfad657e2016-06-01 07:52:17902 categorized_worker_pool_->Start(num_raster_threads);
[email protected]1e1d1e12014-01-17 16:14:29903
penghuang342762b2016-12-02 21:04:58904 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr;
penghuangd6843e42016-12-17 13:57:20905 if (IsRunningInMash()) {
906#if defined(USE_AURA)
benbd3c2482017-01-07 05:48:21907 GetServiceManagerConnection()->GetConnector()->BindInterface(
penghuangd6843e42016-12-17 13:57:20908 ui::mojom::kServiceName, &manager_ptr);
909#else
910 NOTREACHED();
911#endif
912 } else {
ben649b3edd2017-03-23 00:32:02913 ChildThread::Get()->GetConnector()->BindInterface(
914 mojom::kBrowserServiceName, mojo::MakeRequest(&manager_ptr));
penghuangd6843e42016-12-17 13:57:20915 }
916
penghuang342762b2016-12-02 21:04:58917 discardable_shared_memory_manager_ = base::MakeUnique<
918 discardable_memory::ClientDiscardableSharedMemoryManager>(
919 std::move(manager_ptr), GetIOTaskRunner());
920
boliu9760e212015-06-23 22:49:06921 // TODO(boliu): In single process, browser main loop should set up the
922 // discardable memory manager, and should skip this if kSingleProcess.
923 // See crbug.com/503724.
924 base::DiscardableMemoryAllocator::SetInstance(
penghuang342762b2016-12-02 21:04:58925 discardable_shared_memory_manager_.get());
revemancb5a66af2014-10-25 00:34:39926
ben649b3edd2017-03-23 00:32:02927 GetConnector()->BindInterface(mojom::kBrowserServiceName,
928 mojo::MakeRequest(&storage_partition_service_));
hajimehoshi69093272016-05-13 08:30:58929
reveman7b97c322016-09-20 02:10:58930#if defined(OS_LINUX)
931 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY);
932 ChildThreadImpl::current()->SetThreadPriority(
lukasza6710dbd2017-04-07 20:58:03933 categorized_worker_pool_->background_worker_thread_id(),
reveman7b97c322016-09-20 02:10:58934 base::ThreadPriority::BACKGROUND);
935#endif
936
tasakbb0640b2017-05-15 09:02:26937 process_foregrounded_count_ = 0;
tasakb95dbb50c2017-02-08 18:07:50938 needs_to_record_first_active_paint_ = false;
hajimehoshi7bb39582016-10-12 04:30:57939
940 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
fdoray50a38342016-11-21 20:46:04941
942 // If this renderer doesn't run inside the browser process, enable
943 // SequencedWorkerPool. Otherwise, it should already have been enabled.
944 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler
945 // redirection experiment concludes https://crbug.com/622400.
946 if (!command_line.HasSwitch(switches::kSingleProcess))
947 base::SequencedWorkerPool::EnableForProcess();
samans2040988b2017-04-11 23:58:35948
David Benjaminb946811c2017-06-26 23:34:29949 EVP_set_buggy_rsa_parser(
950 base::FeatureList::IsEnabled(features::kBuggyRSAParser));
951
samans2040988b2017-04-11 23:58:35952 GetConnector()->BindInterface(mojom::kBrowserServiceName,
953 mojo::MakeRequest(&frame_sink_provider_));
initial.commit09911bf2008-07-26 23:55:29954}
955
[email protected]f1a29a02011-10-06 23:08:44956RenderThreadImpl::~RenderThreadImpl() {
[email protected]ce79d8512013-04-22 22:44:41957}
958
959void RenderThreadImpl::Shutdown() {
harakenbbfdd9f02017-01-12 07:14:04960 // In a multi-process mode, we immediately exit the renderer.
961 // Historically we had a graceful shutdown sequence here but it was
962 // 1) a waste of performance and 2) a source of lots of complicated
963 // crashes caused by shutdown ordering. Immediate exit eliminates
964 // those problems.
cbrunia3f655b2017-03-20 11:36:41965
966 // Give the V8 isolate a chance to dump internal stats useful for performance
967 // evaluation and debugging.
Blink Reformat1c4d759e2017-04-09 16:34:54968 blink::MainThreadIsolate()->DumpAndResetStats();
cbrunia3f655b2017-03-20 11:36:41969
Adithya Srinivasandf421e82017-06-01 14:36:11970 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
971 switches::kDumpBlinkRuntimeCallStats))
972 blink::LogRuntimeCallStats();
973
harakenbbfdd9f02017-01-12 07:14:04974 // In a single-process mode, we cannot call _exit(0) in Shutdown() because
975 // it will exit the process before the browser side is ready to exit.
976 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
977 switches::kSingleProcess))
haraken940efb92017-02-08 05:58:15978 base::Process::TerminateCurrentProcessImmediately(0);
harakenbbfdd9f02017-01-12 07:14:04979}
[email protected]1223d6ef2011-03-28 16:47:50980
harakenbbfdd9f02017-01-12 07:14:04981bool RenderThreadImpl::ShouldBeDestroyed() {
982 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
983 switches::kSingleProcess));
984 // In a single-process mode, it is unsafe to destruct this renderer thread
985 // because we haven't run the shutdown sequence. Hence we leak the render
986 // thread.
987 //
988 // In this case, we also need to disable at-exit callbacks because some of
989 // the at-exit callbacks are expected to run after the renderer thread
990 // has been destructed.
991 base::AtExitManager::DisableAllAtExitManagers();
992 return false;
initial.commit09911bf2008-07-26 23:55:29993}
994
[email protected]f1a29a02011-10-06 23:08:44995bool RenderThreadImpl::Send(IPC::Message* msg) {
changwan6ed4d432016-05-19 22:03:54996 // There are cases where we want to pump asynchronous messages while waiting
997 // synchronously for the replies to the message to be sent here. However, this
998 // may create an opportunity for re-entrancy into WebKit and other subsystems,
999 // so we need to take care to disable callbacks, timers, and pending network
1000 // loads that could trigger such callbacks.
[email protected]38b592902011-04-16 02:08:421001 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:501002 if (msg->is_sync()) {
1003 if (msg->is_caller_pumping_messages()) {
1004 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:501005 }
[email protected]c1f50aa2010-02-18 03:46:571006 }
1007
[email protected]c1f50aa2010-02-18 03:46:571008 if (pumping_events) {
Alexander Timin163290882017-08-01 17:38:071009 renderer_scheduler_->PauseTimerQueue();
Blink Reformat1c4d759e2017-04-09 16:34:541010 WebView::WillEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571011 }
1012
jam8a021512a2015-02-03 18:16:081013 bool rv = ChildThreadImpl::Send(msg);
[email protected]c1f50aa2010-02-18 03:46:571014
1015 if (pumping_events) {
Blink Reformat1c4d759e2017-04-09 16:34:541016 WebView::DidExitModalLoop();
jdduked73ae5412015-05-11 20:07:161017 renderer_scheduler_->ResumeTimerQueue();
[email protected]c1f50aa2010-02-18 03:46:571018 }
1019
1020 return rv;
1021}
1022
[email protected]f1a29a02011-10-06 23:08:441023IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:061024 return channel();
1025}
1026
[email protected]f1a29a02011-10-06 23:08:441027std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:061028 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:021029 // --lang command line flag.
avi83883c82014-12-23 00:08:491030 const base::CommandLine& parsed_command_line =
1031 *base::CommandLine::ForCurrentProcess();
[email protected]526476902011-10-06 20:34:061032 const std::string& lang =
1033 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:021034 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:061035 return lang;
1036}
1037
[email protected]07bb6332012-01-21 01:07:571038IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
1039 return sync_message_filter();
1040}
1041
avi1023d012015-12-25 02:39:141042void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) {
jam8a021512a2015-02-03 18:16:081043 ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener);
ben76f52b242016-06-18 05:42:481044 auto it = pending_frame_creates_.find(routing_id);
1045 if (it == pending_frame_creates_.end())
rockotf8fdd9b2015-12-16 22:22:351046 return;
1047
1048 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
1049 if (!frame)
1050 return;
1051
ben76f52b242016-06-18 05:42:481052 scoped_refptr<PendingFrameCreate> create(it->second);
benf28ce882017-05-02 16:15:491053 frame->BindFrame(it->second->browser_info(), it->second->TakeFrameRequest(),
csharrison95f01e922017-04-24 18:52:351054 it->second->TakeInterfaceBroker());
ben76f52b242016-06-18 05:42:481055 pending_frame_creates_.erase(it);
[email protected]c1f50aa2010-02-18 03:46:571056}
1057
avi1023d012015-12-25 02:39:141058void RenderThreadImpl::RemoveRoute(int32_t routing_id) {
jam8a021512a2015-02-03 18:16:081059 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id);
[email protected]c1f50aa2010-02-18 03:46:571060}
[email protected]0ec90d522014-03-12 16:28:191061
avi1023d012015-12-25 02:39:141062void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id,
[email protected]a620b132014-04-30 22:39:171063 IPC::Listener* listener) {
[email protected]48e52e42014-03-20 06:58:071064 AddRoute(routing_id, listener);
1065 if (devtools_agent_message_filter_.get()) {
[email protected]a620b132014-04-30 22:39:171066 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread(
[email protected]48e52e42014-03-20 06:58:071067 routing_id);
1068 }
1069}
1070
avi1023d012015-12-25 02:39:141071void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) {
[email protected]48e52e42014-03-20 06:58:071072 RemoveRoute(routing_id);
1073 if (devtools_agent_message_filter_.get()) {
[email protected]a620b132014-04-30 22:39:171074 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread(
[email protected]48e52e42014-03-20 06:58:071075 routing_id);
1076 }
1077}
1078
ben76f52b242016-06-18 05:42:481079void RenderThreadImpl::RegisterPendingFrameCreate(
benf28ce882017-05-02 16:15:491080 const service_manager::BindSourceInfo& browser_info,
rockotf8fdd9b2015-12-16 22:22:351081 int routing_id,
ben76f52b242016-06-18 05:42:481082 mojom::FrameRequest frame_request,
csharrison95f01e922017-04-24 18:52:351083 mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker) {
ben76f52b242016-06-18 05:42:481084 std::pair<PendingFrameCreateMap::iterator, bool> result =
1085 pending_frame_creates_.insert(std::make_pair(
csharrison95f01e922017-04-24 18:52:351086 routing_id, make_scoped_refptr(new PendingFrameCreate(
benf28ce882017-05-02 16:15:491087 browser_info, routing_id, std::move(frame_request),
csharrison95f01e922017-04-24 18:52:351088 std::move(frame_host_interface_broker)))));
rockotf8fdd9b2015-12-16 22:22:351089 CHECK(result.second) << "Inserting a duplicate item.";
1090}
1091
leon.han06e55662016-03-26 17:19:421092mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() {
jamc912ca32016-02-24 20:17:311093 return storage_partition_service_.get();
1094}
1095
jam188f19f2017-06-07 03:56:241096mojom::RendererHost* RenderThreadImpl::GetRendererHost() {
1097 if (!renderer_host_) {
1098 GetConnector()->BindInterface(mojom::kBrowserServiceName,
1099 mojo::MakeRequest(&renderer_host_));
1100 }
1101 return renderer_host_.get();
1102}
1103
[email protected]77fc9b92011-10-15 16:20:371104int RenderThreadImpl::GenerateRoutingID() {
rockote261d2112016-09-21 22:22:231105 int32_t routing_id = MSG_ROUTING_NONE;
1106 render_message_filter()->GenerateRoutingID(&routing_id);
[email protected]77fc9b92011-10-15 16:20:371107 return routing_id;
1108}
1109
[email protected]74122042014-04-25 00:07:301110void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551111 channel()->AddFilter(filter);
1112}
1113
[email protected]74122042014-04-25 00:07:301114void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551115 channel()->RemoveFilter(filter);
1116}
1117
tyoshino832a58a2016-04-18 08:14:081118void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) {
[email protected]526476902011-10-06 20:34:061119 observers_.AddObserver(observer);
nigeltao7cd8d5582016-12-12 06:05:281120 observer->RegisterMojoInterfaces(&associated_interfaces_);
[email protected]526476902011-10-06 20:34:061121}
1122
tyoshino832a58a2016-04-18 08:14:081123void RenderThreadImpl::RemoveObserver(RenderThreadObserver* observer) {
nigeltao7cd8d5582016-12-12 06:05:281124 observer->UnregisterMojoInterfaces(&associated_interfaces_);
[email protected]526476902011-10-06 20:34:061125 observers_.RemoveObserver(observer);
1126}
1127
[email protected]359dfa32011-10-12 01:10:151128void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:261129 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:151130 resource_dispatcher()->set_delegate(delegate);
1131}
1132
vollick1050cc62015-12-03 07:04:541133void RenderThreadImpl::InitializeCompositorThread() {
boliu66024c62016-04-20 04:00:411134 base::Thread::Options options;
vollick1050cc62015-12-03 07:04:541135#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:411136 options.priority = base::ThreadPriority::DISPLAY;
vollick1050cc62015-12-03 07:04:541137#endif
altiminc7369bf2017-04-11 14:29:151138 compositor_thread_ =
1139 blink::scheduler::WebThreadBase::CreateCompositorThread(options);
boliu66024c62016-04-20 04:00:411140 blink_platform_impl_->SetCompositorThread(compositor_thread_.get());
1141 compositor_task_runner_ = compositor_thread_->GetTaskRunner();
1142 compositor_task_runner_->PostTask(
1143 FROM_HERE,
1144 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), false));
reveman7b97c322016-09-20 02:10:581145#if defined(OS_LINUX)
Blink Reformat1c4d759e2017-04-09 16:34:541146 ChildThreadImpl::current()->SetThreadPriority(compositor_thread_->ThreadId(),
reveman7b97c322016-09-20 02:10:581147 base::ThreadPriority::DISPLAY);
1148#endif
vollick1050cc62015-12-03 07:04:541149
boliude5b75b2016-03-11 07:02:141150 SynchronousInputHandlerProxyClient* synchronous_input_handler_proxy_client =
1151 nullptr;
vollick1050cc62015-12-03 07:04:541152#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:411153 if (GetContentClient()->UsingSynchronousCompositing()) {
vollick1050cc62015-12-03 07:04:541154 sync_compositor_message_filter_ =
1155 new SynchronousCompositorFilter(compositor_task_runner_);
1156 AddFilter(sync_compositor_message_filter_.get());
boliude5b75b2016-03-11 07:02:141157 synchronous_input_handler_proxy_client =
1158 sync_compositor_message_filter_.get();
vollick1050cc62015-12-03 07:04:541159 }
1160#endif
boliub2768db2016-06-03 23:35:161161 scoped_refptr<InputEventFilter> compositor_input_event_filter(
1162 new InputEventFilter(main_input_callback_.callback(),
1163 main_thread_compositor_task_runner_,
1164 compositor_task_runner_));
1165 InputHandlerManagerClient* input_handler_manager_client =
1166 compositor_input_event_filter.get();
1167 input_event_filter_ = compositor_input_event_filter;
vollick1050cc62015-12-03 07:04:541168 input_handler_manager_.reset(new InputHandlerManager(
1169 compositor_task_runner_, input_handler_manager_client,
boliude5b75b2016-03-11 07:02:141170 synchronous_input_handler_proxy_client, renderer_scheduler_.get()));
vollick1050cc62015-12-03 07:04:541171}
1172
jam75c44222016-03-23 05:34:241173void RenderThreadImpl::InitializeWebKit(
rockot97a86832016-12-10 04:53:061174 const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) {
jam75c44222016-03-23 05:34:241175 DCHECK(!blink_platform_impl_);
[email protected]d1b8fccc2011-08-03 01:20:131176
avi83883c82014-12-23 00:08:491177 const base::CommandLine& command_line =
1178 *base::CommandLine::ForCurrentProcess();
chunyang.daibe874c52014-11-14 06:45:051179
1180#ifdef ENABLE_VTUNE_JIT_INTERFACE
1181 if (command_line.HasSwitch(switches::kEnableVtune))
1182 gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler());
1183#endif
1184
Lukasz Anforowicz5a024122017-07-19 21:31:571185 blink_platform_impl_.reset(new RendererBlinkPlatformImpl(
1186 renderer_scheduler_.get(), GetConnector()->GetWeakPtr()));
rmcilroy4073ae12015-01-08 13:08:101187 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line);
hlopko852ffcf2016-09-16 16:50:591188 GetContentClient()
1189 ->renderer()
1190 ->SetRuntimeFeaturesDefaultsBeforeBlinkInitialization();
Blink Reformat1c4d759e2017-04-09 16:34:541191 blink::Initialize(blink_platform_impl_.get());
[email protected]d1b8fccc2011-08-03 01:20:131192
Blink Reformat1c4d759e2017-04-09 16:34:541193 v8::Isolate* isolate = blink::MainThreadIsolate();
[email protected]4b5340282014-07-08 11:37:341194 isolate->SetCreateHistogramFunction(CreateHistogram);
1195 isolate->SetAddHistogramSampleFunction(AddHistogramSample);
skyostila37c2a72016-06-29 17:30:071196 renderer_scheduler_->SetRAILModeObserver(this);
[email protected]4b5340282014-07-08 11:37:341197
rmcilroy321f924d2014-11-06 00:56:001198 main_thread_compositor_task_runner_ =
danakj6e3bf8012014-12-16 18:27:531199 renderer_scheduler_->CompositorTaskRunner();
skyostilc30aa402014-10-10 13:49:091200
jdduke691dd572014-12-02 20:47:521201 main_input_callback_.Reset(
1202 base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived),
1203 base::Unretained(this)));
1204
jam75c44222016-03-23 05:34:241205 scoped_refptr<base::SingleThreadTaskRunner> resource_task_queue2;
1206 if (resource_task_queue) {
1207 resource_task_queue2 = resource_task_queue;
1208 } else {
1209 resource_task_queue2 = renderer_scheduler_->LoadingTaskRunner();
1210 }
1211 // Add a filter that forces resource messages to be dispatched via a
1212 // particular task runner.
1213 scoped_refptr<ResourceSchedulingFilter> filter(
1214 new ResourceSchedulingFilter(
1215 resource_task_queue2, resource_dispatcher()));
1216 channel()->AddFilter(filter.get());
1217 resource_dispatcher()->SetResourceSchedulingFilter(filter);
1218
1219 // The ChildResourceMessageFilter and the ResourceDispatcher need to use the
1220 // same queue to ensure tasks are executed in the expected order.
1221 child_resource_message_filter()->SetMainThreadTaskRunner(
1222 resource_task_queue2);
horoe6120582017-04-26 01:48:591223 resource_dispatcher()->SetThreadTaskRunner(resource_task_queue2);
jam75c44222016-03-23 05:34:241224
khushalsagard7178e42017-01-20 01:31:491225 if (!command_line.HasSwitch(switches::kDisableThreadedCompositing))
vollick1050cc62015-12-03 07:04:541226 InitializeCompositorThread();
[email protected]a9fb30aa2011-10-06 06:58:461227
jdduke691dd572014-12-02 20:47:521228 if (!input_event_filter_.get()) {
1229 // Always provide an input event filter implementation to ensure consistent
1230 // input event scheduling and prioritization.
1231 // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and
1232 // MainThreadInputEventFilter, crbug.com/436057.
1233 input_event_filter_ = new MainThreadInputEventFilter(
1234 main_input_callback_.callback(), main_thread_compositor_task_runner_);
1235 }
1236 AddFilter(input_event_filter_.get());
1237
skyostil2d3b5bd2015-05-27 15:40:591238 scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner;
vollick1050cc62015-12-03 07:04:541239 if (compositor_task_runner_)
skyostil2d3b5bd2015-05-27 15:40:591240 compositor_impl_side_task_runner = compositor_task_runner_;
[email protected]7f1f63f2013-03-07 06:07:291241 else
skyostil2d3b5bd2015-05-27 15:40:591242 compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get();
[email protected]1842fe22012-08-13 23:24:351243
simonhonga7e3ac42014-11-11 20:50:221244 compositor_message_filter_ = new CompositorForwardingMessageFilter(
skyostil2d3b5bd2015-05-27 15:40:591245 compositor_impl_side_task_runner.get());
simonhonga7e3ac42014-11-11 20:50:221246 AddFilter(compositor_message_filter_.get());
[email protected]1842fe22012-08-13 23:24:351247
[email protected]58436a12012-03-21 17:10:261248 RenderThreadImpl::RegisterSchemes();
1249
xhwang194acae2014-11-12 22:46:331250 RenderMediaClient::Initialize();
1251
[email protected]b146d6d2012-09-11 10:20:051252 devtools_agent_message_filter_ = new DevToolsAgentFilter();
1253 AddFilter(devtools_agent_message_filter_.get());
1254
ulan4a385192015-11-11 10:59:181255 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]1784b2f2011-11-24 10:53:481256 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
ulan4a385192015-11-11 10:59:181257 } else {
1258 // If we do not track widget visibility, then assume conservatively that
1259 // the isolate is in background. This reduces memory usage.
1260 isolate->IsolateInBackgroundNotification();
1261 }
[email protected]2541d1a2013-07-10 07:33:271262
Alexander Timin163290882017-08-01 17:38:071263 renderer_scheduler_->SetTimerQueueStoppingWhenBackgroundedEnabled(
jdduke73220f02015-09-04 17:03:511264 GetContentClient()
1265 ->renderer()
Alexander Timin163290882017-08-01 17:38:071266 ->AllowStoppingTimersWhenProcessBackgrounded());
jdduke73220f02015-09-04 17:03:511267
reedccf98c52014-10-03 16:40:381268 SkGraphics::SetResourceCacheSingleAllocationByteLimit(
[email protected]dd2c1022014-07-22 23:13:571269 kImageCacheSingleAllocationByteLimit);
1270
reed6e5a72222015-08-06 20:37:161271 // Hook up blink's codecs so skia can call them
reed08cd16372017-02-21 22:11:411272 SkGraphics::SetImageGeneratorFromEncodedDataFactory(
Blink Reformat1c4d759e2017-04-09 16:34:541273 blink::WebImageGenerator::Create);
reed6e5a72222015-08-06 20:37:161274
paritosh.in7e30c902015-04-15 17:04:071275 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) {
1276 std::string allowed_ports =
1277 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts);
1278 net::SetExplicitlyAllowedPorts(allowed_ports);
1279 }
[email protected]d1b8fccc2011-08-03 01:20:131280}
1281
[email protected]58436a12012-03-21 17:10:261282void RenderThreadImpl::RegisterSchemes() {
mkwst8e94fb32015-05-20 05:05:141283 // chrome:
Blink Reformat1c4d759e2017-04-09 16:34:541284 WebString chrome_scheme(WebString::FromASCII(kChromeUIScheme));
1285 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(chrome_scheme);
1286 WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(
mkwst8e94fb32015-05-20 05:05:141287 chrome_scheme);
mkwst8e94fb32015-05-20 05:05:141288
1289 // chrome-devtools:
Blink Reformat1c4d759e2017-04-09 16:34:541290 WebString devtools_scheme(WebString::FromASCII(kChromeDevToolsScheme));
1291 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(devtools_scheme);
meacerce6b66032016-06-02 20:56:051292
1293 // view-source:
Blink Reformat1c4d759e2017-04-09 16:34:541294 WebString view_source_scheme(WebString::FromASCII(kViewSourceScheme));
1295 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(view_source_scheme);
Alex Moshchuk71f485592017-08-16 16:20:001296
1297 // chrome-error:
1298 WebString error_scheme(WebString::FromASCII(kChromeErrorScheme));
1299 WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(error_scheme);
1300 WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(error_scheme);
[email protected]58436a12012-03-21 17:10:261301}
1302
[email protected]e6e30ac2014-01-13 21:24:391303void RenderThreadImpl::RecordAction(const base::UserMetricsAction& action) {
[email protected]97880c82013-12-04 07:09:211304 Send(new ViewHostMsg_UserMetricsRecordAction(action.str_));
1305}
1306
1307void RenderThreadImpl::RecordComputedAction(const std::string& action) {
[email protected]526476902011-10-06 20:34:061308 Send(new ViewHostMsg_UserMetricsRecordAction(action));
1309}
1310
dchengcedca5612016-04-09 01:40:151311std::unique_ptr<base::SharedMemory>
1312RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
sadrulee3ff1f2016-12-09 04:22:011313 return ChildThreadImpl::AllocateSharedMemory(size);
[email protected]00614a82011-10-07 22:39:311314}
1315
Fady Samuel4b5f9862017-07-11 05:27:201316viz::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() {
jbauman2f5c1942014-12-06 03:28:241317 return shared_bitmap_manager();
1318}
1319
[email protected]f1a29a02011-10-06 23:08:441320void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
Blink Reformat1c4d759e2017-04-09 16:34:541321 WebScriptController::RegisterExtension(extension);
[email protected]526476902011-10-06 20:34:061322}
1323
avi1023d012015-12-25 02:39:141324void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) {
[email protected]6593ae12011-11-14 12:09:441325 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:061326 idle_timer_.Stop();
1327 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:441328 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:441329 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:061330}
1331
[email protected]f1a29a02011-10-06 23:08:441332void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:481333 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:261334 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:481335 RunIdleHandlerWhenWidgetsHidden();
1336 if (run_in_foreground_tab) {
jochen5a32aaf2014-09-26 20:37:431337 if (idle_notifications_to_skip_ > 0) {
1338 --idle_notifications_to_skip_;
1339 } else {
ssid0603ca9f2015-06-09 16:48:081340 ReleaseFreeMemory();
jochen5a32aaf2014-09-26 20:37:431341 }
1342 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]1784b2f2011-11-24 10:53:481343 return;
1344 }
[email protected]237a14852012-04-28 02:56:381345
ssid0603ca9f2015-06-09 16:48:081346 ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:061347
[email protected]26e82322014-01-20 14:18:221348 // Continue the idle timer if the webkit shared timer is not suspended or
1349 // something is left to do.
1350 bool continue_timer = !webkit_shared_timer_suspended_;
1351
sullivancd45a3e2014-09-19 14:39:181352 // Schedule next invocation. When the tab is originally hidden, an invocation
1353 // is scheduled for kInitialIdleHandlerDelayMs in
1354 // RenderThreadImpl::WidgetHidden in order to race to a minimal heap.
1355 // After that, idle calls can be much less frequent, so run at a maximum of
1356 // once every kLongIdleHandlerDelayMs.
[email protected]6593ae12011-11-14 12:09:441357 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:061358 // delay = delay + 1 / (delay + 2)
1359 // Using floor(delay) has a dampening effect such as:
sullivancd45a3e2014-09-19 14:39:181360 // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ...
[email protected]6593ae12011-11-14 12:09:441361 // If the delay is in milliseconds, the above formula is equivalent to:
1362 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
1363 // which is equivalent to
1364 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
[email protected]26e82322014-01-20 14:18:221365 if (continue_timer) {
sullivancd45a3e2014-09-19 14:39:181366 ScheduleIdleHandler(
1367 std::max(kLongIdleHandlerDelayMs,
1368 idle_notification_delay_in_ms_ +
1369 1000000 / (idle_notification_delay_in_ms_ + 2000)));
[email protected]26e82322014-01-20 14:18:221370
1371 } else {
1372 idle_timer_.Stop();
1373 }
[email protected]526476902011-10-06 20:34:061374
ericwilligers88e69742016-10-17 19:29:551375 for (auto& observer : observers_)
1376 observer.IdleNotification();
[email protected]526476902011-10-06 20:34:061377}
1378
avi1023d012015-12-25 02:39:141379int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const {
[email protected]6593ae12011-11-14 12:09:441380 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:061381}
1382
[email protected]6593ae12011-11-14 12:09:441383void RenderThreadImpl::SetIdleNotificationDelayInMs(
avi1023d012015-12-25 02:39:141384 int64_t idle_notification_delay_in_ms) {
[email protected]6593ae12011-11-14 12:09:441385 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:081386}
1387
[email protected]5b18406362013-06-18 18:46:431388int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) {
kinukoef647412015-12-23 06:10:431389 return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure);
[email protected]a9bd323d2013-06-17 20:27:561390}
1391
[email protected]b02f5902012-12-19 07:33:001392bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
1393 bool result = false;
1394 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
1395 return result;
1396}
1397
[email protected]1784b2f2011-11-24 10:53:481398void RenderThreadImpl::PostponeIdleNotification() {
1399 idle_notifications_to_skip_ = 2;
1400}
1401
dcastagna7f45dada2015-10-19 20:17:351402media::GpuVideoAcceleratorFactories* RenderThreadImpl::GetGpuFactories() {
[email protected]3bb8bb32013-07-11 13:13:031403 DCHECK(IsMainThread());
1404
dcastagna09bd6b32016-02-01 21:54:281405 if (!gpu_factories_.empty()) {
sadrul85cc5d82016-12-20 03:37:411406 scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider =
dcastagna09bd6b32016-02-01 21:54:281407 gpu_factories_.back()->ContextProviderMainThread();
1408 if (shared_context_provider) {
Xu Xing32549162017-07-17 22:25:431409 viz::ContextProvider::ScopedContextLock lock(
dcastagna09bd6b32016-02-01 21:54:281410 shared_context_provider.get());
1411 if (lock.ContextGL()->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
leon.han21e0e482017-02-23 04:13:321412 return gpu_factories_.back().get();
dcastagna09bd6b32016-02-01 21:54:281413 } else {
1414 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1415 GetMediaThreadTaskRunner();
1416 media_task_runner->PostTask(
1417 FROM_HERE,
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:591418 base::Bind(base::IgnoreResult(
1419 &GpuVideoAcceleratorFactoriesImpl::CheckContextLost),
1420 base::Unretained(gpu_factories_.back().get())));
dcastagna09bd6b32016-02-01 21:54:281421 }
1422 }
1423 }
dcastagna7f45dada2015-10-19 20:17:351424
tobiasjsca238b3b2015-06-24 22:53:541425 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1426
danakj0b4b94e32016-05-10 22:33:011427 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
sadrul6d310fa2016-08-04 02:12:161428 EstablishGpuChannelSync();
danakj0b4b94e32016-05-10 22:33:011429 if (!gpu_channel_host)
1430 return nullptr;
danakj0dd9e1e2016-05-11 22:15:091431 // This context is only used to create textures and mailbox them, so
1432 // use lower limits than the default.
1433 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
danakj9a04adc2016-05-16 22:45:071434 bool support_locking = true;
sadrul85cc5d82016-12-20 03:37:411435 scoped_refptr<ui::ContextProviderCommandBuffer> media_context_provider =
danakj9a04adc2016-05-16 22:45:071436 CreateOffscreenContext(gpu_channel_host, limits, support_locking,
ericrka20c1002017-03-13 21:08:131437 ui::command_buffer_metrics::MEDIA_CONTEXT,
sunnyps8f9139e2017-05-12 17:53:251438 kGpuStreamIdDefault, kGpuStreamPriorityDefault);
danakj0b4b94e32016-05-10 22:33:011439 if (!media_context_provider->BindToCurrentThread())
1440 return nullptr;
danakj0b4b94e32016-05-10 22:33:011441
acolwellb4034942014-08-28 15:42:431442 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1443 GetMediaThreadTaskRunner();
danakj0b4b94e32016-05-10 22:33:011444 const bool enable_video_accelerator =
1445 !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode);
1446 const bool enable_gpu_memory_buffer_video_frames =
dcastagna43c3a86a2016-02-02 21:16:381447#if defined(OS_MACOSX) || defined(OS_LINUX)
dcastagnaa82ed96a2016-05-12 02:52:471448 !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) &&
1449 !cmd_line->HasSwitch(switches::kDisableGpuCompositing) &&
1450 !gpu_channel_host->gpu_info().software_rendering;
jbaumana0bb8982017-05-05 19:50:531451#elif defined(OS_WIN)
1452 !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) &&
1453 !cmd_line->HasSwitch(switches::kDisableGpuCompositing) &&
1454 !gpu_channel_host->gpu_info().software_rendering &&
1455 (cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames) ||
1456 gpu_channel_host->gpu_info().supports_overlays);
dcastagnab65e6072015-09-05 07:18:421457#else
danakj0b4b94e32016-05-10 22:33:011458 cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames);
dcastagnab65e6072015-09-05 07:18:421459#endif
dcastagna5077d6d2016-01-27 00:07:051460
Miguel Casas-Sanchez7d464702017-07-29 14:19:211461 media::mojom::VideoEncodeAcceleratorProviderPtr vea_provider;
1462 gpu_->CreateVideoEncodeAcceleratorProvider(mojo::MakeRequest(&vea_provider));
Miguel Casas-Sanchezdaca32562017-07-11 08:05:451463
Miguel Casas-Sanchezcfcca5d52017-07-07 02:32:591464 gpu_factories_.push_back(GpuVideoAcceleratorFactoriesImpl::Create(
danakj0b4b94e32016-05-10 22:33:011465 std::move(gpu_channel_host), base::ThreadTaskRunnerHandle::Get(),
1466 media_task_runner, std::move(media_context_provider),
ericrk9151705c2016-07-26 19:53:161467 enable_gpu_memory_buffer_video_frames, buffer_to_texture_target_map_,
Miguel Casas-Sanchez7d464702017-07-29 14:19:211468 enable_video_accelerator, vea_provider.PassInterface()));
leon.han21e0e482017-02-23 04:13:321469 return gpu_factories_.back().get();
[email protected]3bb8bb32013-07-11 13:13:031470}
1471
sadrul85cc5d82016-12-20 03:37:411472scoped_refptr<ui::ContextProviderCommandBuffer>
[email protected]f10dc472013-09-27 03:31:591473RenderThreadImpl::SharedMainThreadContextProvider() {
[email protected]e06e1122013-03-15 17:12:381474 DCHECK(IsMainThread());
danakje8ec797e2016-04-19 04:08:431475 if (shared_main_thread_contexts_ &&
1476 shared_main_thread_contexts_->ContextGL()->GetGraphicsResetStatusKHR() ==
1477 GL_NO_ERROR)
1478 return shared_main_thread_contexts_;
1479
sadrul6d310fa2016-08-04 02:12:161480 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
1481 EstablishGpuChannelSync());
danakje8ec797e2016-04-19 04:08:431482 if (!gpu_channel_host) {
1483 shared_main_thread_contexts_ = nullptr;
1484 return nullptr;
[email protected]c29b7ff2013-03-06 03:51:041485 }
danakje8ec797e2016-04-19 04:08:431486
danakj9a04adc2016-05-16 22:45:071487 bool support_locking = false;
danakjc3983552016-05-03 00:04:351488 shared_main_thread_contexts_ = CreateOffscreenContext(
danakj9a04adc2016-05-16 22:45:071489 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking,
sadrul85cc5d82016-12-20 03:37:411490 ui::command_buffer_metrics::RENDERER_MAINTHREAD_CONTEXT,
sunnyps8f9139e2017-05-12 17:53:251491 kGpuStreamIdDefault, kGpuStreamPriorityDefault);
danakje8ec797e2016-04-19 04:08:431492 if (!shared_main_thread_contexts_->BindToCurrentThread())
1493 shared_main_thread_contexts_ = nullptr;
[email protected]f10dc472013-09-27 03:31:591494 return shared_main_thread_contexts_;
[email protected]c29b7ff2013-03-06 03:51:041495}
1496
siva.gunturi5d4feb052015-11-15 16:15:311497#if defined(OS_ANDROID)
boliuf8753bf62016-02-11 20:09:421498
siva.gunturi5d4feb052015-11-15 16:15:311499scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() {
1500 DCHECK(IsMainThread());
boliu30f1b262016-04-19 00:12:331501 if (!stream_texture_factory_.get() ||
1502 stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() !=
1503 GL_NO_ERROR) {
sadrul85cc5d82016-12-20 03:37:411504 scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider =
piman9fc22f32016-05-02 22:21:221505 SharedMainThreadContextProvider();
1506 if (!shared_context_provider) {
penghuange1d86512016-07-08 18:15:001507 stream_texture_factory_ = nullptr;
1508 return nullptr;
siva.gunturi5d4feb052015-11-15 16:15:311509 }
piman9fc22f32016-05-02 22:21:221510 DCHECK(shared_context_provider->GetCommandBufferProxy());
1511 DCHECK(shared_context_provider->GetCommandBufferProxy()->channel());
1512 stream_texture_factory_ =
1513 StreamTextureFactory::Create(std::move(shared_context_provider));
siva.gunturi5d4feb052015-11-15 16:15:311514 }
1515 return stream_texture_factory_;
1516}
boliuf8753bf62016-02-11 20:09:421517
1518bool RenderThreadImpl::EnableStreamTextureCopy() {
boliu30f1b262016-04-19 00:12:331519 return sync_compositor_message_filter_.get();
boliuf8753bf62016-02-11 20:09:421520}
1521
siva.gunturi5d4feb052015-11-15 16:15:311522#endif
1523
[email protected]e9ff79c2012-10-19 21:31:261524AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]59383c782013-04-17 16:43:271525 if (!audio_renderer_mixer_manager_) {
olka7a4679392016-05-27 15:32:581526 audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create();
[email protected]3958e972012-07-17 00:25:411527 }
1528
1529 return audio_renderer_mixer_manager_.get();
1530}
1531
[email protected]73429ca2014-03-06 06:07:471532base::WaitableEvent* RenderThreadImpl::GetShutdownEvent() {
1533 return ChildProcess::current()->GetShutDownEvent();
1534}
1535
staraz067f58242016-11-07 21:06:411536int32_t RenderThreadImpl::GetClientId() {
1537 return client_id_;
1538}
1539
altiminc8885e82017-01-18 13:11:141540scoped_refptr<base::SingleThreadTaskRunner>
1541RenderThreadImpl::GetTimerTaskRunner() {
1542 return renderer_scheduler_->TimerTaskRunner();
1543}
1544
1545scoped_refptr<base::SingleThreadTaskRunner>
1546RenderThreadImpl::GetLoadingTaskRunner() {
1547 return renderer_scheduler_->LoadingTaskRunner();
1548}
1549
Karan Bhatiac89897f2017-08-10 01:06:401550void RenderThreadImpl::SetRendererProcessType(
1551 blink::scheduler::RendererProcessType type) {
1552 renderer_scheduler_->SetRendererProcessType(type);
1553}
1554
rockot067ca55f2016-09-30 22:00:151555void RenderThreadImpl::OnAssociatedInterfaceRequest(
1556 const std::string& name,
1557 mojo::ScopedInterfaceEndpointHandle handle) {
rockot70bbb59492017-01-25 00:56:511558 if (associated_interfaces_.CanBindRequest(name))
1559 associated_interfaces_.BindRequest(name, std::move(handle));
1560 else
1561 ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle));
rockot067ca55f2016-09-30 22:00:151562}
1563
weilifabbf7572017-05-22 19:05:161564scoped_refptr<base::SingleThreadTaskRunner>
1565RenderThreadImpl::GetIOTaskRunner() {
1566 return ChildProcess::current()->io_task_runner();
1567}
1568
danakj6e3bf8012014-12-16 18:27:531569bool RenderThreadImpl::IsGpuRasterizationForced() {
1570 return is_gpu_rasterization_forced_;
1571}
1572
sunnypsd8ce1c22016-05-10 18:02:401573bool RenderThreadImpl::IsAsyncWorkerContextEnabled() {
1574 return is_async_worker_context_enabled_;
1575}
1576
senorblancob60ba952015-01-27 19:12:361577int RenderThreadImpl::GetGpuRasterizationMSAASampleCount() {
1578 return gpu_rasterization_msaa_sample_count_;
1579}
1580
danakj6e3bf8012014-12-16 18:27:531581bool RenderThreadImpl::IsLcdTextEnabled() {
1582 return is_lcd_text_enabled_;
1583}
1584
1585bool RenderThreadImpl::IsDistanceFieldTextEnabled() {
1586 return is_distance_field_text_enabled_;
1587}
1588
1589bool RenderThreadImpl::IsZeroCopyEnabled() {
1590 return is_zero_copy_enabled_;
1591}
1592
ericrk1d17f752015-10-20 03:03:071593bool RenderThreadImpl::IsPartialRasterEnabled() {
1594 return is_partial_raster_enabled_;
jbroman5f7f71932015-08-18 16:24:461595}
1596
ccameronc7fcd132015-11-03 20:14:311597bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() {
1598 return is_gpu_memory_buffer_compositor_resources_enabled_;
1599}
1600
ccamerona7644752014-12-30 01:16:311601bool RenderThreadImpl::IsElasticOverscrollEnabled() {
1602 return is_elastic_overscroll_enabled_;
1603}
1604
Fady Samuel1d744b22017-07-10 21:23:551605const viz::BufferToTextureTargetMap&
ericrk9151705c2016-07-26 19:53:161606RenderThreadImpl::GetBufferToTextureTargetMap() {
1607 return buffer_to_texture_target_map_;
danakj6e3bf8012014-12-16 18:27:531608}
vmiura9084b342015-02-03 22:19:571609
danakj6e3bf8012014-12-16 18:27:531610scoped_refptr<base::SingleThreadTaskRunner>
1611RenderThreadImpl::GetCompositorMainThreadTaskRunner() {
1612 return main_thread_compositor_task_runner_;
1613}
1614
1615scoped_refptr<base::SingleThreadTaskRunner>
1616RenderThreadImpl::GetCompositorImplThreadTaskRunner() {
skyostil2d3b5bd2015-05-27 15:40:591617 return compositor_task_runner_;
danakj6e3bf8012014-12-16 18:27:531618}
1619
1620gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() {
sadrul53546592016-12-17 01:44:211621 return gpu_->gpu_memory_buffer_manager();
danakj6e3bf8012014-12-16 18:27:531622}
1623
skyostil529caa292016-08-10 17:44:511624blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() {
danakj6e3bf8012014-12-16 18:27:531625 return renderer_scheduler_.get();
1626}
1627
Fady Samuelc645ffe2017-07-24 17:28:201628std::unique_ptr<viz::BeginFrameSource>
danakj6e3bf8012014-12-16 18:27:531629RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) {
ricea29649b92016-08-31 09:30:211630 return base::MakeUnique<CompositorExternalBeginFrameSource>(
1631 compositor_message_filter_.get(), sync_message_filter(), routing_id);
danakj6e3bf8012014-12-16 18:27:531632}
1633
Fady Samuelc645ffe2017-07-24 17:28:201634std::unique_ptr<viz::SyntheticBeginFrameSource>
samans09812d32017-03-27 19:51:501635RenderThreadImpl::CreateSyntheticBeginFrameSource() {
1636 base::SingleThreadTaskRunner* compositor_impl_side_task_runner =
1637 compositor_task_runner_ ? compositor_task_runner_.get()
1638 : base::ThreadTaskRunnerHandle::Get().get();
Fady Samuelc645ffe2017-07-24 17:28:201639 return base::MakeUnique<viz::BackToBackBeginFrameSource>(
1640 base::MakeUnique<viz::DelayBasedTimeSource>(
samans09812d32017-03-27 19:51:501641 compositor_impl_side_task_runner));
1642}
1643
reveman34b7a1522015-03-23 20:27:471644cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() {
prashant.nfad657e2016-06-01 07:52:171645 return categorized_worker_pool_->GetTaskGraphRunner();
reveman34b7a1522015-03-23 20:27:471646}
1647
loyso65c93c602015-08-11 05:15:571648bool RenderThreadImpl::IsThreadedAnimationEnabled() {
1649 return is_threaded_animation_enabled_;
1650}
1651
wjmaclean1d970622017-01-21 22:28:241652bool RenderThreadImpl::IsScrollAnimatorEnabled() {
1653 return is_scroll_animator_enabled_;
1654}
1655
skyostila37c2a72016-06-29 17:30:071656void RenderThreadImpl::OnRAILModeChanged(v8::RAILMode rail_mode) {
Blink Reformat1c4d759e2017-04-09 16:34:541657 blink::MainThreadIsolate()->SetRAILMode(rail_mode);
1658 blink::SetRAILModeOnWorkerThreadIsolates(rail_mode);
skyostila37c2a72016-06-29 17:30:071659}
1660
[email protected]b3e83de2012-02-07 03:33:281661bool RenderThreadImpl::IsMainThread() {
1662 return !!current();
1663}
1664
torne88b66452016-05-03 13:22:141665void RenderThreadImpl::OnChannelError() {
1666 // In single-process mode, the renderer can't be restarted after shutdown.
1667 // So, if we get a channel error, crash the whole process right now to get a
1668 // more informative stack, since we will otherwise just crash later when we
1669 // try to restart it.
1670 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
1671 switches::kSingleProcess));
1672 ChildThreadImpl::OnChannelError();
1673}
1674
[email protected]f1a29a02011-10-06 23:08:441675bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
dchenga2d442c22016-10-13 15:39:211676 for (auto& observer : observers_) {
1677 if (observer.OnControlMessageReceived(msg))
[email protected]1223d6ef2011-03-28 16:47:501678 return true;
1679 }
1680
[email protected]70c19a932010-05-14 12:59:111681 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101682 if (appcache_dispatcher_->OnMessageReceived(msg) ||
leon.han7a5714382017-04-16 03:25:001683 dom_storage_dispatcher_->OnMessageReceived(msg)) {
[email protected]a95986a82010-12-24 06:19:281684 return true;
[email protected]1910fe82012-05-10 00:04:101685 }
[email protected]1edc16b82009-04-07 17:45:541686
[email protected]a95986a82010-12-24 06:19:281687 bool handled = true;
[email protected]f1a29a02011-10-06 23:08:441688 IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
[email protected]0ec90d522014-03-12 16:28:191689 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateNewSharedWorker)
[email protected]a95986a82010-12-24 06:19:281690 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281691 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281692 return handled;
initial.commit09911bf2008-07-26 23:55:291693}
1694
jdduke73220f02015-09-04 17:03:511695void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) {
1696 ChildThreadImpl::OnProcessBackgrounded(backgrounded);
1697
Alexander Timin771b3372017-06-15 13:26:471698 renderer_scheduler_->SetRendererBackgrounded(backgrounded);
hajimehoshi69093272016-05-13 08:30:581699 if (backgrounded) {
tasakb95dbb50c2017-02-08 18:07:501700 needs_to_record_first_active_paint_ = false;
tasak335a1872017-06-14 09:50:231701 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1702 FROM_HERE,
1703 base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1704 base::Unretained(this), "5min", process_foregrounded_count_),
1705 base::TimeDelta::FromMinutes(5));
1706 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1707 FROM_HERE,
1708 base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1709 base::Unretained(this), "10min",
1710 process_foregrounded_count_),
1711 base::TimeDelta::FromMinutes(10));
1712 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1713 FROM_HERE,
1714 base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded,
1715 base::Unretained(this), "15min",
1716 process_foregrounded_count_),
1717 base::TimeDelta::FromMinutes(15));
hajimehoshi69093272016-05-13 08:30:581718 } else {
tasakbb0640b2017-05-15 09:02:261719 process_foregrounded_count_++;
hajimehoshi69093272016-05-13 08:30:581720 }
1721}
1722
1723void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1724 ChildThreadImpl::OnProcessPurgeAndSuspend();
tasak6ff44032016-11-07 06:45:251725 if (!RendererIsHidden())
hajimehoshi69093272016-05-13 08:30:581726 return;
tasakff1e62422016-12-22 04:53:551727
tasakc4de4672017-04-26 02:37:361728 if (!base::FeatureList::IsEnabled(features::kPurgeAndSuspend))
1729 return;
1730
1731 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
tasakb95dbb50c2017-02-08 18:07:501732 needs_to_record_first_active_paint_ = true;
tasakc4de4672017-04-26 02:37:361733
1734 RendererMemoryMetrics memory_metrics;
1735 if (!GetRendererMemoryMetrics(&memory_metrics))
1736 return;
1737
1738 purge_and_suspend_memory_metrics_ = memory_metrics;
tasaka27961a2017-05-24 07:33:251739 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1740 FROM_HERE,
1741 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1742 base::Unretained(this), "30min", process_foregrounded_count_),
1743 base::TimeDelta::FromMinutes(30));
1744 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1745 FROM_HERE,
1746 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1747 base::Unretained(this), "60min", process_foregrounded_count_),
1748 base::TimeDelta::FromMinutes(60));
1749 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1750 FROM_HERE,
1751 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1752 base::Unretained(this), "90min", process_foregrounded_count_),
1753 base::TimeDelta::FromMinutes(90));
tasakb46626a2016-10-18 05:54:441754}
1755
bashia0ba0d42017-04-03 08:11:061756bool RenderThreadImpl::GetRendererMemoryMetrics(
keishi51ed0d52017-01-12 10:04:461757 RendererMemoryMetrics* memory_metrics) const {
1758 DCHECK(memory_metrics);
1759
chrisha05e94f22017-04-05 22:06:041760 // Cache this result, as it can change while this code is running, and is used
1761 // as a divisor below.
1762 size_t render_view_count = RenderView::GetRenderViewCount();
1763
1764 // If there are no render views it doesn't make sense to calculate metrics
1765 // right now.
1766 if (render_view_count == 0)
bashia0ba0d42017-04-03 08:11:061767 return false;
1768
keishi51ed0d52017-01-12 10:04:461769 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get();
1770 memory_metrics->partition_alloc_kb =
Blink Reformat1c4d759e2017-04-09 16:34:541771 blink_stats.partition_alloc_total_allocated_bytes / 1024;
1772 memory_metrics->blink_gc_kb =
1773 blink_stats.blink_gc_total_allocated_bytes / 1024;
keishi12b598b92017-06-20 10:25:261774 std::unique_ptr<base::ProcessMetrics> metric(
1775 base::ProcessMetrics::CreateCurrentProcessMetrics());
1776 size_t malloc_usage = metric->GetMallocUsage();
keishi51ed0d52017-01-12 10:04:461777 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024;
1778
1779 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics
1780 discardable_stats = discardable_shared_memory_manager_->GetStatistics();
1781 size_t discardable_usage =
1782 discardable_stats.total_size - discardable_stats.freelist_size;
1783 memory_metrics->discardable_kb = discardable_usage / 1024;
1784
1785 size_t v8_usage = 0;
Blink Reformat1c4d759e2017-04-09 16:34:541786 if (v8::Isolate* isolate = blink::MainThreadIsolate()) {
keishi51ed0d52017-01-12 10:04:461787 v8::HeapStatistics v8_heap_statistics;
1788 isolate->GetHeapStatistics(&v8_heap_statistics);
1789 v8_usage = v8_heap_statistics.total_heap_size();
1790 }
1791 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is
1792 // reported. We should collect memory usages of all isolates using
1793 // memory-infra.
1794 memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024;
Blink Reformat1c4d759e2017-04-09 16:34:541795 size_t total_allocated = blink_stats.partition_alloc_total_allocated_bytes +
1796 blink_stats.blink_gc_total_allocated_bytes +
keishi51ed0d52017-01-12 10:04:461797 malloc_usage + v8_usage + discardable_usage;
1798 memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024;
1799 memory_metrics->non_discardable_total_allocated_mb =
1800 (total_allocated - discardable_usage) / 1024 / 1024;
1801 memory_metrics->total_allocated_per_render_view_mb =
chrisha05e94f22017-04-05 22:06:041802 total_allocated / render_view_count / 1024 / 1024;
bashia0ba0d42017-04-03 08:11:061803
1804 return true;
keishi51ed0d52017-01-12 10:04:461805}
1806
tasak335a1872017-06-14 09:50:231807static void RecordMemoryUsageAfterBackgroundedMB(const char* basename,
1808 const char* suffix,
1809 int memory_usage) {
1810 std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix);
1811 base::UmaHistogramMemoryLargeMB(histogram_name, memory_usage);
1812}
1813
1814void RenderThreadImpl::RecordMemoryUsageAfterBackgrounded(
1815 const char* suffix,
1816 int foregrounded_count) {
1817 // If this renderer is resumed, we should not update UMA.
1818 if (!RendererIsHidden())
1819 return;
1820 // If this renderer was not kept backgrounded for 5/10/15 minutes,
1821 // we should not record current memory usage.
1822 if (foregrounded_count != process_foregrounded_count_)
1823 return;
1824
1825 RendererMemoryMetrics memory_metrics;
1826 if (!GetRendererMemoryMetrics(&memory_metrics))
1827 return;
1828 RecordMemoryUsageAfterBackgroundedMB(
1829 "Memory.Experimental.Renderer.PartitionAlloc.AfterBackgrounded", suffix,
1830 memory_metrics.partition_alloc_kb / 1024);
1831 RecordMemoryUsageAfterBackgroundedMB(
1832 "Memory.Experimental.Renderer.BlinkGC.AfterBackgrounded", suffix,
1833 memory_metrics.blink_gc_kb / 1024);
1834 RecordMemoryUsageAfterBackgroundedMB(
1835 "Memory.Experimental.Renderer.Malloc.AfterBackgrounded", suffix,
1836 memory_metrics.malloc_mb);
1837 RecordMemoryUsageAfterBackgroundedMB(
1838 "Memory.Experimental.Renderer.Discardable.AfterBackgrounded", suffix,
1839 memory_metrics.discardable_kb / 1024);
1840 RecordMemoryUsageAfterBackgroundedMB(
1841 "Memory.Experimental.Renderer.V8MainThreaIsolate.AfterBackgrounded",
1842 suffix, memory_metrics.v8_main_thread_isolate_mb);
1843 RecordMemoryUsageAfterBackgroundedMB(
1844 "Memory.Experimental.Renderer.TotalAllocated.AfterBackgrounded", suffix,
1845 memory_metrics.total_allocated_mb);
1846}
1847
tasak72f64042017-01-19 14:02:531848#define GET_MEMORY_GROWTH(current, previous, allocator) \
1849 (current.allocator > previous.allocator \
1850 ? current.allocator - previous.allocator \
1851 : 0)
1852
tasaka27961a2017-05-24 07:33:251853static void RecordPurgeAndSuspendMemoryGrowthKB(const char* basename,
1854 const char* suffix,
1855 int memory_usage) {
1856 std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix);
1857 base::UmaHistogramMemoryKB(histogram_name, memory_usage);
1858}
tasakbb0640b2017-05-15 09:02:261859
1860void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics(
1861 const char* suffix,
1862 int foregrounded_count_when_purged) {
tasak72f64042017-01-19 14:02:531863 // If this renderer is resumed, we should not update UMA.
1864 if (!RendererIsHidden())
1865 return;
tasakbb0640b2017-05-15 09:02:261866 if (foregrounded_count_when_purged != process_foregrounded_count_)
1867 return;
tasak72f64042017-01-19 14:02:531868
1869 RendererMemoryMetrics memory_metrics;
bashia0ba0d42017-04-03 08:11:061870 if (!GetRendererMemoryMetrics(&memory_metrics))
1871 return;
1872
tasaka27961a2017-05-24 07:33:251873 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261874 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix,
tasak72f64042017-01-19 14:02:531875 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1876 partition_alloc_kb));
tasaka27961a2017-05-24 07:33:251877 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261878 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix,
tasak72f64042017-01-19 14:02:531879 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1880 blink_gc_kb));
tasaka27961a2017-05-24 07:33:251881 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261882 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix,
tasak72f64042017-01-19 14:02:531883 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261884 malloc_mb) *
1885 1024);
tasaka27961a2017-05-24 07:33:251886 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261887 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix,
tasak72f64042017-01-19 14:02:531888 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1889 discardable_kb));
tasaka27961a2017-05-24 07:33:251890 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261891 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix,
tasak72f64042017-01-19 14:02:531892 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261893 v8_main_thread_isolate_mb) *
1894 1024);
tasaka27961a2017-05-24 07:33:251895 RecordPurgeAndSuspendMemoryGrowthKB(
tasakbb0640b2017-05-15 09:02:261896 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix,
tasak72f64042017-01-19 14:02:531897 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
tasakbb0640b2017-05-15 09:02:261898 total_allocated_mb) *
1899 1024);
jdduke73220f02015-09-04 17:03:511900}
1901
sadrul6d310fa2016-08-04 02:12:161902scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
[email protected]d13f35d2012-05-18 02:28:151903 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1904
piman9fc22f32016-05-02 22:21:221905 if (gpu_channel_) {
[email protected]1082b1d2010-03-30 00:31:221906 // Do nothing if we already have a GPU channel or are already
1907 // establishing one.
[email protected]7951bfe2013-06-13 01:43:341908 if (!gpu_channel_->IsLost())
piman9fc22f32016-05-02 22:21:221909 return gpu_channel_;
[email protected]6217d392010-03-25 22:08:351910
1911 // Recreate the channel if it has been lost.
piman765e5282015-05-08 03:43:011912 gpu_channel_->DestroyChannel();
penghuange1d86512016-07-08 18:15:001913 gpu_channel_ = nullptr;
[email protected]6217d392010-03-25 22:08:351914 }
1915
sadrul53546592016-12-17 01:44:211916 gpu_channel_ = gpu_->EstablishGpuChannelSync();
1917 if (gpu_channel_)
1918 GetContentClient()->SetGpuInfo(gpu_channel_->gpu_info());
piman9fc22f32016-05-02 22:21:221919 return gpu_channel_;
[email protected]3bf4d532010-03-27 00:23:341920}
1921
danakjc7afae52017-06-20 21:12:411922void RenderThreadImpl::RequestNewLayerTreeFrameSink(
danakj83066a32016-06-21 02:34:491923 bool use_software,
1924 int routing_id,
1925 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue,
fsamuelcf3002e2017-03-20 23:13:471926 const GURL& url,
danakjc7afae52017-06-20 21:12:411927 const LayerTreeFrameSinkCallback& callback) {
danakj83066a32016-06-21 02:34:491928 const base::CommandLine& command_line =
1929 *base::CommandLine::ForCurrentProcess();
1930 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1931 use_software = true;
1932
samans09812d32017-03-27 19:51:501933 // In disable gpu vsync mode, also let the renderer tick as fast as it
1934 // can. The top level begin frame source will also be running as a back
1935 // to back begin frame source, but using a synthetic begin frame source
1936 // here reduces latency when in this mode (at least for frames
1937 // starting--it potentially increases it for input on the other hand.)
Fady Samuelc645ffe2017-07-24 17:28:201938 std::unique_ptr<viz::SyntheticBeginFrameSource> synthetic_begin_frame_source;
samans09812d32017-03-27 19:51:501939 if (command_line.HasSwitch(switches::kDisableGpuVsync) &&
1940 command_line.GetSwitchValueASCII(switches::kDisableGpuVsync) != "gpu") {
1941 synthetic_begin_frame_source = CreateSyntheticBeginFrameSource();
1942 }
1943
sadrul943e3b32016-08-04 18:22:591944#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:141945 if (!use_software && IsRunningInMash()) {
Scott Violet986ac472017-08-10 16:38:341946 if (!RendererWindowTreeClient::Get(routing_id)) {
1947 callback.Run(nullptr);
1948 return;
1949 }
sadrulbe22c4f2017-03-14 06:59:251950 scoped_refptr<gpu::GpuChannelHost> channel = EstablishGpuChannelSync();
1951 // If the channel could not be established correctly, then return null. This
1952 // would cause the compositor to wait and try again at a later time.
fsamuelcf3002e2017-03-20 23:13:471953 if (!channel) {
1954 callback.Run(nullptr);
1955 return;
1956 }
fsamuel95c974eb2017-03-22 10:00:251957 RendererWindowTreeClient::Get(routing_id)
danakjc7afae52017-06-20 21:12:411958 ->RequestLayerTreeFrameSink(
fsamuel95c974eb2017-03-22 10:00:251959 gpu_->CreateContextProvider(std::move(channel)),
1960 GetGpuMemoryBufferManager(), callback);
fsamuelcf3002e2017-03-20 23:13:471961 return;
danakj83066a32016-06-21 02:34:491962 }
1963#endif
1964
Gary Klassen4d0f0232017-07-27 23:23:121965 viz::mojom::CompositorFrameSinkPtrInfo sink_info;
1966 viz::mojom::CompositorFrameSinkRequest sink_request =
samansa61ab212017-05-24 12:11:431967 mojo::MakeRequest(&sink_info);
Gary Klassen4d0f0232017-07-27 23:23:121968 viz::mojom::CompositorFrameSinkClientPtr client;
1969 viz::mojom::CompositorFrameSinkClientRequest client_request =
samansa61ab212017-05-24 12:11:431970 mojo::MakeRequest(&client);
1971
danakj83066a32016-06-21 02:34:491972 if (command_line.HasSwitch(switches::kEnableVulkan)) {
1973 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider =
1974 cc::VulkanInProcessContextProvider::Create();
1975 if (vulkan_context_provider) {
1976 DCHECK(!layout_test_mode());
samansa61ab212017-05-24 12:11:431977 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
1978 std::move(client));
danakjc7afae52017-06-20 21:12:411979 callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>(
samans7e6675cc2017-06-05 20:16:081980 std::move(vulkan_context_provider),
1981 std::move(synthetic_begin_frame_source), std::move(sink_info),
Valery Arkhangorodsky513ac8fd2017-08-02 23:09:231982 std::move(client_request), nullptr /* hit_test_data_provider */,
samans7e6675cc2017-06-05 20:16:081983 base::MakeUnique<RendererLocalSurfaceIdProvider>(),
1984 false /* enable_surface_synchroninzation */));
fsamuelcf3002e2017-03-20 23:13:471985 return;
danakj83066a32016-06-21 02:34:491986 }
1987 }
1988
1989 // Create a gpu process channel and verify we want to use GPU compositing
1990 // before creating any context providers.
1991 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
1992 if (!use_software) {
sadrul6d310fa2016-08-04 02:12:161993 gpu_channel_host = EstablishGpuChannelSync();
danakj83066a32016-06-21 02:34:491994 if (!gpu_channel_host) {
1995 // Cause the compositor to wait and try again.
fsamuelcf3002e2017-03-20 23:13:471996 callback.Run(nullptr);
1997 return;
danakj83066a32016-06-21 02:34:491998 }
1999 // We may get a valid channel, but with a software renderer. In that case,
2000 // disable GPU compositing.
2001 if (gpu_channel_host->gpu_info().software_rendering)
2002 use_software = true;
2003 }
2004
2005 if (use_software) {
2006 DCHECK(!layout_test_mode());
samansa61ab212017-05-24 12:11:432007 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
2008 std::move(client));
danakjc7afae52017-06-20 21:12:412009 callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>(
samans7e6675cc2017-06-05 20:16:082010 nullptr, nullptr, nullptr, shared_bitmap_manager(),
2011 std::move(synthetic_begin_frame_source), std::move(sink_info),
Valery Arkhangorodsky513ac8fd2017-08-02 23:09:232012 std::move(client_request), nullptr /* hit_test_data_provider */,
samans7e6675cc2017-06-05 20:16:082013 base::MakeUnique<RendererLocalSurfaceIdProvider>(),
2014 false /* enable_surface_synchroninzation */));
fsamuelcf3002e2017-03-20 23:13:472015 return;
danakj83066a32016-06-21 02:34:492016 }
2017
sadrul85cc5d82016-12-20 03:37:412018 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider =
danakj83066a32016-06-21 02:34:492019 SharedCompositorWorkerContextProvider();
2020 if (!worker_context_provider) {
2021 // Cause the compositor to wait and try again.
fsamuelcf3002e2017-03-20 23:13:472022 callback.Run(nullptr);
2023 return;
danakj83066a32016-06-21 02:34:492024 }
2025
2026 // The renderer compositor context doesn't do a lot of stuff, so we don't
2027 // expect it to need a lot of space for commands or transfer. Raster and
2028 // uploads happen on the worker context instead.
2029 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
2030
2031 // This is for an offscreen context for the compositor. So the default
2032 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
2033 gpu::gles2::ContextCreationAttribHelper attributes;
2034 attributes.alpha_size = -1;
2035 attributes.depth_size = 0;
2036 attributes.stencil_size = 0;
2037 attributes.samples = 0;
2038 attributes.sample_buffers = 0;
2039 attributes.bind_generates_resource = false;
2040 attributes.lose_context_when_out_of_memory = true;
2041
2042 constexpr bool automatic_flushes = false;
2043 constexpr bool support_locking = false;
2044
2045 // The compositor context shares resources with the worker context unless
2046 // the worker is async.
sadrul85cc5d82016-12-20 03:37:412047 ui::ContextProviderCommandBuffer* share_context =
2048 worker_context_provider.get();
danakj83066a32016-06-21 02:34:492049 if (IsAsyncWorkerContextEnabled())
2050 share_context = nullptr;
2051
sadrul85cc5d82016-12-20 03:37:412052 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider(
2053 new ui::ContextProviderCommandBuffer(
sunnyps8f9139e2017-05-12 17:53:252054 gpu_channel_host, kGpuStreamIdDefault, kGpuStreamPriorityDefault,
2055 gpu::kNullSurfaceHandle, url, automatic_flushes, support_locking,
2056 limits, attributes, share_context,
sadrul85cc5d82016-12-20 03:37:412057 ui::command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT));
danakj83066a32016-06-21 02:34:492058
danakj83066a32016-06-21 02:34:492059 if (layout_test_deps_) {
danakjc7afae52017-06-20 21:12:412060 callback.Run(layout_test_deps_->CreateLayerTreeFrameSink(
jbroman6ccbc7d472016-07-27 04:45:412061 routing_id, std::move(gpu_channel_host), std::move(context_provider),
fsamuelcf3002e2017-03-20 23:13:472062 std::move(worker_context_provider), GetGpuMemoryBufferManager(), this));
2063 return;
danakj83066a32016-06-21 02:34:492064 }
2065
2066#if defined(OS_ANDROID)
2067 if (sync_compositor_message_filter_) {
Fady Samuelc645ffe2017-07-24 17:28:202068 std::unique_ptr<viz::BeginFrameSource> begin_frame_source =
samans09812d32017-03-27 19:51:502069 synthetic_begin_frame_source
2070 ? std::move(synthetic_begin_frame_source)
2071 : CreateExternalBeginFrameSource(routing_id);
danakjc7afae52017-06-20 21:12:412072 callback.Run(base::MakeUnique<SynchronousLayerTreeFrameSink>(
danakja40dd4482016-06-28 01:14:102073 std::move(context_provider), std::move(worker_context_provider),
danakje9cf5812017-02-16 22:22:552074 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id,
danakjc7afae52017-06-20 21:12:412075 g_next_layer_tree_frame_sink_id++, std::move(begin_frame_source),
enne077ba4862016-09-12 20:59:532076 sync_compositor_message_filter_.get(),
fsamuelcf3002e2017-03-20 23:13:472077 std::move(frame_swap_message_queue)));
2078 return;
danakj83066a32016-06-21 02:34:492079 }
2080#endif
samansa61ab212017-05-24 12:11:432081 frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request),
2082 std::move(client));
danakjc7afae52017-06-20 21:12:412083 callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>(
samans2040988b2017-04-11 23:58:352084 std::move(context_provider), std::move(worker_context_provider),
samans7e6675cc2017-06-05 20:16:082085 GetGpuMemoryBufferManager(), nullptr,
2086 std::move(synthetic_begin_frame_source), std::move(sink_info),
Valery Arkhangorodsky513ac8fd2017-08-02 23:09:232087 std::move(client_request), nullptr /* hit_test_data_provider */,
samans7e6675cc2017-06-05 20:16:082088 base::MakeUnique<RendererLocalSurfaceIdProvider>(),
2089 false /* enable_surface_synchroninzation */));
danakj83066a32016-06-21 02:34:492090}
2091
rockot067ca55f2016-09-30 22:00:152092AssociatedInterfaceRegistry*
2093RenderThreadImpl::GetAssociatedInterfaceRegistry() {
2094 return &associated_interfaces_;
2095}
2096
jbroman6ccbc7d472016-07-27 04:45:412097std::unique_ptr<cc::SwapPromise>
2098RenderThreadImpl::RequestCopyOfOutputForLayoutTest(
2099 int32_t routing_id,
Fady Samueldfecb7d2017-07-26 11:41:042100 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:412101 DCHECK(layout_test_deps_);
2102 return layout_test_deps_->RequestCopyOfOutput(routing_id, std::move(request));
2103}
2104
altimineb6bd1962017-05-03 14:52:382105std::unique_ptr<blink::WebMediaStreamCenter>
2106RenderThreadImpl::CreateMediaStreamCenter(
[email protected]180ef242013-11-07 06:50:462107 blink::WebMediaStreamCenterClient* client) {
altimineb6bd1962017-05-03 14:52:382108 std::unique_ptr<blink::WebMediaStreamCenter> media_stream_center;
Brett Wilson0748bf412016-11-22 17:55:462109#if BUILDFLAG(ENABLE_WEBRTC)
altimineb6bd1962017-05-03 14:52:382110 if (!media_stream_center) {
2111 media_stream_center =
2112 GetContentClient()->renderer()->OverrideCreateWebMediaStreamCenter(
2113 client);
2114 if (!media_stream_center) {
2115 media_stream_center = base::MakeUnique<MediaStreamCenter>(
2116 client, GetPeerConnectionDependencyFactory());
[email protected]68e5fee2013-02-18 10:04:222117 }
2118 }
[email protected]d8cd8372012-03-09 10:49:512119#endif
altimineb6bd1962017-05-03 14:52:382120 return media_stream_center;
[email protected]d8cd8372012-03-09 10:49:512121}
2122
Brett Wilson0748bf412016-11-22 17:55:462123#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]0107d8a2014-05-16 10:20:342124PeerConnectionDependencyFactory*
2125RenderThreadImpl::GetPeerConnectionDependencyFactory() {
[email protected]83e0a482014-05-22 18:07:182126 return peer_connection_factory_.get();
[email protected]6ee10bd2012-09-13 09:01:532127}
[email protected]22fe91d2014-08-12 17:07:122128#endif
[email protected]6ee10bd2012-09-13 09:01:532129
rockot1587e332016-07-27 17:44:142130mojom::RenderFrameMessageFilter*
2131RenderThreadImpl::render_frame_message_filter() {
2132 if (!render_frame_message_filter_)
2133 GetChannel()->GetRemoteAssociatedInterface(&render_frame_message_filter_);
2134 return render_frame_message_filter_.get();
2135}
2136
rockote261d2112016-09-21 22:22:232137mojom::RenderMessageFilter* RenderThreadImpl::render_message_filter() {
2138 if (!render_message_filter_)
2139 GetChannel()->GetRemoteAssociatedInterface(&render_message_filter_);
2140 return render_message_filter_.get();
2141}
2142
penghuang346a46f92016-03-31 21:37:522143gpu::GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
piman9fc22f32016-05-02 22:21:222144 if (!gpu_channel_)
danakj3873e852016-05-05 00:46:072145 return nullptr;
[email protected]7951bfe2013-06-13 01:43:342146 if (gpu_channel_->IsLost())
danakj3873e852016-05-05 00:46:072147 return nullptr;
[email protected]6217d392010-03-25 22:08:352148 return gpu_channel_.get();
2149}
2150
rockot067ca55f2016-09-30 22:00:152151void RenderThreadImpl::CreateView(mojom::CreateViewParamsPtr params) {
2152 CompositorDependencies* compositor_deps = this;
wjmaclean1d970622017-01-21 22:28:242153 is_scroll_animator_enabled_ = params->web_preferences.enable_scroll_animator;
rockot067ca55f2016-09-30 22:00:152154 // When bringing in render_view, also bring in webkit's glue and jsbindings.
nickf7b38222016-11-22 21:59:352155 RenderViewImpl::Create(compositor_deps, *params,
2156 RenderWidget::ShowCallback());
rockot067ca55f2016-09-30 22:00:152157}
2158
rockot53be7caf2016-10-04 20:17:082159void RenderThreadImpl::CreateFrame(mojom::CreateFrameParamsPtr params) {
2160 // Debug cases of https://crbug.com/626802.
2161 base::debug::SetCrashKeyValue("newframe_routing_id",
2162 base::IntToString(params->routing_id));
2163 base::debug::SetCrashKeyValue("newframe_proxy_id",
2164 base::IntToString(params->proxy_routing_id));
2165 base::debug::SetCrashKeyValue("newframe_opener_id",
2166 base::IntToString(params->opener_routing_id));
2167 base::debug::SetCrashKeyValue("newframe_parent_id",
2168 base::IntToString(params->parent_routing_id));
2169 base::debug::SetCrashKeyValue("newframe_widget_id",
2170 base::IntToString(
2171 params->widget_params->routing_id));
2172 base::debug::SetCrashKeyValue("newframe_widget_hidden",
2173 params->widget_params->hidden ? "yes" : "no");
2174 base::debug::SetCrashKeyValue("newframe_replicated_origin",
2175 params->replication_state.origin.Serialize());
2176 base::debug::SetCrashKeyValue("newframe_oopifs_possible",
2177 SiteIsolationPolicy::AreCrossProcessFramesPossible() ? "yes" : "no");
2178 CompositorDependencies* compositor_deps = this;
2179 RenderFrameImpl::CreateFrame(
2180 params->routing_id, params->proxy_routing_id, params->opener_routing_id,
2181 params->parent_routing_id, params->previous_sibling_routing_id,
2182 params->replication_state, compositor_deps, *params->widget_params,
2183 params->frame_owner_properties);
2184}
2185
2186void RenderThreadImpl::CreateFrameProxy(
2187 int32_t routing_id,
2188 int32_t render_view_routing_id,
2189 int32_t opener_routing_id,
2190 int32_t parent_routing_id,
2191 const FrameReplicationState& replicated_state) {
nick3b5a21f2016-11-22 23:07:112192 RenderFrameProxy::CreateFrameProxy(
2193 routing_id, render_view_routing_id,
2194 RenderFrameImpl::ResolveOpener(opener_routing_id), parent_routing_id,
2195 replicated_state);
rockot53be7caf2016-10-04 20:17:082196}
2197
rockota2db0da2016-10-18 17:39:112198void RenderThreadImpl::OnNetworkConnectionChanged(
2199 net::NetworkChangeNotifier::ConnectionType type,
2200 double max_bandwidth_mbps) {
2201 bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE;
Blink Reformat1c4d759e2017-04-09 16:34:542202 WebNetworkStateNotifier::SetOnLine(online);
rockota2db0da2016-10-18 17:39:112203 for (auto& observer : observers_)
2204 observer.NetworkStateChanged(online);
Blink Reformat1c4d759e2017-04-09 16:34:542205 WebNetworkStateNotifier::SetWebConnection(
rockota2db0da2016-10-18 17:39:112206 NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps);
2207}
2208
tbansal15973c32017-05-10 18:40:442209void RenderThreadImpl::OnNetworkQualityChanged(
tbansalb612c5d2017-05-25 18:53:062210 net::EffectiveConnectionType type,
tbansal99d8aeb2017-05-22 19:12:582211 base::TimeDelta http_rtt,
2212 base::TimeDelta transport_rtt,
tbansal15973c32017-05-10 18:40:442213 double downlink_throughput_kbps) {
2214 UMA_HISTOGRAM_BOOLEAN("NQE.RenderThreadNotified", true);
tbansalb612c5d2017-05-25 18:53:062215 WebNetworkStateNotifier::SetNetworkQuality(
2216 EffectiveConnectionTypeToWebEffectiveConnectionType(type), http_rtt,
2217 transport_rtt, downlink_throughput_kbps);
tbansal15973c32017-05-10 18:40:442218}
2219
rockota2db0da2016-10-18 17:39:112220void RenderThreadImpl::SetWebKitSharedTimersSuspended(bool suspend) {
2221#if defined(OS_ANDROID)
2222 if (suspend) {
Alexander Timin163290882017-08-01 17:38:072223 renderer_scheduler_->PauseTimerQueue();
rockota2db0da2016-10-18 17:39:112224 } else {
2225 renderer_scheduler_->ResumeTimerQueue();
2226 }
2227 webkit_shared_timer_suspended_ = suspend;
2228#else
2229 NOTREACHED();
2230#endif
2231}
2232
2233void RenderThreadImpl::UpdateScrollbarTheme(
2234 mojom::UpdateScrollbarThemeParamsPtr params) {
2235#if defined(OS_MACOSX)
2236 static_cast<WebScrollbarBehaviorImpl*>(
Blink Reformat1c4d759e2017-04-09 16:34:542237 blink_platform_impl_->ScrollbarBehavior())
rockota2db0da2016-10-18 17:39:112238 ->set_jump_on_track_click(params->jump_on_track_click);
2239
Blink Reformat1c4d759e2017-04-09 16:34:542240 blink::WebScrollbarTheme::UpdateScrollbarsWithNSDefaults(
rockota2db0da2016-10-18 17:39:112241 params->initial_button_delay, params->autoscroll_button_delay,
2242 params->preferred_scroller_style, params->redraw,
2243 params->button_placement);
Greg Kerra7b943b2017-07-24 23:17:172244
2245 is_elastic_overscroll_enabled_ = params->scroll_view_rubber_banding;
rockota2db0da2016-10-18 17:39:112246#else
2247 NOTREACHED();
2248#endif
2249}
2250
2251void RenderThreadImpl::OnSystemColorsChanged(
2252 int32_t aqua_color_variant,
2253 const std::string& highlight_text_color,
2254 const std::string& highlight_color) {
2255#if defined(OS_MACOSX)
2256 SystemColorsDidChange(aqua_color_variant, highlight_text_color,
2257 highlight_color);
2258#else
2259 NOTREACHED();
2260#endif
2261}
2262
2263void RenderThreadImpl::PurgePluginListCache(bool reload_pages) {
brettw4b461082016-11-19 18:55:162264#if BUILDFLAG(ENABLE_PLUGINS)
rockota2db0da2016-10-18 17:39:112265 // The call below will cause a GetPlugins call with refresh=true, but at this
2266 // point we already know that the browser has refreshed its list, so disable
2267 // refresh temporarily to prevent each renderer process causing the list to be
2268 // regenerated.
2269 blink_platform_impl_->set_plugin_refresh_allowed(false);
Blink Reformat1c4d759e2017-04-09 16:34:542270 blink::ResetPluginCache(reload_pages);
rockota2db0da2016-10-18 17:39:112271 blink_platform_impl_->set_plugin_refresh_allowed(true);
2272
2273 for (auto& observer : observers_)
2274 observer.PluginListChanged();
2275#else
2276 NOTREACHED();
2277#endif
2278}
2279
[email protected]0ec90d522014-03-12 16:28:192280void RenderThreadImpl::OnCreateNewSharedWorker(
2281 const WorkerProcessMsg_CreateWorker_Params& params) {
2282 // EmbeddedSharedWorkerStub will self-destruct.
mkwstcfa98932016-03-09 13:06:192283 new EmbeddedSharedWorkerStub(
2284 params.url, params.name, params.content_security_policy,
2285 params.security_policy_type, params.creation_address_space,
Yuki Yamada68992b02017-07-31 06:13:452286 params.pause_on_start, params.route_id, params.data_saver_enabled,
2287 mojo::ScopedMessagePipeHandle(params.content_settings_handle));
[email protected]0ec90d522014-03-12 16:28:192288}
2289
[email protected]5071cb22013-07-10 02:19:062290void RenderThreadImpl::OnMemoryPressure(
2291 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
hong.zhengb28b5332016-05-11 02:33:392292 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
rmcilroy7fbb3bd52015-02-17 19:02:142293 if (blink_platform_impl_) {
Blink Reformat1c4d759e2017-04-09 16:34:542294 blink::WebMemoryCoordinator::OnMemoryPressure(
bashic577bfc2016-01-08 03:42:352295 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
hajimehoshi7bb39582016-10-12 04:30:572296 }
2297 if (memory_pressure_level ==
2298 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
2299 ReleaseFreeMemory();
2300 ClearMemory();
2301 }
2302}
rmcilroyab967c972015-02-17 23:15:002303
hajimehoshi7bb39582016-10-12 04:30:572304void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
hajimehoshi7bb39582016-10-12 04:30:572305 if (blink_platform_impl_) {
Blink Reformat1c4d759e2017-04-09 16:34:542306 blink::WebMemoryCoordinator::OnMemoryStateChange(
hajimehoshi7bb39582016-10-12 04:30:572307 static_cast<blink::MemoryState>(state));
2308 }
bashi233f65e2017-02-09 08:36:032309}
2310
2311void RenderThreadImpl::OnPurgeMemory() {
bashib9058f282017-03-30 01:55:242312 // Record amount of purged memory after 2 seconds. 2 seconds is arbitrary
2313 // but it works most cases.
2314 RendererMemoryMetrics metrics;
bashia0ba0d42017-04-03 08:11:062315 if (!GetRendererMemoryMetrics(&metrics))
2316 return;
2317
bashib9058f282017-03-30 01:55:242318 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
2319 FROM_HERE,
2320 base::Bind(&RenderThreadImpl::RecordPurgeMemory, base::Unretained(this),
2321 std::move(metrics)),
2322 base::TimeDelta::FromSeconds(2));
2323
bashi233f65e2017-02-09 08:36:032324 OnTrimMemoryImmediately();
2325 ReleaseFreeMemory();
2326 ClearMemory();
2327 if (blink_platform_impl_)
Blink Reformat1c4d759e2017-04-09 16:34:542328 blink::WebMemoryCoordinator::OnPurgeMemory();
hajimehoshi7bb39582016-10-12 04:30:572329}
2330
bashib9058f282017-03-30 01:55:242331void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
2332 RendererMemoryMetrics after;
bashia0ba0d42017-04-03 08:11:062333 if (!GetRendererMemoryMetrics(&after))
2334 return;
bashib9058f282017-03-30 01:55:242335 int64_t mbytes = static_cast<int64_t>(before.total_allocated_mb) -
2336 static_cast<int64_t>(after.total_allocated_mb);
2337 if (mbytes < 0)
2338 mbytes = 0;
2339 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer.PurgedMemory",
2340 mbytes);
2341}
2342
hajimehoshi7bb39582016-10-12 04:30:572343void RenderThreadImpl::ClearMemory() {
2344 // Do not call into blink if it is not initialized.
2345 if (blink_platform_impl_) {
2346 // Purge Skia font cache, by setting it to 0 and then again to the
2347 // previous limit.
2348 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2349 SkGraphics::SetFontCacheLimit(font_cache_limit);
rmcilroy7fbb3bd52015-02-17 19:02:142350 }
[email protected]5071cb22013-07-10 02:19:062351}
2352
Marijn Kruisselbrink8c276412017-07-29 06:11:212353scoped_refptr<base::TaskRunner> RenderThreadImpl::GetFileThreadTaskRunner() {
2354 return blink_platform_impl_->BaseFileTaskRunner();
[email protected]c6a7b862010-08-20 22:19:382355}
[email protected]e9ff79c2012-10-19 21:31:262356
acolwellb4034942014-08-28 15:42:432357scoped_refptr<base::SingleThreadTaskRunner>
2358RenderThreadImpl::GetMediaThreadTaskRunner() {
fdoraye94d8642016-07-07 19:19:012359 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
[email protected]c1330c82013-06-06 02:23:252360 if (!media_thread_) {
2361 media_thread_.reset(new base::Thread("Media"));
2362 media_thread_->Start();
2363 }
skyostil2d3b5bd2015-05-27 15:40:592364 return media_thread_->task_runner();
[email protected]c1330c82013-06-06 02:23:252365}
2366
dcastagna4517a182015-08-05 19:51:032367base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() {
prashant.nfad657e2016-06-01 07:52:172368 return categorized_worker_pool_.get();
dcastagnab880e8f2015-06-30 20:16:062369}
2370
sadrul85cc5d82016-12-20 03:37:412371scoped_refptr<ui::ContextProviderCommandBuffer>
danakj0b4b94e32016-05-10 22:33:012372RenderThreadImpl::SharedCompositorWorkerContextProvider() {
revemand180dfc32015-09-24 00:19:432373 DCHECK(IsMainThread());
2374 // Try to reuse existing shared worker context provider.
revemand180dfc32015-09-24 00:19:432375 if (shared_worker_context_provider_) {
2376 // Note: If context is lost, delete reference after releasing the lock.
Xu Xing32549162017-07-17 22:25:432377 viz::ContextProvider::ScopedContextLock lock(
boliu11afa7e2016-04-18 18:04:142378 shared_worker_context_provider_.get());
revemand180dfc32015-09-24 00:19:432379 if (shared_worker_context_provider_->ContextGL()
danakje8ec797e2016-04-19 04:08:432380 ->GetGraphicsResetStatusKHR() == GL_NO_ERROR)
2381 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432382 }
danakje8ec797e2016-04-19 04:08:432383
sadrul6d310fa2016-08-04 02:12:162384 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
2385 EstablishGpuChannelSync());
danakje8ec797e2016-04-19 04:08:432386 if (!gpu_channel_host) {
2387 shared_worker_context_provider_ = nullptr;
2388 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432389 }
danakje8ec797e2016-04-19 04:08:432390
sunnyps8f9139e2017-05-12 17:53:252391 int32_t stream_id = kGpuStreamIdDefault;
2392 gpu::SchedulingPriority stream_priority = kGpuStreamPriorityDefault;
sunnypsd8ce1c22016-05-10 18:02:402393 if (is_async_worker_context_enabled_) {
sunnyps8f9139e2017-05-12 17:53:252394 stream_id = kGpuStreamIdWorker;
2395 stream_priority = kGpuStreamPriorityWorker;
sunnypsd8ce1c22016-05-10 18:02:402396 }
2397
danakj9a04adc2016-05-16 22:45:072398 bool support_locking = true;
danakj0dd9e1e2016-05-11 22:15:092399 shared_worker_context_provider_ = CreateOffscreenContext(
danakj9a04adc2016-05-16 22:45:072400 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking,
sadrul85cc5d82016-12-20 03:37:412401 ui::command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id,
danakj0dd9e1e2016-05-11 22:15:092402 stream_priority);
danakje8ec797e2016-04-19 04:08:432403 if (!shared_worker_context_provider_->BindToCurrentThread())
2404 shared_worker_context_provider_ = nullptr;
revemand180dfc32015-09-24 00:19:432405 return shared_worker_context_provider_;
2406}
2407
juncai2f298a82017-04-18 03:51:392408void RenderThreadImpl::SampleGamepads(device::Gamepads* data) {
Blink Reformat1c4d759e2017-04-09 16:34:542409 blink_platform_impl_->SampleGamepads(*data);
[email protected]0ff736562014-05-09 09:09:472410}
2411
rmcilroyaa296052015-04-14 15:35:272412bool RenderThreadImpl::RendererIsHidden() const {
2413 return widget_count_ > 0 && hidden_widget_count_ == widget_count_;
2414}
2415
[email protected]b2db9272014-01-10 17:42:002416void RenderThreadImpl::WidgetCreated() {
rmcilroyaa296052015-04-14 15:35:272417 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002418 widget_count_++;
rmcilroyaa296052015-04-14 15:35:272419 if (renderer_was_hidden)
2420 OnRendererVisible();
[email protected]b2db9272014-01-10 17:42:002421}
2422
2423void RenderThreadImpl::WidgetDestroyed() {
rmcilroyaa296052015-04-14 15:35:272424 // TODO(rmcilroy): Remove the restriction that destroyed widgets must be
2425 // unhidden before WidgetDestroyed is called.
2426 DCHECK_GT(widget_count_, 0);
2427 DCHECK_GT(widget_count_, hidden_widget_count_);
[email protected]b2db9272014-01-10 17:42:002428 widget_count_--;
rmcilroyaa296052015-04-14 15:35:272429 if (RendererIsHidden())
2430 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002431}
2432
2433void RenderThreadImpl::WidgetHidden() {
2434 DCHECK_LT(hidden_widget_count_, widget_count_);
2435 hidden_widget_count_++;
rmcilroyaa296052015-04-14 15:35:272436 if (RendererIsHidden())
2437 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002438}
2439
2440void RenderThreadImpl::WidgetRestored() {
rmcilroyaa296052015-04-14 15:35:272441 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002442 DCHECK_GT(hidden_widget_count_, 0);
2443 hidden_widget_count_--;
rmcilroyaa296052015-04-14 15:35:272444 if (renderer_was_hidden)
2445 OnRendererVisible();
2446}
[email protected]b2db9272014-01-10 17:42:002447
rmcilroyaa296052015-04-14 15:35:272448void RenderThreadImpl::OnRendererHidden() {
Blink Reformat1c4d759e2017-04-09 16:34:542449 blink::MainThreadIsolate()->IsolateInBackgroundNotification();
rmcilroyaa296052015-04-14 15:35:272450 // TODO(rmcilroy): Remove IdleHandler and replace it with an IdleTask
2451 // scheduled by the RendererScheduler - http://crbug.com/469210.
ulan4a385192015-11-11 10:59:182452 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
2453 return;
Alexander Timin771b3372017-06-15 13:26:472454 renderer_scheduler_->SetRendererHidden(true);
ulan4a385192015-11-11 10:59:182455 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
rmcilroyaa296052015-04-14 15:35:272456}
2457
2458void RenderThreadImpl::OnRendererVisible() {
Blink Reformat1c4d759e2017-04-09 16:34:542459 blink::MainThreadIsolate()->IsolateInForegroundNotification();
rmcilroyaa296052015-04-14 15:35:272460 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]b2db9272014-01-10 17:42:002461 return;
Alexander Timin771b3372017-06-15 13:26:472462 renderer_scheduler_->SetRendererHidden(false);
[email protected]b2db9272014-01-10 17:42:002463 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
2464}
2465
ssid0603ca9f2015-06-09 16:48:082466void RenderThreadImpl::ReleaseFreeMemory() {
2467 base::allocator::ReleaseFreeMemory();
penghuang342762b2016-12-02 21:04:582468 discardable_shared_memory_manager_->ReleaseFreeMemory();
ssid0603ca9f2015-06-09 16:48:082469
2470 if (blink_platform_impl_)
Blink Reformat1c4d759e2017-04-09 16:34:542471 blink::DecommitFreeableMemory();
ssid0603ca9f2015-06-09 16:48:082472}
2473
ben76f52b242016-06-18 05:42:482474RenderThreadImpl::PendingFrameCreate::PendingFrameCreate(
benf28ce882017-05-02 16:15:492475 const service_manager::BindSourceInfo& browser_info,
rockotf8fdd9b2015-12-16 22:22:352476 int routing_id,
ben76f52b242016-06-18 05:42:482477 mojom::FrameRequest frame_request,
csharrison95f01e922017-04-24 18:52:352478 mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker)
benf28ce882017-05-02 16:15:492479 : browser_info_(browser_info),
2480 routing_id_(routing_id),
ben76f52b242016-06-18 05:42:482481 frame_request_(std::move(frame_request)),
csharrison95f01e922017-04-24 18:52:352482 frame_host_interface_broker_(std::move(frame_host_interface_broker)) {
ben76f52b242016-06-18 05:42:482483 // The RenderFrame may be deleted before the CreateFrame message is received.
2484 // In that case, the RenderFrameHost should cancel the create, which is
csharrison95f01e922017-04-24 18:52:352485 // detected by setting an error handler on |frame_host_interface_broker_|.
2486 frame_host_interface_broker_.set_connection_error_handler(
2487 base::Bind(&RenderThreadImpl::PendingFrameCreate::OnConnectionError,
2488 base::Unretained(this)));
rockotf8fdd9b2015-12-16 22:22:352489}
2490
ben76f52b242016-06-18 05:42:482491RenderThreadImpl::PendingFrameCreate::~PendingFrameCreate() {
rockotf8fdd9b2015-12-16 22:22:352492}
2493
ben76f52b242016-06-18 05:42:482494void RenderThreadImpl::PendingFrameCreate::OnConnectionError() {
rockotf8fdd9b2015-12-16 22:22:352495 size_t erased =
ben76f52b242016-06-18 05:42:482496 RenderThreadImpl::current()->pending_frame_creates_.erase(routing_id_);
rockotf8fdd9b2015-12-16 22:22:352497 DCHECK_EQ(1u, erased);
2498}
2499
hong.zhengb28b5332016-05-11 02:33:392500void RenderThreadImpl::OnSyncMemoryPressure(
2501 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
Blink Reformat1c4d759e2017-04-09 16:34:542502 if (!blink::MainThreadIsolate())
hong.zhengb28b5332016-05-11 02:33:392503 return;
2504
2505 v8::MemoryPressureLevel v8_memory_pressure_level =
2506 static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
2507
Luke Halliwell16136de2017-07-05 21:15:562508#if !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND)
hong.zhengb28b5332016-05-11 02:33:392509 // In order to reduce performance impact, translate critical level to
Luke Halliwell16136de2017-07-05 21:15:562510 // moderate level for foreground renderer.
hong.zhengb28b5332016-05-11 02:33:392511 if (!RendererIsHidden() &&
2512 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
2513 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
Luke Halliwell16136de2017-07-05 21:15:562514#endif // !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND)
hong.zhengb28b5332016-05-11 02:33:392515
Blink Reformat1c4d759e2017-04-09 16:34:542516 blink::MainThreadIsolate()->MemoryPressureNotification(
hong.zhengb28b5332016-05-11 02:33:392517 v8_memory_pressure_level);
2518 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2519 v8_memory_pressure_level);
2520}
2521
bashic4b4afcb2016-08-23 06:37:522522// Note that this would be called only when memory_coordinator is enabled.
2523// OnSyncMemoryPressure() is never called in that case.
2524void RenderThreadImpl::OnTrimMemoryImmediately() {
Blink Reformat1c4d759e2017-04-09 16:34:542525 if (blink::MainThreadIsolate()) {
2526 blink::MainThreadIsolate()->MemoryPressureNotification(
bashic4b4afcb2016-08-23 06:37:522527 v8::MemoryPressureLevel::kCritical);
2528 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2529 v8::MemoryPressureLevel::kCritical);
2530 }
2531}
2532
rockot067ca55f2016-09-30 22:00:152533void RenderThreadImpl::OnRendererInterfaceRequest(
2534 mojom::RendererAssociatedRequest request) {
2535 DCHECK(!renderer_binding_.is_bound());
2536 renderer_binding_.Bind(std::move(request));
2537}
bashic4b4afcb2016-08-23 06:37:522538
[email protected]e9ff79c2012-10-19 21:31:262539} // namespace content