blob: cfce434c28a04c749f16a15dfadc2c5c17e062c5 [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"
[email protected]06533c0b2009-03-05 21:39:1114#include "base/command_line.h"
creis9f7248b2016-01-27 20:27:3915#include "base/debug/crash_logging.h"
[email protected]94f9a0f682009-06-15 18:30:3016#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0317#include "base/logging.h"
avi1023d012015-12-25 02:39:1418#include "base/macros.h"
reveman1af05cb32015-03-17 23:18:1619#include "base/memory/discardable_memory_allocator.h"
dchengcedca5612016-04-09 01:40:1520#include "base/memory/ptr_util.h"
[email protected]8bac37b2013-07-18 19:13:5621#include "base/memory/shared_memory.h"
[email protected]835d7c82010-10-14 04:38:3822#include "base/metrics/field_trial.h"
[email protected]6cf19311f2011-04-14 23:06:0223#include "base/metrics/histogram.h"
[email protected]433df472012-03-07 20:33:3924#include "base/path_service.h"
fdoray2df4a9e2016-07-18 23:47:1625#include "base/run_loop.h"
[email protected]21aa99682013-06-11 07:17:0126#include "base/strings/string16.h"
[email protected]1e1d1e12014-01-17 16:14:2927#include "base/strings/string_number_conversions.h"
hablichd6a4f122015-10-28 11:34:4928#include "base/strings/string_split.h"
[email protected]3dda5852014-02-19 06:42:1429#include "base/strings/string_tokenizer.h"
ccameron6728bae32015-01-09 20:18:0630#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0031#include "base/strings/utf_string_conversions.h"
reveman34b7a1522015-03-23 20:27:4732#include "base/threading/simple_thread.h"
[email protected]1357c322010-12-30 22:18:5633#include "base/threading/thread_local.h"
[email protected]d293572a2013-05-23 18:50:4534#include "base/threading/thread_restrictions.h"
gab30f26df2016-05-11 19:37:5535#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0136#include "base/trace_event/trace_event.h"
[email protected]7a4de7a62010-08-17 18:38:2437#include "base/values.h"
avi1023d012015-12-25 02:39:1438#include "build/build_config.h"
jbroman0d302162015-09-05 05:46:2339#include "cc/base/histograms.h"
[email protected]d72493152014-01-08 17:37:4540#include "cc/base/switches.h"
[email protected]38564622014-08-19 02:47:1841#include "cc/blink/web_external_bitmap_impl.h"
42#include "cc/blink/web_layer_impl.h"
danakj83066a32016-06-21 02:34:4943#include "cc/output/output_surface.h"
44#include "cc/output/vulkan_in_process_context_provider.h"
danakj920156852015-05-18 20:22:2945#include "cc/raster/task_graph_runner.h"
vollick1050cc62015-12-03 07:04:5446#include "cc/trees/layer_tree_host_common.h"
loysoa6edaaff2015-05-25 03:26:4447#include "cc/trees/layer_tree_settings.h"
sadrulff12c002016-01-14 20:52:2048#include "components/scheduler/child/compositor_worker_scheduler.h"
vollick1050cc62015-12-03 07:04:5449#include "components/scheduler/child/webthread_base.h"
sadrulff12c002016-01-14 20:52:2050#include "components/scheduler/child/webthread_impl_for_worker_scheduler.h"
jochen83c639f02015-04-22 17:07:3751#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]a8cb3b73b2013-08-12 05:50:5052#include "content/child/appcache/appcache_dispatcher.h"
53#include "content/child/appcache/appcache_frontend_impl.h"
dmurph1fb98482016-03-30 21:14:2654#include "content/child/blob_storage/blob_message_filter.h"
revemancb5a66af2014-10-25 00:34:3955#include "content/child/child_discardable_shared_memory_manager.h"
reveman22dd9292014-10-13 20:52:0556#include "content/child/child_gpu_memory_buffer_manager.h"
[email protected]10208ea2013-06-06 20:08:0357#include "content/child/child_histogram_message_filter.h"
alexclarke0bc36e8d32014-12-17 17:29:2058#include "content/child/child_resource_message_filter.h"
jbauman2f5c1942014-12-06 03:28:2459#include "content/child/child_shared_bitmap_manager.h"
[email protected]fdeac262014-07-10 12:52:5160#include "content/child/content_child_helpers.h"
[email protected]89c36f82013-07-17 06:23:2761#include "content/child/db_message_filter.h"
[email protected]c7199a6e2013-06-04 12:56:0162#include "content/child/indexed_db/indexed_db_dispatcher.h"
63#include "content/child/indexed_db/indexed_db_message_filter.h"
[email protected]10208ea2013-06-06 20:08:0364#include "content/child/resource_dispatcher.h"
alexclarke0bc36e8d32014-12-17 17:29:2065#include "content/child/resource_scheduling_filter.h"
[email protected]643255da2013-06-12 20:55:1366#include "content/child/runtime_features.h"
[email protected]57cf97882013-06-26 20:39:0167#include "content/child/thread_safe_sender.h"
[email protected]c7199a6e2013-06-04 12:56:0168#include "content/child/web_database_observer_impl.h"
hajimehoshi384b3b112016-06-01 06:21:5269#include "content/child/websocket_message_filter.h"
kinukoef647412015-12-23 06:10:4370#include "content/child/worker_thread_registry.h"
[email protected]bdae9812011-10-15 00:33:0371#include "content/common/child_process_messages.h"
[email protected]89c36f82013-07-17 06:23:2772#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4173#include "content/common/dom_storage/dom_storage_messages.h"
[email protected]82307f6b2014-08-07 03:30:1274#include "content/common/frame_messages.h"
[email protected]c29b7ff2013-03-06 03:51:0475#include "content/common/gpu/client/context_provider_command_buffer.h"
fsamuelc28d985e2016-03-22 23:05:0276#include "content/common/gpu_process_launch_causes.h"
avia7c3f51c2015-09-16 00:30:3177#include "content/common/render_process_messages.h"
[email protected]94dc971d2011-03-05 19:08:3278#include "content/common/resource_messages.h"
mek27c9d742015-07-16 18:30:1879#include "content/common/service_worker/embedded_worker_setup.mojom.h"
[email protected]778574e2011-03-21 22:03:5080#include "content/common/view_messages.h"
[email protected]0ec90d522014-03-12 16:28:1981#include "content/common/worker_messages.h"
[email protected]a458504b2012-07-23 19:57:0682#include "content/public/common/content_constants.h"
[email protected]433df472012-03-07 20:33:3983#include "content/public/common/content_paths.h"
[email protected]c08950d22011-10-13 22:20:2984#include "content/public/common/content_switches.h"
[email protected]daf82f82011-10-31 22:35:3185#include "content/public/common/renderer_preferences.h"
[email protected]58436a12012-03-21 17:10:2686#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3487#include "content/public/renderer/content_renderer_client.h"
tyoshino832a58a2016-04-18 08:14:0888#include "content/public/renderer/render_thread_observer.h"
[email protected]64ffa0442011-10-03 22:08:3689#include "content/public/renderer/render_view_visitor.h"
fsamuel6c1dfeb2014-12-18 19:21:3390#include "content/renderer/browser_plugin/browser_plugin_manager.h"
jsbell279efb42015-03-31 17:02:4691#include "content/renderer/cache_storage/cache_storage_dispatcher.h"
92#include "content/renderer/cache_storage/cache_storage_message_filter.h"
prashant.nfad657e2016-06-01 07:52:1793#include "content/renderer/categorized_worker_pool.h"
[email protected]70019152012-12-19 11:44:1994#include "content/renderer/devtools/devtools_agent_filter.h"
alph666f80f2014-12-08 15:52:1195#include "content/renderer/devtools/v8_sampling_profiler.h"
[email protected]1910fe82012-05-10 00:04:1096#include "content/renderer/dom_storage/dom_storage_dispatcher.h"
97#include "content/renderer/dom_storage/webstoragearea_impl.h"
98#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
simonhonga7e3ac42014-11-11 20:50:2299#include "content/renderer/gpu/compositor_external_begin_frame_source.h"
100#include "content/renderer/gpu/compositor_forwarding_message_filter.h"
[email protected]1842fe22012-08-13 23:24:35101#include "content/renderer/gpu/compositor_output_surface.h"
danakj83066a32016-06-21 02:34:49102#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]7a72d452013-12-13 10:01:13103#include "content/renderer/input/input_event_filter.h"
104#include "content/renderer/input/input_handler_manager.h"
jdduke691dd572014-12-02 20:47:52105#include "content/renderer/input/main_thread_input_event_filter.h"
[email protected]da9f30a2014-06-18 19:39:04106#include "content/renderer/media/aec_dump_message_filter.h"
[email protected]f7eb0a392011-07-12 10:19:51107#include "content/renderer/media/audio_input_message_filter.h"
108#include "content/renderer/media/audio_message_filter.h"
[email protected]3958e972012-07-17 00:25:41109#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]d8cd8372012-03-09 10:49:51110#include "content/renderer/media/media_stream_center.h"
[email protected]a9875152013-06-22 04:03:03111#include "content/renderer/media/midi_message_filter.h"
xhwang194acae2014-11-12 22:46:33112#include "content/renderer/media/render_media_client.h"
[email protected]2329bfc72014-02-28 02:03:21113#include "content/renderer/media/renderer_gpu_video_accelerator_factories.h"
[email protected]80b161a2011-06-27 17:42:11114#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]ba164c912011-06-14 22:07:34115#include "content/renderer/media/video_capture_message_filter.h"
[email protected]d7ff5fb2014-05-29 19:50:25116#include "content/renderer/net_info_helper.h"
[email protected]4761cf12012-09-12 10:37:55117#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]82307f6b2014-08-07 03:30:12118#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:05119#include "content/renderer/render_process_impl.h"
[email protected]310ebd6302011-10-10 19:06:28120#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:09121#include "content/renderer/renderer_blink_platform_impl.h"
jdduke94ae1f32015-02-05 06:27:13122#include "content/renderer/scheduler/resource_dispatch_throttler.h"
[email protected]7670d4332013-11-29 04:35:00123#include "content/renderer/service_worker/embedded_worker_dispatcher.h"
mek27c9d742015-07-16 18:30:18124#include "content/renderer/service_worker/service_worker_context_client.h"
kinuko5af4ffe2015-06-09 03:38:46125#include "content/renderer/service_worker/service_worker_context_message_filter.h"
[email protected]0ec90d522014-03-12 16:28:19126#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
chunyang.daibe874c52014-11-14 06:45:05127#include "gin/public/debug.h"
dongseong.hwang72183b02014-12-08 10:41:55128#include "gpu/GLES2/gl2extchromium.h"
danakj6f4e1e22016-04-20 03:27:34129#include "gpu/command_buffer/client/shared_memory_limits.h"
danakj870925d42016-05-03 20:07:38130#include "gpu/ipc/client/command_buffer_proxy_impl.h"
penghuang346a46f92016-03-31 21:37:52131#include "gpu/ipc/client/gpu_channel_host.h"
[email protected]46f36a492010-07-28 19:36:41132#include "ipc/ipc_channel_handle.h"
amistryd4aa70d2016-06-23 07:52:37133#include "ipc/ipc_channel_mojo.h"
[email protected]cb6037d2009-11-16 22:55:17134#include "ipc/ipc_platform_file.h"
[email protected]433df472012-03-07 20:33:39135#include "media/base/media.h"
servolk8b3b39b2015-03-03 19:08:18136#include "media/renderers/gpu_video_accelerator_factories.h"
[email protected]f68c1462014-04-24 18:17:53137#include "mojo/common/common_type_converters.h"
rockot85dce0862015-11-13 01:33:59138#include "mojo/public/cpp/bindings/strong_binding.h"
[email protected]620161e2011-03-07 18:05:26139#include "net/base/net_errors.h"
eroman9ab64842015-07-21 05:07:52140#include "net/base/port_util.h"
hablichd6a4f122015-10-28 11:34:49141#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
tfarina7a4a7fd2016-01-20 14:23:44142#include "net/base/url_util.h"
rockotcef38272016-07-15 22:47:47143#include "services/shell/public/cpp/interface_provider.h"
144#include "services/shell/public/cpp/interface_registry.h"
[email protected]b48c53ad2014-02-05 21:59:18145#include "skia/ext/event_tracer_impl.h"
ssid59c969162015-07-28 13:02:58146#include "skia/ext/skia_memory_dump_provider.h"
reed6e5a72222015-08-06 20:37:16147#include "third_party/WebKit/public/platform/WebImageGenerator.h"
[email protected]89c36f82013-07-17 06:23:27148#include "third_party/WebKit/public/platform/WebString.h"
skyostil457b0a12014-09-09 10:12:07149#include "third_party/WebKit/public/platform/WebThread.h"
hong.zhenga35a480d2014-12-25 17:11:09150#include "third_party/WebKit/public/web/WebCache.h"
[email protected]2255a9332013-06-17 05:12:31151#include "third_party/WebKit/public/web/WebDatabase.h"
152#include "third_party/WebKit/public/web/WebDocument.h"
153#include "third_party/WebKit/public/web/WebFrame.h"
154#include "third_party/WebKit/public/web/WebKit.h"
bashi5e843ac2016-06-17 07:44:35155#include "third_party/WebKit/public/web/WebMemoryCoordinator.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
[email protected]2255a9332013-06-17 05:12:31157#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
158#include "third_party/WebKit/public/web/WebScriptController.h"
159#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebView.h"
jshin0a9aa632015-04-29 18:35:29161#include "third_party/icu/source/i18n/unicode/timezone.h"
[email protected]ddbb53342014-01-06 10:59:47162#include "third_party/skia/include/core/SkGraphics.h"
[email protected]c49201a2012-05-24 11:04:57163#include "ui/base/layout.h"
[email protected]18ad6772011-09-20 21:51:32164#include "ui/base/ui_base_switches.h"
[email protected]2c62b562009-01-27 19:04:50165
[email protected]33b02992014-03-01 01:06:29166#if defined(OS_ANDROID)
167#include <cpu-features.h>
boliubee541f42015-11-05 00:52:53168#include "content/renderer/android/synchronous_compositor_filter.h"
danakj83066a32016-06-21 02:34:49169#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]33b02992014-03-01 01:06:29170#include "content/renderer/media/android/renderer_demuxer_android.h"
boliue81d16132016-04-26 00:54:41171#include "content/renderer/media/android/stream_texture_factory.h"
dalecurtis88af3932016-02-20 00:12:20172#include "media/base/android/media_codec_util.h"
[email protected]33b02992014-03-01 01:06:29173#endif
174
175#if defined(OS_MACOSX)
ccamerona7644752014-12-30 01:16:31176#include "base/mac/mac_util.h"
rsesek1efb3c32015-09-29 15:39:50177#include "content/renderer/theme_helper_mac.h"
[email protected]33b02992014-03-01 01:06:29178#include "content/renderer/webscrollbarbehavior_impl_mac.h"
179#endif
180
181#if defined(OS_POSIX)
182#include "ipc/ipc_channel_posix.h"
183#endif
184
[email protected]da00a2882009-03-09 17:51:19185#if defined(OS_WIN)
186#include <windows.h>
187#include <objbase.h>
188#endif
189
[email protected]22fe91d2014-08-12 17:07:12190#if defined(ENABLE_WEBRTC)
191#include "content/renderer/media/peer_connection_tracker.h"
192#include "content/renderer/media/rtc_peer_connection_handler.h"
193#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]22fe91d2014-08-12 17:07:12194#endif
195
chunyang.daibe874c52014-11-14 06:45:05196#ifdef ENABLE_VTUNE_JIT_INTERFACE
197#include "v8/src/third_party/vtune/v8-vtune.h"
198#endif
199
penghuang83ec46d2016-06-28 22:49:33200#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA)
fsamuel6c6da0232015-11-26 05:13:46201#include "content/public/common/mojo_shell_connection.h"
danakj83066a32016-06-21 02:34:49202#include "content/renderer/mus/render_widget_mus_connection.h"
fsamuel2545ecc2015-12-05 00:44:46203#include "content/renderer/mus/render_widget_window_tree_client_factory.h"
ben6b0453d12016-07-02 04:27:19204#include "services/ui/common/gpu_service.h"
fsamuel6c6da0232015-11-26 05:13:46205#endif
206
ochangdd89a1e2016-06-08 16:39:01207#if defined(ENABLE_IPC_FUZZER)
208#include "content/common/external_ipc_dumper.h"
209#endif
210
[email protected]d293572a2013-05-23 18:50:45211using base::ThreadRestrictions;
[email protected]180ef242013-11-07 06:50:46212using blink::WebDocument;
213using blink::WebFrame;
214using blink::WebNetworkStateNotifier;
215using blink::WebRuntimeFeatures;
216using blink::WebScriptController;
217using blink::WebSecurityPolicy;
218using blink::WebString;
219using blink::WebView;
sadrulff12c002016-01-14 20:52:20220using scheduler::WebThreadImplForWorkerScheduler;
[email protected]e9ff79c2012-10-19 21:31:26221
222namespace content {
initial.commit09911bf2008-07-26 23:55:29223
[email protected]42f1d7822009-07-23 18:17:55224namespace {
[email protected]da9ccfb2012-01-28 00:34:40225
avi1023d012015-12-25 02:39:14226const int64_t kInitialIdleHandlerDelayMs = 1000;
227const int64_t kLongIdleHandlerDelayMs = 30 * 1000;
[email protected]bee16aab2009-08-26 15:55:03228
jdduke94ae1f32015-02-05 06:27:13229#if defined(OS_ANDROID)
230// On Android, resource messages can each take ~1.5ms to dispatch on the browser
231// IO thread. Limiting the message rate to 3/frame at 60hz ensures that the
232// induced work takes but a fraction (~1/4) of the overall frame budget.
233const int kMaxResourceRequestsPerFlushWhenThrottled = 3;
234#else
235const int kMaxResourceRequestsPerFlushWhenThrottled = 8;
236#endif
237const double kThrottledResourceRequestFlushPeriodS = 1. / 60.;
238
[email protected]dd2c1022014-07-22 23:13:57239// Maximum allocation size allowed for image scaling filters that
240// require pre-scaling. Skia will fallback to a filter that doesn't
241// require pre-scaling if the default filter would require an
242// allocation that exceeds this limit.
243const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
244
danakj83066a32016-06-21 02:34:49245// Unique identifier for each output surface created.
246uint32_t g_next_output_surface_id = 1;
247
[email protected]f1a29a02011-10-06 23:08:44248// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
[email protected]f3ede412010-06-21 22:52:16249// incorrectly from the wrong thread.
[email protected]da9ccfb2012-01-28 00:34:40250base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
[email protected]6de0fd1d2011-11-15 13:31:49251 lazy_tls = LAZY_INSTANCE_INITIALIZER;
[email protected]1edc16b82009-04-07 17:45:54252
hong.zhengb28b5332016-05-11 02:33:39253// v8::MemoryPressureLevel should correspond to base::MemoryPressureListener.
254static_assert(static_cast<v8::MemoryPressureLevel>(
255 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
256 v8::MemoryPressureLevel::kNone, "none level not align");
257static_assert(static_cast<v8::MemoryPressureLevel>(
258 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
259 v8::MemoryPressureLevel::kModerate, "moderate level not align");
260static_assert(static_cast<v8::MemoryPressureLevel>(
261 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
262 v8::MemoryPressureLevel::kCritical, "critical level not align");
263
hong.zheng2e296f822016-06-29 02:47:44264// WebMemoryPressureLevel should correspond to base::MemoryPressureListener.
265static_assert(static_cast<blink::WebMemoryPressureLevel>(
266 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
267 blink::WebMemoryPressureLevelNone,
268 "blink::WebMemoryPressureLevelNone not align");
269static_assert(static_cast<blink::WebMemoryPressureLevel>(
270 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
271 blink::WebMemoryPressureLevelModerate,
272 "blink::WebMemoryPressureLevelModerate not align");
273static_assert(static_cast<blink::WebMemoryPressureLevel>(
274 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
275 blink::WebMemoryPressureLevelCritical,
276 "blink::WebMemoryPressureLevelCritical not align");
277
sadrulff12c002016-01-14 20:52:20278class WebThreadForCompositor : public WebThreadImplForWorkerScheduler {
279 public:
280 explicit WebThreadForCompositor(base::Thread::Options options)
281 : WebThreadImplForWorkerScheduler("Compositor", options) {
282 Init();
283 }
284 ~WebThreadForCompositor() override {}
285
286 private:
287 // WebThreadImplForWorkerScheduler:
dchengcedca5612016-04-09 01:40:15288 std::unique_ptr<scheduler::WorkerScheduler> CreateWorkerScheduler() override {
289 return base::WrapUnique(new scheduler::CompositorWorkerScheduler(thread()));
sadrulff12c002016-01-14 20:52:20290 }
291
292 DISALLOW_COPY_AND_ASSIGN(WebThreadForCompositor);
293};
294
[email protected]b2d98762012-09-03 17:04:06295void* CreateHistogram(
[email protected]d1b8fccc2011-08-03 01:20:13296 const char *name, int min, int max, size_t buckets) {
297 if (min <= 0)
298 min = 1;
[email protected]b2d98762012-09-03 17:04:06299 std::string histogram_name;
300 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
301 if (render_thread_impl) { // Can be null in tests.
302 histogram_name = render_thread_impl->
303 histogram_customizer()->ConvertToCustomHistogramName(name);
304 } else {
305 histogram_name = std::string(name);
306 }
[email protected]de415552013-01-23 04:12:17307 base::HistogramBase* histogram = base::Histogram::FactoryGet(
[email protected]b2d98762012-09-03 17:04:06308 histogram_name, min, max, buckets,
309 base::Histogram::kUmaTargetedHistogramFlag);
[email protected]d1b8fccc2011-08-03 01:20:13310 return histogram;
311}
312
[email protected]b2d98762012-09-03 17:04:06313void AddHistogramSample(void* hist, int sample) {
[email protected]d1b8fccc2011-08-03 01:20:13314 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
315 histogram->Add(sample);
316}
317
dchengcedca5612016-04-09 01:40:15318std::unique_ptr<cc::SharedBitmap> AllocateSharedBitmapFunction(
jbauman9015c8b2014-12-11 00:49:37319 const gfx::Size& size) {
jam8a021512a2015-02-03 18:16:08320 return ChildThreadImpl::current()->shared_bitmap_manager()->
321 AllocateSharedBitmap(size);
[email protected]2541d1a2013-07-10 07:33:27322}
323
[email protected]8f13def2014-02-04 00:51:36324void EnableBlinkPlatformLogChannels(const std::string& channels) {
[email protected]6bd867b2013-07-24 22:10:20325 if (channels.empty())
326 return;
327 base::StringTokenizer t(channels, ", ");
328 while (t.GetNext())
[email protected]180ef242013-11-07 06:50:46329 blink::enableLogChannel(t.token().c_str());
[email protected]6bd867b2013-07-24 22:10:20330}
331
[email protected]df9accd2014-03-13 18:18:30332void NotifyTimezoneChangeOnThisThread() {
333 v8::Isolate* isolate = v8::Isolate::GetCurrent();
334 if (!isolate)
335 return;
336 v8::Date::DateTimeConfigurationChangeNotification(isolate);
337}
338
ben76f52b242016-06-18 05:42:48339class FrameFactoryImpl : public mojom::FrameFactory {
rockotf8fdd9b2015-12-16 22:22:35340 public:
ben76f52b242016-06-18 05:42:48341 explicit FrameFactoryImpl(mojom::FrameFactoryRequest request)
dcheng07945f632015-12-26 07:59:32342 : routing_id_highmark_(-1), binding_(this, std::move(request)) {}
rockotf8fdd9b2015-12-16 22:22:35343
ben76f52b242016-06-18 05:42:48344 private:
345 // mojom::FrameFactory:
346 void CreateFrame(int32_t frame_routing_id,
347 mojom::FrameRequest frame_request,
348 mojom::FrameHostPtr frame_host) override {
rockotf8fdd9b2015-12-16 22:22:35349 // TODO(morrita): This is for investigating http://crbug.com/415059 and
350 // should be removed once it is fixed.
351 CHECK_LT(routing_id_highmark_, frame_routing_id);
352 routing_id_highmark_ = frame_routing_id;
353
354 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id);
355 // We can receive a GetServiceProviderForFrame message for a frame not yet
356 // created due to a race between the message and a ViewMsg_New IPC that
357 // triggers creation of the RenderFrame we want.
358 if (!frame) {
ben76f52b242016-06-18 05:42:48359 RenderThreadImpl::current()->RegisterPendingFrameCreate(
360 frame_routing_id, std::move(frame_request), std::move(frame_host));
rockotf8fdd9b2015-12-16 22:22:35361 return;
362 }
363
ben76f52b242016-06-18 05:42:48364 frame->Bind(std::move(frame_request), std::move(frame_host));
rockotf8fdd9b2015-12-16 22:22:35365 }
366
367 private:
368 int32_t routing_id_highmark_;
ben76f52b242016-06-18 05:42:48369 mojo::StrongBinding<mojom::FrameFactory> binding_;
rockotf8fdd9b2015-12-16 22:22:35370};
371
ben76f52b242016-06-18 05:42:48372void CreateFrameFactory(mojom::FrameFactoryRequest request) {
373 new FrameFactoryImpl(std::move(request));
rockotf8fdd9b2015-12-16 22:22:35374}
375
mek27c9d742015-07-16 18:30:18376void SetupEmbeddedWorkerOnWorkerThread(
ben13be6082016-06-29 15:08:58377 shell::mojom::InterfaceProviderRequest request,
378 shell::mojom::InterfaceProviderPtrInfo remote_interfaces) {
mek27c9d742015-07-16 18:30:18379 ServiceWorkerContextClient* client =
380 ServiceWorkerContextClient::ThreadSpecificInstance();
381 // It is possible for client to be null if for some reason the worker died
382 // before this call made it to the worker thread. In that case just do
383 // nothing and let mojo close the connection.
384 if (!client)
385 return;
ben13be6082016-06-29 15:08:58386 client->BindInterfaceProviders(std::move(request),
387 mojo::MakeProxy(std::move(remote_interfaces)));
mek27c9d742015-07-16 18:30:18388}
389
leon.hanbe782c42016-03-22 05:05:22390class EmbeddedWorkerSetupImpl : public mojom::EmbeddedWorkerSetup {
mek27c9d742015-07-16 18:30:18391 public:
392 explicit EmbeddedWorkerSetupImpl(
leon.hanbe782c42016-03-22 05:05:22393 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request)
dcheng07945f632015-12-26 07:59:32394 : binding_(this, std::move(request)) {}
mek27c9d742015-07-16 18:30:18395
ben95787952016-02-10 07:46:20396 void ExchangeInterfaceProviders(
mek27c9d742015-07-16 18:30:18397 int32_t thread_id,
ben13be6082016-06-29 15:08:58398 shell::mojom::InterfaceProviderRequest request,
399 shell::mojom::InterfaceProviderPtr remote_interfaces) override {
kinukoef647412015-12-23 06:10:43400 WorkerThreadRegistry::Instance()->GetTaskRunnerFor(thread_id)->PostTask(
mek27c9d742015-07-16 18:30:18401 FROM_HERE,
ben13be6082016-06-29 15:08:58402 base::Bind(&SetupEmbeddedWorkerOnWorkerThread, base::Passed(&request),
403 base::Passed(remote_interfaces.PassInterface())));
mek27c9d742015-07-16 18:30:18404 }
405
406 private:
leon.hanbe782c42016-03-22 05:05:22407 mojo::StrongBinding<mojom::EmbeddedWorkerSetup> binding_;
mek27c9d742015-07-16 18:30:18408};
409
410void CreateEmbeddedWorkerSetup(
leon.hanbe782c42016-03-22 05:05:22411 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request) {
dcheng07945f632015-12-26 07:59:32412 new EmbeddedWorkerSetupImpl(std::move(request));
mek27c9d742015-07-16 18:30:18413}
414
jie.a.chen0ffadce32015-08-07 12:59:23415void StringToUintVector(const std::string& str, std::vector<unsigned>* vector) {
416 DCHECK(vector->empty());
brettw83dc1612015-08-12 07:31:18417 std::vector<std::string> pieces = base::SplitString(
418 str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
jie.a.chen0ffadce32015-08-07 12:59:23419 DCHECK_EQ(pieces.size(), static_cast<size_t>(gfx::BufferFormat::LAST) + 1);
420 for (size_t i = 0; i < pieces.size(); ++i) {
421 unsigned number = 0;
422 bool succeed = base::StringToUint(pieces[i], &number);
423 DCHECK(succeed);
424 vector->push_back(number);
425 }
426}
427
danakjc3983552016-05-03 00:04:35428scoped_refptr<ContextProviderCommandBuffer> CreateOffscreenContext(
429 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
danakj0dd9e1e2016-05-11 22:15:09430 const gpu::SharedMemoryLimits& limits,
danakj9a04adc2016-05-16 22:45:07431 bool support_locking,
sunnypsd8ce1c22016-05-10 18:02:40432 command_buffer_metrics::ContextType type,
433 int32_t stream_id,
434 gpu::GpuStreamPriority stream_priority) {
danakje8ec797e2016-04-19 04:08:43435 DCHECK(gpu_channel_host);
436 // This is used to create a few different offscreen contexts:
437 // - The shared main thread context (offscreen) used by blink for canvas.
438 // - The worker context (offscreen) used for GPU raster and video decoding.
439 // This is for an offscreen context, so the default framebuffer doesn't need
440 // alpha, depth, stencil, antialiasing.
441 gpu::gles2::ContextCreationAttribHelper attributes;
442 attributes.alpha_size = -1;
443 attributes.depth_size = 0;
444 attributes.stencil_size = 0;
445 attributes.samples = 0;
446 attributes.sample_buffers = 0;
447 attributes.bind_generates_resource = false;
448 attributes.lose_context_when_out_of_memory = true;
sunnypsd8ce1c22016-05-10 18:02:40449 const bool automatic_flushes = false;
danakjc3983552016-05-03 00:04:35450 return make_scoped_refptr(new ContextProviderCommandBuffer(
sunnypsd8ce1c22016-05-10 18:02:40451 std::move(gpu_channel_host), stream_id, stream_priority,
452 gpu::kNullSurfaceHandle,
danakjba37f812016-05-03 03:58:03453 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext"),
pimand488e8b42016-06-30 19:06:59454 automatic_flushes, support_locking, limits, attributes, nullptr, type));
danakje8ec797e2016-04-19 04:08:43455}
456
penghuange1d86512016-07-08 18:15:00457bool IsRunningInMash() {
458 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
459 return cmdline->HasSwitch(switches::kIsRunningInMash);
460}
461
[email protected]b2d98762012-09-03 17:04:06462} // namespace
463
[email protected]fdeac262014-07-10 12:52:51464// For measuring memory usage after each task. Behind a command line flag.
465class MemoryObserver : public base::MessageLoop::TaskObserver {
466 public:
467 MemoryObserver() {}
dcheng6d18e402014-10-21 12:32:52468 ~MemoryObserver() override {}
[email protected]fdeac262014-07-10 12:52:51469
dcheng6d18e402014-10-21 12:32:52470 void WillProcessTask(const base::PendingTask& pending_task) override {}
[email protected]fdeac262014-07-10 12:52:51471
dcheng6d18e402014-10-21 12:32:52472 void DidProcessTask(const base::PendingTask& pending_task) override {
asvitkinec0fb8022014-08-26 04:39:35473 LOCAL_HISTOGRAM_MEMORY_KB("Memory.RendererUsed", GetMemoryUsageKB());
[email protected]fdeac262014-07-10 12:52:51474 }
475
476 private:
477 DISALLOW_COPY_AND_ASSIGN(MemoryObserver);
478};
479
[email protected]b2d98762012-09-03 17:04:06480RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
481 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
482 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
483 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
hablich4598ddc2015-11-07 18:37:28484 custom_histograms_.insert("V8.MemoryHeapUsed");
485 custom_histograms_.insert("V8.MemoryHeapCommitted");
[email protected]b2d98762012-09-03 17:04:06486}
487
488RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
489
490void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost(
491 const std::string& host, size_t view_count) {
avi83883c82014-12-23 00:08:49492 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
493 switches::kDisableHistogramCustomizer)) {
[email protected]9baee832012-12-10 11:07:15494 return;
495 }
[email protected]b2d98762012-09-03 17:04:06496 // Check if all RenderViews are displaying a page from the same host. If there
497 // is only one RenderView, the common host is this view's host. If there are
498 // many, check if this one shares the common host of the other
499 // RenderViews. It's ok to not detect some cases where the RenderViews share a
500 // common host. This information is only used for producing custom histograms.
501 if (view_count == 1)
502 SetCommonHost(host);
503 else if (host != common_host_)
504 SetCommonHost(std::string());
505}
506
507std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName(
508 const char* histogram_name) const {
509 std::string name(histogram_name);
510 if (!common_host_histogram_suffix_.empty() &&
511 custom_histograms_.find(name) != custom_histograms_.end())
512 name += common_host_histogram_suffix_;
513 return name;
514}
515
516void RenderThreadImpl::HistogramCustomizer::SetCommonHost(
517 const std::string& host) {
518 if (host != common_host_) {
519 common_host_ = host;
520 common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host);
[email protected]4b5340282014-07-08 11:37:34521 blink::mainThreadIsolate()->SetCreateHistogramFunction(CreateHistogram);
[email protected]b2d98762012-09-03 17:04:06522 }
523}
524
hablichd6a4f122015-10-28 11:34:49525std::string RenderThreadImpl::HistogramCustomizer::HostToCustomHistogramSuffix(
526 const std::string& host) {
527 if (host == "mail.google.com")
528 return ".gmail";
529 if (host == "docs.google.com" || host == "drive.google.com")
530 return ".docs";
531 if (host == "plus.google.com")
532 return ".plus";
533 if (host == "inbox.google.com")
534 return ".inbox";
hpayerdd4def052016-02-06 19:06:10535 if (host == "calendar.google.com")
536 return ".calendar";
hablichd6a4f122015-10-28 11:34:49537 if (host == "www.youtube.com")
538 return ".youtube";
539 if (IsAlexaTop10NonGoogleSite(host))
540 return ".top10";
541
542 return std::string();
543}
544
545bool RenderThreadImpl::HistogramCustomizer::IsAlexaTop10NonGoogleSite(
546 const std::string& host) {
547 // The Top10 sites have different TLD and/or subdomains depending on the
548 // localization.
549 if (host == "sina.com.cn")
550 return true;
551
552 std::string sanitized_host =
553 net::registry_controlled_domains::GetDomainAndRegistry(
554 host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
555
556 if (sanitized_host == "facebook.com")
557 return true;
558 if (sanitized_host == "baidu.com")
559 return true;
560 if (sanitized_host == "qq.com")
561 return true;
562 if (sanitized_host == "twitter.com")
563 return true;
564 if (sanitized_host == "taobao.com")
565 return true;
566 if (sanitized_host == "live.com")
567 return true;
568
569 if (!sanitized_host.empty()) {
570 std::vector<base::StringPiece> host_tokens = base::SplitStringPiece(
571 sanitized_host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
572
573 if (host_tokens.size() >= 2) {
574 if ((host_tokens[0] == "yahoo") || (host_tokens[0] == "amazon") ||
575 (host_tokens[0] == "wikipedia")) {
576 return true;
577 }
578 }
579 }
580 return false;
581}
582
leon.han2c0f9f12015-07-11 02:01:19583// static
584RenderThreadImpl* RenderThreadImpl::Create(
585 const InProcessChildThreadParams& params) {
dchengcedca5612016-04-09 01:40:15586 std::unique_ptr<scheduler::RendererScheduler> renderer_scheduler =
leon.han2c0f9f12015-07-11 02:01:19587 scheduler::RendererScheduler::Create();
jam75c44222016-03-23 05:34:24588 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
589 return new RenderThreadImpl(
590 params, std::move(renderer_scheduler), test_task_counter);
leon.han2c0f9f12015-07-11 02:01:19591}
592
593// static
594RenderThreadImpl* RenderThreadImpl::Create(
dchengcedca5612016-04-09 01:40:15595 std::unique_ptr<base::MessageLoop> main_message_loop,
596 std::unique_ptr<scheduler::RendererScheduler> renderer_scheduler) {
dcheng07945f632015-12-26 07:59:32597 return new RenderThreadImpl(std::move(main_message_loop),
598 std::move(renderer_scheduler));
leon.han2c0f9f12015-07-11 02:01:19599}
600
[email protected]f1a29a02011-10-06 23:08:44601RenderThreadImpl* RenderThreadImpl::current() {
[email protected]526476902011-10-06 20:34:06602 return lazy_tls.Pointer()->Get();
603}
604
leon.han2c0f9f12015-07-11 02:01:19605RenderThreadImpl::RenderThreadImpl(
606 const InProcessChildThreadParams& params,
dchengcedca5612016-04-09 01:40:15607 std::unique_ptr<scheduler::RendererScheduler> scheduler,
jam75c44222016-03-23 05:34:24608 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue)
morritac6238ab2015-03-18 01:48:29609 : ChildThreadImpl(Options::Builder()
prashant.nfad657e2016-06-01 07:52:17610 .InBrowserProcess(params)
611 .UseMojoChannel(true)
rockotcef38272016-07-15 22:47:47612 .AutoStartMojoShellConnection(false)
prashant.nfad657e2016-06-01 07:52:17613 .Build()),
dcheng07945f632015-12-26 07:59:32614 renderer_scheduler_(std::move(scheduler)),
prashant.nfad657e2016-06-01 07:52:17615 categorized_worker_pool_(new CategorizedWorkerPool()) {
jam75c44222016-03-23 05:34:24616 Init(resource_task_queue);
morritac6238ab2015-03-18 01:48:29617}
618
[email protected]42f1d7822009-07-23 18:17:55619// When we run plugins in process, we actually run them on the render thread,
620// which means that we need to make the render thread pump UI events.
haraken53f081d2014-11-11 01:03:40621RenderThreadImpl::RenderThreadImpl(
dchengcedca5612016-04-09 01:40:15622 std::unique_ptr<base::MessageLoop> main_message_loop,
623 std::unique_ptr<scheduler::RendererScheduler> scheduler)
rockotcef38272016-07-15 22:47:47624 : ChildThreadImpl(Options::Builder()
625 .UseMojoChannel(true)
626 .AutoStartMojoShellConnection(false)
627 .Build()),
dcheng07945f632015-12-26 07:59:32628 renderer_scheduler_(std::move(scheduler)),
629 main_message_loop_(std::move(main_message_loop)),
prashant.nfad657e2016-06-01 07:52:17630 categorized_worker_pool_(new CategorizedWorkerPool()) {
jam75c44222016-03-23 05:34:24631 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter;
632 Init(test_task_counter);
haraken53f081d2014-11-11 01:03:40633}
634
jam75c44222016-03-23 05:34:24635void RenderThreadImpl::Init(
636 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) {
fdorayf6d86242015-10-08 16:49:53637 TRACE_EVENT0("startup", "RenderThreadImpl::Init");
[email protected]a872ea1f2010-08-11 04:45:33638
ssidb2e3ece2015-02-09 16:02:20639 base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex(
[email protected]91a2aea2013-07-08 23:14:39640 base::PlatformThread::CurrentId(),
641 kTraceEventRendererMainThreadSortIndex);
642
haibinluc643d33c2016-06-03 02:22:34643#if defined(USE_EXTERNAL_POPUP_MENU)
sievers9dff72052015-11-16 18:35:57644 // On Mac and Android Java UI, the select popups are rendered by the browser.
[email protected]180ef242013-11-07 06:50:46645 blink::WebView::setUseExternalPopupMenus(true);
[email protected]53c607c2011-03-21 23:19:04646#endif
647
[email protected]94f9a0f682009-06-15 18:30:30648 lazy_tls.Pointer()->Set(this);
[email protected]b3e83de2012-02-07 03:33:28649
[email protected]06c694d2012-02-01 22:26:16650 // Register this object as the main thread.
651 ChildProcess::current()->set_main_thread(this);
652
penghuange1d86512016-07-08 18:15:00653#if defined(MOJO_SHELL_CLIENT)
rockotcef38272016-07-15 22:47:47654 if (IsRunningInMash())
655 ui::GpuService::Initialize(GetMojoShellConnection()->GetConnector());
penghuange1d86512016-07-08 18:15:00656#endif
657
jam75c44222016-03-23 05:34:24658 InitializeWebKit(resource_task_queue);
659
[email protected]31f87132010-04-21 23:36:21660 // In single process the single process is all there is.
[email protected]26e82322014-01-20 14:18:22661 webkit_shared_timer_suspended_ = false;
[email protected]bee16aab2009-08-26 15:55:03662 widget_count_ = 0;
663 hidden_widget_count_ = 0;
[email protected]6593ae12011-11-14 12:09:44664 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
[email protected]1784b2f2011-11-24 10:53:48665 idle_notifications_to_skip_ = 0;
[email protected]8d86fce2009-02-26 23:37:55666
[email protected]d5b2fdf2013-06-05 09:36:55667 appcache_dispatcher_.reset(
[email protected]a8cb3b73b2013-08-12 05:50:50668 new AppCacheDispatcher(Get(), new AppCacheFrontendImpl()));
[email protected]1910fe82012-05-10 00:04:10669 dom_storage_dispatcher_.reset(new DomStorageDispatcher());
[email protected]1e8d91e2013-06-27 00:12:43670 main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher(
671 thread_safe_sender()));
jsbellabadb9b2015-03-23 21:03:44672 main_thread_cache_storage_dispatcher_.reset(
jsbell279efb42015-03-31 17:02:46673 new CacheStorageDispatcher(thread_safe_sender()));
[email protected]7670d4332013-11-29 04:35:00674 embedded_worker_dispatcher_.reset(new EmbeddedWorkerDispatcher());
[email protected]dd9241932010-02-24 19:23:13675
jdduke94ae1f32015-02-05 06:27:13676 // Note: This may reorder messages from the ResourceDispatcher with respect to
677 // other subsystems.
678 resource_dispatch_throttler_.reset(new ResourceDispatchThrottler(
679 static_cast<RenderThread*>(this), renderer_scheduler_.get(),
680 base::TimeDelta::FromSecondsD(kThrottledResourceRequestFlushPeriodS),
681 kMaxResourceRequestsPerFlushWhenThrottled));
682 resource_dispatcher()->set_message_sender(resource_dispatch_throttler_.get());
683
penghuange1d86512016-07-08 18:15:00684 media_stream_center_ = nullptr;
[email protected]d8cd8372012-03-09 10:49:51685
thestig529ad8a2016-07-08 20:30:12686 blob_message_filter_ = new BlobMessageFilter(GetFileThreadTaskRunner());
dmurph1fb98482016-03-30 21:14:26687 AddFilter(blob_message_filter_.get());
[email protected]017022b2009-07-27 23:06:34688 db_message_filter_ = new DBMessageFilter();
689 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13690
[email protected]45048072014-01-14 13:51:29691 vc_manager_.reset(new VideoCaptureImplManager());
[email protected]c9c43a02013-12-17 08:59:54692 AddFilter(vc_manager_->video_capture_message_filter());
693
fsamuel6c1dfeb2014-12-18 19:21:33694 browser_plugin_manager_.reset(new BrowserPluginManager());
695 AddObserver(browser_plugin_manager_.get());
696
[email protected]4761cf12012-09-12 10:37:55697#if defined(ENABLE_WEBRTC)
[email protected]af089972013-01-10 04:04:40698 peer_connection_tracker_.reset(new PeerConnectionTracker());
699 AddObserver(peer_connection_tracker_.get());
700
thestig529ad8a2016-07-08 20:30:12701 p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOTaskRunner().get());
[email protected]fc72bb12013-06-02 21:13:46702 AddFilter(p2p_socket_dispatcher_.get());
[email protected]921480f62013-07-20 03:42:57703
ivocadd54f0d2015-12-18 23:17:05704 peer_connection_factory_.reset(
705 new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get()));
706
skyostil2d3b5bd2015-05-27 15:40:59707 aec_dump_message_filter_ = new AecDumpMessageFilter(
thestig529ad8a2016-07-08 20:30:12708 GetIOTaskRunner(), message_loop()->task_runner());
ivocadd54f0d2015-12-18 23:17:05709
[email protected]da9f30a2014-06-18 19:39:04710 AddFilter(aec_dump_message_filter_.get());
711
[email protected]4761cf12012-09-12 10:37:55712#endif // defined(ENABLE_WEBRTC)
[email protected]e25f4d72011-06-08 20:58:46713
thestig529ad8a2016-07-08 20:30:12714 audio_input_message_filter_ = new AudioInputMessageFilter(GetIOTaskRunner());
[email protected]f7eb0a392011-07-12 10:19:51715 AddFilter(audio_input_message_filter_.get());
716
thestig529ad8a2016-07-08 20:30:12717 audio_message_filter_ = new AudioMessageFilter(GetIOTaskRunner());
[email protected]f7eb0a392011-07-12 10:19:51718 AddFilter(audio_message_filter_.get());
719
thestig529ad8a2016-07-08 20:30:12720 midi_message_filter_ = new MidiMessageFilter(GetIOTaskRunner());
[email protected]a9875152013-06-22 04:03:03721 AddFilter(midi_message_filter_.get());
722
[email protected]ce944c62013-11-19 16:34:36723 AddFilter((new IndexedDBMessageFilter(thread_safe_sender()))->GetFilter());
[email protected]31bfae72011-12-16 02:04:38724
jsbellabadb9b2015-03-23 21:03:44725 AddFilter((new CacheStorageMessageFilter(thread_safe_sender()))->GetFilter());
726
kinuko5af4ffe2015-06-09 03:38:46727 AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter());
[email protected]ddbb53342014-01-06 10:59:47728
rockotcef38272016-07-15 22:47:47729#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA)
730 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
731 switches::kUseMusInRenderer)) {
732 CreateRenderWidgetWindowTreeClientFactory(GetMojoShellConnection());
733 }
734#endif
735
736 // Must be called before RenderThreadStarted() below.
737 StartMojoShellConnection();
738
[email protected]e9ff79c2012-10-19 21:31:26739 GetContentClient()->renderer()->RenderThreadStarted();
[email protected]6779aa12011-03-29 17:32:24740
[email protected]b48c53ad2014-02-05 21:59:18741 InitSkiaEventTracer();
ssid59c969162015-07-28 13:02:58742 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
primiano186d6bfe2015-10-30 13:21:40743 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr);
[email protected]b48c53ad2014-02-05 21:59:18744
avi83883c82014-12-23 00:08:49745 const base::CommandLine& command_line =
746 *base::CommandLine::ForCurrentProcess();
[email protected]e54ab492012-06-12 19:40:01747
ochangdd89a1e2016-06-08 16:39:01748#if defined(ENABLE_IPC_FUZZER)
749 if (command_line.HasSwitch(switches::kIpcDumpDirectory)) {
750 base::FilePath dump_directory =
751 command_line.GetSwitchValuePath(switches::kIpcDumpDirectory);
752 IPC::ChannelProxy::OutgoingMessageFilter* filter =
753 LoadExternalIPCDumper(dump_directory);
754 GetChannel()->set_outgoing_message_filter(filter);
755 }
756#endif
757
jbroman0d302162015-09-05 05:46:23758 cc::SetClientNameForMetrics("Renderer");
loysoa6edaaff2015-05-25 03:26:44759
loyso65c93c602015-08-11 05:15:57760 is_threaded_animation_enabled_ =
761 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
762
reveman91a0a872014-11-04 03:40:32763 is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy);
ericrk1d17f752015-10-20 03:03:07764 is_partial_raster_enabled_ =
dongseong.hwang23db47f2016-03-08 07:50:02765 !command_line.HasSwitch(switches::kDisablePartialRaster);
ccameronc7fcd132015-11-03 20:14:31766 is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch(
767 switches::kEnableGpuMemoryBufferCompositorResources);
[email protected]a23530d2014-03-11 06:04:14768
jame1f453c2016-03-21 15:51:34769#if defined(OS_MACOSX)
thakis114a1ef2016-04-26 16:02:59770 base::ScopedCFTypeRef<CFStringRef> key(
771 base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding"));
772 Boolean key_exists = false;
773 Boolean value = CFPreferencesGetAppBooleanValue(
774 key, kCFPreferencesCurrentApplication, &key_exists);
775 is_elastic_overscroll_enabled_ = !key_exists || value;
ccamerona7644752014-12-30 01:16:31776#else
777 is_elastic_overscroll_enabled_ = false;
778#endif
779
danakje6eb185c2015-02-27 23:52:05780 std::string image_texture_target_string =
dcastagna7f2f7192015-06-16 18:44:35781 command_line.GetSwitchValueASCII(switches::kContentImageTextureTarget);
jie.a.chen0ffadce32015-08-07 12:59:23782 StringToUintVector(image_texture_target_string, &use_image_texture_targets_);
reveman44b807f12014-11-26 02:44:50783
[email protected]a23530d2014-03-11 06:04:14784 if (command_line.HasSwitch(switches::kDisableLCDText)) {
785 is_lcd_text_enabled_ = false;
786 } else if (command_line.HasSwitch(switches::kEnableLCDText)) {
787 is_lcd_text_enabled_ = true;
788 } else {
789#if defined(OS_ANDROID)
790 is_lcd_text_enabled_ = false;
791#else
792 is_lcd_text_enabled_ = true;
793#endif
794 }
795
[email protected]b8d82c22014-03-31 20:12:46796 is_gpu_rasterization_enabled_ =
797 command_line.HasSwitch(switches::kEnableGpuRasterization);
798 is_gpu_rasterization_forced_ =
799 command_line.HasSwitch(switches::kForceGpuRasterization);
sunnypsd8ce1c22016-05-10 18:02:40800 is_async_worker_context_enabled_ =
801 command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext);
[email protected]a23530d2014-03-11 06:04:14802
senorblancob60ba952015-01-27 19:12:36803 if (command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) {
804 std::string string_value = command_line.GetSwitchValueASCII(
805 switches::kGpuRasterizationMSAASampleCount);
806 bool parsed_msaa_sample_count =
807 base::StringToInt(string_value, &gpu_rasterization_msaa_sample_count_);
808 DCHECK(parsed_msaa_sample_count) << string_value;
809 DCHECK_GE(gpu_rasterization_msaa_sample_count_, 0);
810 } else {
senorblanco2a5b0e12015-08-14 21:55:37811 gpu_rasterization_msaa_sample_count_ = -1;
senorblancob60ba952015-01-27 19:12:36812 }
813
[email protected]b242b142014-05-07 14:48:49814 if (command_line.HasSwitch(switches::kDisableDistanceFieldText)) {
815 is_distance_field_text_enabled_ = false;
816 } else if (command_line.HasSwitch(switches::kEnableDistanceFieldText)) {
817 is_distance_field_text_enabled_ = true;
818 } else {
819 is_distance_field_text_enabled_ = false;
820 }
821
[email protected]433df472012-03-07 20:33:39822 // Note that under Linux, the media library will normally already have
823 // been initialized by the Zygote before this instance became a Renderer.
chcunninghamfd11b3c2015-06-09 02:09:42824 media::InitializeMediaLibrary();
[email protected]433df472012-03-07 20:33:39825
dalecurtis88af3932016-02-20 00:12:20826#if defined(OS_ANDROID)
827 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
828 media::MediaCodecUtil::IsMediaCodecAvailable()) {
829 media::EnablePlatformDecoderSupport();
830 }
831#endif
832
[email protected]5071cb22013-07-10 02:19:06833 memory_pressure_listener_.reset(new base::MemoryPressureListener(
hong.zhengb28b5332016-05-11 02:33:39834 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
835 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
836 base::Unretained(this))));
[email protected]5071cb22013-07-10 02:19:06837
danakj16275d4c2015-06-11 19:23:51838 int num_raster_threads = 0;
839 std::string string_value =
840 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
841 bool parsed_num_raster_threads =
842 base::StringToInt(string_value, &num_raster_threads);
843 DCHECK(parsed_num_raster_threads) << string_value;
844 DCHECK_GT(num_raster_threads, 0);
vmiura78b69282015-02-14 00:01:17845
vmpstr6c0b5112016-04-25 22:12:14846 // TODO(vmpstr): If the flag sticks, we should clean it up and always have
847 // image decode tasks.
vmpstr9dd810a2016-01-19 21:16:10848 are_image_decode_tasks_enabled_ = true;
halliwell4b3deee2014-12-19 19:57:49849
prashant.nfad657e2016-06-01 07:52:17850 categorized_worker_pool_->Start(num_raster_threads);
[email protected]1e1d1e12014-01-17 16:14:29851
boliu9760e212015-06-23 22:49:06852 // TODO(boliu): In single process, browser main loop should set up the
853 // discardable memory manager, and should skip this if kSingleProcess.
854 // See crbug.com/503724.
855 base::DiscardableMemoryAllocator::SetInstance(
856 ChildThreadImpl::discardable_shared_memory_manager());
revemancb5a66af2014-10-25 00:34:39857
bend1dd50f52016-06-26 22:10:48858 GetContentClient()->renderer()->ExposeInterfacesToBrowser(
859 GetInterfaceRegistry());
rockot229fb28e2016-06-16 04:46:16860
bend1dd50f52016-06-26 22:10:48861 GetInterfaceRegistry()->AddInterface(base::Bind(CreateFrameFactory));
862 GetInterfaceRegistry()->AddInterface(base::Bind(CreateEmbeddedWorkerSetup));
fsamuel6c6da0232015-11-26 05:13:46863
bend1dd50f52016-06-26 22:10:48864 GetRemoteInterfaces()->GetInterface(
jamc912ca32016-02-24 20:17:31865 mojo::GetProxy(&storage_partition_service_));
hajimehoshi69093272016-05-13 08:30:58866
867 is_renderer_suspended_ = false;
initial.commit09911bf2008-07-26 23:55:29868}
869
[email protected]f1a29a02011-10-06 23:08:44870RenderThreadImpl::~RenderThreadImpl() {
[email protected]ce79d8512013-04-22 22:44:41871}
872
873void RenderThreadImpl::Shutdown() {
[email protected]1223d6ef2011-03-28 16:47:50874 FOR_EACH_OBSERVER(
tyoshino832a58a2016-04-18 08:14:08875 RenderThreadObserver, observers_, OnRenderProcessShutdown());
[email protected]1223d6ef2011-03-28 16:47:50876
[email protected]fdeac262014-07-10 12:52:51877 if (memory_observer_) {
878 message_loop()->RemoveTaskObserver(memory_observer_.get());
879 memory_observer_.reset();
880 }
881
[email protected]12cbfda32010-01-30 01:04:25882 // Wait for all databases to be closed.
tfarina556a7232014-10-05 01:02:09883 if (blink_platform_impl_) {
michaelnb15028542015-10-29 03:33:24884 // Crash the process if they fail to close after a generous amount of time.
885 bool all_closed = blink_platform_impl_->web_database_observer_impl()
886 ->WaitForAllDatabasesToClose(base::TimeDelta::FromSeconds(60));
887 CHECK(all_closed);
[email protected]1406f892013-11-12 19:38:19888 }
[email protected]12cbfda32010-01-30 01:04:25889
[email protected]8d86fce2009-02-26 23:37:55890 // Shutdown in reverse of the initialization order.
[email protected]fc72bb12013-06-02 21:13:46891 if (devtools_agent_message_filter_.get()) {
[email protected]b146d6d2012-09-11 10:20:05892 RemoveFilter(devtools_agent_message_filter_.get());
penghuange1d86512016-07-08 18:15:00893 devtools_agent_message_filter_ = nullptr;
[email protected]b146d6d2012-09-11 10:20:05894 }
[email protected]82622452011-07-22 09:57:20895
[email protected]f7eb0a392011-07-12 10:19:51896 RemoveFilter(audio_input_message_filter_.get());
penghuange1d86512016-07-08 18:15:00897 audio_input_message_filter_ = nullptr;
[email protected]f7eb0a392011-07-12 10:19:51898
[email protected]45048072014-01-14 13:51:29899#if defined(ENABLE_WEBRTC)
[email protected]51c7985e2014-05-23 22:00:08900 RTCPeerConnectionHandler::DestructAllHandlers();
tommi6c33f252014-11-24 12:29:51901 // |peer_connection_factory_| cannot be deleted until after the main message
902 // loop has been destroyed. This is because there may be pending tasks that
903 // hold on to objects produced by the PC factory that depend on threads owned
904 // by the PC factory. Once those tasks have been freed, the factory can be
905 // deleted.
[email protected]45048072014-01-14 13:51:29906#endif
[email protected]80b161a2011-06-27 17:42:11907 RemoveFilter(vc_manager_->video_capture_message_filter());
[email protected]45048072014-01-14 13:51:29908 vc_manager_.reset();
[email protected]80b161a2011-06-27 17:42:11909
[email protected]017022b2009-07-27 23:06:34910 RemoveFilter(db_message_filter_.get());
penghuange1d86512016-07-08 18:15:00911 db_message_filter_ = nullptr;
[email protected]12cbfda32010-01-30 01:04:25912
[email protected]c6a7b862010-08-20 22:19:38913 // Shutdown the file thread if it's running.
[email protected]59383c782013-04-17 16:43:27914 if (file_thread_)
[email protected]c6a7b862010-08-20 22:19:38915 file_thread_->Stop();
916
simonhonga7e3ac42014-11-11 20:50:22917 if (compositor_message_filter_.get()) {
918 RemoveFilter(compositor_message_filter_.get());
penghuange1d86512016-07-08 18:15:00919 compositor_message_filter_ = nullptr;
[email protected]23d2b7e2012-08-14 00:34:09920 }
[email protected]1842fe22012-08-13 23:24:35921
boliubee541f42015-11-05 00:52:53922#if defined(OS_ANDROID)
923 if (sync_compositor_message_filter_) {
924 RemoveFilter(sync_compositor_message_filter_.get());
925 sync_compositor_message_filter_ = nullptr;
926 }
siva.gunturi5d4feb052015-11-15 16:15:31927 stream_texture_factory_ = nullptr;
boliubee541f42015-11-05 00:52:53928#endif
929
[email protected]b4ef7742014-03-19 06:12:56930 media_thread_.reset();
dalecurtis3ba0480e2014-09-09 20:21:30931
sadrulff12c002016-01-14 20:52:20932 blink_platform_impl_->SetCompositorThread(nullptr);
vollick1050cc62015-12-03 07:04:54933
dcastagna7f45dada2015-10-19 20:17:35934 compositor_thread_.reset();
935
dalecurtis3ba0480e2014-09-09 20:21:30936 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after.
937 RemoveFilter(audio_message_filter_.get());
penghuange1d86512016-07-08 18:15:00938 audio_message_filter_ = nullptr;
dalecurtis3ba0480e2014-09-09 20:21:30939
prashant.nfad657e2016-06-01 07:52:17940 categorized_worker_pool_->Shutdown();
reveman34b7a1522015-03-23 20:27:47941
jdduke691dd572014-12-02 20:47:52942 main_input_callback_.Cancel();
[email protected]b0255682013-06-07 21:24:08943 input_handler_manager_.reset();
[email protected]cadac622013-06-11 16:46:36944 if (input_event_filter_.get()) {
[email protected]b0255682013-06-07 21:24:08945 RemoveFilter(input_event_filter_.get());
penghuange1d86512016-07-08 18:15:00946 input_event_filter_ = nullptr;
[email protected]a9fb30aa2011-10-06 06:58:46947 }
948
[email protected]51f82b02014-05-27 00:02:57949 // RemoveEmbeddedWorkerRoute may be called while deleting
950 // EmbeddedWorkerDispatcher. So it must be deleted before deleting
951 // RenderThreadImpl.
952 embedded_worker_dispatcher_.reset();
953
[email protected]c5739b9e2013-11-07 06:30:22954 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might
955 // hold pointers to V8 objects (e.g., via pending requests).
956 main_thread_indexed_db_dispatcher_.reset();
957
penghuange1d86512016-07-08 18:15:00958 main_thread_compositor_task_runner_ = nullptr;
skyostil457b0a12014-09-09 10:12:07959
dcastagna09bd6b32016-02-01 21:54:28960 gpu_factories_.clear();
dcastagna7f45dada2015-10-19 20:17:35961
vmiuraeeb91772015-04-15 01:00:51962 // Context providers must be released prior to destroying the GPU channel.
revemand180dfc32015-09-24 00:19:43963 shared_worker_context_provider_ = nullptr;
piman765e5282015-05-08 03:43:01964 shared_main_thread_contexts_ = nullptr;
vmiuraeeb91772015-04-15 01:00:51965
haraken53f081d2014-11-11 01:03:40966 if (gpu_channel_.get())
967 gpu_channel_->DestroyChannel();
[email protected]8fd8de92008-08-12 23:50:30968
reveman413413fb2016-01-14 00:43:07969 ChildThreadImpl::Shutdown();
970
fdoray2df4a9e2016-07-18 23:47:16971 // Shut down the message loop (if provided when the RenderThreadImpl was
972 // constructed) and the renderer scheduler before shutting down Blink. This
973 // prevents a scenario where a pending task in the message loop accesses Blink
974 // objects after Blink shuts down.
skyostila37c2a72016-06-29 17:30:07975 renderer_scheduler_->SetRAILModeObserver(nullptr);
rmcilroy168f3dc2015-03-17 13:09:15976 renderer_scheduler_->Shutdown();
haraken534ab852016-01-29 03:52:56977 if (main_message_loop_)
fdoray2df4a9e2016-07-18 23:47:16978 base::RunLoop().RunUntilIdle();
haraken534ab852016-01-29 03:52:56979
rickyzf2c93062015-09-15 09:10:57980 if (blink_platform_impl_) {
981 blink_platform_impl_->Shutdown();
haraken534ab852016-01-29 03:52:56982 // This must be at the very end of the shutdown sequence.
983 // blink::shutdown() must be called after all strong references from
984 // Chromium to Blink are cleared.
haraken53f081d2014-11-11 01:03:40985 blink::shutdown();
rickyzf2c93062015-09-15 09:10:57986 }
haraken53f081d2014-11-11 01:03:40987
haraken534ab852016-01-29 03:52:56988 // Delay shutting down DiscardableSharedMemoryManager until blink::shutdown
989 // is complete, because blink::shutdown destructs Blink Resources and they
990 // may try to unlock their underlying discardable memory.
991 ChildThreadImpl::ShutdownDiscardableSharedMemoryManager();
992
993 // The message loop must be cleared after shutting down
994 // the DiscardableSharedMemoryManager, which needs to send messages
995 // to the browser process.
996 main_message_loop_.reset();
997
penghuange1d86512016-07-08 18:15:00998 lazy_tls.Pointer()->Set(nullptr);
initial.commit09911bf2008-07-26 23:55:29999}
1000
[email protected]f1a29a02011-10-06 23:08:441001bool RenderThreadImpl::Send(IPC::Message* msg) {
changwan6ed4d432016-05-19 22:03:541002 // There are cases where we want to pump asynchronous messages while waiting
1003 // synchronously for the replies to the message to be sent here. However, this
1004 // may create an opportunity for re-entrancy into WebKit and other subsystems,
1005 // so we need to take care to disable callbacks, timers, and pending network
1006 // loads that could trigger such callbacks.
[email protected]38b592902011-04-16 02:08:421007 bool pumping_events = false;
[email protected]80fc08c52010-03-09 07:43:501008 if (msg->is_sync()) {
1009 if (msg->is_caller_pumping_messages()) {
1010 pumping_events = true;
[email protected]80fc08c52010-03-09 07:43:501011 }
[email protected]c1f50aa2010-02-18 03:46:571012 }
1013
[email protected]c1f50aa2010-02-18 03:46:571014 if (pumping_events) {
jdduked73ae5412015-05-11 20:07:161015 renderer_scheduler_->SuspendTimerQueue();
changwan6ed4d432016-05-19 22:03:541016 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571017 }
1018
jam8a021512a2015-02-03 18:16:081019 bool rv = ChildThreadImpl::Send(msg);
[email protected]c1f50aa2010-02-18 03:46:571020
1021 if (pumping_events) {
changwan6ed4d432016-05-19 22:03:541022 WebView::didExitModalLoop();
jdduked73ae5412015-05-11 20:07:161023 renderer_scheduler_->ResumeTimerQueue();
[email protected]c1f50aa2010-02-18 03:46:571024 }
1025
1026 return rv;
1027}
1028
[email protected]f1a29a02011-10-06 23:08:441029IPC::SyncChannel* RenderThreadImpl::GetChannel() {
[email protected]526476902011-10-06 20:34:061030 return channel();
1031}
1032
[email protected]f1a29a02011-10-06 23:08:441033std::string RenderThreadImpl::GetLocale() {
[email protected]526476902011-10-06 20:34:061034 // The browser process should have passed the locale to the renderer via the
[email protected]dfd53652012-10-25 00:20:021035 // --lang command line flag.
avi83883c82014-12-23 00:08:491036 const base::CommandLine& parsed_command_line =
1037 *base::CommandLine::ForCurrentProcess();
[email protected]526476902011-10-06 20:34:061038 const std::string& lang =
1039 parsed_command_line.GetSwitchValueASCII(switches::kLang);
[email protected]dfd53652012-10-25 00:20:021040 DCHECK(!lang.empty());
[email protected]526476902011-10-06 20:34:061041 return lang;
1042}
1043
[email protected]07bb6332012-01-21 01:07:571044IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() {
1045 return sync_message_filter();
1046}
1047
skyostil12262cf2015-05-21 14:49:311048scoped_refptr<base::SingleThreadTaskRunner>
thestig529ad8a2016-07-08 20:30:121049RenderThreadImpl::GetIOTaskRunner() {
skyostil12262cf2015-05-21 14:49:311050 return ChildProcess::current()->io_task_runner();
[email protected]96191d52012-05-17 01:37:111051}
1052
avi1023d012015-12-25 02:39:141053void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) {
jam8a021512a2015-02-03 18:16:081054 ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener);
ben76f52b242016-06-18 05:42:481055 auto it = pending_frame_creates_.find(routing_id);
1056 if (it == pending_frame_creates_.end())
rockotf8fdd9b2015-12-16 22:22:351057 return;
1058
1059 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
1060 if (!frame)
1061 return;
1062
ben76f52b242016-06-18 05:42:481063 scoped_refptr<PendingFrameCreate> create(it->second);
1064 frame->Bind(it->second->TakeFrameRequest(), it->second->TakeFrameHost());
1065 pending_frame_creates_.erase(it);
[email protected]c1f50aa2010-02-18 03:46:571066}
1067
avi1023d012015-12-25 02:39:141068void RenderThreadImpl::RemoveRoute(int32_t routing_id) {
jam8a021512a2015-02-03 18:16:081069 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id);
[email protected]c1f50aa2010-02-18 03:46:571070}
[email protected]0ec90d522014-03-12 16:28:191071
avi1023d012015-12-25 02:39:141072void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id,
[email protected]a620b132014-04-30 22:39:171073 IPC::Listener* listener) {
[email protected]48e52e42014-03-20 06:58:071074 AddRoute(routing_id, listener);
1075 if (devtools_agent_message_filter_.get()) {
[email protected]a620b132014-04-30 22:39:171076 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread(
[email protected]48e52e42014-03-20 06:58:071077 routing_id);
1078 }
1079}
1080
avi1023d012015-12-25 02:39:141081void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) {
[email protected]48e52e42014-03-20 06:58:071082 RemoveRoute(routing_id);
1083 if (devtools_agent_message_filter_.get()) {
[email protected]a620b132014-04-30 22:39:171084 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread(
[email protected]48e52e42014-03-20 06:58:071085 routing_id);
1086 }
1087}
1088
ben76f52b242016-06-18 05:42:481089void RenderThreadImpl::RegisterPendingFrameCreate(
rockotf8fdd9b2015-12-16 22:22:351090 int routing_id,
ben76f52b242016-06-18 05:42:481091 mojom::FrameRequest frame_request,
1092 mojom::FrameHostPtr frame_host) {
1093 std::pair<PendingFrameCreateMap::iterator, bool> result =
1094 pending_frame_creates_.insert(std::make_pair(
rockotf8fdd9b2015-12-16 22:22:351095 routing_id,
ben76f52b242016-06-18 05:42:481096 make_scoped_refptr(new PendingFrameCreate(
1097 routing_id, std::move(frame_request), std::move(frame_host)))));
rockotf8fdd9b2015-12-16 22:22:351098 CHECK(result.second) << "Inserting a duplicate item.";
1099}
1100
leon.han06e55662016-03-26 17:19:421101mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() {
jamc912ca32016-02-24 20:17:311102 return storage_partition_service_.get();
1103}
1104
[email protected]77fc9b92011-10-15 16:20:371105int RenderThreadImpl::GenerateRoutingID() {
1106 int routing_id = MSG_ROUTING_NONE;
1107 Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
1108 return routing_id;
1109}
1110
[email protected]74122042014-04-25 00:07:301111void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551112 channel()->AddFilter(filter);
1113}
1114
[email protected]74122042014-04-25 00:07:301115void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) {
[email protected]42f1d7822009-07-23 18:17:551116 channel()->RemoveFilter(filter);
1117}
1118
tyoshino832a58a2016-04-18 08:14:081119void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) {
[email protected]526476902011-10-06 20:34:061120 observers_.AddObserver(observer);
1121}
1122
tyoshino832a58a2016-04-18 08:14:081123void RenderThreadImpl::RemoveObserver(RenderThreadObserver* observer) {
[email protected]526476902011-10-06 20:34:061124 observers_.RemoveObserver(observer);
1125}
1126
[email protected]359dfa32011-10-12 01:10:151127void RenderThreadImpl::SetResourceDispatcherDelegate(
[email protected]e9ff79c2012-10-19 21:31:261128 ResourceDispatcherDelegate* delegate) {
[email protected]359dfa32011-10-12 01:10:151129 resource_dispatcher()->set_delegate(delegate);
1130}
1131
vollick1050cc62015-12-03 07:04:541132void RenderThreadImpl::InitializeCompositorThread() {
boliu66024c62016-04-20 04:00:411133 base::Thread::Options options;
vollick1050cc62015-12-03 07:04:541134#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:411135 options.priority = base::ThreadPriority::DISPLAY;
vollick1050cc62015-12-03 07:04:541136#endif
boliu66024c62016-04-20 04:00:411137 compositor_thread_.reset(new WebThreadForCompositor(options));
1138 blink_platform_impl_->SetCompositorThread(compositor_thread_.get());
1139 compositor_task_runner_ = compositor_thread_->GetTaskRunner();
1140 compositor_task_runner_->PostTask(
1141 FROM_HERE,
1142 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), false));
vollick1050cc62015-12-03 07:04:541143
boliude5b75b2016-03-11 07:02:141144 SynchronousInputHandlerProxyClient* synchronous_input_handler_proxy_client =
1145 nullptr;
vollick1050cc62015-12-03 07:04:541146#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:411147 if (GetContentClient()->UsingSynchronousCompositing()) {
vollick1050cc62015-12-03 07:04:541148 sync_compositor_message_filter_ =
1149 new SynchronousCompositorFilter(compositor_task_runner_);
1150 AddFilter(sync_compositor_message_filter_.get());
boliude5b75b2016-03-11 07:02:141151 synchronous_input_handler_proxy_client =
1152 sync_compositor_message_filter_.get();
vollick1050cc62015-12-03 07:04:541153 }
1154#endif
boliub2768db2016-06-03 23:35:161155 scoped_refptr<InputEventFilter> compositor_input_event_filter(
1156 new InputEventFilter(main_input_callback_.callback(),
1157 main_thread_compositor_task_runner_,
1158 compositor_task_runner_));
1159 InputHandlerManagerClient* input_handler_manager_client =
1160 compositor_input_event_filter.get();
1161 input_event_filter_ = compositor_input_event_filter;
vollick1050cc62015-12-03 07:04:541162 input_handler_manager_.reset(new InputHandlerManager(
1163 compositor_task_runner_, input_handler_manager_client,
boliude5b75b2016-03-11 07:02:141164 synchronous_input_handler_proxy_client, renderer_scheduler_.get()));
vollick1050cc62015-12-03 07:04:541165}
1166
jam75c44222016-03-23 05:34:241167void RenderThreadImpl::InitializeWebKit(
1168 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) {
1169 DCHECK(!blink_platform_impl_);
[email protected]d1b8fccc2011-08-03 01:20:131170
avi83883c82014-12-23 00:08:491171 const base::CommandLine& command_line =
1172 *base::CommandLine::ForCurrentProcess();
chunyang.daibe874c52014-11-14 06:45:051173
1174#ifdef ENABLE_VTUNE_JIT_INTERFACE
1175 if (command_line.HasSwitch(switches::kEnableVtune))
1176 gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler());
1177#endif
1178
rmcilroy4073ae12015-01-08 13:08:101179 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line);
1180
sammcbebeb602016-04-06 06:42:551181 blink_platform_impl_.reset(new RendererBlinkPlatformImpl(
1182 renderer_scheduler_.get(),
bend1dd50f52016-06-26 22:10:481183 GetRemoteInterfaces()->GetWeakPtr()));
tfarina556a7232014-10-05 01:02:091184 blink::initialize(blink_platform_impl_.get());
[email protected]d1b8fccc2011-08-03 01:20:131185
[email protected]4b5340282014-07-08 11:37:341186 v8::Isolate* isolate = blink::mainThreadIsolate();
[email protected]4b5340282014-07-08 11:37:341187 isolate->SetCreateHistogramFunction(CreateHistogram);
1188 isolate->SetAddHistogramSampleFunction(AddHistogramSample);
skyostila37c2a72016-06-29 17:30:071189 renderer_scheduler_->SetRAILModeObserver(this);
[email protected]4b5340282014-07-08 11:37:341190
rmcilroy321f924d2014-11-06 00:56:001191 main_thread_compositor_task_runner_ =
danakj6e3bf8012014-12-16 18:27:531192 renderer_scheduler_->CompositorTaskRunner();
skyostilc30aa402014-10-10 13:49:091193
jdduke691dd572014-12-02 20:47:521194 main_input_callback_.Reset(
1195 base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived),
1196 base::Unretained(this)));
1197
jam75c44222016-03-23 05:34:241198 scoped_refptr<base::SingleThreadTaskRunner> resource_task_queue2;
1199 if (resource_task_queue) {
1200 resource_task_queue2 = resource_task_queue;
1201 } else {
1202 resource_task_queue2 = renderer_scheduler_->LoadingTaskRunner();
1203 }
1204 // Add a filter that forces resource messages to be dispatched via a
1205 // particular task runner.
1206 scoped_refptr<ResourceSchedulingFilter> filter(
1207 new ResourceSchedulingFilter(
1208 resource_task_queue2, resource_dispatcher()));
1209 channel()->AddFilter(filter.get());
1210 resource_dispatcher()->SetResourceSchedulingFilter(filter);
1211
1212 // The ChildResourceMessageFilter and the ResourceDispatcher need to use the
1213 // same queue to ensure tasks are executed in the expected order.
1214 child_resource_message_filter()->SetMainThreadTaskRunner(
1215 resource_task_queue2);
1216 resource_dispatcher()->SetMainThreadTaskRunner(resource_task_queue2);
1217
hajimehoshi384b3b112016-06-01 06:21:521218 websocket_message_filter()->SetLoadingTaskRunner(
1219 renderer_scheduler_->LoadingTaskRunner());
1220
khushalsagara5b15d72016-01-07 06:15:401221 if (!command_line.HasSwitch(switches::kDisableThreadedCompositing) &&
1222 !command_line.HasSwitch(switches::kUseRemoteCompositing))
vollick1050cc62015-12-03 07:04:541223 InitializeCompositorThread();
[email protected]a9fb30aa2011-10-06 06:58:461224
jdduke691dd572014-12-02 20:47:521225 if (!input_event_filter_.get()) {
1226 // Always provide an input event filter implementation to ensure consistent
1227 // input event scheduling and prioritization.
1228 // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and
1229 // MainThreadInputEventFilter, crbug.com/436057.
1230 input_event_filter_ = new MainThreadInputEventFilter(
1231 main_input_callback_.callback(), main_thread_compositor_task_runner_);
1232 }
1233 AddFilter(input_event_filter_.get());
1234
skyostil2d3b5bd2015-05-27 15:40:591235 scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner;
vollick1050cc62015-12-03 07:04:541236 if (compositor_task_runner_)
skyostil2d3b5bd2015-05-27 15:40:591237 compositor_impl_side_task_runner = compositor_task_runner_;
[email protected]7f1f63f2013-03-07 06:07:291238 else
skyostil2d3b5bd2015-05-27 15:40:591239 compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get();
[email protected]1842fe22012-08-13 23:24:351240
simonhonga7e3ac42014-11-11 20:50:221241 compositor_message_filter_ = new CompositorForwardingMessageFilter(
skyostil2d3b5bd2015-05-27 15:40:591242 compositor_impl_side_task_runner.get());
simonhonga7e3ac42014-11-11 20:50:221243 AddFilter(compositor_message_filter_.get());
[email protected]1842fe22012-08-13 23:24:351244
[email protected]58436a12012-03-21 17:10:261245 RenderThreadImpl::RegisterSchemes();
1246
[email protected]8f13def2014-02-04 00:51:361247 EnableBlinkPlatformLogChannels(
1248 command_line.GetSwitchValueASCII(switches::kBlinkPlatformLogChannels));
[email protected]d1b8fccc2011-08-03 01:20:131249
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
alph666f80f2014-12-08 15:52:111255 v8_sampling_profiler_.reset(new V8SamplingProfiler());
1256
ulan4a385192015-11-11 10:59:181257 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
[email protected]1784b2f2011-11-24 10:53:481258 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
ulan4a385192015-11-11 10:59:181259 } else {
1260 // If we do not track widget visibility, then assume conservatively that
1261 // the isolate is in background. This reduces memory usage.
1262 isolate->IsolateInBackgroundNotification();
1263 }
[email protected]2541d1a2013-07-10 07:33:271264
jdduke73220f02015-09-04 17:03:511265 renderer_scheduler_->SetTimerQueueSuspensionWhenBackgroundedEnabled(
1266 GetContentClient()
1267 ->renderer()
1268 ->AllowTimerSuspensionWhenProcessBackgrounded());
1269
jbauman9015c8b2014-12-11 00:49:371270 cc_blink::SetSharedBitmapAllocationFunction(AllocateSharedBitmapFunction);
[email protected]d72493152014-01-08 17:37:451271
reedccf98c52014-10-03 16:40:381272 SkGraphics::SetResourceCacheSingleAllocationByteLimit(
[email protected]dd2c1022014-07-22 23:13:571273 kImageCacheSingleAllocationByteLimit);
1274
reed6e5a72222015-08-06 20:37:161275 // Hook up blink's codecs so skia can call them
1276 SkGraphics::SetImageGeneratorFromEncodedFactory(
1277 blink::WebImageGenerator::create);
1278
[email protected]fdeac262014-07-10 12:52:511279 if (command_line.HasSwitch(switches::kMemoryMetrics)) {
1280 memory_observer_.reset(new MemoryObserver());
1281 message_loop()->AddTaskObserver(memory_observer_.get());
1282 }
paritosh.in7e30c902015-04-15 17:04:071283
1284 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) {
1285 std::string allowed_ports =
1286 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts);
1287 net::SetExplicitlyAllowedPorts(allowed_ports);
1288 }
[email protected]d1b8fccc2011-08-03 01:20:131289}
1290
[email protected]58436a12012-03-21 17:10:261291void RenderThreadImpl::RegisterSchemes() {
mkwst8e94fb32015-05-20 05:05:141292 // chrome:
1293 WebString chrome_scheme(base::ASCIIToUTF16(kChromeUIScheme));
1294 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_scheme);
1295 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
1296 chrome_scheme);
1297 WebSecurityPolicy::registerURLSchemeAsSecure(chrome_scheme);
1298 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(chrome_scheme);
1299
1300 // chrome-devtools:
1301 WebString devtools_scheme(base::ASCIIToUTF16(kChromeDevToolsScheme));
1302 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(devtools_scheme);
meacerce6b66032016-06-02 20:56:051303
1304 // view-source:
1305 WebString view_source_scheme(base::ASCIIToUTF16(kViewSourceScheme));
1306 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(view_source_scheme);
[email protected]58436a12012-03-21 17:10:261307}
1308
[email protected]df9accd2014-03-13 18:18:301309void RenderThreadImpl::NotifyTimezoneChange() {
1310 NotifyTimezoneChangeOnThisThread();
1311 RenderThread::Get()->PostTaskToAllWebWorkers(
1312 base::Bind(&NotifyTimezoneChangeOnThisThread));
1313}
1314
[email protected]e6e30ac2014-01-13 21:24:391315void RenderThreadImpl::RecordAction(const base::UserMetricsAction& action) {
[email protected]97880c82013-12-04 07:09:211316 Send(new ViewHostMsg_UserMetricsRecordAction(action.str_));
1317}
1318
1319void RenderThreadImpl::RecordComputedAction(const std::string& action) {
[email protected]526476902011-10-06 20:34:061320 Send(new ViewHostMsg_UserMetricsRecordAction(action));
1321}
1322
dchengcedca5612016-04-09 01:40:151323std::unique_ptr<base::SharedMemory>
1324RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
erikchen4e01cbe2016-05-25 22:00:051325 return ChildThreadImpl::AllocateSharedMemory(size, thread_safe_sender(),
1326 nullptr);
[email protected]00614a82011-10-07 22:39:311327}
1328
jbauman2f5c1942014-12-06 03:28:241329cc::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() {
1330 return shared_bitmap_manager();
1331}
1332
[email protected]f1a29a02011-10-06 23:08:441333void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
[email protected]526476902011-10-06 20:34:061334 WebScriptController::registerExtension(extension);
[email protected]526476902011-10-06 20:34:061335}
1336
avi1023d012015-12-25 02:39:141337void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) {
[email protected]6593ae12011-11-14 12:09:441338 idle_notification_delay_in_ms_ = initial_delay_ms;
[email protected]526476902011-10-06 20:34:061339 idle_timer_.Stop();
1340 idle_timer_.Start(FROM_HERE,
[email protected]6593ae12011-11-14 12:09:441341 base::TimeDelta::FromMilliseconds(initial_delay_ms),
[email protected]f1a29a02011-10-06 23:08:441342 this, &RenderThreadImpl::IdleHandler);
[email protected]526476902011-10-06 20:34:061343}
1344
[email protected]f1a29a02011-10-06 23:08:441345void RenderThreadImpl::IdleHandler() {
[email protected]1784b2f2011-11-24 10:53:481346 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
[email protected]e9ff79c2012-10-19 21:31:261347 GetContentClient()->renderer()->
[email protected]1784b2f2011-11-24 10:53:481348 RunIdleHandlerWhenWidgetsHidden();
1349 if (run_in_foreground_tab) {
jochen5a32aaf2014-09-26 20:37:431350 if (idle_notifications_to_skip_ > 0) {
1351 --idle_notifications_to_skip_;
1352 } else {
ssid0603ca9f2015-06-09 16:48:081353 ReleaseFreeMemory();
jochen5a32aaf2014-09-26 20:37:431354 }
1355 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
[email protected]1784b2f2011-11-24 10:53:481356 return;
1357 }
[email protected]237a14852012-04-28 02:56:381358
ssid0603ca9f2015-06-09 16:48:081359 ReleaseFreeMemory();
[email protected]526476902011-10-06 20:34:061360
[email protected]26e82322014-01-20 14:18:221361 // Continue the idle timer if the webkit shared timer is not suspended or
1362 // something is left to do.
1363 bool continue_timer = !webkit_shared_timer_suspended_;
1364
sullivancd45a3e2014-09-19 14:39:181365 // Schedule next invocation. When the tab is originally hidden, an invocation
1366 // is scheduled for kInitialIdleHandlerDelayMs in
1367 // RenderThreadImpl::WidgetHidden in order to race to a minimal heap.
1368 // After that, idle calls can be much less frequent, so run at a maximum of
1369 // once every kLongIdleHandlerDelayMs.
[email protected]6593ae12011-11-14 12:09:441370 // Dampen the delay using the algorithm (if delay is in seconds):
[email protected]526476902011-10-06 20:34:061371 // delay = delay + 1 / (delay + 2)
1372 // Using floor(delay) has a dampening effect such as:
sullivancd45a3e2014-09-19 14:39:181373 // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ...
[email protected]6593ae12011-11-14 12:09:441374 // If the delay is in milliseconds, the above formula is equivalent to:
1375 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
1376 // which is equivalent to
1377 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
[email protected]26e82322014-01-20 14:18:221378 if (continue_timer) {
sullivancd45a3e2014-09-19 14:39:181379 ScheduleIdleHandler(
1380 std::max(kLongIdleHandlerDelayMs,
1381 idle_notification_delay_in_ms_ +
1382 1000000 / (idle_notification_delay_in_ms_ + 2000)));
[email protected]26e82322014-01-20 14:18:221383
1384 } else {
1385 idle_timer_.Stop();
1386 }
[email protected]526476902011-10-06 20:34:061387
tyoshino832a58a2016-04-18 08:14:081388 FOR_EACH_OBSERVER(RenderThreadObserver, observers_, IdleNotification());
[email protected]526476902011-10-06 20:34:061389}
1390
avi1023d012015-12-25 02:39:141391int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const {
[email protected]6593ae12011-11-14 12:09:441392 return idle_notification_delay_in_ms_;
[email protected]526476902011-10-06 20:34:061393}
1394
[email protected]6593ae12011-11-14 12:09:441395void RenderThreadImpl::SetIdleNotificationDelayInMs(
avi1023d012015-12-25 02:39:141396 int64_t idle_notification_delay_in_ms) {
[email protected]6593ae12011-11-14 12:09:441397 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
[email protected]4a7d6392011-09-19 20:55:081398}
1399
[email protected]a1a7ff32012-07-19 14:03:511400void RenderThreadImpl::UpdateHistograms(int sequence_number) {
1401 child_histogram_message_filter()->SendHistograms(sequence_number);
1402}
1403
[email protected]5b18406362013-06-18 18:46:431404int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) {
kinukoef647412015-12-23 06:10:431405 return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure);
[email protected]a9bd323d2013-06-17 20:27:561406}
1407
[email protected]b02f5902012-12-19 07:33:001408bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) {
1409 bool result = false;
1410 Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list));
1411 return result;
1412}
1413
[email protected]1784b2f2011-11-24 10:53:481414void RenderThreadImpl::PostponeIdleNotification() {
1415 idle_notifications_to_skip_ = 2;
1416}
1417
dcastagna7f45dada2015-10-19 20:17:351418media::GpuVideoAcceleratorFactories* RenderThreadImpl::GetGpuFactories() {
[email protected]3bb8bb32013-07-11 13:13:031419 DCHECK(IsMainThread());
1420
dcastagna09bd6b32016-02-01 21:54:281421 if (!gpu_factories_.empty()) {
1422 scoped_refptr<ContextProviderCommandBuffer> shared_context_provider =
1423 gpu_factories_.back()->ContextProviderMainThread();
1424 if (shared_context_provider) {
1425 cc::ContextProvider::ScopedContextLock lock(
1426 shared_context_provider.get());
1427 if (lock.ContextGL()->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
1428 return gpu_factories_.back();
1429 } else {
1430 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1431 GetMediaThreadTaskRunner();
1432 media_task_runner->PostTask(
1433 FROM_HERE,
1434 base::Bind(
1435 base::IgnoreResult(
1436 &RendererGpuVideoAcceleratorFactories::CheckContextLost),
1437 base::Unretained(gpu_factories_.back())));
1438 }
1439 }
1440 }
dcastagna7f45dada2015-10-19 20:17:351441
tobiasjsca238b3b2015-06-24 22:53:541442 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
1443
danakj0b4b94e32016-05-10 22:33:011444 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
1445 EstablishGpuChannelSync(CAUSE_FOR_GPU_LAUNCH_MEDIA_CONTEXT);
1446 if (!gpu_channel_host)
1447 return nullptr;
danakj0dd9e1e2016-05-11 22:15:091448 // This context is only used to create textures and mailbox them, so
1449 // use lower limits than the default.
1450 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
danakj9a04adc2016-05-16 22:45:071451 bool support_locking = true;
danakj0b4b94e32016-05-10 22:33:011452 scoped_refptr<ContextProviderCommandBuffer> media_context_provider =
danakj9a04adc2016-05-16 22:45:071453 CreateOffscreenContext(gpu_channel_host, limits, support_locking,
danakj0dd9e1e2016-05-11 22:15:091454 command_buffer_metrics::RENDER_WORKER_CONTEXT,
1455 gpu::GPU_STREAM_DEFAULT,
1456 gpu::GpuStreamPriority::NORMAL);
danakj0b4b94e32016-05-10 22:33:011457 if (!media_context_provider->BindToCurrentThread())
1458 return nullptr;
danakj0b4b94e32016-05-10 22:33:011459
acolwellb4034942014-08-28 15:42:431460 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
1461 GetMediaThreadTaskRunner();
danakj0b4b94e32016-05-10 22:33:011462 const bool enable_video_accelerator =
1463 !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode);
1464 const bool enable_gpu_memory_buffer_video_frames =
dcastagna43c3a86a2016-02-02 21:16:381465#if defined(OS_MACOSX) || defined(OS_LINUX)
dcastagnaa82ed96a2016-05-12 02:52:471466 !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) &&
1467 !cmd_line->HasSwitch(switches::kDisableGpuCompositing) &&
1468 !gpu_channel_host->gpu_info().software_rendering;
dcastagnab65e6072015-09-05 07:18:421469#else
danakj0b4b94e32016-05-10 22:33:011470 cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames);
dcastagnab65e6072015-09-05 07:18:421471#endif
danakj0b4b94e32016-05-10 22:33:011472 std::vector<unsigned> image_texture_targets;
1473 std::string video_frame_image_texture_target_string =
1474 cmd_line->GetSwitchValueASCII(switches::kVideoImageTextureTarget);
1475 StringToUintVector(video_frame_image_texture_target_string,
1476 &image_texture_targets);
dcastagna5077d6d2016-01-27 00:07:051477
danakj0b4b94e32016-05-10 22:33:011478 gpu_factories_.push_back(RendererGpuVideoAcceleratorFactories::Create(
1479 std::move(gpu_channel_host), base::ThreadTaskRunnerHandle::Get(),
1480 media_task_runner, std::move(media_context_provider),
1481 enable_gpu_memory_buffer_video_frames, image_texture_targets,
1482 enable_video_accelerator));
1483 return gpu_factories_.back();
[email protected]3bb8bb32013-07-11 13:13:031484}
1485
danakj615aac22016-04-29 21:28:161486scoped_refptr<ContextProviderCommandBuffer>
[email protected]f10dc472013-09-27 03:31:591487RenderThreadImpl::SharedMainThreadContextProvider() {
[email protected]e06e1122013-03-15 17:12:381488 DCHECK(IsMainThread());
danakje8ec797e2016-04-19 04:08:431489 if (shared_main_thread_contexts_ &&
1490 shared_main_thread_contexts_->ContextGL()->GetGraphicsResetStatusKHR() ==
1491 GL_NO_ERROR)
1492 return shared_main_thread_contexts_;
1493
1494 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(EstablishGpuChannelSync(
danakj3873e852016-05-05 00:46:071495 CAUSE_FOR_GPU_LAUNCH_RENDERER_SHARED_MAIN_THREAD_CONTEXT));
danakje8ec797e2016-04-19 04:08:431496 if (!gpu_channel_host) {
1497 shared_main_thread_contexts_ = nullptr;
1498 return nullptr;
[email protected]c29b7ff2013-03-06 03:51:041499 }
danakje8ec797e2016-04-19 04:08:431500
danakj9a04adc2016-05-16 22:45:071501 bool support_locking = false;
danakjc3983552016-05-03 00:04:351502 shared_main_thread_contexts_ = CreateOffscreenContext(
danakj9a04adc2016-05-16 22:45:071503 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking,
sunnypsd8ce1c22016-05-10 18:02:401504 command_buffer_metrics::RENDERER_MAINTHREAD_CONTEXT,
1505 gpu::GPU_STREAM_DEFAULT, gpu::GpuStreamPriority::NORMAL);
danakje8ec797e2016-04-19 04:08:431506 if (!shared_main_thread_contexts_->BindToCurrentThread())
1507 shared_main_thread_contexts_ = nullptr;
[email protected]f10dc472013-09-27 03:31:591508 return shared_main_thread_contexts_;
[email protected]c29b7ff2013-03-06 03:51:041509}
1510
siva.gunturi5d4feb052015-11-15 16:15:311511#if defined(OS_ANDROID)
boliuf8753bf62016-02-11 20:09:421512
siva.gunturi5d4feb052015-11-15 16:15:311513scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() {
1514 DCHECK(IsMainThread());
boliu30f1b262016-04-19 00:12:331515 if (!stream_texture_factory_.get() ||
1516 stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() !=
1517 GL_NO_ERROR) {
piman9fc22f32016-05-02 22:21:221518 scoped_refptr<ContextProviderCommandBuffer> shared_context_provider =
1519 SharedMainThreadContextProvider();
1520 if (!shared_context_provider) {
penghuange1d86512016-07-08 18:15:001521 stream_texture_factory_ = nullptr;
1522 return nullptr;
siva.gunturi5d4feb052015-11-15 16:15:311523 }
piman9fc22f32016-05-02 22:21:221524 DCHECK(shared_context_provider->GetCommandBufferProxy());
1525 DCHECK(shared_context_provider->GetCommandBufferProxy()->channel());
1526 stream_texture_factory_ =
1527 StreamTextureFactory::Create(std::move(shared_context_provider));
siva.gunturi5d4feb052015-11-15 16:15:311528 }
1529 return stream_texture_factory_;
1530}
boliuf8753bf62016-02-11 20:09:421531
1532bool RenderThreadImpl::EnableStreamTextureCopy() {
boliu30f1b262016-04-19 00:12:331533 return sync_compositor_message_filter_.get();
boliuf8753bf62016-02-11 20:09:421534}
1535
siva.gunturi5d4feb052015-11-15 16:15:311536#endif
1537
[email protected]e9ff79c2012-10-19 21:31:261538AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() {
[email protected]59383c782013-04-17 16:43:271539 if (!audio_renderer_mixer_manager_) {
olka7a4679392016-05-27 15:32:581540 audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create();
[email protected]3958e972012-07-17 00:25:411541 }
1542
1543 return audio_renderer_mixer_manager_.get();
1544}
1545
[email protected]73429ca2014-03-06 06:07:471546base::WaitableEvent* RenderThreadImpl::GetShutdownEvent() {
1547 return ChildProcess::current()->GetShutDownEvent();
1548}
1549
[email protected]4a7d6392011-09-19 20:55:081550#if defined(OS_WIN)
[email protected]feb32372012-11-21 01:14:561551void RenderThreadImpl::PreCacheFontCharacters(const LOGFONT& log_font,
[email protected]fcf75d42013-12-03 20:11:261552 const base::string16& str) {
avia7c3f51c2015-09-16 00:30:311553 Send(new RenderProcessHostMsg_PreCacheFontCharacters(log_font, str));
[email protected]feb32372012-11-21 01:14:561554}
1555
[email protected]4a7d6392011-09-19 20:55:081556#endif // OS_WIN
1557
danakj6e3bf8012014-12-16 18:27:531558bool RenderThreadImpl::IsGpuRasterizationForced() {
1559 return is_gpu_rasterization_forced_;
1560}
1561
1562bool RenderThreadImpl::IsGpuRasterizationEnabled() {
1563 return is_gpu_rasterization_enabled_;
1564}
1565
sunnypsd8ce1c22016-05-10 18:02:401566bool RenderThreadImpl::IsAsyncWorkerContextEnabled() {
1567 return is_async_worker_context_enabled_;
1568}
1569
senorblancob60ba952015-01-27 19:12:361570int RenderThreadImpl::GetGpuRasterizationMSAASampleCount() {
1571 return gpu_rasterization_msaa_sample_count_;
1572}
1573
danakj6e3bf8012014-12-16 18:27:531574bool RenderThreadImpl::IsLcdTextEnabled() {
1575 return is_lcd_text_enabled_;
1576}
1577
1578bool RenderThreadImpl::IsDistanceFieldTextEnabled() {
1579 return is_distance_field_text_enabled_;
1580}
1581
1582bool RenderThreadImpl::IsZeroCopyEnabled() {
1583 return is_zero_copy_enabled_;
1584}
1585
ericrk1d17f752015-10-20 03:03:071586bool RenderThreadImpl::IsPartialRasterEnabled() {
1587 return is_partial_raster_enabled_;
jbroman5f7f71932015-08-18 16:24:461588}
1589
ccameronc7fcd132015-11-03 20:14:311590bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() {
1591 return is_gpu_memory_buffer_compositor_resources_enabled_;
1592}
1593
ccamerona7644752014-12-30 01:16:311594bool RenderThreadImpl::IsElasticOverscrollEnabled() {
1595 return is_elastic_overscroll_enabled_;
1596}
1597
jie.a.chen0ffadce32015-08-07 12:59:231598std::vector<unsigned> RenderThreadImpl::GetImageTextureTargets() {
1599 return use_image_texture_targets_;
danakj6e3bf8012014-12-16 18:27:531600}
vmiura9084b342015-02-03 22:19:571601
danakj6e3bf8012014-12-16 18:27:531602scoped_refptr<base::SingleThreadTaskRunner>
1603RenderThreadImpl::GetCompositorMainThreadTaskRunner() {
1604 return main_thread_compositor_task_runner_;
1605}
1606
1607scoped_refptr<base::SingleThreadTaskRunner>
1608RenderThreadImpl::GetCompositorImplThreadTaskRunner() {
skyostil2d3b5bd2015-05-27 15:40:591609 return compositor_task_runner_;
danakj6e3bf8012014-12-16 18:27:531610}
1611
1612gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() {
1613 return gpu_memory_buffer_manager();
1614}
1615
jochen83c639f02015-04-22 17:07:371616scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() {
danakj6e3bf8012014-12-16 18:27:531617 return renderer_scheduler_.get();
1618}
1619
dchengcedca5612016-04-09 01:40:151620std::unique_ptr<cc::BeginFrameSource>
danakj6e3bf8012014-12-16 18:27:531621RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) {
dchengcedca5612016-04-09 01:40:151622 return base::WrapUnique(new CompositorExternalBeginFrameSource(
danakj6e3bf8012014-12-16 18:27:531623 compositor_message_filter_.get(), sync_message_filter(), routing_id));
1624}
1625
nyquist16febb42016-02-12 00:15:041626cc::ImageSerializationProcessor*
1627RenderThreadImpl::GetImageSerializationProcessor() {
1628 return GetContentClient()->renderer()->GetImageSerializationProcessor();
1629}
1630
reveman34b7a1522015-03-23 20:27:471631cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() {
prashant.nfad657e2016-06-01 07:52:171632 return categorized_worker_pool_->GetTaskGraphRunner();
reveman34b7a1522015-03-23 20:27:471633}
1634
vmpstrdfd22862015-09-25 17:42:411635bool RenderThreadImpl::AreImageDecodeTasksEnabled() {
1636 return are_image_decode_tasks_enabled_;
reveman34b7a1522015-03-23 20:27:471637}
1638
loyso65c93c602015-08-11 05:15:571639bool RenderThreadImpl::IsThreadedAnimationEnabled() {
1640 return is_threaded_animation_enabled_;
1641}
1642
skyostila37c2a72016-06-29 17:30:071643void RenderThreadImpl::OnRAILModeChanged(v8::RAILMode rail_mode) {
1644 blink::mainThreadIsolate()->SetRAILMode(rail_mode);
1645 blink::setRAILModeOnWorkerThreadIsolates(rail_mode);
1646}
1647
[email protected]b3e83de2012-02-07 03:33:281648bool RenderThreadImpl::IsMainThread() {
1649 return !!current();
1650}
1651
skyostild4452912015-05-14 14:41:531652scoped_refptr<base::SingleThreadTaskRunner>
1653RenderThreadImpl::GetIOThreadTaskRunner() {
1654 return io_thread_task_runner_;
[email protected]b3e83de2012-02-07 03:33:281655}
1656
dchengcedca5612016-04-09 01:40:151657std::unique_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory(
[email protected]3f892832013-01-11 03:23:591658 size_t size) {
piman08f75532015-10-05 18:58:011659 return HostAllocateSharedMemoryBuffer(size);
[email protected]b3e83de2012-02-07 03:33:281660}
1661
torne88b66452016-05-03 13:22:141662void RenderThreadImpl::OnChannelError() {
1663 // In single-process mode, the renderer can't be restarted after shutdown.
1664 // So, if we get a channel error, crash the whole process right now to get a
1665 // more informative stack, since we will otherwise just crash later when we
1666 // try to restart it.
1667 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
1668 switches::kSingleProcess));
1669 ChildThreadImpl::OnChannelError();
1670}
1671
[email protected]f1a29a02011-10-06 23:08:441672bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
tyoshino832a58a2016-04-18 08:14:081673 base::ObserverListBase<RenderThreadObserver>::Iterator it(&observers_);
1674 RenderThreadObserver* observer;
penghuange1d86512016-07-08 18:15:001675 while ((observer = it.GetNext()) != nullptr) {
[email protected]1223d6ef2011-03-28 16:47:501676 if (observer->OnControlMessageReceived(msg))
1677 return true;
1678 }
1679
[email protected]70c19a932010-05-14 12:59:111680 // Some messages are handled by delegates.
[email protected]1910fe82012-05-10 00:04:101681 if (appcache_dispatcher_->OnMessageReceived(msg) ||
[email protected]7670d4332013-11-29 04:35:001682 dom_storage_dispatcher_->OnMessageReceived(msg) ||
1683 embedded_worker_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]82307f6b2014-08-07 03:30:121689 IPC_MESSAGE_HANDLER(FrameMsg_NewFrame, OnCreateNewFrame)
1690 IPC_MESSAGE_HANDLER(FrameMsg_NewFrameProxy, OnCreateNewFrameProxy)
[email protected]8930d472009-02-21 08:05:281691 // TODO(port): removed from render_messages_internal.h;
1692 // is there a new non-windows message I should add here?
1693 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
jkarlin300a1d22015-09-18 19:32:521694 IPC_MESSAGE_HANDLER(ViewMsg_NetworkConnectionChanged,
1695 OnNetworkConnectionChanged)
[email protected]0ec90d522014-03-12 16:28:191696 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateNewSharedWorker)
[email protected]df9accd2014-03-13 18:18:301697 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
[email protected]b0988b22013-11-08 08:25:581698#if defined(OS_ANDROID)
[email protected]44363382013-03-12 07:22:471699 IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended,
1700 OnSetWebKitSharedTimersSuspended)
[email protected]b0988b22013-11-08 08:25:581701#endif
1702#if defined(OS_MACOSX)
1703 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScrollbarTheme, OnUpdateScrollbarTheme)
rsesek1efb3c32015-09-29 15:39:501704 IPC_MESSAGE_HANDLER(ViewMsg_SystemColorsChanged, OnSystemColorsChanged)
[email protected]b0988b22013-11-08 08:25:581705#endif
thestigc4cac8f2014-09-04 21:17:501706#if defined(ENABLE_PLUGINS)
1707 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
1708#endif
[email protected]a95986a82010-12-24 06:19:281709 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:281710 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281711 return handled;
initial.commit09911bf2008-07-26 23:55:291712}
1713
jdduke73220f02015-09-04 17:03:511714void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) {
1715 ChildThreadImpl::OnProcessBackgrounded(backgrounded);
1716
hajimehoshi69093272016-05-13 08:30:581717 if (backgrounded) {
jdduke73220f02015-09-04 17:03:511718 renderer_scheduler_->OnRendererBackgrounded();
hajimehoshi69093272016-05-13 08:30:581719 } else {
jdduke73220f02015-09-04 17:03:511720 renderer_scheduler_->OnRendererForegrounded();
hajimehoshi69093272016-05-13 08:30:581721 is_renderer_suspended_ = false;
1722 }
1723}
1724
1725void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1726 ChildThreadImpl::OnProcessPurgeAndSuspend();
1727 if (is_renderer_suspended_)
1728 return;
1729 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077)
1730 is_renderer_suspended_ = true;
1731 renderer_scheduler_->SuspendRenderer();
jdduke73220f02015-09-04 17:03:511732}
1733
alexmos9f8705a2015-05-06 19:58:591734void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) {
kenrba7199832015-01-22 23:44:591735 CompositorDependencies* compositor_deps = this;
alexmos9f8705a2015-05-06 19:58:591736 RenderFrameImpl::CreateFrame(
alexmosa181efc2015-09-03 00:39:041737 params.routing_id, params.proxy_routing_id, params.opener_routing_id,
1738 params.parent_routing_id, params.previous_sibling_routing_id,
lazyboy70605c32015-11-03 01:27:311739 params.replication_state, compositor_deps, params.widget_params,
1740 params.frame_owner_properties);
[email protected]82307f6b2014-08-07 03:30:121741}
1742
alexmosbc7eafa2014-12-06 01:38:091743void RenderThreadImpl::OnCreateNewFrameProxy(
1744 int routing_id,
alexmosbc7eafa2014-12-06 01:38:091745 int render_view_routing_id,
alexmosa181efc2015-09-03 00:39:041746 int opener_routing_id,
1747 int parent_routing_id,
alexmosbc7eafa2014-12-06 01:38:091748 const FrameReplicationState& replicated_state) {
creis9f7248b2016-01-27 20:27:391749 // Debug cases of https://crbug.com/575245.
1750 base::debug::SetCrashKeyValue("newproxy_proxy_id",
1751 base::IntToString(routing_id));
1752 base::debug::SetCrashKeyValue("newproxy_view_id",
1753 base::IntToString(render_view_routing_id));
1754 base::debug::SetCrashKeyValue("newproxy_opener_id",
1755 base::IntToString(opener_routing_id));
1756 base::debug::SetCrashKeyValue("newproxy_parent_id",
1757 base::IntToString(parent_routing_id));
alexmosa181efc2015-09-03 00:39:041758 RenderFrameProxy::CreateFrameProxy(routing_id, render_view_routing_id,
1759 opener_routing_id, parent_routing_id,
1760 replicated_state);
[email protected]82307f6b2014-08-07 03:30:121761}
1762
[email protected]f1a29a02011-10-06 23:08:441763void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
danakj6e3bf8012014-12-16 18:27:531764 CompositorDependencies* compositor_deps = this;
[email protected]be645db2009-02-06 20:36:331765 // When bringing in render_view, also bring in webkit's glue and jsbindings.
dcheng35d31c112015-07-22 00:17:361766 RenderViewImpl::Create(compositor_deps, params, false);
[email protected]7f874dec2009-02-06 01:48:271767}
[email protected]4274e582009-01-27 22:09:561768
piman9fc22f32016-05-02 22:21:221769scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:261770 CauseForGpuLaunch cause_for_gpu_launch) {
[email protected]d13f35d2012-05-18 02:28:151771 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1772
piman9fc22f32016-05-02 22:21:221773 if (gpu_channel_) {
[email protected]1082b1d2010-03-30 00:31:221774 // Do nothing if we already have a GPU channel or are already
1775 // establishing one.
[email protected]7951bfe2013-06-13 01:43:341776 if (!gpu_channel_->IsLost())
piman9fc22f32016-05-02 22:21:221777 return gpu_channel_;
[email protected]6217d392010-03-25 22:08:351778
1779 // Recreate the channel if it has been lost.
piman765e5282015-05-08 03:43:011780 gpu_channel_->DestroyChannel();
penghuange1d86512016-07-08 18:15:001781 gpu_channel_ = nullptr;
[email protected]6217d392010-03-25 22:08:351782 }
1783
penghuange1d86512016-07-08 18:15:001784 if (!IsRunningInMash()) {
1785 int client_id = 0;
1786 IPC::ChannelHandle channel_handle;
1787 gpu::GPUInfo gpu_info;
1788 // Ask the browser for the channel name.
1789 if (!Send(new ChildProcessHostMsg_EstablishGpuChannel(
1790 cause_for_gpu_launch, &client_id, &channel_handle, &gpu_info)) ||
[email protected]8bc550e2012-02-07 11:05:561791#if defined(OS_POSIX)
penghuange1d86512016-07-08 18:15:001792 channel_handle.socket.fd == -1 ||
[email protected]8bc550e2012-02-07 11:05:561793#endif
penghuange1d86512016-07-08 18:15:001794 channel_handle.name.empty()) {
1795 // Otherwise cancel the connection.
1796 return nullptr;
1797 }
1798 GetContentClient()->SetGpuInfo(gpu_info);
1799
1800 // Cache some variables that are needed on the compositor thread for our
1801 // implementation of GpuChannelHostFactory.
1802 io_thread_task_runner_ = ChildProcess::current()->io_task_runner();
1803
1804 gpu_channel_ =
1805 gpu::GpuChannelHost::Create(this, client_id, gpu_info, channel_handle,
1806 ChildProcess::current()->GetShutDownEvent(),
1807 gpu_memory_buffer_manager());
1808 } else {
1809#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA)
1810 gpu_channel_ = ui::GpuService::GetInstance()->EstablishGpuChannelSync();
1811#else
1812 NOTREACHED();
1813#endif
[email protected]b42a9f62011-06-08 20:36:041814 }
piman9fc22f32016-05-02 22:21:221815 return gpu_channel_;
[email protected]3bf4d532010-03-27 00:23:341816}
1817
danakj83066a32016-06-21 02:34:491818std::unique_ptr<cc::OutputSurface>
1819RenderThreadImpl::CreateCompositorOutputSurface(
1820 bool use_software,
1821 int routing_id,
1822 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue,
1823 const GURL& url) {
1824 const base::CommandLine& command_line =
1825 *base::CommandLine::ForCurrentProcess();
1826 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1827 use_software = true;
1828
penghuang83ec46d2016-06-28 22:49:331829#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA)
rockotcef38272016-07-15 22:47:471830 if (GetMojoShellConnection() && !use_software &&
danakj83066a32016-06-21 02:34:491831 command_line.HasSwitch(switches::kUseMusInRenderer)) {
1832 RenderWidgetMusConnection* connection =
1833 RenderWidgetMusConnection::GetOrCreate(routing_id);
1834 return connection->CreateOutputSurface();
1835 }
1836#endif
1837
1838 uint32_t output_surface_id = g_next_output_surface_id++;
1839
1840 if (command_line.HasSwitch(switches::kEnableVulkan)) {
1841 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider =
1842 cc::VulkanInProcessContextProvider::Create();
1843 if (vulkan_context_provider) {
1844 DCHECK(!layout_test_mode());
1845 return base::WrapUnique(new CompositorOutputSurface(
danakja40dd4482016-06-28 01:14:101846 routing_id, output_surface_id, std::move(vulkan_context_provider),
1847 std::move(frame_swap_message_queue)));
danakj83066a32016-06-21 02:34:491848 }
1849 }
1850
1851 // Create a gpu process channel and verify we want to use GPU compositing
1852 // before creating any context providers.
1853 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
1854 if (!use_software) {
1855 gpu_channel_host = EstablishGpuChannelSync(
1856 CAUSE_FOR_GPU_LAUNCH_RENDERER_VERIFY_GPU_COMPOSITING);
1857 if (!gpu_channel_host) {
1858 // Cause the compositor to wait and try again.
1859 return nullptr;
1860 }
1861 // We may get a valid channel, but with a software renderer. In that case,
1862 // disable GPU compositing.
1863 if (gpu_channel_host->gpu_info().software_rendering)
1864 use_software = true;
1865 }
1866
1867 if (use_software) {
1868 DCHECK(!layout_test_mode());
danakja40dd4482016-06-28 01:14:101869 return base::WrapUnique(new CompositorOutputSurface(
1870 routing_id, output_surface_id, nullptr, nullptr,
1871 std::move(frame_swap_message_queue)));
danakj83066a32016-06-21 02:34:491872 }
1873
1874 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider =
1875 SharedCompositorWorkerContextProvider();
1876 if (!worker_context_provider) {
1877 // Cause the compositor to wait and try again.
1878 return nullptr;
1879 }
1880
1881 // The renderer compositor context doesn't do a lot of stuff, so we don't
1882 // expect it to need a lot of space for commands or transfer. Raster and
1883 // uploads happen on the worker context instead.
1884 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
1885
1886 // This is for an offscreen context for the compositor. So the default
1887 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
1888 gpu::gles2::ContextCreationAttribHelper attributes;
1889 attributes.alpha_size = -1;
1890 attributes.depth_size = 0;
1891 attributes.stencil_size = 0;
1892 attributes.samples = 0;
1893 attributes.sample_buffers = 0;
1894 attributes.bind_generates_resource = false;
1895 attributes.lose_context_when_out_of_memory = true;
1896
1897 constexpr bool automatic_flushes = false;
1898 constexpr bool support_locking = false;
1899
1900 // The compositor context shares resources with the worker context unless
1901 // the worker is async.
1902 ContextProviderCommandBuffer* share_context = worker_context_provider.get();
1903 if (IsAsyncWorkerContextEnabled())
1904 share_context = nullptr;
1905
1906 scoped_refptr<ContextProviderCommandBuffer> context_provider(
1907 new ContextProviderCommandBuffer(
danakja40dd4482016-06-28 01:14:101908 gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
danakj83066a32016-06-21 02:34:491909 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, url,
pimand488e8b42016-06-30 19:06:591910 automatic_flushes, support_locking, limits, attributes, share_context,
danakj83066a32016-06-21 02:34:491911 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT));
1912
danakj83066a32016-06-21 02:34:491913 if (layout_test_deps_) {
1914 return layout_test_deps_->CreateOutputSurface(
danakja40dd4482016-06-28 01:14:101915 std::move(gpu_channel_host), std::move(context_provider),
1916 std::move(worker_context_provider), this);
danakj83066a32016-06-21 02:34:491917 }
1918
1919#if defined(OS_ANDROID)
1920 if (sync_compositor_message_filter_) {
1921 return base::WrapUnique(new SynchronousCompositorOutputSurface(
danakja40dd4482016-06-28 01:14:101922 std::move(context_provider), std::move(worker_context_provider),
1923 routing_id, output_surface_id, sync_compositor_message_filter_.get(),
1924 std::move(frame_swap_message_queue)));
danakj83066a32016-06-21 02:34:491925 }
1926#endif
1927
1928 return base::WrapUnique(new CompositorOutputSurface(
1929 routing_id, output_surface_id, std::move(context_provider),
danakja40dd4482016-06-28 01:14:101930 std::move(worker_context_provider), std::move(frame_swap_message_queue)));
danakj83066a32016-06-21 02:34:491931}
1932
[email protected]180ef242013-11-07 06:50:461933blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1934 blink::WebMediaStreamCenterClient* client) {
[email protected]d8cd8372012-03-09 10:49:511935#if defined(ENABLE_WEBRTC)
[email protected]68e5fee2013-02-18 10:04:221936 if (!media_stream_center_) {
1937 media_stream_center_ = GetContentClient()->renderer()
1938 ->OverrideCreateWebMediaStreamCenter(client);
1939 if (!media_stream_center_) {
dchengcedca5612016-04-09 01:40:151940 std::unique_ptr<MediaStreamCenter> media_stream_center(
[email protected]0107d8a2014-05-16 10:20:341941 new MediaStreamCenter(client, GetPeerConnectionDependencyFactory()));
[email protected]c1298742013-07-17 04:06:321942 media_stream_center_ = media_stream_center.release();
[email protected]68e5fee2013-02-18 10:04:221943 }
1944 }
[email protected]d8cd8372012-03-09 10:49:511945#endif
1946 return media_stream_center_;
1947}
1948
[email protected]22fe91d2014-08-12 17:07:121949#if defined(ENABLE_WEBRTC)
[email protected]0107d8a2014-05-16 10:20:341950PeerConnectionDependencyFactory*
1951RenderThreadImpl::GetPeerConnectionDependencyFactory() {
[email protected]83e0a482014-05-22 18:07:181952 return peer_connection_factory_.get();
[email protected]6ee10bd2012-09-13 09:01:531953}
[email protected]22fe91d2014-08-12 17:07:121954#endif
[email protected]6ee10bd2012-09-13 09:01:531955
penghuang346a46f92016-03-31 21:37:521956gpu::GpuChannelHost* RenderThreadImpl::GetGpuChannel() {
piman9fc22f32016-05-02 22:21:221957 if (!gpu_channel_)
danakj3873e852016-05-05 00:46:071958 return nullptr;
[email protected]7951bfe2013-06-13 01:43:341959 if (gpu_channel_->IsLost())
danakj3873e852016-05-05 00:46:071960 return nullptr;
[email protected]6217d392010-03-25 22:08:351961 return gpu_channel_.get();
1962}
1963
thestigc4cac8f2014-09-04 21:17:501964#if defined(ENABLE_PLUGINS)
[email protected]f1a29a02011-10-06 23:08:441965void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) {
[email protected]b547fd42009-04-23 23:16:271966 // The call below will cause a GetPlugins call with refresh=true, but at this
1967 // point we already know that the browser has refreshed its list, so disable
1968 // refresh temporarily to prevent each renderer process causing the list to be
1969 // regenerated.
tfarina556a7232014-10-05 01:02:091970 blink_platform_impl_->set_plugin_refresh_allowed(false);
[email protected]180ef242013-11-07 06:50:461971 blink::resetPluginCache(reload_pages);
tfarina556a7232014-10-05 01:02:091972 blink_platform_impl_->set_plugin_refresh_allowed(true);
[email protected]3b48dbc2012-01-06 16:34:171973
tyoshino832a58a2016-04-18 08:14:081974 FOR_EACH_OBSERVER(RenderThreadObserver, observers_, PluginListChanged());
[email protected]b547fd42009-04-23 23:16:271975}
thestigc4cac8f2014-09-04 21:17:501976#endif
[email protected]85c55dc2009-11-06 03:05:461977
jkarlin300a1d22015-09-18 19:32:521978void RenderThreadImpl::OnNetworkConnectionChanged(
1979 net::NetworkChangeNotifier::ConnectionType type,
1980 double max_bandwidth_mbps) {
[email protected]8c2a34b2014-06-10 16:27:271981 bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE;
[email protected]6eac57a2011-07-12 21:15:091982 WebNetworkStateNotifier::setOnLine(online);
[email protected]d7ff5fb2014-05-29 19:50:251983 FOR_EACH_OBSERVER(
tyoshino832a58a2016-04-18 08:14:081984 RenderThreadObserver, observers_, NetworkStateChanged(online));
jkarlin300a1d22015-09-18 19:32:521985 WebNetworkStateNotifier::setWebConnection(
1986 NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps);
[email protected]6eac57a2011-07-12 21:15:091987}
1988
jshin0a9aa632015-04-29 18:35:291989void RenderThreadImpl::OnUpdateTimezone(const std::string& zone_id) {
jochen22b6f9a2014-11-26 11:30:561990 if (!blink_platform_impl_)
1991 return;
jshin0a9aa632015-04-29 18:35:291992 if (!zone_id.empty()) {
1993 icu::TimeZone *new_zone = icu::TimeZone::createTimeZone(
1994 icu::UnicodeString::fromUTF8(zone_id));
1995 icu::TimeZone::adoptDefault(new_zone);
1996 VLOG(1) << "ICU default timezone is set to " << zone_id;
1997 }
[email protected]df9accd2014-03-13 18:18:301998 NotifyTimezoneChange();
1999}
2000
[email protected]b0988b22013-11-08 08:25:582001#if defined(OS_ANDROID)
[email protected]44363382013-03-12 07:22:472002void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) {
jdduked73ae5412015-05-11 20:07:162003 if (suspend) {
jdduked73ae5412015-05-11 20:07:162004 renderer_scheduler_->SuspendTimerQueue();
2005 } else {
jdduked73ae5412015-05-11 20:07:162006 renderer_scheduler_->ResumeTimerQueue();
[email protected]3b96b7b52014-01-13 18:36:072007 }
jdduked73ae5412015-05-11 20:07:162008 webkit_shared_timer_suspended_ = suspend;
[email protected]44363382013-03-12 07:22:472009}
[email protected]b0988b22013-11-08 08:25:582010#endif
2011
2012#if defined(OS_MACOSX)
[email protected]291857a2014-01-23 17:49:112013void RenderThreadImpl::OnUpdateScrollbarTheme(
kerrnelc39eeb72015-06-25 21:11:482014 const ViewMsg_UpdateScrollbarTheme_Params& params) {
[email protected]33b02992014-03-01 01:06:292015 static_cast<WebScrollbarBehaviorImpl*>(
tfarina556a7232014-10-05 01:02:092016 blink_platform_impl_->scrollbarBehavior())
kerrnelc39eeb72015-06-25 21:11:482017 ->set_jump_on_track_click(params.jump_on_track_click);
2018
kerrnela84d95e2015-07-31 17:34:212019 blink::WebScrollbarTheme::updateScrollbarsWithNSDefaults(
kerrnelc39eeb72015-06-25 21:11:482020 params.initial_button_delay, params.autoscroll_button_delay,
kerrnela84d95e2015-07-31 17:34:212021 params.preferred_scroller_style, params.redraw,
bokanb9c004262016-02-17 23:22:102022 params.button_placement);
[email protected]b0988b22013-11-08 08:25:582023}
rsesek1efb3c32015-09-29 15:39:502024
2025void RenderThreadImpl::OnSystemColorsChanged(
2026 int aqua_color_variant,
2027 const std::string& highlight_text_color,
2028 const std::string& highlight_color) {
2029 SystemColorsDidChange(aqua_color_variant, highlight_text_color,
2030 highlight_color);
2031}
[email protected]b0988b22013-11-08 08:25:582032#endif
[email protected]44363382013-03-12 07:22:472033
[email protected]0ec90d522014-03-12 16:28:192034void RenderThreadImpl::OnCreateNewSharedWorker(
2035 const WorkerProcessMsg_CreateWorker_Params& params) {
2036 // EmbeddedSharedWorkerStub will self-destruct.
mkwstcfa98932016-03-09 13:06:192037 new EmbeddedSharedWorkerStub(
2038 params.url, params.name, params.content_security_policy,
2039 params.security_policy_type, params.creation_address_space,
2040 params.pause_on_start, params.route_id);
[email protected]0ec90d522014-03-12 16:28:192041}
2042
[email protected]5071cb22013-07-10 02:19:062043void RenderThreadImpl::OnMemoryPressure(
2044 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
hong.zhengb28b5332016-05-11 02:33:392045 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
ssiddda2ba022015-06-18 21:12:392046 ReleaseFreeMemory();
[email protected]5071cb22013-07-10 02:19:062047
rmcilroyab967c972015-02-17 23:15:002048 // Do not call into blink if it is not initialized.
rmcilroy7fbb3bd52015-02-17 19:02:142049 if (blink_platform_impl_) {
bashi5e843ac2016-06-17 07:44:352050 blink::WebMemoryCoordinator::onMemoryPressure(
bashic577bfc2016-01-08 03:42:352051 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
rmcilroyab967c972015-02-17 23:15:002052
rmcilroyab967c972015-02-17 23:15:002053 if (memory_pressure_level ==
2054 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
rmcilroyab967c972015-02-17 23:15:002055 // Purge Skia font cache, by setting it to 0 and then again to the
2056 // previous limit.
2057 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2058 SkGraphics::SetFontCacheLimit(font_cache_limit);
2059 }
rmcilroy7fbb3bd52015-02-17 19:02:142060 }
[email protected]5071cb22013-07-10 02:19:062061}
2062
skyostil2d3b5bd2015-05-27 15:40:592063scoped_refptr<base::SingleThreadTaskRunner>
thestig529ad8a2016-07-08 20:30:122064RenderThreadImpl::GetFileThreadTaskRunner() {
fdoraye94d8642016-07-07 19:19:012065 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
[email protected]59383c782013-04-17 16:43:272066 if (!file_thread_) {
[email protected]c6a7b862010-08-20 22:19:382067 file_thread_.reset(new base::Thread("Renderer::FILE"));
2068 file_thread_->Start();
2069 }
skyostil2d3b5bd2015-05-27 15:40:592070 return file_thread_->task_runner();
[email protected]c6a7b862010-08-20 22:19:382071}
[email protected]e9ff79c2012-10-19 21:31:262072
acolwellb4034942014-08-28 15:42:432073scoped_refptr<base::SingleThreadTaskRunner>
2074RenderThreadImpl::GetMediaThreadTaskRunner() {
fdoraye94d8642016-07-07 19:19:012075 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
[email protected]c1330c82013-06-06 02:23:252076 if (!media_thread_) {
2077 media_thread_.reset(new base::Thread("Media"));
2078 media_thread_->Start();
[email protected]6ca6a082013-09-22 20:10:052079
2080#if defined(OS_ANDROID)
2081 renderer_demuxer_ = new RendererDemuxerAndroid();
2082 AddFilter(renderer_demuxer_.get());
2083#endif
[email protected]c1330c82013-06-06 02:23:252084 }
skyostil2d3b5bd2015-05-27 15:40:592085 return media_thread_->task_runner();
[email protected]c1330c82013-06-06 02:23:252086}
2087
dcastagna4517a182015-08-05 19:51:032088base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() {
prashant.nfad657e2016-06-01 07:52:172089 return categorized_worker_pool_.get();
dcastagnab880e8f2015-06-30 20:16:062090}
2091
revemand180dfc32015-09-24 00:19:432092scoped_refptr<ContextProviderCommandBuffer>
danakj0b4b94e32016-05-10 22:33:012093RenderThreadImpl::SharedCompositorWorkerContextProvider() {
revemand180dfc32015-09-24 00:19:432094 DCHECK(IsMainThread());
2095 // Try to reuse existing shared worker context provider.
revemand180dfc32015-09-24 00:19:432096 if (shared_worker_context_provider_) {
2097 // Note: If context is lost, delete reference after releasing the lock.
boliu11afa7e2016-04-18 18:04:142098 cc::ContextProvider::ScopedContextLock lock(
2099 shared_worker_context_provider_.get());
revemand180dfc32015-09-24 00:19:432100 if (shared_worker_context_provider_->ContextGL()
danakje8ec797e2016-04-19 04:08:432101 ->GetGraphicsResetStatusKHR() == GL_NO_ERROR)
2102 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432103 }
danakje8ec797e2016-04-19 04:08:432104
2105 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(EstablishGpuChannelSync(
danakj3873e852016-05-05 00:46:072106 CAUSE_FOR_GPU_LAUNCH_SHARED_WORKER_THREAD_CONTEXT));
danakje8ec797e2016-04-19 04:08:432107 if (!gpu_channel_host) {
2108 shared_worker_context_provider_ = nullptr;
2109 return shared_worker_context_provider_;
revemand180dfc32015-09-24 00:19:432110 }
danakje8ec797e2016-04-19 04:08:432111
sunnypsd8ce1c22016-05-10 18:02:402112 int32_t stream_id = gpu::GPU_STREAM_DEFAULT;
2113 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL;
2114 if (is_async_worker_context_enabled_) {
2115 stream_id = gpu_channel_host->GenerateStreamID();
2116 stream_priority = gpu::GpuStreamPriority::LOW;
2117 }
2118
danakj9a04adc2016-05-16 22:45:072119 bool support_locking = true;
danakj0dd9e1e2016-05-11 22:15:092120 shared_worker_context_provider_ = CreateOffscreenContext(
danakj9a04adc2016-05-16 22:45:072121 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking,
danakj0dd9e1e2016-05-11 22:15:092122 command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id,
2123 stream_priority);
danakje8ec797e2016-04-19 04:08:432124 if (!shared_worker_context_provider_->BindToCurrentThread())
2125 shared_worker_context_provider_ = nullptr;
revemand180dfc32015-09-24 00:19:432126 return shared_worker_context_provider_;
2127}
2128
[email protected]180ef242013-11-07 06:50:462129void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) {
tfarina556a7232014-10-05 01:02:092130 blink_platform_impl_->sampleGamepads(*data);
[email protected]0ff736562014-05-09 09:09:472131}
2132
rmcilroyaa296052015-04-14 15:35:272133bool RenderThreadImpl::RendererIsHidden() const {
2134 return widget_count_ > 0 && hidden_widget_count_ == widget_count_;
2135}
2136
[email protected]b2db9272014-01-10 17:42:002137void RenderThreadImpl::WidgetCreated() {
rmcilroyaa296052015-04-14 15:35:272138 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002139 widget_count_++;
rmcilroyaa296052015-04-14 15:35:272140 if (renderer_was_hidden)
2141 OnRendererVisible();
[email protected]b2db9272014-01-10 17:42:002142}
2143
2144void RenderThreadImpl::WidgetDestroyed() {
rmcilroyaa296052015-04-14 15:35:272145 // TODO(rmcilroy): Remove the restriction that destroyed widgets must be
2146 // unhidden before WidgetDestroyed is called.
2147 DCHECK_GT(widget_count_, 0);
2148 DCHECK_GT(widget_count_, hidden_widget_count_);
[email protected]b2db9272014-01-10 17:42:002149 widget_count_--;
rmcilroyaa296052015-04-14 15:35:272150 if (RendererIsHidden())
2151 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002152}
2153
2154void RenderThreadImpl::WidgetHidden() {
2155 DCHECK_LT(hidden_widget_count_, widget_count_);
2156 hidden_widget_count_++;
rmcilroyaa296052015-04-14 15:35:272157 if (RendererIsHidden())
2158 OnRendererHidden();
[email protected]b2db9272014-01-10 17:42:002159}
2160
2161void RenderThreadImpl::WidgetRestored() {
rmcilroyaa296052015-04-14 15:35:272162 bool renderer_was_hidden = RendererIsHidden();
[email protected]b2db9272014-01-10 17:42:002163 DCHECK_GT(hidden_widget_count_, 0);
2164 hidden_widget_count_--;
rmcilroyaa296052015-04-14 15:35:272165 if (renderer_was_hidden)
2166 OnRendererVisible();
2167}
[email protected]b2db9272014-01-10 17:42:002168
rmcilroyaa296052015-04-14 15:35:272169void RenderThreadImpl::OnRendererHidden() {
ulan432cd6e42016-03-01 15:59:142170 blink::mainThreadIsolate()->IsolateInBackgroundNotification();
rmcilroyaa296052015-04-14 15:35:272171 // TODO(rmcilroy): Remove IdleHandler and replace it with an IdleTask
2172 // scheduled by the RendererScheduler - http://crbug.com/469210.
ulan4a385192015-11-11 10:59:182173 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
2174 return;
2175 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
rmcilroyaa296052015-04-14 15:35:272176}
2177
2178void RenderThreadImpl::OnRendererVisible() {
ulan432cd6e42016-03-01 15:59:142179 blink::mainThreadIsolate()->IsolateInForegroundNotification();
rmcilroyaa296052015-04-14 15:35:272180 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
[email protected]b2db9272014-01-10 17:42:002181 return;
[email protected]b2db9272014-01-10 17:42:002182 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
2183}
2184
ssid0603ca9f2015-06-09 16:48:082185void RenderThreadImpl::ReleaseFreeMemory() {
2186 base::allocator::ReleaseFreeMemory();
2187 discardable_shared_memory_manager()->ReleaseFreeMemory();
2188
2189 if (blink_platform_impl_)
2190 blink::decommitFreeableMemory();
2191}
2192
ben76f52b242016-06-18 05:42:482193RenderThreadImpl::PendingFrameCreate::PendingFrameCreate(
rockotf8fdd9b2015-12-16 22:22:352194 int routing_id,
ben76f52b242016-06-18 05:42:482195 mojom::FrameRequest frame_request,
2196 mojom::FrameHostPtr frame_host)
rockotf8fdd9b2015-12-16 22:22:352197 : routing_id_(routing_id),
ben76f52b242016-06-18 05:42:482198 frame_request_(std::move(frame_request)),
2199 frame_host_(std::move(frame_host)) {
2200 // The RenderFrame may be deleted before the CreateFrame message is received.
2201 // In that case, the RenderFrameHost should cancel the create, which is
2202 // detected by setting an error handler on |frame_host_|.
2203 frame_host_.set_connection_error_handler(base::Bind(
2204 &RenderThreadImpl::PendingFrameCreate::OnConnectionError,
rockotf8fdd9b2015-12-16 22:22:352205 base::Unretained(this)));
2206}
2207
ben76f52b242016-06-18 05:42:482208RenderThreadImpl::PendingFrameCreate::~PendingFrameCreate() {
rockotf8fdd9b2015-12-16 22:22:352209}
2210
ben76f52b242016-06-18 05:42:482211void RenderThreadImpl::PendingFrameCreate::OnConnectionError() {
rockotf8fdd9b2015-12-16 22:22:352212 size_t erased =
ben76f52b242016-06-18 05:42:482213 RenderThreadImpl::current()->pending_frame_creates_.erase(routing_id_);
rockotf8fdd9b2015-12-16 22:22:352214 DCHECK_EQ(1u, erased);
2215}
2216
hong.zhengb28b5332016-05-11 02:33:392217void RenderThreadImpl::OnSyncMemoryPressure(
2218 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2219 if (!blink::mainThreadIsolate())
2220 return;
2221
2222 v8::MemoryPressureLevel v8_memory_pressure_level =
2223 static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
2224
2225 // In order to reduce performance impact, translate critical level to
2226 // moderate level for foregroud renderer.
2227 if (!RendererIsHidden() &&
2228 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
2229 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
2230
2231 blink::mainThreadIsolate()->MemoryPressureNotification(
2232 v8_memory_pressure_level);
2233 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2234 v8_memory_pressure_level);
2235}
2236
[email protected]e9ff79c2012-10-19 21:31:262237} // namespace content