[email protected] | d3d6325d | 2012-01-03 21:17:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 5 | #include "content/renderer/render_thread_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 61a9b2d8 | 2010-02-26 00:31:08 | [diff] [blame] | 8 | #include <limits> |
[email protected] | 75e126b93 | 2009-09-28 19:38:49 | [diff] [blame] | 9 | #include <map> |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 10 | #include <utility> |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 13 | #include "base/allocator/allocator_extension.h" |
haraken | bbfdd9f0 | 2017-01-12 07:14:04 | [diff] [blame] | 14 | #include "base/at_exit.h" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 15 | #include "base/command_line.h" |
creis | 9f7248b | 2016-01-27 20:27:39 | [diff] [blame] | 16 | #include "base/debug/crash_logging.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 17 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 18 | #include "base/logging.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 19 | #include "base/macros.h" |
reveman | 1af05cb3 | 2015-03-17 23:18:16 | [diff] [blame] | 20 | #include "base/memory/discardable_memory_allocator.h" |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 21 | #include "base/memory/memory_coordinator_client_registry.h" |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 22 | #include "base/memory/ptr_util.h" |
[email protected] | 8bac37b | 2013-07-18 19:13:56 | [diff] [blame] | 23 | #include "base/memory/shared_memory.h" |
gab | f64a25e | 2017-05-12 19:42:56 | [diff] [blame] | 24 | #include "base/message_loop/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 25 | #include "base/metrics/field_trial.h" |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 26 | #include "base/metrics/histogram_functions.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 27 | #include "base/metrics/histogram_macros.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 28 | #include "base/path_service.h" |
tasak | b46626a | 2016-10-18 05:54:44 | [diff] [blame] | 29 | #include "base/process/process_metrics.h" |
fdoray | 2df4a9e | 2016-07-18 23:47:16 | [diff] [blame] | 30 | #include "base/run_loop.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 31 | #include "base/strings/string16.h" |
[email protected] | 1e1d1e1 | 2014-01-17 16:14:29 | [diff] [blame] | 32 | #include "base/strings/string_number_conversions.h" |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 33 | #include "base/strings/string_split.h" |
ccameron | 6728bae3 | 2015-01-09 20:18:06 | [diff] [blame] | 34 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 35 | #include "base/strings/utf_string_conversions.h" |
fdoray | 50a3834 | 2016-11-21 20:46:04 | [diff] [blame] | 36 | #include "base/threading/sequenced_worker_pool.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 37 | #include "base/threading/simple_thread.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 38 | #include "base/threading/thread_local.h" |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 39 | #include "base/threading/thread_restrictions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 40 | #include "base/threading/thread_task_runner_handle.h" |
ccameron | 9c48d1d4 | 2016-09-22 01:46:01 | [diff] [blame] | 41 | #include "base/trace_event/memory_dump_manager.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 42 | #include "base/trace_event/trace_event.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 43 | #include "base/values.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 44 | #include "build/build_config.h" |
jbroman | 0d30216 | 2015-09-05 05:46:23 | [diff] [blame] | 45 | #include "cc/base/histograms.h" |
[email protected] | d7249315 | 2014-01-08 17:37:45 | [diff] [blame] | 46 | #include "cc/base/switches.h" |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 47 | #include "cc/blink/web_layer_impl.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 48 | #include "cc/output/layer_tree_frame_sink.h" |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 49 | #include "cc/output/vulkan_in_process_context_provider.h" |
danakj | 92015685 | 2015-05-18 20:22:29 | [diff] [blame] | 50 | #include "cc/raster/task_graph_runner.h" |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 51 | #include "cc/trees/layer_tree_host_common.h" |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 52 | #include "cc/trees/layer_tree_settings.h" |
penghuang | d81c1a6 | 2016-11-02 20:06:06 | [diff] [blame] | 53 | #include "components/discardable_memory/client/client_discardable_shared_memory_manager.h" |
dalecurtis | 4a9839a | 2017-05-04 23:40:47 | [diff] [blame] | 54 | #include "components/metrics/public/interfaces/single_sample_metrics.mojom.h" |
| 55 | #include "components/metrics/single_sample_metrics.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 56 | #include "components/viz/client/client_layer_tree_frame_sink.h" |
danakj | 9242985 | 2017-06-29 00:19:03 | [diff] [blame] | 57 | #include "components/viz/client/client_shared_bitmap_manager.h" |
Valery Arkhangorodsky | 513ac8fd | 2017-08-02 23:09:23 | [diff] [blame] | 58 | #include "components/viz/client/hit_test_data_provider.h" |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 59 | #include "components/viz/client/local_surface_id_provider.h" |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 60 | #include "components/viz/common/quads/copy_output_request.h" |
Fady Samuel | 1d744b2 | 2017-07-10 21:23:55 | [diff] [blame] | 61 | #include "components/viz/common/resources/buffer_to_texture_target_map.h" |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 62 | #include "content/child/appcache/appcache_dispatcher.h" |
| 63 | #include "content/child/appcache/appcache_frontend_impl.h" |
dmurph | 1fb9848 | 2016-03-30 21:14:26 | [diff] [blame] | 64 | #include "content/child/blob_storage/blob_message_filter.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 65 | #include "content/child/child_histogram_message_filter.h" |
alexclarke | 0bc36e8d3 | 2014-12-17 17:29:20 | [diff] [blame] | 66 | #include "content/child/child_resource_message_filter.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 67 | #include "content/child/db_message_filter.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 68 | #include "content/child/indexed_db/indexed_db_dispatcher.h" |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 69 | #include "content/child/memory/child_memory_coordinator_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 70 | #include "content/child/resource_dispatcher.h" |
alexclarke | 0bc36e8d3 | 2014-12-17 17:29:20 | [diff] [blame] | 71 | #include "content/child/resource_scheduling_filter.h" |
[email protected] | 643255da | 2013-06-12 20:55:13 | [diff] [blame] | 72 | #include "content/child/runtime_features.h" |
[email protected] | 57cf9788 | 2013-06-26 20:39:01 | [diff] [blame] | 73 | #include "content/child/thread_safe_sender.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 74 | #include "content/child/web_database_observer_impl.h" |
kinuko | ef64741 | 2015-12-23 06:10:43 | [diff] [blame] | 75 | #include "content/child/worker_thread_registry.h" |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 76 | #include "content/common/child_process_messages.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 77 | #include "content/common/content_constants_internal.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 78 | #include "content/common/dom_storage/dom_storage_messages.h" |
thakis | 18e42641 | 2017-03-15 12:06:37 | [diff] [blame] | 79 | #include "content/common/features.h" |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 80 | #include "content/common/frame_messages.h" |
raymes | bba82b3 | 2016-07-19 00:41:38 | [diff] [blame] | 81 | #include "content/common/frame_owner_properties.h" |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 82 | #include "content/common/gpu_stream_constants.h" |
avi | a7c3f51c | 2015-09-16 00:30:31 | [diff] [blame] | 83 | #include "content/common/render_process_messages.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 84 | #include "content/common/resource_messages.h" |
alexmos | 6873421 | 2016-08-27 00:06:31 | [diff] [blame] | 85 | #include "content/common/site_isolation_policy.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 86 | #include "content/common/view_messages.h" |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 87 | #include "content/common/worker_messages.h" |
[email protected] | a458504b | 2012-07-23 19:57:06 | [diff] [blame] | 88 | #include "content/public/common/content_constants.h" |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 89 | #include "content/public/common/content_features.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 90 | #include "content/public/common/content_paths.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 91 | #include "content/public/common/content_switches.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 92 | #include "content/public/common/renderer_preferences.h" |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 93 | #include "content/public/common/service_manager_connection.h" |
ben | 649b3edd | 2017-03-23 00:32:02 | [diff] [blame] | 94 | #include "content/public/common/service_names.mojom.h" |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 95 | #include "content/public/common/simple_connection_filter.h" |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 96 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 97 | #include "content/public/renderer/content_renderer_client.h" |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 98 | #include "content/public/renderer/render_thread_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 99 | #include "content/public/renderer/render_view_visitor.h" |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 100 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
jsbell | 279efb4 | 2015-03-31 17:02:46 | [diff] [blame] | 101 | #include "content/renderer/cache_storage/cache_storage_dispatcher.h" |
| 102 | #include "content/renderer/cache_storage/cache_storage_message_filter.h" |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 103 | #include "content/renderer/categorized_worker_pool.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 104 | #include "content/renderer/devtools/devtools_agent_filter.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 105 | #include "content/renderer/dom_storage/dom_storage_dispatcher.h" |
| 106 | #include "content/renderer/dom_storage/webstoragearea_impl.h" |
| 107 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
tbansal | b612c5d | 2017-05-25 18:53:06 | [diff] [blame] | 108 | #include "content/renderer/effective_connection_type_helper.h" |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 109 | #include "content/renderer/gpu/compositor_external_begin_frame_source.h" |
| 110 | #include "content/renderer/gpu/compositor_forwarding_message_filter.h" |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 111 | #include "content/renderer/gpu/frame_swap_message_queue.h" |
[email protected] | 7a72d45 | 2013-12-13 10:01:13 | [diff] [blame] | 112 | #include "content/renderer/input/input_event_filter.h" |
| 113 | #include "content/renderer/input/input_handler_manager.h" |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 114 | #include "content/renderer/input/main_thread_input_event_filter.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 115 | #include "content/renderer/media/audio_input_message_filter.h" |
| 116 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 117 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
Miguel Casas-Sanchez | cfcca5d5 | 2017-07-07 02:32:59 | [diff] [blame] | 118 | #include "content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h" |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 119 | #include "content/renderer/media/media_stream_center.h" |
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 120 | #include "content/renderer/media/midi_message_filter.h" |
xhwang | 194acae | 2014-11-12 22:46:33 | [diff] [blame] | 121 | #include "content/renderer/media/render_media_client.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 122 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | d7ff5fb | 2014-05-29 19:50:25 | [diff] [blame] | 123 | #include "content/renderer/net_info_helper.h" |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 124 | #include "content/renderer/p2p/socket_dispatcher.h" |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 125 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 126 | #include "content/renderer/render_process_impl.h" |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 127 | #include "content/renderer/render_view_impl.h" |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 128 | #include "content/renderer/renderer_blink_platform_impl.h" |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 129 | #include "content/renderer/scheduler/resource_dispatch_throttler.h" |
shimazu | 5de409e4 | 2016-09-29 08:45:28 | [diff] [blame] | 130 | #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h" |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 131 | #include "content/renderer/service_worker/service_worker_context_client.h" |
kinuko | 5af4ffe | 2015-06-09 03:38:46 | [diff] [blame] | 132 | #include "content/renderer/service_worker/service_worker_context_message_filter.h" |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 133 | #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" |
juncai | 2f298a8 | 2017-04-18 03:51:39 | [diff] [blame] | 134 | #include "device/gamepad/public/cpp/gamepads.h" |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 135 | #include "gin/public/debug.h" |
dongseong.hwang | 72183b0 | 2014-12-08 10:41:55 | [diff] [blame] | 136 | #include "gpu/GLES2/gl2extchromium.h" |
danakj | 6f4e1e2 | 2016-04-20 03:27:34 | [diff] [blame] | 137 | #include "gpu/command_buffer/client/shared_memory_limits.h" |
danakj | 870925d4 | 2016-05-03 20:07:38 | [diff] [blame] | 138 | #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 139 | #include "gpu/ipc/client/gpu_channel_host.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 140 | #include "ipc/ipc_channel_handle.h" |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 141 | #include "ipc/ipc_channel_mojo.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 142 | #include "ipc/ipc_platform_file.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 143 | #include "media/base/media.h" |
chcunningham | 9a285ed | 2017-03-08 21:48:56 | [diff] [blame] | 144 | #include "media/base/media_switches.h" |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 145 | #include "media/media_features.h" |
servolk | 8b3b39b | 2015-03-03 19:08:18 | [diff] [blame] | 146 | #include "media/renderers/gpu_video_accelerator_factories.h" |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 147 | #include "mojo/public/cpp/bindings/strong_binding.h" |
Yuki Yamada | 68992b0 | 2017-07-31 06:13:45 | [diff] [blame] | 148 | #include "mojo/public/cpp/system/message_pipe.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 149 | #include "net/base/net_errors.h" |
eroman | 9ab6484 | 2015-07-21 05:07:52 | [diff] [blame] | 150 | #include "net/base/port_util.h" |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 151 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
tfarina | 7a4a7fd | 2016-01-20 14:23:44 | [diff] [blame] | 152 | #include "net/base/url_util.h" |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 153 | #include "ppapi/features/features.h" |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 154 | #include "services/service_manager/public/cpp/binder_registry.h" |
penghuang | d6843e4 | 2016-12-17 13:57:20 | [diff] [blame] | 155 | #include "services/service_manager/public/cpp/connector.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 156 | #include "services/service_manager/public/cpp/interface_provider.h" |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 157 | #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
penghuang | d6843e4 | 2016-12-17 13:57:20 | [diff] [blame] | 158 | #include "services/ui/public/interfaces/constants.mojom.h" |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 159 | #include "skia/ext/event_tracer_impl.h" |
ssid | 59c96916 | 2015-07-28 13:02:58 | [diff] [blame] | 160 | #include "skia/ext/skia_memory_dump_provider.h" |
kinuko | ed1ed1d | 2017-02-08 09:13:43 | [diff] [blame] | 161 | #include "third_party/WebKit/public/platform/WebCache.h" |
reed | 6e5a7222 | 2015-08-06 20:37:16 | [diff] [blame] | 162 | #include "third_party/WebKit/public/platform/WebImageGenerator.h" |
bashi | 5f4c7892 | 2016-08-18 23:06:08 | [diff] [blame] | 163 | #include "third_party/WebKit/public/platform/WebMemoryCoordinator.h" |
kinuko | fbfee76 | 2017-03-08 04:01:06 | [diff] [blame] | 164 | #include "third_party/WebKit/public/platform/WebNetworkStateNotifier.h" |
nverne | 61d2da87 | 2017-05-24 10:15:30 | [diff] [blame] | 165 | #include "third_party/WebKit/public/platform/WebRuntimeFeatures.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 166 | #include "third_party/WebKit/public/platform/WebString.h" |
skyostil | 457b0a1 | 2014-09-09 10:12:07 | [diff] [blame] | 167 | #include "third_party/WebKit/public/platform/WebThread.h" |
altimin | c7369bf | 2017-04-11 14:29:15 | [diff] [blame] | 168 | #include "third_party/WebKit/public/platform/scheduler/child/webthread_base.h" |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 169 | #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 170 | #include "third_party/WebKit/public/web/WebDatabase.h" |
| 171 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 172 | #include "third_party/WebKit/public/web/WebFrame.h" |
| 173 | #include "third_party/WebKit/public/web/WebKit.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 174 | #include "third_party/WebKit/public/web/WebScriptController.h" |
| 175 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 176 | #include "third_party/WebKit/public/web/WebView.h" |
David Benjamin | b946811c | 2017-06-26 23:34:29 | [diff] [blame] | 177 | #include "third_party/boringssl/src/include/openssl/evp.h" |
[email protected] | ddbb5334 | 2014-01-06 10:59:47 | [diff] [blame] | 178 | #include "third_party/skia/include/core/SkGraphics.h" |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 179 | #include "ui/base/layout.h" |
[email protected] | 18ad677 | 2011-09-20 21:51:32 | [diff] [blame] | 180 | #include "ui/base/ui_base_switches.h" |
mlamouri | 7c14965 | 2017-03-24 00:00:09 | [diff] [blame] | 181 | #include "ui/display/display_switches.h" |
enne | e292bdc | 2016-09-15 19:57:15 | [diff] [blame] | 182 | #include "ui/gl/gl_switches.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 183 | |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 184 | #if defined(OS_ANDROID) |
| 185 | #include <cpu-features.h> |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 186 | #include "content/renderer/android/synchronous_compositor_filter.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 187 | #include "content/renderer/android/synchronous_layer_tree_frame_sink.h" |
boliu | e81d1613 | 2016-04-26 00:54:41 | [diff] [blame] | 188 | #include "content/renderer/media/android/stream_texture_factory.h" |
dalecurtis | 88af393 | 2016-02-20 00:12:20 | [diff] [blame] | 189 | #include "media/base/android/media_codec_util.h" |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 190 | #endif |
| 191 | |
| 192 | #if defined(OS_MACOSX) |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 193 | #include "base/mac/mac_util.h" |
lgrey | 023fd36 | 2017-06-08 19:20:52 | [diff] [blame] | 194 | #include "base/process/process.h" |
| 195 | #include "content/common/mac/app_nap_activity.h" |
rsesek | 1efb3c3 | 2015-09-29 15:39:50 | [diff] [blame] | 196 | #include "content/renderer/theme_helper_mac.h" |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 197 | #include "content/renderer/webscrollbarbehavior_impl_mac.h" |
| 198 | #endif |
| 199 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 200 | #if defined(OS_WIN) |
| 201 | #include <windows.h> |
| 202 | #include <objbase.h> |
| 203 | #endif |
| 204 | |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 205 | #if BUILDFLAG(ENABLE_WEBRTC) |
liushouqun | 517b129 | 2016-09-14 05:58:59 | [diff] [blame] | 206 | #include "content/renderer/media/aec_dump_message_filter.h" |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 207 | #include "content/renderer/media/peer_connection_tracker.h" |
| 208 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 209 | #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 210 | #endif |
| 211 | |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 212 | #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 213 | #include "v8/src/third_party/vtune/v8-vtune.h" |
| 214 | #endif |
| 215 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 216 | #include "content/public/common/service_manager_connection.h" |
fsamuel | 2545ecc | 2015-12-05 00:44:46 | [diff] [blame] | 217 | #include "content/renderer/mus/render_widget_window_tree_client_factory.h" |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 218 | #include "content/renderer/mus/renderer_window_tree_client.h" |
sadrul | 04cfa89 | 2016-12-09 17:53:49 | [diff] [blame] | 219 | #include "services/ui/public/cpp/gpu/gpu.h" |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 220 | |
ochang | dd89a1e | 2016-06-08 16:39:01 | [diff] [blame] | 221 | #if defined(ENABLE_IPC_FUZZER) |
| 222 | #include "content/common/external_ipc_dumper.h" |
| 223 | #endif |
| 224 | |
tasak | b46626a | 2016-10-18 05:54:44 | [diff] [blame] | 225 | #if defined(OS_MACOSX) |
| 226 | #include <malloc/malloc.h> |
| 227 | #else |
| 228 | #include <malloc.h> |
| 229 | #endif |
| 230 | |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 231 | using base::ThreadRestrictions; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 232 | using blink::WebDocument; |
| 233 | using blink::WebFrame; |
| 234 | using blink::WebNetworkStateNotifier; |
| 235 | using blink::WebRuntimeFeatures; |
| 236 | using blink::WebScriptController; |
| 237 | using blink::WebSecurityPolicy; |
| 238 | using blink::WebString; |
| 239 | using blink::WebView; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 240 | |
| 241 | namespace content { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 242 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 243 | namespace { |
[email protected] | da9ccfb | 2012-01-28 00:34:40 | [diff] [blame] | 244 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 245 | const int64_t kInitialIdleHandlerDelayMs = 1000; |
| 246 | const int64_t kLongIdleHandlerDelayMs = 30 * 1000; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 247 | |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 248 | #if defined(OS_ANDROID) |
| 249 | // On Android, resource messages can each take ~1.5ms to dispatch on the browser |
| 250 | // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the |
| 251 | // induced work takes but a fraction (~1/4) of the overall frame budget. |
| 252 | const int kMaxResourceRequestsPerFlushWhenThrottled = 3; |
| 253 | #else |
| 254 | const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
| 255 | #endif |
| 256 | const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
| 257 | |
[email protected] | dd2c102 | 2014-07-22 23:13:57 | [diff] [blame] | 258 | // Maximum allocation size allowed for image scaling filters that |
| 259 | // require pre-scaling. Skia will fallback to a filter that doesn't |
| 260 | // require pre-scaling if the default filter would require an |
| 261 | // allocation that exceeds this limit. |
| 262 | const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 263 | |
samans | 2040988b | 2017-04-11 23:58:35 | [diff] [blame] | 264 | #if defined(OS_ANDROID) |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 265 | // Unique identifier for each output surface created. |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 266 | uint32_t g_next_layer_tree_frame_sink_id = 1; |
samans | 2040988b | 2017-04-11 23:58:35 | [diff] [blame] | 267 | #endif |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 268 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 269 | // An implementation of mojom::RenderMessageFilter which can be mocked out |
| 270 | // for tests which may indirectly send messages over this interface. |
| 271 | mojom::RenderMessageFilter* g_render_message_filter_for_testing; |
| 272 | |
olegmax | 045f7fb1 | 2017-05-19 07:58:55 | [diff] [blame] | 273 | // An implementation of RendererBlinkPlatformImpl which can be mocked out |
| 274 | // for tests. |
| 275 | RendererBlinkPlatformImpl* g_current_blink_platform_impl_for_testing; |
| 276 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 277 | // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
[email protected] | f3ede41 | 2010-06-21 22:52:16 | [diff] [blame] | 278 | // incorrectly from the wrong thread. |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 279 | base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 280 | lazy_tls = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 281 | |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 282 | // v8::MemoryPressureLevel should correspond to base::MemoryPressureListener. |
| 283 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 284 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 285 | v8::MemoryPressureLevel::kNone, "none level not align"); |
| 286 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 287 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 288 | v8::MemoryPressureLevel::kModerate, "moderate level not align"); |
| 289 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 290 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 291 | v8::MemoryPressureLevel::kCritical, "critical level not align"); |
| 292 | |
hong.zheng | 2e296f82 | 2016-06-29 02:47:44 | [diff] [blame] | 293 | // WebMemoryPressureLevel should correspond to base::MemoryPressureListener. |
| 294 | static_assert(static_cast<blink::WebMemoryPressureLevel>( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 295 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 296 | blink::kWebMemoryPressureLevelNone, |
| 297 | "blink::WebMemoryPressureLevelNone not align"); |
| 298 | static_assert( |
| 299 | static_cast<blink::WebMemoryPressureLevel>( |
| 300 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 301 | blink::kWebMemoryPressureLevelModerate, |
| 302 | "blink::WebMemoryPressureLevelModerate not align"); |
| 303 | static_assert( |
| 304 | static_cast<blink::WebMemoryPressureLevel>( |
| 305 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 306 | blink::kWebMemoryPressureLevelCritical, |
| 307 | "blink::WebMemoryPressureLevelCritical not align"); |
hong.zheng | 2e296f82 | 2016-06-29 02:47:44 | [diff] [blame] | 308 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 309 | void* CreateHistogram( |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 310 | const char *name, int min, int max, size_t buckets) { |
| 311 | if (min <= 0) |
| 312 | min = 1; |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 313 | std::string histogram_name; |
| 314 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 315 | if (render_thread_impl) { // Can be null in tests. |
| 316 | histogram_name = render_thread_impl-> |
| 317 | histogram_customizer()->ConvertToCustomHistogramName(name); |
| 318 | } else { |
| 319 | histogram_name = std::string(name); |
| 320 | } |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 321 | base::HistogramBase* histogram = base::Histogram::FactoryGet( |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 322 | histogram_name, min, max, buckets, |
| 323 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 324 | return histogram; |
| 325 | } |
| 326 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 327 | void AddHistogramSample(void* hist, int sample) { |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 328 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
| 329 | histogram->Add(sample); |
| 330 | } |
| 331 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 332 | class FrameFactoryImpl : public mojom::FrameFactory { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 333 | public: |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 334 | explicit FrameFactoryImpl(const service_manager::BindSourceInfo& source_info) |
| 335 | : source_info_(source_info), routing_id_highmark_(-1) {} |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 336 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 337 | private: |
| 338 | // mojom::FrameFactory: |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 339 | void CreateFrame( |
| 340 | int32_t frame_routing_id, |
| 341 | mojom::FrameRequest frame_request, |
| 342 | mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker) override { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 343 | // TODO(morrita): This is for investigating http://crbug.com/415059 and |
| 344 | // should be removed once it is fixed. |
| 345 | CHECK_LT(routing_id_highmark_, frame_routing_id); |
| 346 | routing_id_highmark_ = frame_routing_id; |
| 347 | |
| 348 | RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id); |
| 349 | // We can receive a GetServiceProviderForFrame message for a frame not yet |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 350 | // created due to a race between the message and a |
| 351 | // mojom::Renderer::CreateView IPC that triggers creation of the RenderFrame |
| 352 | // we want. |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 353 | if (!frame) { |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 354 | RenderThreadImpl::current()->RegisterPendingFrameCreate( |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 355 | source_info_, frame_routing_id, std::move(frame_request), |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 356 | std::move(frame_host_interface_broker)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 357 | return; |
| 358 | } |
| 359 | |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 360 | frame->BindFrame(source_info_, std::move(frame_request), |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 361 | std::move(frame_host_interface_broker)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | private: |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 365 | service_manager::BindSourceInfo source_info_; |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 366 | int32_t routing_id_highmark_; |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 367 | }; |
| 368 | |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 369 | void CreateFrameFactory(mojom::FrameFactoryRequest request, |
| 370 | const service_manager::BindSourceInfo& source_info) { |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 371 | mojo::MakeStrongBinding(base::MakeUnique<FrameFactoryImpl>(source_info), |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 372 | std::move(request)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 373 | } |
| 374 | |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 375 | scoped_refptr<ui::ContextProviderCommandBuffer> CreateOffscreenContext( |
danakj | c398355 | 2016-05-03 00:04:35 | [diff] [blame] | 376 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 377 | const gpu::SharedMemoryLimits& limits, |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 378 | bool support_locking, |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 379 | ui::command_buffer_metrics::ContextType type, |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 380 | int32_t stream_id, |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 381 | gpu::SchedulingPriority stream_priority) { |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 382 | DCHECK(gpu_channel_host); |
| 383 | // This is used to create a few different offscreen contexts: |
| 384 | // - The shared main thread context (offscreen) used by blink for canvas. |
| 385 | // - The worker context (offscreen) used for GPU raster and video decoding. |
| 386 | // This is for an offscreen context, so the default framebuffer doesn't need |
| 387 | // alpha, depth, stencil, antialiasing. |
| 388 | gpu::gles2::ContextCreationAttribHelper attributes; |
| 389 | attributes.alpha_size = -1; |
| 390 | attributes.depth_size = 0; |
| 391 | attributes.stencil_size = 0; |
| 392 | attributes.samples = 0; |
| 393 | attributes.sample_buffers = 0; |
| 394 | attributes.bind_generates_resource = false; |
| 395 | attributes.lose_context_when_out_of_memory = true; |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 396 | const bool automatic_flushes = false; |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 397 | return make_scoped_refptr(new ui::ContextProviderCommandBuffer( |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 398 | std::move(gpu_channel_host), stream_id, stream_priority, |
| 399 | gpu::kNullSurfaceHandle, |
zmo | 09ea813b | 2017-01-20 23:38:36 | [diff] [blame] | 400 | GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext/" + |
| 401 | ui::command_buffer_metrics::ContextTypeToString(type)), |
piman | d488e8b4 | 2016-06-30 19:06:59 | [diff] [blame] | 402 | automatic_flushes, support_locking, limits, attributes, nullptr, type)); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 403 | } |
| 404 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 405 | bool IsRunningInMash() { |
| 406 | const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 407 | return cmdline->HasSwitch(switches::kIsRunningInMash); |
| 408 | } |
| 409 | |
dalecurtis | 4a9839a | 2017-05-04 23:40:47 | [diff] [blame] | 410 | // Hook that allows single-sample metric code from //components/metrics to |
| 411 | // connect from the renderer process to the browser process. |
| 412 | void CreateSingleSampleMetricsProvider( |
| 413 | scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 414 | service_manager::Connector* connector, |
| 415 | metrics::mojom::SingleSampleMetricsProviderRequest request) { |
| 416 | if (task_runner->BelongsToCurrentThread()) { |
| 417 | connector->BindInterface(mojom::kBrowserServiceName, std::move(request)); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | task_runner->PostTask( |
| 422 | FROM_HERE, |
| 423 | base::Bind(&CreateSingleSampleMetricsProvider, std::move(task_runner), |
| 424 | connector, base::Passed(&request))); |
| 425 | } |
| 426 | |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 427 | class RendererLocalSurfaceIdProvider : public viz::LocalSurfaceIdProvider { |
| 428 | public: |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 429 | const viz::LocalSurfaceId& GetLocalSurfaceIdForFrame( |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 430 | const cc::CompositorFrame& frame) override { |
| 431 | auto new_surface_properties = |
| 432 | RenderWidgetSurfaceProperties::FromCompositorFrame(frame); |
| 433 | if (!local_surface_id_.is_valid() || |
| 434 | new_surface_properties != surface_properties_) { |
| 435 | local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 436 | surface_properties_ = new_surface_properties; |
| 437 | } |
| 438 | return local_surface_id_; |
| 439 | } |
| 440 | |
| 441 | private: |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 442 | viz::LocalSurfaceIdAllocator local_surface_id_allocator_; |
| 443 | viz::LocalSurfaceId local_surface_id_; |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 444 | RenderWidgetSurfaceProperties surface_properties_; |
| 445 | }; |
| 446 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 447 | } // namespace |
| 448 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 449 | RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { |
| 450 | custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); |
| 451 | custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted"); |
| 452 | custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed"); |
hablich | 4598ddc | 2015-11-07 18:37:28 | [diff] [blame] | 453 | custom_histograms_.insert("V8.MemoryHeapUsed"); |
| 454 | custom_histograms_.insert("V8.MemoryHeapCommitted"); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} |
| 458 | |
| 459 | void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost( |
| 460 | const std::string& host, size_t view_count) { |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 461 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 462 | switches::kDisableHistogramCustomizer)) { |
[email protected] | 9baee83 | 2012-12-10 11:07:15 | [diff] [blame] | 463 | return; |
| 464 | } |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 465 | // Check if all RenderViews are displaying a page from the same host. If there |
| 466 | // is only one RenderView, the common host is this view's host. If there are |
| 467 | // many, check if this one shares the common host of the other |
| 468 | // RenderViews. It's ok to not detect some cases where the RenderViews share a |
| 469 | // common host. This information is only used for producing custom histograms. |
| 470 | if (view_count == 1) |
| 471 | SetCommonHost(host); |
| 472 | else if (host != common_host_) |
| 473 | SetCommonHost(std::string()); |
| 474 | } |
| 475 | |
| 476 | std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName( |
| 477 | const char* histogram_name) const { |
| 478 | std::string name(histogram_name); |
| 479 | if (!common_host_histogram_suffix_.empty() && |
| 480 | custom_histograms_.find(name) != custom_histograms_.end()) |
| 481 | name += common_host_histogram_suffix_; |
| 482 | return name; |
| 483 | } |
| 484 | |
| 485 | void RenderThreadImpl::HistogramCustomizer::SetCommonHost( |
| 486 | const std::string& host) { |
| 487 | if (host != common_host_) { |
| 488 | common_host_ = host; |
| 489 | common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 490 | blink::MainThreadIsolate()->SetCreateHistogramFunction(CreateHistogram); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 494 | std::string RenderThreadImpl::HistogramCustomizer::HostToCustomHistogramSuffix( |
| 495 | const std::string& host) { |
| 496 | if (host == "mail.google.com") |
| 497 | return ".gmail"; |
| 498 | if (host == "docs.google.com" || host == "drive.google.com") |
| 499 | return ".docs"; |
| 500 | if (host == "plus.google.com") |
| 501 | return ".plus"; |
| 502 | if (host == "inbox.google.com") |
| 503 | return ".inbox"; |
hpayer | dd4def05 | 2016-02-06 19:06:10 | [diff] [blame] | 504 | if (host == "calendar.google.com") |
| 505 | return ".calendar"; |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 506 | if (host == "www.youtube.com") |
| 507 | return ".youtube"; |
| 508 | if (IsAlexaTop10NonGoogleSite(host)) |
| 509 | return ".top10"; |
| 510 | |
| 511 | return std::string(); |
| 512 | } |
| 513 | |
| 514 | bool RenderThreadImpl::HistogramCustomizer::IsAlexaTop10NonGoogleSite( |
| 515 | const std::string& host) { |
| 516 | // The Top10 sites have different TLD and/or subdomains depending on the |
| 517 | // localization. |
| 518 | if (host == "sina.com.cn") |
| 519 | return true; |
| 520 | |
| 521 | std::string sanitized_host = |
| 522 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 523 | host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 524 | |
| 525 | if (sanitized_host == "facebook.com") |
| 526 | return true; |
| 527 | if (sanitized_host == "baidu.com") |
| 528 | return true; |
| 529 | if (sanitized_host == "qq.com") |
| 530 | return true; |
| 531 | if (sanitized_host == "twitter.com") |
| 532 | return true; |
| 533 | if (sanitized_host == "taobao.com") |
| 534 | return true; |
| 535 | if (sanitized_host == "live.com") |
| 536 | return true; |
| 537 | |
| 538 | if (!sanitized_host.empty()) { |
| 539 | std::vector<base::StringPiece> host_tokens = base::SplitStringPiece( |
| 540 | sanitized_host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 541 | |
| 542 | if (host_tokens.size() >= 2) { |
| 543 | if ((host_tokens[0] == "yahoo") || (host_tokens[0] == "amazon") || |
| 544 | (host_tokens[0] == "wikipedia")) { |
| 545 | return true; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | return false; |
| 550 | } |
| 551 | |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 552 | // static |
| 553 | RenderThreadImpl* RenderThreadImpl::Create( |
| 554 | const InProcessChildThreadParams& params) { |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 555 | std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler = |
| 556 | blink::scheduler::RendererScheduler::Create(); |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 557 | scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; |
| 558 | return new RenderThreadImpl( |
| 559 | params, std::move(renderer_scheduler), test_task_counter); |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | // static |
| 563 | RenderThreadImpl* RenderThreadImpl::Create( |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 564 | std::unique_ptr<base::MessageLoop> main_message_loop, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 565 | std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler) { |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 566 | return new RenderThreadImpl(std::move(main_message_loop), |
| 567 | std::move(renderer_scheduler)); |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 568 | } |
| 569 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 570 | // static |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 571 | RenderThreadImpl* RenderThreadImpl::current() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 572 | return lazy_tls.Pointer()->Get(); |
| 573 | } |
| 574 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 575 | // static |
| 576 | mojom::RenderMessageFilter* RenderThreadImpl::current_render_message_filter() { |
| 577 | if (g_render_message_filter_for_testing) |
| 578 | return g_render_message_filter_for_testing; |
| 579 | DCHECK(current()); |
| 580 | return current()->render_message_filter(); |
| 581 | } |
| 582 | |
| 583 | // static |
olegmax | 045f7fb1 | 2017-05-19 07:58:55 | [diff] [blame] | 584 | RendererBlinkPlatformImpl* RenderThreadImpl::current_blink_platform_impl() { |
| 585 | if (g_current_blink_platform_impl_for_testing) |
| 586 | return g_current_blink_platform_impl_for_testing; |
| 587 | DCHECK(current()); |
| 588 | return current()->blink_platform_impl(); |
| 589 | } |
| 590 | |
| 591 | // static |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 592 | void RenderThreadImpl::SetRenderMessageFilterForTesting( |
| 593 | mojom::RenderMessageFilter* render_message_filter) { |
| 594 | g_render_message_filter_for_testing = render_message_filter; |
| 595 | } |
| 596 | |
olegmax | 045f7fb1 | 2017-05-19 07:58:55 | [diff] [blame] | 597 | // static |
| 598 | void RenderThreadImpl::SetRendererBlinkPlatformImplForTesting( |
| 599 | RendererBlinkPlatformImpl* blink_platform_impl) { |
| 600 | g_current_blink_platform_impl_for_testing = blink_platform_impl; |
| 601 | } |
| 602 | |
staraz | 067f5824 | 2016-11-07 21:06:41 | [diff] [blame] | 603 | // In single-process mode used for debugging, we don't pass a renderer client |
| 604 | // ID via command line because RenderThreadImpl lives in the same process as |
| 605 | // the browser |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 606 | RenderThreadImpl::RenderThreadImpl( |
| 607 | const InProcessChildThreadParams& params, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 608 | std::unique_ptr<blink::scheduler::RendererScheduler> scheduler, |
rockot | 97a8683 | 2016-12-10 04:53:06 | [diff] [blame] | 609 | const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 610 | : ChildThreadImpl(Options::Builder() |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 611 | .InBrowserProcess(params) |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 612 | .AutoStartServiceManagerConnection(false) |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 613 | .ConnectToBrowser(true) |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 614 | .Build()), |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 615 | renderer_scheduler_(std::move(scheduler)), |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 616 | categorized_worker_pool_(new CategorizedWorkerPool()), |
staraz | 067f5824 | 2016-11-07 21:06:41 | [diff] [blame] | 617 | renderer_binding_(this), |
Lukasz Anforowicz | 5a02412 | 2017-07-19 21:31:57 | [diff] [blame] | 618 | client_id_(1) { |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 619 | Init(resource_task_queue); |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 622 | // When we run plugins in process, we actually run them on the render thread, |
| 623 | // which means that we need to make the render thread pump UI events. |
haraken | 53f081d | 2014-11-11 01:03:40 | [diff] [blame] | 624 | RenderThreadImpl::RenderThreadImpl( |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 625 | std::unique_ptr<base::MessageLoop> main_message_loop, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 626 | std::unique_ptr<blink::scheduler::RendererScheduler> scheduler) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 627 | : ChildThreadImpl(Options::Builder() |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 628 | .AutoStartServiceManagerConnection(false) |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 629 | .ConnectToBrowser(true) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 630 | .Build()), |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 631 | renderer_scheduler_(std::move(scheduler)), |
| 632 | main_message_loop_(std::move(main_message_loop)), |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 633 | categorized_worker_pool_(new CategorizedWorkerPool()), |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 634 | is_scroll_animator_enabled_(false), |
Lukasz Anforowicz | 5a02412 | 2017-07-19 21:31:57 | [diff] [blame] | 635 | renderer_binding_(this) { |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 636 | scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; |
staraz | 067f5824 | 2016-11-07 21:06:41 | [diff] [blame] | 637 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 638 | switches::kRendererClientId)); |
| 639 | base::StringToInt(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 640 | switches::kRendererClientId), |
| 641 | &client_id_); |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 642 | Init(test_task_counter); |
haraken | 53f081d | 2014-11-11 01:03:40 | [diff] [blame] | 643 | } |
| 644 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 645 | void RenderThreadImpl::Init( |
rockot | 97a8683 | 2016-12-10 04:53:06 | [diff] [blame] | 646 | const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { |
fdoray | f6d8624 | 2015-10-08 16:49:53 | [diff] [blame] | 647 | TRACE_EVENT0("startup", "RenderThreadImpl::Init"); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 648 | |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 649 | base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex( |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 650 | base::PlatformThread::CurrentId(), |
| 651 | kTraceEventRendererMainThreadSortIndex); |
| 652 | |
thakis | 18e42641 | 2017-03-15 12:06:37 | [diff] [blame] | 653 | #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) |
sievers | 9dff7205 | 2015-11-16 18:35:57 | [diff] [blame] | 654 | // On Mac and Android Java UI, the select popups are rendered by the browser. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 655 | blink::WebView::SetUseExternalPopupMenus(true); |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 656 | #endif |
| 657 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 658 | lazy_tls.Pointer()->Set(this); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 659 | |
[email protected] | 06c694d | 2012-02-01 22:26:16 | [diff] [blame] | 660 | // Register this object as the main thread. |
| 661 | ChildProcess::current()->set_main_thread(this); |
| 662 | |
dalecurtis | 4a9839a | 2017-05-04 23:40:47 | [diff] [blame] | 663 | metrics::InitializeSingleSampleMetricsFactory( |
| 664 | base::BindRepeating(&CreateSingleSampleMetricsProvider, |
| 665 | message_loop()->task_runner(), GetConnector())); |
| 666 | |
ben | 649b3edd | 2017-03-23 00:32:02 | [diff] [blame] | 667 | gpu_ = ui::Gpu::Create( |
| 668 | GetConnector(), |
| 669 | IsRunningInMash() ? ui::mojom::kServiceName : mojom::kBrowserServiceName, |
| 670 | GetIOTaskRunner()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 671 | |
Gary Klassen | b7868627 | 2017-08-11 22:38:13 | [diff] [blame] | 672 | viz::mojom::SharedBitmapAllocationNotifierPtr |
danakj | 9242985 | 2017-06-29 00:19:03 | [diff] [blame] | 673 | shared_bitmap_allocation_notifier_ptr; |
Saman Sami | 9b76854 | 2017-07-14 20:42:34 | [diff] [blame] | 674 | GetConnector()->BindInterface( |
| 675 | mojom::kBrowserServiceName, |
danakj | 9242985 | 2017-06-29 00:19:03 | [diff] [blame] | 676 | mojo::MakeRequest(&shared_bitmap_allocation_notifier_ptr)); |
| 677 | shared_bitmap_manager_ = base::MakeUnique<viz::ClientSharedBitmapManager>( |
Gary Klassen | b7868627 | 2017-08-11 22:38:13 | [diff] [blame] | 678 | viz::mojom::ThreadSafeSharedBitmapAllocationNotifierPtr::Create( |
danakj | 9242985 | 2017-06-29 00:19:03 | [diff] [blame] | 679 | shared_bitmap_allocation_notifier_ptr.PassInterface(), |
| 680 | GetChannel()->ipc_task_runner_refptr())); |
jcivelli | 0f21bd5 | 2016-12-07 21:21:33 | [diff] [blame] | 681 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 682 | InitializeWebKit(resource_task_queue); |
| 683 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 684 | // In single process the single process is all there is. |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 685 | webkit_shared_timer_suspended_ = false; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 686 | widget_count_ = 0; |
| 687 | hidden_widget_count_ = 0; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 688 | idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 689 | idle_notifications_to_skip_ = 0; |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 690 | |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 691 | appcache_dispatcher_.reset( |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 692 | new AppCacheDispatcher(Get(), new AppCacheFrontendImpl())); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 693 | dom_storage_dispatcher_.reset(new DomStorageDispatcher()); |
reillyg | 39fb466 | 2016-11-22 20:27:17 | [diff] [blame] | 694 | main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 695 | main_thread_cache_storage_dispatcher_.reset( |
jsbell | 279efb4 | 2015-03-31 17:02:46 | [diff] [blame] | 696 | new CacheStorageDispatcher(thread_safe_sender())); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 697 | |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 698 | // Note: This may reorder messages from the ResourceDispatcher with respect to |
| 699 | // other subsystems. |
| 700 | resource_dispatch_throttler_.reset(new ResourceDispatchThrottler( |
| 701 | static_cast<RenderThread*>(this), renderer_scheduler_.get(), |
| 702 | base::TimeDelta::FromSecondsD(kThrottledResourceRequestFlushPeriodS), |
| 703 | kMaxResourceRequestsPerFlushWhenThrottled)); |
| 704 | resource_dispatcher()->set_message_sender(resource_dispatch_throttler_.get()); |
| 705 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 706 | blob_message_filter_ = new BlobMessageFilter(GetFileThreadTaskRunner()); |
dmurph | 1fb9848 | 2016-03-30 21:14:26 | [diff] [blame] | 707 | AddFilter(blob_message_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 708 | db_message_filter_ = new DBMessageFilter(); |
| 709 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 710 | |
[email protected] | 4504807 | 2014-01-14 13:51:29 | [diff] [blame] | 711 | vc_manager_.reset(new VideoCaptureImplManager()); |
[email protected] | c9c43a0 | 2013-12-17 08:59:54 | [diff] [blame] | 712 | |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 713 | browser_plugin_manager_.reset(new BrowserPluginManager()); |
| 714 | AddObserver(browser_plugin_manager_.get()); |
| 715 | |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 716 | #if BUILDFLAG(ENABLE_WEBRTC) |
[email protected] | af08997 | 2013-01-10 04:04:40 | [diff] [blame] | 717 | peer_connection_tracker_.reset(new PeerConnectionTracker()); |
| 718 | AddObserver(peer_connection_tracker_.get()); |
| 719 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 720 | p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOTaskRunner().get()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 721 | AddFilter(p2p_socket_dispatcher_.get()); |
[email protected] | 921480f6 | 2013-07-20 03:42:57 | [diff] [blame] | 722 | |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 723 | peer_connection_factory_.reset( |
| 724 | new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get())); |
| 725 | |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 726 | aec_dump_message_filter_ = new AecDumpMessageFilter( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 727 | GetIOTaskRunner(), message_loop()->task_runner()); |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 728 | |
[email protected] | da9f30a | 2014-06-18 19:39:04 | [diff] [blame] | 729 | AddFilter(aec_dump_message_filter_.get()); |
| 730 | |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 731 | #endif // BUILDFLAG(ENABLE_WEBRTC) |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 732 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 733 | audio_input_message_filter_ = new AudioInputMessageFilter(GetIOTaskRunner()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 734 | AddFilter(audio_input_message_filter_.get()); |
| 735 | |
Max Morin | d4c4887d | 2017-06-08 07:41:34 | [diff] [blame] | 736 | scoped_refptr<AudioMessageFilter> audio_message_filter; |
| 737 | if (!base::FeatureList::IsEnabled( |
| 738 | features::kUseMojoAudioOutputStreamFactory)) { |
| 739 | // In case we shouldn't use mojo factories, we need to create an |
| 740 | // AudioMessageFilter which |audio_ipc_factory_| can use for IPC. |
| 741 | audio_message_filter = |
| 742 | base::MakeRefCounted<AudioMessageFilter>(GetIOTaskRunner()); |
| 743 | AddFilter(audio_message_filter.get()); |
| 744 | } |
| 745 | |
maxmorin | 017ba8c6 | 2017-06-02 10:23:09 | [diff] [blame] | 746 | audio_ipc_factory_.emplace(std::move(audio_message_filter), |
| 747 | GetIOTaskRunner()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 748 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 749 | midi_message_filter_ = new MidiMessageFilter(GetIOTaskRunner()); |
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 750 | AddFilter(midi_message_filter_.get()); |
| 751 | |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 752 | AddFilter((new CacheStorageMessageFilter(thread_safe_sender()))->GetFilter()); |
| 753 | |
kinuko | 5af4ffe | 2015-06-09 03:38:46 | [diff] [blame] | 754 | AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter()); |
[email protected] | ddbb5334 | 2014-01-06 10:59:47 | [diff] [blame] | 755 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 756 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 757 | if (IsRunningInMash()) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 758 | CreateRenderWidgetWindowTreeClientFactory(GetServiceManagerConnection()); |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 759 | } |
| 760 | #endif |
| 761 | |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 762 | auto registry = base::MakeUnique<service_manager::BinderRegistryWithArgs< |
| 763 | const service_manager::BindSourceInfo&>>(); |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 764 | registry->AddInterface(base::Bind(&CreateFrameFactory), |
| 765 | base::ThreadTaskRunnerHandle::Get()); |
Matt Falkenhagen | 38ab68b | 2017-06-28 08:33:23 | [diff] [blame] | 766 | registry->AddInterface(base::Bind(&EmbeddedWorkerInstanceClientImpl::Create, |
Makoto Shimazu | 166906a | 2017-07-12 06:04:01 | [diff] [blame] | 767 | base::TimeTicks::Now(), GetIOTaskRunner()), |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 768 | base::ThreadTaskRunnerHandle::Get()); |
| 769 | GetServiceManagerConnection()->AddConnectionFilter( |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 770 | base::MakeUnique<SimpleConnectionFilterWithSourceInfo>( |
| 771 | std::move(registry))); |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 772 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 773 | GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 774 | |
ben | bd9dc80 | 2017-04-19 01:37:43 | [diff] [blame] | 775 | StartServiceManagerConnection(); |
| 776 | |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 777 | GetAssociatedInterfaceRegistry()->AddInterface( |
| 778 | base::Bind(&RenderThreadImpl::OnRendererInterfaceRequest, |
| 779 | base::Unretained(this))); |
| 780 | |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 781 | InitSkiaEventTracer(); |
ssid | 59c96916 | 2015-07-28 13:02:58 | [diff] [blame] | 782 | base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
primiano | 186d6bfe | 2015-10-30 13:21:40 | [diff] [blame] | 783 | skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr); |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 784 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 785 | const base::CommandLine& command_line = |
| 786 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | e54ab49 | 2012-06-12 19:40:01 | [diff] [blame] | 787 | |
ochang | dd89a1e | 2016-06-08 16:39:01 | [diff] [blame] | 788 | #if defined(ENABLE_IPC_FUZZER) |
| 789 | if (command_line.HasSwitch(switches::kIpcDumpDirectory)) { |
| 790 | base::FilePath dump_directory = |
| 791 | command_line.GetSwitchValuePath(switches::kIpcDumpDirectory); |
| 792 | IPC::ChannelProxy::OutgoingMessageFilter* filter = |
| 793 | LoadExternalIPCDumper(dump_directory); |
| 794 | GetChannel()->set_outgoing_message_filter(filter); |
| 795 | } |
| 796 | #endif |
| 797 | |
jbroman | 0d30216 | 2015-09-05 05:46:23 | [diff] [blame] | 798 | cc::SetClientNameForMetrics("Renderer"); |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 799 | |
loyso | 65c93c60 | 2015-08-11 05:15:57 | [diff] [blame] | 800 | is_threaded_animation_enabled_ = |
| 801 | !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation); |
| 802 | |
reveman | 91a0a87 | 2014-11-04 03:40:32 | [diff] [blame] | 803 | is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy); |
ericrk | 1d17f75 | 2015-10-20 03:03:07 | [diff] [blame] | 804 | is_partial_raster_enabled_ = |
dongseong.hwang | 23db47f | 2016-03-08 07:50:02 | [diff] [blame] | 805 | !command_line.HasSwitch(switches::kDisablePartialRaster); |
ccameron | c7fcd13 | 2015-11-03 20:14:31 | [diff] [blame] | 806 | is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch( |
| 807 | switches::kEnableGpuMemoryBufferCompositorResources); |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 808 | |
jam | e1f453c | 2016-03-21 15:51:34 | [diff] [blame] | 809 | #if defined(OS_MACOSX) |
lgrey | 023fd36 | 2017-06-08 19:20:52 | [diff] [blame] | 810 | if (base::Process::IsAppNapEnabled()) { |
| 811 | AppNapActivity::InitializeAppNapSupport(); |
| 812 | } |
Greg Kerr | a7b943b | 2017-07-24 23:17:17 | [diff] [blame] | 813 | #endif |
| 814 | |
| 815 | // On macOS this value is adjusted in `UpdateScrollbarTheme()`, |
| 816 | // but the system default is true. |
| 817 | #if defined(OS_MACOSX) |
| 818 | is_elastic_overscroll_enabled_ = true; |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 819 | #else |
| 820 | is_elastic_overscroll_enabled_ = false; |
| 821 | #endif |
| 822 | |
danakj | e6eb185c | 2015-02-27 23:52:05 | [diff] [blame] | 823 | std::string image_texture_target_string = |
dcastagna | 7f2f719 | 2015-06-16 18:44:35 | [diff] [blame] | 824 | command_line.GetSwitchValueASCII(switches::kContentImageTextureTarget); |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 825 | buffer_to_texture_target_map_ = |
Fady Samuel | 1d744b2 | 2017-07-10 21:23:55 | [diff] [blame] | 826 | viz::StringToBufferToTextureTargetMap(image_texture_target_string); |
reveman | 44b807f1 | 2014-11-26 02:44:50 | [diff] [blame] | 827 | |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 828 | if (command_line.HasSwitch(switches::kDisableLCDText)) { |
| 829 | is_lcd_text_enabled_ = false; |
| 830 | } else if (command_line.HasSwitch(switches::kEnableLCDText)) { |
| 831 | is_lcd_text_enabled_ = true; |
| 832 | } else { |
| 833 | #if defined(OS_ANDROID) |
| 834 | is_lcd_text_enabled_ = false; |
| 835 | #else |
| 836 | is_lcd_text_enabled_ = true; |
| 837 | #endif |
| 838 | } |
| 839 | |
[email protected] | b8d82c2 | 2014-03-31 20:12:46 | [diff] [blame] | 840 | is_gpu_rasterization_forced_ = |
| 841 | command_line.HasSwitch(switches::kForceGpuRasterization); |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 842 | is_async_worker_context_enabled_ = |
| 843 | command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext); |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 844 | |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 845 | if (command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) { |
| 846 | std::string string_value = command_line.GetSwitchValueASCII( |
| 847 | switches::kGpuRasterizationMSAASampleCount); |
| 848 | bool parsed_msaa_sample_count = |
| 849 | base::StringToInt(string_value, &gpu_rasterization_msaa_sample_count_); |
| 850 | DCHECK(parsed_msaa_sample_count) << string_value; |
| 851 | DCHECK_GE(gpu_rasterization_msaa_sample_count_, 0); |
| 852 | } else { |
senorblanco | 2a5b0e1 | 2015-08-14 21:55:37 | [diff] [blame] | 853 | gpu_rasterization_msaa_sample_count_ = -1; |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | b242b14 | 2014-05-07 14:48:49 | [diff] [blame] | 856 | if (command_line.HasSwitch(switches::kDisableDistanceFieldText)) { |
| 857 | is_distance_field_text_enabled_ = false; |
| 858 | } else if (command_line.HasSwitch(switches::kEnableDistanceFieldText)) { |
| 859 | is_distance_field_text_enabled_ = true; |
| 860 | } else { |
| 861 | is_distance_field_text_enabled_ = false; |
| 862 | } |
| 863 | |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 864 | // Note that under Linux, the media library will normally already have |
| 865 | // been initialized by the Zygote before this instance became a Renderer. |
chcunningham | fd11b3c | 2015-06-09 02:09:42 | [diff] [blame] | 866 | media::InitializeMediaLibrary(); |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 867 | |
dalecurtis | 88af393 | 2016-02-20 00:12:20 | [diff] [blame] | 868 | #if defined(OS_ANDROID) |
| 869 | if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
| 870 | media::MediaCodecUtil::IsMediaCodecAvailable()) { |
| 871 | media::EnablePlatformDecoderSupport(); |
| 872 | } |
| 873 | #endif |
| 874 | |
bashi | 296ebda | 2017-03-28 03:27:09 | [diff] [blame] | 875 | memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 876 | base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 877 | base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 878 | base::Unretained(this)))); |
| 879 | |
| 880 | if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 881 | // Disable MemoryPressureListener when memory coordinator is enabled. |
| 882 | base::MemoryPressureListener::SetNotificationsSuppressed(true); |
| 883 | |
| 884 | // TODO(bashi): Revisit how to manage the lifetime of |
| 885 | // ChildMemoryCoordinatorImpl. |
| 886 | // https://codereview.chromium.org/2094583002/#msg52 |
| 887 | mojom::MemoryCoordinatorHandlePtr parent_coordinator; |
| 888 | GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 889 | mojo::MakeRequest(&parent_coordinator)); |
| 890 | memory_coordinator_ = CreateChildMemoryCoordinator( |
| 891 | std::move(parent_coordinator), this); |
| 892 | } |
| 893 | |
danakj | 16275d4c | 2015-06-11 19:23:51 | [diff] [blame] | 894 | int num_raster_threads = 0; |
| 895 | std::string string_value = |
| 896 | command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 897 | bool parsed_num_raster_threads = |
| 898 | base::StringToInt(string_value, &num_raster_threads); |
| 899 | DCHECK(parsed_num_raster_threads) << string_value; |
| 900 | DCHECK_GT(num_raster_threads, 0); |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 901 | |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 902 | categorized_worker_pool_->Start(num_raster_threads); |
[email protected] | 1e1d1e1 | 2014-01-17 16:14:29 | [diff] [blame] | 903 | |
penghuang | 342762b | 2016-12-02 21:04:58 | [diff] [blame] | 904 | discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr; |
penghuang | d6843e4 | 2016-12-17 13:57:20 | [diff] [blame] | 905 | if (IsRunningInMash()) { |
| 906 | #if defined(USE_AURA) |
ben | bd3c248 | 2017-01-07 05:48:21 | [diff] [blame] | 907 | GetServiceManagerConnection()->GetConnector()->BindInterface( |
penghuang | d6843e4 | 2016-12-17 13:57:20 | [diff] [blame] | 908 | ui::mojom::kServiceName, &manager_ptr); |
| 909 | #else |
| 910 | NOTREACHED(); |
| 911 | #endif |
| 912 | } else { |
ben | 649b3edd | 2017-03-23 00:32:02 | [diff] [blame] | 913 | ChildThread::Get()->GetConnector()->BindInterface( |
| 914 | mojom::kBrowserServiceName, mojo::MakeRequest(&manager_ptr)); |
penghuang | d6843e4 | 2016-12-17 13:57:20 | [diff] [blame] | 915 | } |
| 916 | |
penghuang | 342762b | 2016-12-02 21:04:58 | [diff] [blame] | 917 | discardable_shared_memory_manager_ = base::MakeUnique< |
| 918 | discardable_memory::ClientDiscardableSharedMemoryManager>( |
| 919 | std::move(manager_ptr), GetIOTaskRunner()); |
| 920 | |
boliu | 9760e21 | 2015-06-23 22:49:06 | [diff] [blame] | 921 | // TODO(boliu): In single process, browser main loop should set up the |
| 922 | // discardable memory manager, and should skip this if kSingleProcess. |
| 923 | // See crbug.com/503724. |
| 924 | base::DiscardableMemoryAllocator::SetInstance( |
penghuang | 342762b | 2016-12-02 21:04:58 | [diff] [blame] | 925 | discardable_shared_memory_manager_.get()); |
reveman | cb5a66af | 2014-10-25 00:34:39 | [diff] [blame] | 926 | |
ben | 649b3edd | 2017-03-23 00:32:02 | [diff] [blame] | 927 | GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 928 | mojo::MakeRequest(&storage_partition_service_)); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 929 | |
reveman | 7b97c32 | 2016-09-20 02:10:58 | [diff] [blame] | 930 | #if defined(OS_LINUX) |
| 931 | ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); |
| 932 | ChildThreadImpl::current()->SetThreadPriority( |
lukasza | 6710dbd | 2017-04-07 20:58:03 | [diff] [blame] | 933 | categorized_worker_pool_->background_worker_thread_id(), |
reveman | 7b97c32 | 2016-09-20 02:10:58 | [diff] [blame] | 934 | base::ThreadPriority::BACKGROUND); |
| 935 | #endif |
| 936 | |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 937 | process_foregrounded_count_ = 0; |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 938 | needs_to_record_first_active_paint_ = false; |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 939 | |
| 940 | base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
fdoray | 50a3834 | 2016-11-21 20:46:04 | [diff] [blame] | 941 | |
| 942 | // If this renderer doesn't run inside the browser process, enable |
| 943 | // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 944 | // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 945 | // redirection experiment concludes https://crbug.com/622400. |
| 946 | if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 947 | base::SequencedWorkerPool::EnableForProcess(); |
samans | 2040988b | 2017-04-11 23:58:35 | [diff] [blame] | 948 | |
David Benjamin | b946811c | 2017-06-26 23:34:29 | [diff] [blame] | 949 | EVP_set_buggy_rsa_parser( |
| 950 | base::FeatureList::IsEnabled(features::kBuggyRSAParser)); |
| 951 | |
samans | 2040988b | 2017-04-11 23:58:35 | [diff] [blame] | 952 | GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 953 | mojo::MakeRequest(&frame_sink_provider_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 956 | RenderThreadImpl::~RenderThreadImpl() { |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | void RenderThreadImpl::Shutdown() { |
haraken | bbfdd9f0 | 2017-01-12 07:14:04 | [diff] [blame] | 960 | // In a multi-process mode, we immediately exit the renderer. |
| 961 | // Historically we had a graceful shutdown sequence here but it was |
| 962 | // 1) a waste of performance and 2) a source of lots of complicated |
| 963 | // crashes caused by shutdown ordering. Immediate exit eliminates |
| 964 | // those problems. |
cbruni | a3f655b | 2017-03-20 11:36:41 | [diff] [blame] | 965 | |
| 966 | // Give the V8 isolate a chance to dump internal stats useful for performance |
| 967 | // evaluation and debugging. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 968 | blink::MainThreadIsolate()->DumpAndResetStats(); |
cbruni | a3f655b | 2017-03-20 11:36:41 | [diff] [blame] | 969 | |
Adithya Srinivasan | df421e8 | 2017-06-01 14:36:11 | [diff] [blame] | 970 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 971 | switches::kDumpBlinkRuntimeCallStats)) |
| 972 | blink::LogRuntimeCallStats(); |
| 973 | |
haraken | bbfdd9f0 | 2017-01-12 07:14:04 | [diff] [blame] | 974 | // In a single-process mode, we cannot call _exit(0) in Shutdown() because |
| 975 | // it will exit the process before the browser side is ready to exit. |
| 976 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 977 | switches::kSingleProcess)) |
haraken | 940efb9 | 2017-02-08 05:58:15 | [diff] [blame] | 978 | base::Process::TerminateCurrentProcessImmediately(0); |
haraken | bbfdd9f0 | 2017-01-12 07:14:04 | [diff] [blame] | 979 | } |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 980 | |
haraken | bbfdd9f0 | 2017-01-12 07:14:04 | [diff] [blame] | 981 | bool RenderThreadImpl::ShouldBeDestroyed() { |
| 982 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 983 | switches::kSingleProcess)); |
| 984 | // In a single-process mode, it is unsafe to destruct this renderer thread |
| 985 | // because we haven't run the shutdown sequence. Hence we leak the render |
| 986 | // thread. |
| 987 | // |
| 988 | // In this case, we also need to disable at-exit callbacks because some of |
| 989 | // the at-exit callbacks are expected to run after the renderer thread |
| 990 | // has been destructed. |
| 991 | base::AtExitManager::DisableAllAtExitManagers(); |
| 992 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 993 | } |
| 994 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 995 | bool RenderThreadImpl::Send(IPC::Message* msg) { |
changwan | 6ed4d43 | 2016-05-19 22:03:54 | [diff] [blame] | 996 | // There are cases where we want to pump asynchronous messages while waiting |
| 997 | // synchronously for the replies to the message to be sent here. However, this |
| 998 | // may create an opportunity for re-entrancy into WebKit and other subsystems, |
| 999 | // so we need to take care to disable callbacks, timers, and pending network |
| 1000 | // loads that could trigger such callbacks. |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 1001 | bool pumping_events = false; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 1002 | if (msg->is_sync()) { |
| 1003 | if (msg->is_caller_pumping_messages()) { |
| 1004 | pumping_events = true; |
[email protected] | 80fc08c5 | 2010-03-09 07:43:50 | [diff] [blame] | 1005 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1008 | if (pumping_events) { |
Alexander Timin | 16329088 | 2017-08-01 17:38:07 | [diff] [blame] | 1009 | renderer_scheduler_->PauseTimerQueue(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1010 | WebView::WillEnterModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1011 | } |
| 1012 | |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 1013 | bool rv = ChildThreadImpl::Send(msg); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1014 | |
| 1015 | if (pumping_events) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1016 | WebView::DidExitModalLoop(); |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 1017 | renderer_scheduler_->ResumeTimerQueue(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | return rv; |
| 1021 | } |
| 1022 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1023 | IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1024 | return channel(); |
| 1025 | } |
| 1026 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1027 | std::string RenderThreadImpl::GetLocale() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1028 | // The browser process should have passed the locale to the renderer via the |
[email protected] | dfd5365 | 2012-10-25 00:20:02 | [diff] [blame] | 1029 | // --lang command line flag. |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1030 | const base::CommandLine& parsed_command_line = |
| 1031 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1032 | const std::string& lang = |
| 1033 | parsed_command_line.GetSwitchValueASCII(switches::kLang); |
[email protected] | dfd5365 | 2012-10-25 00:20:02 | [diff] [blame] | 1034 | DCHECK(!lang.empty()); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1035 | return lang; |
| 1036 | } |
| 1037 | |
[email protected] | 07bb633 | 2012-01-21 01:07:57 | [diff] [blame] | 1038 | IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() { |
| 1039 | return sync_message_filter(); |
| 1040 | } |
| 1041 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1042 | void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) { |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 1043 | ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener); |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1044 | auto it = pending_frame_creates_.find(routing_id); |
| 1045 | if (it == pending_frame_creates_.end()) |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1046 | return; |
| 1047 | |
| 1048 | RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
| 1049 | if (!frame) |
| 1050 | return; |
| 1051 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1052 | scoped_refptr<PendingFrameCreate> create(it->second); |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 1053 | frame->BindFrame(it->second->browser_info(), it->second->TakeFrameRequest(), |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1054 | it->second->TakeInterfaceBroker()); |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1055 | pending_frame_creates_.erase(it); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1056 | } |
| 1057 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1058 | void RenderThreadImpl::RemoveRoute(int32_t routing_id) { |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 1059 | ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1060 | } |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 1061 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1062 | void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id, |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1063 | IPC::Listener* listener) { |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1064 | AddRoute(routing_id, listener); |
| 1065 | if (devtools_agent_message_filter_.get()) { |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1066 | devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1067 | routing_id); |
| 1068 | } |
| 1069 | } |
| 1070 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1071 | void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) { |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1072 | RemoveRoute(routing_id); |
| 1073 | if (devtools_agent_message_filter_.get()) { |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1074 | devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1075 | routing_id); |
| 1076 | } |
| 1077 | } |
| 1078 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1079 | void RenderThreadImpl::RegisterPendingFrameCreate( |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 1080 | const service_manager::BindSourceInfo& browser_info, |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1081 | int routing_id, |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1082 | mojom::FrameRequest frame_request, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1083 | mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker) { |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1084 | std::pair<PendingFrameCreateMap::iterator, bool> result = |
| 1085 | pending_frame_creates_.insert(std::make_pair( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1086 | routing_id, make_scoped_refptr(new PendingFrameCreate( |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 1087 | browser_info, routing_id, std::move(frame_request), |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1088 | std::move(frame_host_interface_broker))))); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1089 | CHECK(result.second) << "Inserting a duplicate item."; |
| 1090 | } |
| 1091 | |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 1092 | mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() { |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 1093 | return storage_partition_service_.get(); |
| 1094 | } |
| 1095 | |
jam | 188f19f | 2017-06-07 03:56:24 | [diff] [blame] | 1096 | mojom::RendererHost* RenderThreadImpl::GetRendererHost() { |
| 1097 | if (!renderer_host_) { |
| 1098 | GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 1099 | mojo::MakeRequest(&renderer_host_)); |
| 1100 | } |
| 1101 | return renderer_host_.get(); |
| 1102 | } |
| 1103 | |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 1104 | int RenderThreadImpl::GenerateRoutingID() { |
rockot | e261d211 | 2016-09-21 22:22:23 | [diff] [blame] | 1105 | int32_t routing_id = MSG_ROUTING_NONE; |
| 1106 | render_message_filter()->GenerateRoutingID(&routing_id); |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 1107 | return routing_id; |
| 1108 | } |
| 1109 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 1110 | void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 1111 | channel()->AddFilter(filter); |
| 1112 | } |
| 1113 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 1114 | void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 1115 | channel()->RemoveFilter(filter); |
| 1116 | } |
| 1117 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1118 | void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1119 | observers_.AddObserver(observer); |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 1120 | observer->RegisterMojoInterfaces(&associated_interfaces_); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1121 | } |
| 1122 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1123 | void RenderThreadImpl::RemoveObserver(RenderThreadObserver* observer) { |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 1124 | observer->UnregisterMojoInterfaces(&associated_interfaces_); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1125 | observers_.RemoveObserver(observer); |
| 1126 | } |
| 1127 | |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 1128 | void RenderThreadImpl::SetResourceDispatcherDelegate( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1129 | ResourceDispatcherDelegate* delegate) { |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 1130 | resource_dispatcher()->set_delegate(delegate); |
| 1131 | } |
| 1132 | |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1133 | void RenderThreadImpl::InitializeCompositorThread() { |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1134 | base::Thread::Options options; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1135 | #if defined(OS_ANDROID) |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1136 | options.priority = base::ThreadPriority::DISPLAY; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1137 | #endif |
altimin | c7369bf | 2017-04-11 14:29:15 | [diff] [blame] | 1138 | compositor_thread_ = |
| 1139 | blink::scheduler::WebThreadBase::CreateCompositorThread(options); |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1140 | blink_platform_impl_->SetCompositorThread(compositor_thread_.get()); |
| 1141 | compositor_task_runner_ = compositor_thread_->GetTaskRunner(); |
| 1142 | compositor_task_runner_->PostTask( |
| 1143 | FROM_HERE, |
| 1144 | base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), false)); |
reveman | 7b97c32 | 2016-09-20 02:10:58 | [diff] [blame] | 1145 | #if defined(OS_LINUX) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1146 | ChildThreadImpl::current()->SetThreadPriority(compositor_thread_->ThreadId(), |
reveman | 7b97c32 | 2016-09-20 02:10:58 | [diff] [blame] | 1147 | base::ThreadPriority::DISPLAY); |
| 1148 | #endif |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1149 | |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1150 | SynchronousInputHandlerProxyClient* synchronous_input_handler_proxy_client = |
| 1151 | nullptr; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1152 | #if defined(OS_ANDROID) |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1153 | if (GetContentClient()->UsingSynchronousCompositing()) { |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1154 | sync_compositor_message_filter_ = |
| 1155 | new SynchronousCompositorFilter(compositor_task_runner_); |
| 1156 | AddFilter(sync_compositor_message_filter_.get()); |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1157 | synchronous_input_handler_proxy_client = |
| 1158 | sync_compositor_message_filter_.get(); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1159 | } |
| 1160 | #endif |
boliu | b2768db | 2016-06-03 23:35:16 | [diff] [blame] | 1161 | scoped_refptr<InputEventFilter> compositor_input_event_filter( |
| 1162 | new InputEventFilter(main_input_callback_.callback(), |
| 1163 | main_thread_compositor_task_runner_, |
| 1164 | compositor_task_runner_)); |
| 1165 | InputHandlerManagerClient* input_handler_manager_client = |
| 1166 | compositor_input_event_filter.get(); |
| 1167 | input_event_filter_ = compositor_input_event_filter; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1168 | input_handler_manager_.reset(new InputHandlerManager( |
| 1169 | compositor_task_runner_, input_handler_manager_client, |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1170 | synchronous_input_handler_proxy_client, renderer_scheduler_.get())); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1171 | } |
| 1172 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1173 | void RenderThreadImpl::InitializeWebKit( |
rockot | 97a8683 | 2016-12-10 04:53:06 | [diff] [blame] | 1174 | const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1175 | DCHECK(!blink_platform_impl_); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1176 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1177 | const base::CommandLine& command_line = |
| 1178 | *base::CommandLine::ForCurrentProcess(); |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 1179 | |
| 1180 | #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 1181 | if (command_line.HasSwitch(switches::kEnableVtune)) |
| 1182 | gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler()); |
| 1183 | #endif |
| 1184 | |
Lukasz Anforowicz | 5a02412 | 2017-07-19 21:31:57 | [diff] [blame] | 1185 | blink_platform_impl_.reset(new RendererBlinkPlatformImpl( |
| 1186 | renderer_scheduler_.get(), GetConnector()->GetWeakPtr())); |
rmcilroy | 4073ae1 | 2015-01-08 13:08:10 | [diff] [blame] | 1187 | SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line); |
hlopko | 852ffcf | 2016-09-16 16:50:59 | [diff] [blame] | 1188 | GetContentClient() |
| 1189 | ->renderer() |
| 1190 | ->SetRuntimeFeaturesDefaultsBeforeBlinkInitialization(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1191 | blink::Initialize(blink_platform_impl_.get()); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1192 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1193 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 1194 | isolate->SetCreateHistogramFunction(CreateHistogram); |
| 1195 | isolate->SetAddHistogramSampleFunction(AddHistogramSample); |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 1196 | renderer_scheduler_->SetRAILModeObserver(this); |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 1197 | |
rmcilroy | 321f924d | 2014-11-06 00:56:00 | [diff] [blame] | 1198 | main_thread_compositor_task_runner_ = |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1199 | renderer_scheduler_->CompositorTaskRunner(); |
skyostil | c30aa40 | 2014-10-10 13:49:09 | [diff] [blame] | 1200 | |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 1201 | main_input_callback_.Reset( |
| 1202 | base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived), |
| 1203 | base::Unretained(this))); |
| 1204 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1205 | scoped_refptr<base::SingleThreadTaskRunner> resource_task_queue2; |
| 1206 | if (resource_task_queue) { |
| 1207 | resource_task_queue2 = resource_task_queue; |
| 1208 | } else { |
| 1209 | resource_task_queue2 = renderer_scheduler_->LoadingTaskRunner(); |
| 1210 | } |
| 1211 | // Add a filter that forces resource messages to be dispatched via a |
| 1212 | // particular task runner. |
| 1213 | scoped_refptr<ResourceSchedulingFilter> filter( |
| 1214 | new ResourceSchedulingFilter( |
| 1215 | resource_task_queue2, resource_dispatcher())); |
| 1216 | channel()->AddFilter(filter.get()); |
| 1217 | resource_dispatcher()->SetResourceSchedulingFilter(filter); |
| 1218 | |
| 1219 | // The ChildResourceMessageFilter and the ResourceDispatcher need to use the |
| 1220 | // same queue to ensure tasks are executed in the expected order. |
| 1221 | child_resource_message_filter()->SetMainThreadTaskRunner( |
| 1222 | resource_task_queue2); |
horo | e612058 | 2017-04-26 01:48:59 | [diff] [blame] | 1223 | resource_dispatcher()->SetThreadTaskRunner(resource_task_queue2); |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1224 | |
khushalsagar | d7178e4 | 2017-01-20 01:31:49 | [diff] [blame] | 1225 | if (!command_line.HasSwitch(switches::kDisableThreadedCompositing)) |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1226 | InitializeCompositorThread(); |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 1227 | |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 1228 | if (!input_event_filter_.get()) { |
| 1229 | // Always provide an input event filter implementation to ensure consistent |
| 1230 | // input event scheduling and prioritization. |
| 1231 | // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and |
| 1232 | // MainThreadInputEventFilter, crbug.com/436057. |
| 1233 | input_event_filter_ = new MainThreadInputEventFilter( |
| 1234 | main_input_callback_.callback(), main_thread_compositor_task_runner_); |
| 1235 | } |
| 1236 | AddFilter(input_event_filter_.get()); |
| 1237 | |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1238 | scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1239 | if (compositor_task_runner_) |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1240 | compositor_impl_side_task_runner = compositor_task_runner_; |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 1241 | else |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1242 | compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get(); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1243 | |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 1244 | compositor_message_filter_ = new CompositorForwardingMessageFilter( |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1245 | compositor_impl_side_task_runner.get()); |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 1246 | AddFilter(compositor_message_filter_.get()); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1247 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1248 | RenderThreadImpl::RegisterSchemes(); |
| 1249 | |
xhwang | 194acae | 2014-11-12 22:46:33 | [diff] [blame] | 1250 | RenderMediaClient::Initialize(); |
| 1251 | |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 1252 | devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 1253 | AddFilter(devtools_agent_message_filter_.get()); |
| 1254 | |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 1255 | if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1256 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 1257 | } else { |
| 1258 | // If we do not track widget visibility, then assume conservatively that |
| 1259 | // the isolate is in background. This reduces memory usage. |
| 1260 | isolate->IsolateInBackgroundNotification(); |
| 1261 | } |
[email protected] | 2541d1a | 2013-07-10 07:33:27 | [diff] [blame] | 1262 | |
Alexander Timin | 16329088 | 2017-08-01 17:38:07 | [diff] [blame] | 1263 | renderer_scheduler_->SetTimerQueueStoppingWhenBackgroundedEnabled( |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1264 | GetContentClient() |
| 1265 | ->renderer() |
Alexander Timin | 16329088 | 2017-08-01 17:38:07 | [diff] [blame] | 1266 | ->AllowStoppingTimersWhenProcessBackgrounded()); |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1267 | |
reed | ccf98c5 | 2014-10-03 16:40:38 | [diff] [blame] | 1268 | SkGraphics::SetResourceCacheSingleAllocationByteLimit( |
[email protected] | dd2c102 | 2014-07-22 23:13:57 | [diff] [blame] | 1269 | kImageCacheSingleAllocationByteLimit); |
| 1270 | |
reed | 6e5a7222 | 2015-08-06 20:37:16 | [diff] [blame] | 1271 | // Hook up blink's codecs so skia can call them |
reed | 08cd1637 | 2017-02-21 22:11:41 | [diff] [blame] | 1272 | SkGraphics::SetImageGeneratorFromEncodedDataFactory( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1273 | blink::WebImageGenerator::Create); |
reed | 6e5a7222 | 2015-08-06 20:37:16 | [diff] [blame] | 1274 | |
paritosh.in | 7e30c90 | 2015-04-15 17:04:07 | [diff] [blame] | 1275 | if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { |
| 1276 | std::string allowed_ports = |
| 1277 | command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); |
| 1278 | net::SetExplicitlyAllowedPorts(allowed_ports); |
| 1279 | } |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1280 | } |
| 1281 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1282 | void RenderThreadImpl::RegisterSchemes() { |
mkwst | 8e94fb3 | 2015-05-20 05:05:14 | [diff] [blame] | 1283 | // chrome: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1284 | WebString chrome_scheme(WebString::FromASCII(kChromeUIScheme)); |
| 1285 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(chrome_scheme); |
| 1286 | WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs( |
mkwst | 8e94fb3 | 2015-05-20 05:05:14 | [diff] [blame] | 1287 | chrome_scheme); |
mkwst | 8e94fb3 | 2015-05-20 05:05:14 | [diff] [blame] | 1288 | |
| 1289 | // chrome-devtools: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1290 | WebString devtools_scheme(WebString::FromASCII(kChromeDevToolsScheme)); |
| 1291 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(devtools_scheme); |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 1292 | |
| 1293 | // view-source: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1294 | WebString view_source_scheme(WebString::FromASCII(kViewSourceScheme)); |
| 1295 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(view_source_scheme); |
Alex Moshchuk | 71f48559 | 2017-08-16 16:20:00 | [diff] [blame^] | 1296 | |
| 1297 | // chrome-error: |
| 1298 | WebString error_scheme(WebString::FromASCII(kChromeErrorScheme)); |
| 1299 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(error_scheme); |
| 1300 | WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(error_scheme); |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1301 | } |
| 1302 | |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 1303 | void RenderThreadImpl::RecordAction(const base::UserMetricsAction& action) { |
[email protected] | 97880c8 | 2013-12-04 07:09:21 | [diff] [blame] | 1304 | Send(new ViewHostMsg_UserMetricsRecordAction(action.str_)); |
| 1305 | } |
| 1306 | |
| 1307 | void RenderThreadImpl::RecordComputedAction(const std::string& action) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1308 | Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
| 1309 | } |
| 1310 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1311 | std::unique_ptr<base::SharedMemory> |
| 1312 | RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) { |
sadrul | ee3ff1f | 2016-12-09 04:22:01 | [diff] [blame] | 1313 | return ChildThreadImpl::AllocateSharedMemory(size); |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 1314 | } |
| 1315 | |
Fady Samuel | 4b5f986 | 2017-07-11 05:27:20 | [diff] [blame] | 1316 | viz::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() { |
jbauman | 2f5c194 | 2014-12-06 03:28:24 | [diff] [blame] | 1317 | return shared_bitmap_manager(); |
| 1318 | } |
| 1319 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1320 | void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1321 | WebScriptController::RegisterExtension(extension); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1322 | } |
| 1323 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1324 | void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1325 | idle_notification_delay_in_ms_ = initial_delay_ms; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1326 | idle_timer_.Stop(); |
| 1327 | idle_timer_.Start(FROM_HERE, |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1328 | base::TimeDelta::FromMilliseconds(initial_delay_ms), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1329 | this, &RenderThreadImpl::IdleHandler); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1330 | } |
| 1331 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1332 | void RenderThreadImpl::IdleHandler() { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1333 | bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1334 | GetContentClient()->renderer()-> |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1335 | RunIdleHandlerWhenWidgetsHidden(); |
| 1336 | if (run_in_foreground_tab) { |
jochen | 5a32aaf | 2014-09-26 20:37:43 | [diff] [blame] | 1337 | if (idle_notifications_to_skip_ > 0) { |
| 1338 | --idle_notifications_to_skip_; |
| 1339 | } else { |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 1340 | ReleaseFreeMemory(); |
jochen | 5a32aaf | 2014-09-26 20:37:43 | [diff] [blame] | 1341 | } |
| 1342 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1343 | return; |
| 1344 | } |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 1345 | |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 1346 | ReleaseFreeMemory(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1347 | |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1348 | // Continue the idle timer if the webkit shared timer is not suspended or |
| 1349 | // something is left to do. |
| 1350 | bool continue_timer = !webkit_shared_timer_suspended_; |
| 1351 | |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1352 | // Schedule next invocation. When the tab is originally hidden, an invocation |
| 1353 | // is scheduled for kInitialIdleHandlerDelayMs in |
| 1354 | // RenderThreadImpl::WidgetHidden in order to race to a minimal heap. |
| 1355 | // After that, idle calls can be much less frequent, so run at a maximum of |
| 1356 | // once every kLongIdleHandlerDelayMs. |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1357 | // Dampen the delay using the algorithm (if delay is in seconds): |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1358 | // delay = delay + 1 / (delay + 2) |
| 1359 | // Using floor(delay) has a dampening effect such as: |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1360 | // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ... |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1361 | // If the delay is in milliseconds, the above formula is equivalent to: |
| 1362 | // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
| 1363 | // which is equivalent to |
| 1364 | // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1365 | if (continue_timer) { |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1366 | ScheduleIdleHandler( |
| 1367 | std::max(kLongIdleHandlerDelayMs, |
| 1368 | idle_notification_delay_in_ms_ + |
| 1369 | 1000000 / (idle_notification_delay_in_ms_ + 2000))); |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1370 | |
| 1371 | } else { |
| 1372 | idle_timer_.Stop(); |
| 1373 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1374 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1375 | for (auto& observer : observers_) |
| 1376 | observer.IdleNotification(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1377 | } |
| 1378 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1379 | int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1380 | return idle_notification_delay_in_ms_; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1381 | } |
| 1382 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1383 | void RenderThreadImpl::SetIdleNotificationDelayInMs( |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1384 | int64_t idle_notification_delay_in_ms) { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1385 | idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1386 | } |
| 1387 | |
[email protected] | 5b1840636 | 2013-06-18 18:46:43 | [diff] [blame] | 1388 | int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) { |
kinuko | ef64741 | 2015-12-23 06:10:43 | [diff] [blame] | 1389 | return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure); |
[email protected] | a9bd323d | 2013-06-17 20:27:56 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | b02f590 | 2012-12-19 07:33:00 | [diff] [blame] | 1392 | bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) { |
| 1393 | bool result = false; |
| 1394 | Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list)); |
| 1395 | return result; |
| 1396 | } |
| 1397 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1398 | void RenderThreadImpl::PostponeIdleNotification() { |
| 1399 | idle_notifications_to_skip_ = 2; |
| 1400 | } |
| 1401 | |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 1402 | media::GpuVideoAcceleratorFactories* RenderThreadImpl::GetGpuFactories() { |
[email protected] | 3bb8bb3 | 2013-07-11 13:13:03 | [diff] [blame] | 1403 | DCHECK(IsMainThread()); |
| 1404 | |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1405 | if (!gpu_factories_.empty()) { |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 1406 | scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider = |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1407 | gpu_factories_.back()->ContextProviderMainThread(); |
| 1408 | if (shared_context_provider) { |
Xu Xing | 3254916 | 2017-07-17 22:25:43 | [diff] [blame] | 1409 | viz::ContextProvider::ScopedContextLock lock( |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1410 | shared_context_provider.get()); |
| 1411 | if (lock.ContextGL()->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
leon.han | 21e0e48 | 2017-02-23 04:13:32 | [diff] [blame] | 1412 | return gpu_factories_.back().get(); |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1413 | } else { |
| 1414 | scoped_refptr<base::SingleThreadTaskRunner> media_task_runner = |
| 1415 | GetMediaThreadTaskRunner(); |
| 1416 | media_task_runner->PostTask( |
| 1417 | FROM_HERE, |
Miguel Casas-Sanchez | cfcca5d5 | 2017-07-07 02:32:59 | [diff] [blame] | 1418 | base::Bind(base::IgnoreResult( |
| 1419 | &GpuVideoAcceleratorFactoriesImpl::CheckContextLost), |
| 1420 | base::Unretained(gpu_factories_.back().get()))); |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | } |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 1424 | |
tobiasjs | ca238b3b | 2015-06-24 22:53:54 | [diff] [blame] | 1425 | const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 1426 | |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1427 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1428 | EstablishGpuChannelSync(); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1429 | if (!gpu_channel_host) |
| 1430 | return nullptr; |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 1431 | // This context is only used to create textures and mailbox them, so |
| 1432 | // use lower limits than the default. |
| 1433 | gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext(); |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1434 | bool support_locking = true; |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 1435 | scoped_refptr<ui::ContextProviderCommandBuffer> media_context_provider = |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1436 | CreateOffscreenContext(gpu_channel_host, limits, support_locking, |
ericrk | a20c100 | 2017-03-13 21:08:13 | [diff] [blame] | 1437 | ui::command_buffer_metrics::MEDIA_CONTEXT, |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 1438 | kGpuStreamIdDefault, kGpuStreamPriorityDefault); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1439 | if (!media_context_provider->BindToCurrentThread()) |
| 1440 | return nullptr; |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1441 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1442 | scoped_refptr<base::SingleThreadTaskRunner> media_task_runner = |
| 1443 | GetMediaThreadTaskRunner(); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1444 | const bool enable_video_accelerator = |
| 1445 | !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode); |
| 1446 | const bool enable_gpu_memory_buffer_video_frames = |
dcastagna | 43c3a86a | 2016-02-02 21:16:38 | [diff] [blame] | 1447 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
dcastagna | a82ed96a | 2016-05-12 02:52:47 | [diff] [blame] | 1448 | !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) && |
| 1449 | !cmd_line->HasSwitch(switches::kDisableGpuCompositing) && |
| 1450 | !gpu_channel_host->gpu_info().software_rendering; |
jbauman | a0bb898 | 2017-05-05 19:50:53 | [diff] [blame] | 1451 | #elif defined(OS_WIN) |
| 1452 | !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) && |
| 1453 | !cmd_line->HasSwitch(switches::kDisableGpuCompositing) && |
| 1454 | !gpu_channel_host->gpu_info().software_rendering && |
| 1455 | (cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames) || |
| 1456 | gpu_channel_host->gpu_info().supports_overlays); |
dcastagna | b65e607 | 2015-09-05 07:18:42 | [diff] [blame] | 1457 | #else |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1458 | cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames); |
dcastagna | b65e607 | 2015-09-05 07:18:42 | [diff] [blame] | 1459 | #endif |
dcastagna | 5077d6d | 2016-01-27 00:07:05 | [diff] [blame] | 1460 | |
Miguel Casas-Sanchez | 7d46470 | 2017-07-29 14:19:21 | [diff] [blame] | 1461 | media::mojom::VideoEncodeAcceleratorProviderPtr vea_provider; |
| 1462 | gpu_->CreateVideoEncodeAcceleratorProvider(mojo::MakeRequest(&vea_provider)); |
Miguel Casas-Sanchez | daca3256 | 2017-07-11 08:05:45 | [diff] [blame] | 1463 | |
Miguel Casas-Sanchez | cfcca5d5 | 2017-07-07 02:32:59 | [diff] [blame] | 1464 | gpu_factories_.push_back(GpuVideoAcceleratorFactoriesImpl::Create( |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1465 | std::move(gpu_channel_host), base::ThreadTaskRunnerHandle::Get(), |
| 1466 | media_task_runner, std::move(media_context_provider), |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 1467 | enable_gpu_memory_buffer_video_frames, buffer_to_texture_target_map_, |
Miguel Casas-Sanchez | 7d46470 | 2017-07-29 14:19:21 | [diff] [blame] | 1468 | enable_video_accelerator, vea_provider.PassInterface())); |
leon.han | 21e0e48 | 2017-02-23 04:13:32 | [diff] [blame] | 1469 | return gpu_factories_.back().get(); |
[email protected] | 3bb8bb3 | 2013-07-11 13:13:03 | [diff] [blame] | 1470 | } |
| 1471 | |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 1472 | scoped_refptr<ui::ContextProviderCommandBuffer> |
[email protected] | f10dc47 | 2013-09-27 03:31:59 | [diff] [blame] | 1473 | RenderThreadImpl::SharedMainThreadContextProvider() { |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1474 | DCHECK(IsMainThread()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1475 | if (shared_main_thread_contexts_ && |
| 1476 | shared_main_thread_contexts_->ContextGL()->GetGraphicsResetStatusKHR() == |
| 1477 | GL_NO_ERROR) |
| 1478 | return shared_main_thread_contexts_; |
| 1479 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1480 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 1481 | EstablishGpuChannelSync()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1482 | if (!gpu_channel_host) { |
| 1483 | shared_main_thread_contexts_ = nullptr; |
| 1484 | return nullptr; |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1485 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1486 | |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1487 | bool support_locking = false; |
danakj | c398355 | 2016-05-03 00:04:35 | [diff] [blame] | 1488 | shared_main_thread_contexts_ = CreateOffscreenContext( |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1489 | std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking, |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 1490 | ui::command_buffer_metrics::RENDERER_MAINTHREAD_CONTEXT, |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 1491 | kGpuStreamIdDefault, kGpuStreamPriorityDefault); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1492 | if (!shared_main_thread_contexts_->BindToCurrentThread()) |
| 1493 | shared_main_thread_contexts_ = nullptr; |
[email protected] | f10dc47 | 2013-09-27 03:31:59 | [diff] [blame] | 1494 | return shared_main_thread_contexts_; |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1495 | } |
| 1496 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1497 | #if defined(OS_ANDROID) |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1498 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1499 | scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() { |
| 1500 | DCHECK(IsMainThread()); |
boliu | 30f1b26 | 2016-04-19 00:12:33 | [diff] [blame] | 1501 | if (!stream_texture_factory_.get() || |
| 1502 | stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() != |
| 1503 | GL_NO_ERROR) { |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 1504 | scoped_refptr<ui::ContextProviderCommandBuffer> shared_context_provider = |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1505 | SharedMainThreadContextProvider(); |
| 1506 | if (!shared_context_provider) { |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1507 | stream_texture_factory_ = nullptr; |
| 1508 | return nullptr; |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1509 | } |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1510 | DCHECK(shared_context_provider->GetCommandBufferProxy()); |
| 1511 | DCHECK(shared_context_provider->GetCommandBufferProxy()->channel()); |
| 1512 | stream_texture_factory_ = |
| 1513 | StreamTextureFactory::Create(std::move(shared_context_provider)); |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1514 | } |
| 1515 | return stream_texture_factory_; |
| 1516 | } |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1517 | |
| 1518 | bool RenderThreadImpl::EnableStreamTextureCopy() { |
boliu | 30f1b26 | 2016-04-19 00:12:33 | [diff] [blame] | 1519 | return sync_compositor_message_filter_.get(); |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1520 | } |
| 1521 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1522 | #endif |
| 1523 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1524 | AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1525 | if (!audio_renderer_mixer_manager_) { |
olka | 7a467939 | 2016-05-27 15:32:58 | [diff] [blame] | 1526 | audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create(); |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | return audio_renderer_mixer_manager_.get(); |
| 1530 | } |
| 1531 | |
[email protected] | 73429ca | 2014-03-06 06:07:47 | [diff] [blame] | 1532 | base::WaitableEvent* RenderThreadImpl::GetShutdownEvent() { |
| 1533 | return ChildProcess::current()->GetShutDownEvent(); |
| 1534 | } |
| 1535 | |
staraz | 067f5824 | 2016-11-07 21:06:41 | [diff] [blame] | 1536 | int32_t RenderThreadImpl::GetClientId() { |
| 1537 | return client_id_; |
| 1538 | } |
| 1539 | |
altimin | c8885e8 | 2017-01-18 13:11:14 | [diff] [blame] | 1540 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1541 | RenderThreadImpl::GetTimerTaskRunner() { |
| 1542 | return renderer_scheduler_->TimerTaskRunner(); |
| 1543 | } |
| 1544 | |
| 1545 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1546 | RenderThreadImpl::GetLoadingTaskRunner() { |
| 1547 | return renderer_scheduler_->LoadingTaskRunner(); |
| 1548 | } |
| 1549 | |
Karan Bhatia | c89897f | 2017-08-10 01:06:40 | [diff] [blame] | 1550 | void RenderThreadImpl::SetRendererProcessType( |
| 1551 | blink::scheduler::RendererProcessType type) { |
| 1552 | renderer_scheduler_->SetRendererProcessType(type); |
| 1553 | } |
| 1554 | |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 1555 | void RenderThreadImpl::OnAssociatedInterfaceRequest( |
| 1556 | const std::string& name, |
| 1557 | mojo::ScopedInterfaceEndpointHandle handle) { |
rockot | 70bbb5949 | 2017-01-25 00:56:51 | [diff] [blame] | 1558 | if (associated_interfaces_.CanBindRequest(name)) |
| 1559 | associated_interfaces_.BindRequest(name, std::move(handle)); |
| 1560 | else |
| 1561 | ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle)); |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 1562 | } |
| 1563 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 1564 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1565 | RenderThreadImpl::GetIOTaskRunner() { |
| 1566 | return ChildProcess::current()->io_task_runner(); |
| 1567 | } |
| 1568 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1569 | bool RenderThreadImpl::IsGpuRasterizationForced() { |
| 1570 | return is_gpu_rasterization_forced_; |
| 1571 | } |
| 1572 | |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 1573 | bool RenderThreadImpl::IsAsyncWorkerContextEnabled() { |
| 1574 | return is_async_worker_context_enabled_; |
| 1575 | } |
| 1576 | |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 1577 | int RenderThreadImpl::GetGpuRasterizationMSAASampleCount() { |
| 1578 | return gpu_rasterization_msaa_sample_count_; |
| 1579 | } |
| 1580 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1581 | bool RenderThreadImpl::IsLcdTextEnabled() { |
| 1582 | return is_lcd_text_enabled_; |
| 1583 | } |
| 1584 | |
| 1585 | bool RenderThreadImpl::IsDistanceFieldTextEnabled() { |
| 1586 | return is_distance_field_text_enabled_; |
| 1587 | } |
| 1588 | |
| 1589 | bool RenderThreadImpl::IsZeroCopyEnabled() { |
| 1590 | return is_zero_copy_enabled_; |
| 1591 | } |
| 1592 | |
ericrk | 1d17f75 | 2015-10-20 03:03:07 | [diff] [blame] | 1593 | bool RenderThreadImpl::IsPartialRasterEnabled() { |
| 1594 | return is_partial_raster_enabled_; |
jbroman | 5f7f7193 | 2015-08-18 16:24:46 | [diff] [blame] | 1595 | } |
| 1596 | |
ccameron | c7fcd13 | 2015-11-03 20:14:31 | [diff] [blame] | 1597 | bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() { |
| 1598 | return is_gpu_memory_buffer_compositor_resources_enabled_; |
| 1599 | } |
| 1600 | |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 1601 | bool RenderThreadImpl::IsElasticOverscrollEnabled() { |
| 1602 | return is_elastic_overscroll_enabled_; |
| 1603 | } |
| 1604 | |
Fady Samuel | 1d744b2 | 2017-07-10 21:23:55 | [diff] [blame] | 1605 | const viz::BufferToTextureTargetMap& |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 1606 | RenderThreadImpl::GetBufferToTextureTargetMap() { |
| 1607 | return buffer_to_texture_target_map_; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1608 | } |
vmiura | 9084b34 | 2015-02-03 22:19:57 | [diff] [blame] | 1609 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1610 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1611 | RenderThreadImpl::GetCompositorMainThreadTaskRunner() { |
| 1612 | return main_thread_compositor_task_runner_; |
| 1613 | } |
| 1614 | |
| 1615 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1616 | RenderThreadImpl::GetCompositorImplThreadTaskRunner() { |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1617 | return compositor_task_runner_; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() { |
sadrul | 5354659 | 2016-12-17 01:44:21 | [diff] [blame] | 1621 | return gpu_->gpu_memory_buffer_manager(); |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1622 | } |
| 1623 | |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 1624 | blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() { |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1625 | return renderer_scheduler_.get(); |
| 1626 | } |
| 1627 | |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 1628 | std::unique_ptr<viz::BeginFrameSource> |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1629 | RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) { |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 1630 | return base::MakeUnique<CompositorExternalBeginFrameSource>( |
| 1631 | compositor_message_filter_.get(), sync_message_filter(), routing_id); |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1632 | } |
| 1633 | |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 1634 | std::unique_ptr<viz::SyntheticBeginFrameSource> |
samans | 09812d3 | 2017-03-27 19:51:50 | [diff] [blame] | 1635 | RenderThreadImpl::CreateSyntheticBeginFrameSource() { |
| 1636 | base::SingleThreadTaskRunner* compositor_impl_side_task_runner = |
| 1637 | compositor_task_runner_ ? compositor_task_runner_.get() |
| 1638 | : base::ThreadTaskRunnerHandle::Get().get(); |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 1639 | return base::MakeUnique<viz::BackToBackBeginFrameSource>( |
| 1640 | base::MakeUnique<viz::DelayBasedTimeSource>( |
samans | 09812d3 | 2017-03-27 19:51:50 | [diff] [blame] | 1641 | compositor_impl_side_task_runner)); |
| 1642 | } |
| 1643 | |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 1644 | cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() { |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 1645 | return categorized_worker_pool_->GetTaskGraphRunner(); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 1646 | } |
| 1647 | |
loyso | 65c93c60 | 2015-08-11 05:15:57 | [diff] [blame] | 1648 | bool RenderThreadImpl::IsThreadedAnimationEnabled() { |
| 1649 | return is_threaded_animation_enabled_; |
| 1650 | } |
| 1651 | |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 1652 | bool RenderThreadImpl::IsScrollAnimatorEnabled() { |
| 1653 | return is_scroll_animator_enabled_; |
| 1654 | } |
| 1655 | |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 1656 | void RenderThreadImpl::OnRAILModeChanged(v8::RAILMode rail_mode) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1657 | blink::MainThreadIsolate()->SetRAILMode(rail_mode); |
| 1658 | blink::SetRAILModeOnWorkerThreadIsolates(rail_mode); |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 1659 | } |
| 1660 | |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1661 | bool RenderThreadImpl::IsMainThread() { |
| 1662 | return !!current(); |
| 1663 | } |
| 1664 | |
torne | 88b6645 | 2016-05-03 13:22:14 | [diff] [blame] | 1665 | void RenderThreadImpl::OnChannelError() { |
| 1666 | // In single-process mode, the renderer can't be restarted after shutdown. |
| 1667 | // So, if we get a channel error, crash the whole process right now to get a |
| 1668 | // more informative stack, since we will otherwise just crash later when we |
| 1669 | // try to restart it. |
| 1670 | CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1671 | switches::kSingleProcess)); |
| 1672 | ChildThreadImpl::OnChannelError(); |
| 1673 | } |
| 1674 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1675 | bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 1676 | for (auto& observer : observers_) { |
| 1677 | if (observer.OnControlMessageReceived(msg)) |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 1678 | return true; |
| 1679 | } |
| 1680 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 1681 | // Some messages are handled by delegates. |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1682 | if (appcache_dispatcher_->OnMessageReceived(msg) || |
leon.han | 7a571438 | 2017-04-16 03:25:00 | [diff] [blame] | 1683 | dom_storage_dispatcher_->OnMessageReceived(msg)) { |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1684 | return true; |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1685 | } |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 1686 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1687 | bool handled = true; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1688 | IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 1689 | IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateNewSharedWorker) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1690 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1691 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1692 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1693 | } |
| 1694 | |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1695 | void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1696 | ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1697 | |
Alexander Timin | 771b337 | 2017-06-15 13:26:47 | [diff] [blame] | 1698 | renderer_scheduler_->SetRendererBackgrounded(backgrounded); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1699 | if (backgrounded) { |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1700 | needs_to_record_first_active_paint_ = false; |
tasak | 335a187 | 2017-06-14 09:50:23 | [diff] [blame] | 1701 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1702 | FROM_HERE, |
| 1703 | base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded, |
| 1704 | base::Unretained(this), "5min", process_foregrounded_count_), |
| 1705 | base::TimeDelta::FromMinutes(5)); |
| 1706 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1707 | FROM_HERE, |
| 1708 | base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded, |
| 1709 | base::Unretained(this), "10min", |
| 1710 | process_foregrounded_count_), |
| 1711 | base::TimeDelta::FromMinutes(10)); |
| 1712 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1713 | FROM_HERE, |
| 1714 | base::Bind(&RenderThreadImpl::RecordMemoryUsageAfterBackgrounded, |
| 1715 | base::Unretained(this), "15min", |
| 1716 | process_foregrounded_count_), |
| 1717 | base::TimeDelta::FromMinutes(15)); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1718 | } else { |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1719 | process_foregrounded_count_++; |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1724 | ChildThreadImpl::OnProcessPurgeAndSuspend(); |
tasak | 6ff4403 | 2016-11-07 06:45:25 | [diff] [blame] | 1725 | if (!RendererIsHidden()) |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1726 | return; |
tasak | ff1e6242 | 2016-12-22 04:53:55 | [diff] [blame] | 1727 | |
tasak | c4de467 | 2017-04-26 02:37:36 | [diff] [blame] | 1728 | if (!base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1729 | return; |
| 1730 | |
| 1731 | base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1732 | needs_to_record_first_active_paint_ = true; |
tasak | c4de467 | 2017-04-26 02:37:36 | [diff] [blame] | 1733 | |
| 1734 | RendererMemoryMetrics memory_metrics; |
| 1735 | if (!GetRendererMemoryMetrics(&memory_metrics)) |
| 1736 | return; |
| 1737 | |
| 1738 | purge_and_suspend_memory_metrics_ = memory_metrics; |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1739 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1740 | FROM_HERE, |
| 1741 | base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1742 | base::Unretained(this), "30min", process_foregrounded_count_), |
| 1743 | base::TimeDelta::FromMinutes(30)); |
| 1744 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1745 | FROM_HERE, |
| 1746 | base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1747 | base::Unretained(this), "60min", process_foregrounded_count_), |
| 1748 | base::TimeDelta::FromMinutes(60)); |
| 1749 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1750 | FROM_HERE, |
| 1751 | base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1752 | base::Unretained(this), "90min", process_foregrounded_count_), |
| 1753 | base::TimeDelta::FromMinutes(90)); |
tasak | b46626a | 2016-10-18 05:54:44 | [diff] [blame] | 1754 | } |
| 1755 | |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 1756 | bool RenderThreadImpl::GetRendererMemoryMetrics( |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1757 | RendererMemoryMetrics* memory_metrics) const { |
| 1758 | DCHECK(memory_metrics); |
| 1759 | |
chrisha | 05e94f2 | 2017-04-05 22:06:04 | [diff] [blame] | 1760 | // Cache this result, as it can change while this code is running, and is used |
| 1761 | // as a divisor below. |
| 1762 | size_t render_view_count = RenderView::GetRenderViewCount(); |
| 1763 | |
| 1764 | // If there are no render views it doesn't make sense to calculate metrics |
| 1765 | // right now. |
| 1766 | if (render_view_count == 0) |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 1767 | return false; |
| 1768 | |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1769 | blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); |
| 1770 | memory_metrics->partition_alloc_kb = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1771 | blink_stats.partition_alloc_total_allocated_bytes / 1024; |
| 1772 | memory_metrics->blink_gc_kb = |
| 1773 | blink_stats.blink_gc_total_allocated_bytes / 1024; |
keishi | 12b598b9 | 2017-06-20 10:25:26 | [diff] [blame] | 1774 | std::unique_ptr<base::ProcessMetrics> metric( |
| 1775 | base::ProcessMetrics::CreateCurrentProcessMetrics()); |
| 1776 | size_t malloc_usage = metric->GetMallocUsage(); |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1777 | memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; |
| 1778 | |
| 1779 | discardable_memory::ClientDiscardableSharedMemoryManager::Statistics |
| 1780 | discardable_stats = discardable_shared_memory_manager_->GetStatistics(); |
| 1781 | size_t discardable_usage = |
| 1782 | discardable_stats.total_size - discardable_stats.freelist_size; |
| 1783 | memory_metrics->discardable_kb = discardable_usage / 1024; |
| 1784 | |
| 1785 | size_t v8_usage = 0; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1786 | if (v8::Isolate* isolate = blink::MainThreadIsolate()) { |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1787 | v8::HeapStatistics v8_heap_statistics; |
| 1788 | isolate->GetHeapStatistics(&v8_heap_statistics); |
| 1789 | v8_usage = v8_heap_statistics.total_heap_size(); |
| 1790 | } |
| 1791 | // TODO(tasak): Currently only memory usage of mainThreadIsolate() is |
| 1792 | // reported. We should collect memory usages of all isolates using |
| 1793 | // memory-infra. |
| 1794 | memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1795 | size_t total_allocated = blink_stats.partition_alloc_total_allocated_bytes + |
| 1796 | blink_stats.blink_gc_total_allocated_bytes + |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1797 | malloc_usage + v8_usage + discardable_usage; |
| 1798 | memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024; |
| 1799 | memory_metrics->non_discardable_total_allocated_mb = |
| 1800 | (total_allocated - discardable_usage) / 1024 / 1024; |
| 1801 | memory_metrics->total_allocated_per_render_view_mb = |
chrisha | 05e94f2 | 2017-04-05 22:06:04 | [diff] [blame] | 1802 | total_allocated / render_view_count / 1024 / 1024; |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 1803 | |
| 1804 | return true; |
keishi | 51ed0d5 | 2017-01-12 10:04:46 | [diff] [blame] | 1805 | } |
| 1806 | |
tasak | 335a187 | 2017-06-14 09:50:23 | [diff] [blame] | 1807 | static void RecordMemoryUsageAfterBackgroundedMB(const char* basename, |
| 1808 | const char* suffix, |
| 1809 | int memory_usage) { |
| 1810 | std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix); |
| 1811 | base::UmaHistogramMemoryLargeMB(histogram_name, memory_usage); |
| 1812 | } |
| 1813 | |
| 1814 | void RenderThreadImpl::RecordMemoryUsageAfterBackgrounded( |
| 1815 | const char* suffix, |
| 1816 | int foregrounded_count) { |
| 1817 | // If this renderer is resumed, we should not update UMA. |
| 1818 | if (!RendererIsHidden()) |
| 1819 | return; |
| 1820 | // If this renderer was not kept backgrounded for 5/10/15 minutes, |
| 1821 | // we should not record current memory usage. |
| 1822 | if (foregrounded_count != process_foregrounded_count_) |
| 1823 | return; |
| 1824 | |
| 1825 | RendererMemoryMetrics memory_metrics; |
| 1826 | if (!GetRendererMemoryMetrics(&memory_metrics)) |
| 1827 | return; |
| 1828 | RecordMemoryUsageAfterBackgroundedMB( |
| 1829 | "Memory.Experimental.Renderer.PartitionAlloc.AfterBackgrounded", suffix, |
| 1830 | memory_metrics.partition_alloc_kb / 1024); |
| 1831 | RecordMemoryUsageAfterBackgroundedMB( |
| 1832 | "Memory.Experimental.Renderer.BlinkGC.AfterBackgrounded", suffix, |
| 1833 | memory_metrics.blink_gc_kb / 1024); |
| 1834 | RecordMemoryUsageAfterBackgroundedMB( |
| 1835 | "Memory.Experimental.Renderer.Malloc.AfterBackgrounded", suffix, |
| 1836 | memory_metrics.malloc_mb); |
| 1837 | RecordMemoryUsageAfterBackgroundedMB( |
| 1838 | "Memory.Experimental.Renderer.Discardable.AfterBackgrounded", suffix, |
| 1839 | memory_metrics.discardable_kb / 1024); |
| 1840 | RecordMemoryUsageAfterBackgroundedMB( |
| 1841 | "Memory.Experimental.Renderer.V8MainThreaIsolate.AfterBackgrounded", |
| 1842 | suffix, memory_metrics.v8_main_thread_isolate_mb); |
| 1843 | RecordMemoryUsageAfterBackgroundedMB( |
| 1844 | "Memory.Experimental.Renderer.TotalAllocated.AfterBackgrounded", suffix, |
| 1845 | memory_metrics.total_allocated_mb); |
| 1846 | } |
| 1847 | |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1848 | #define GET_MEMORY_GROWTH(current, previous, allocator) \ |
| 1849 | (current.allocator > previous.allocator \ |
| 1850 | ? current.allocator - previous.allocator \ |
| 1851 | : 0) |
| 1852 | |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1853 | static void RecordPurgeAndSuspendMemoryGrowthKB(const char* basename, |
| 1854 | const char* suffix, |
| 1855 | int memory_usage) { |
| 1856 | std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix); |
| 1857 | base::UmaHistogramMemoryKB(histogram_name, memory_usage); |
| 1858 | } |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1859 | |
| 1860 | void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics( |
| 1861 | const char* suffix, |
| 1862 | int foregrounded_count_when_purged) { |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1863 | // If this renderer is resumed, we should not update UMA. |
| 1864 | if (!RendererIsHidden()) |
| 1865 | return; |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1866 | if (foregrounded_count_when_purged != process_foregrounded_count_) |
| 1867 | return; |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1868 | |
| 1869 | RendererMemoryMetrics memory_metrics; |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 1870 | if (!GetRendererMemoryMetrics(&memory_metrics)) |
| 1871 | return; |
| 1872 | |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1873 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1874 | "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1875 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1876 | partition_alloc_kb)); |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1877 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1878 | "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1879 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1880 | blink_gc_kb)); |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1881 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1882 | "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1883 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1884 | malloc_mb) * |
| 1885 | 1024); |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1886 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1887 | "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1888 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1889 | discardable_kb)); |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1890 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1891 | "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1892 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1893 | v8_main_thread_isolate_mb) * |
| 1894 | 1024); |
tasak | a27961a | 2017-05-24 07:33:25 | [diff] [blame] | 1895 | RecordPurgeAndSuspendMemoryGrowthKB( |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1896 | "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix, |
tasak | 72f6404 | 2017-01-19 14:02:53 | [diff] [blame] | 1897 | GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
tasak | bb0640b | 2017-05-15 09:02:26 | [diff] [blame] | 1898 | total_allocated_mb) * |
| 1899 | 1024); |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1900 | } |
| 1901 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1902 | scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 1903 | TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1904 | |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1905 | if (gpu_channel_) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 1906 | // Do nothing if we already have a GPU channel or are already |
| 1907 | // establishing one. |
[email protected] | 7951bfe | 2013-06-13 01:43:34 | [diff] [blame] | 1908 | if (!gpu_channel_->IsLost()) |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1909 | return gpu_channel_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1910 | |
| 1911 | // Recreate the channel if it has been lost. |
piman | 765e528 | 2015-05-08 03:43:01 | [diff] [blame] | 1912 | gpu_channel_->DestroyChannel(); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1913 | gpu_channel_ = nullptr; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1914 | } |
| 1915 | |
sadrul | 5354659 | 2016-12-17 01:44:21 | [diff] [blame] | 1916 | gpu_channel_ = gpu_->EstablishGpuChannelSync(); |
| 1917 | if (gpu_channel_) |
| 1918 | GetContentClient()->SetGpuInfo(gpu_channel_->gpu_info()); |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1919 | return gpu_channel_; |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 1920 | } |
| 1921 | |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1922 | void RenderThreadImpl::RequestNewLayerTreeFrameSink( |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1923 | bool use_software, |
| 1924 | int routing_id, |
| 1925 | scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue, |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 1926 | const GURL& url, |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1927 | const LayerTreeFrameSinkCallback& callback) { |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1928 | const base::CommandLine& command_line = |
| 1929 | *base::CommandLine::ForCurrentProcess(); |
| 1930 | if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
| 1931 | use_software = true; |
| 1932 | |
samans | 09812d3 | 2017-03-27 19:51:50 | [diff] [blame] | 1933 | // In disable gpu vsync mode, also let the renderer tick as fast as it |
| 1934 | // can. The top level begin frame source will also be running as a back |
| 1935 | // to back begin frame source, but using a synthetic begin frame source |
| 1936 | // here reduces latency when in this mode (at least for frames |
| 1937 | // starting--it potentially increases it for input on the other hand.) |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 1938 | std::unique_ptr<viz::SyntheticBeginFrameSource> synthetic_begin_frame_source; |
samans | 09812d3 | 2017-03-27 19:51:50 | [diff] [blame] | 1939 | if (command_line.HasSwitch(switches::kDisableGpuVsync) && |
| 1940 | command_line.GetSwitchValueASCII(switches::kDisableGpuVsync) != "gpu") { |
| 1941 | synthetic_begin_frame_source = CreateSyntheticBeginFrameSource(); |
| 1942 | } |
| 1943 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 1944 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 1945 | if (!use_software && IsRunningInMash()) { |
Scott Violet | 986ac47 | 2017-08-10 16:38:34 | [diff] [blame] | 1946 | if (!RendererWindowTreeClient::Get(routing_id)) { |
| 1947 | callback.Run(nullptr); |
| 1948 | return; |
| 1949 | } |
sadrul | be22c4f | 2017-03-14 06:59:25 | [diff] [blame] | 1950 | scoped_refptr<gpu::GpuChannelHost> channel = EstablishGpuChannelSync(); |
| 1951 | // If the channel could not be established correctly, then return null. This |
| 1952 | // would cause the compositor to wait and try again at a later time. |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 1953 | if (!channel) { |
| 1954 | callback.Run(nullptr); |
| 1955 | return; |
| 1956 | } |
fsamuel | 95c974eb | 2017-03-22 10:00:25 | [diff] [blame] | 1957 | RendererWindowTreeClient::Get(routing_id) |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1958 | ->RequestLayerTreeFrameSink( |
fsamuel | 95c974eb | 2017-03-22 10:00:25 | [diff] [blame] | 1959 | gpu_->CreateContextProvider(std::move(channel)), |
| 1960 | GetGpuMemoryBufferManager(), callback); |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 1961 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1962 | } |
| 1963 | #endif |
| 1964 | |
Gary Klassen | 4d0f023 | 2017-07-27 23:23:12 | [diff] [blame] | 1965 | viz::mojom::CompositorFrameSinkPtrInfo sink_info; |
| 1966 | viz::mojom::CompositorFrameSinkRequest sink_request = |
samans | a61ab21 | 2017-05-24 12:11:43 | [diff] [blame] | 1967 | mojo::MakeRequest(&sink_info); |
Gary Klassen | 4d0f023 | 2017-07-27 23:23:12 | [diff] [blame] | 1968 | viz::mojom::CompositorFrameSinkClientPtr client; |
| 1969 | viz::mojom::CompositorFrameSinkClientRequest client_request = |
samans | a61ab21 | 2017-05-24 12:11:43 | [diff] [blame] | 1970 | mojo::MakeRequest(&client); |
| 1971 | |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1972 | if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 1973 | scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 1974 | cc::VulkanInProcessContextProvider::Create(); |
| 1975 | if (vulkan_context_provider) { |
| 1976 | DCHECK(!layout_test_mode()); |
samans | a61ab21 | 2017-05-24 12:11:43 | [diff] [blame] | 1977 | frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request), |
| 1978 | std::move(client)); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1979 | callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>( |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 1980 | std::move(vulkan_context_provider), |
| 1981 | std::move(synthetic_begin_frame_source), std::move(sink_info), |
Valery Arkhangorodsky | 513ac8fd | 2017-08-02 23:09:23 | [diff] [blame] | 1982 | std::move(client_request), nullptr /* hit_test_data_provider */, |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 1983 | base::MakeUnique<RendererLocalSurfaceIdProvider>(), |
| 1984 | false /* enable_surface_synchroninzation */)); |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 1985 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | // Create a gpu process channel and verify we want to use GPU compositing |
| 1990 | // before creating any context providers. |
| 1991 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
| 1992 | if (!use_software) { |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1993 | gpu_channel_host = EstablishGpuChannelSync(); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1994 | if (!gpu_channel_host) { |
| 1995 | // Cause the compositor to wait and try again. |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 1996 | callback.Run(nullptr); |
| 1997 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1998 | } |
| 1999 | // We may get a valid channel, but with a software renderer. In that case, |
| 2000 | // disable GPU compositing. |
| 2001 | if (gpu_channel_host->gpu_info().software_rendering) |
| 2002 | use_software = true; |
| 2003 | } |
| 2004 | |
| 2005 | if (use_software) { |
| 2006 | DCHECK(!layout_test_mode()); |
samans | a61ab21 | 2017-05-24 12:11:43 | [diff] [blame] | 2007 | frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request), |
| 2008 | std::move(client)); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 2009 | callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>( |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 2010 | nullptr, nullptr, nullptr, shared_bitmap_manager(), |
| 2011 | std::move(synthetic_begin_frame_source), std::move(sink_info), |
Valery Arkhangorodsky | 513ac8fd | 2017-08-02 23:09:23 | [diff] [blame] | 2012 | std::move(client_request), nullptr /* hit_test_data_provider */, |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 2013 | base::MakeUnique<RendererLocalSurfaceIdProvider>(), |
| 2014 | false /* enable_surface_synchroninzation */)); |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 2015 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2016 | } |
| 2017 | |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2018 | scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2019 | SharedCompositorWorkerContextProvider(); |
| 2020 | if (!worker_context_provider) { |
| 2021 | // Cause the compositor to wait and try again. |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 2022 | callback.Run(nullptr); |
| 2023 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | // The renderer compositor context doesn't do a lot of stuff, so we don't |
| 2027 | // expect it to need a lot of space for commands or transfer. Raster and |
| 2028 | // uploads happen on the worker context instead. |
| 2029 | gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext(); |
| 2030 | |
| 2031 | // This is for an offscreen context for the compositor. So the default |
| 2032 | // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
| 2033 | gpu::gles2::ContextCreationAttribHelper attributes; |
| 2034 | attributes.alpha_size = -1; |
| 2035 | attributes.depth_size = 0; |
| 2036 | attributes.stencil_size = 0; |
| 2037 | attributes.samples = 0; |
| 2038 | attributes.sample_buffers = 0; |
| 2039 | attributes.bind_generates_resource = false; |
| 2040 | attributes.lose_context_when_out_of_memory = true; |
| 2041 | |
| 2042 | constexpr bool automatic_flushes = false; |
| 2043 | constexpr bool support_locking = false; |
| 2044 | |
| 2045 | // The compositor context shares resources with the worker context unless |
| 2046 | // the worker is async. |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2047 | ui::ContextProviderCommandBuffer* share_context = |
| 2048 | worker_context_provider.get(); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2049 | if (IsAsyncWorkerContextEnabled()) |
| 2050 | share_context = nullptr; |
| 2051 | |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2052 | scoped_refptr<ui::ContextProviderCommandBuffer> context_provider( |
| 2053 | new ui::ContextProviderCommandBuffer( |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 2054 | gpu_channel_host, kGpuStreamIdDefault, kGpuStreamPriorityDefault, |
| 2055 | gpu::kNullSurfaceHandle, url, automatic_flushes, support_locking, |
| 2056 | limits, attributes, share_context, |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2057 | ui::command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2058 | |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2059 | if (layout_test_deps_) { |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 2060 | callback.Run(layout_test_deps_->CreateLayerTreeFrameSink( |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 2061 | routing_id, std::move(gpu_channel_host), std::move(context_provider), |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 2062 | std::move(worker_context_provider), GetGpuMemoryBufferManager(), this)); |
| 2063 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | #if defined(OS_ANDROID) |
| 2067 | if (sync_compositor_message_filter_) { |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 2068 | std::unique_ptr<viz::BeginFrameSource> begin_frame_source = |
samans | 09812d3 | 2017-03-27 19:51:50 | [diff] [blame] | 2069 | synthetic_begin_frame_source |
| 2070 | ? std::move(synthetic_begin_frame_source) |
| 2071 | : CreateExternalBeginFrameSource(routing_id); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 2072 | callback.Run(base::MakeUnique<SynchronousLayerTreeFrameSink>( |
danakj | a40dd448 | 2016-06-28 01:14:10 | [diff] [blame] | 2073 | std::move(context_provider), std::move(worker_context_provider), |
danakj | e9cf581 | 2017-02-16 22:22:55 | [diff] [blame] | 2074 | GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 2075 | g_next_layer_tree_frame_sink_id++, std::move(begin_frame_source), |
enne | 077ba486 | 2016-09-12 20:59:53 | [diff] [blame] | 2076 | sync_compositor_message_filter_.get(), |
fsamuel | cf3002e | 2017-03-20 23:13:47 | [diff] [blame] | 2077 | std::move(frame_swap_message_queue))); |
| 2078 | return; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2079 | } |
| 2080 | #endif |
samans | a61ab21 | 2017-05-24 12:11:43 | [diff] [blame] | 2081 | frame_sink_provider_->CreateForWidget(routing_id, std::move(sink_request), |
| 2082 | std::move(client)); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 2083 | callback.Run(base::MakeUnique<viz::ClientLayerTreeFrameSink>( |
samans | 2040988b | 2017-04-11 23:58:35 | [diff] [blame] | 2084 | std::move(context_provider), std::move(worker_context_provider), |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 2085 | GetGpuMemoryBufferManager(), nullptr, |
| 2086 | std::move(synthetic_begin_frame_source), std::move(sink_info), |
Valery Arkhangorodsky | 513ac8fd | 2017-08-02 23:09:23 | [diff] [blame] | 2087 | std::move(client_request), nullptr /* hit_test_data_provider */, |
samans | 7e6675cc | 2017-06-05 20:16:08 | [diff] [blame] | 2088 | base::MakeUnique<RendererLocalSurfaceIdProvider>(), |
| 2089 | false /* enable_surface_synchroninzation */)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 2090 | } |
| 2091 | |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 2092 | AssociatedInterfaceRegistry* |
| 2093 | RenderThreadImpl::GetAssociatedInterfaceRegistry() { |
| 2094 | return &associated_interfaces_; |
| 2095 | } |
| 2096 | |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 2097 | std::unique_ptr<cc::SwapPromise> |
| 2098 | RenderThreadImpl::RequestCopyOfOutputForLayoutTest( |
| 2099 | int32_t routing_id, |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 2100 | std::unique_ptr<viz::CopyOutputRequest> request) { |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 2101 | DCHECK(layout_test_deps_); |
| 2102 | return layout_test_deps_->RequestCopyOfOutput(routing_id, std::move(request)); |
| 2103 | } |
| 2104 | |
altimin | eb6bd196 | 2017-05-03 14:52:38 | [diff] [blame] | 2105 | std::unique_ptr<blink::WebMediaStreamCenter> |
| 2106 | RenderThreadImpl::CreateMediaStreamCenter( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2107 | blink::WebMediaStreamCenterClient* client) { |
altimin | eb6bd196 | 2017-05-03 14:52:38 | [diff] [blame] | 2108 | std::unique_ptr<blink::WebMediaStreamCenter> media_stream_center; |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 2109 | #if BUILDFLAG(ENABLE_WEBRTC) |
altimin | eb6bd196 | 2017-05-03 14:52:38 | [diff] [blame] | 2110 | if (!media_stream_center) { |
| 2111 | media_stream_center = |
| 2112 | GetContentClient()->renderer()->OverrideCreateWebMediaStreamCenter( |
| 2113 | client); |
| 2114 | if (!media_stream_center) { |
| 2115 | media_stream_center = base::MakeUnique<MediaStreamCenter>( |
| 2116 | client, GetPeerConnectionDependencyFactory()); |
[email protected] | 68e5fee | 2013-02-18 10:04:22 | [diff] [blame] | 2117 | } |
| 2118 | } |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 2119 | #endif |
altimin | eb6bd196 | 2017-05-03 14:52:38 | [diff] [blame] | 2120 | return media_stream_center; |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 2121 | } |
| 2122 | |
Brett Wilson | 0748bf41 | 2016-11-22 17:55:46 | [diff] [blame] | 2123 | #if BUILDFLAG(ENABLE_WEBRTC) |
[email protected] | 0107d8a | 2014-05-16 10:20:34 | [diff] [blame] | 2124 | PeerConnectionDependencyFactory* |
| 2125 | RenderThreadImpl::GetPeerConnectionDependencyFactory() { |
[email protected] | 83e0a48 | 2014-05-22 18:07:18 | [diff] [blame] | 2126 | return peer_connection_factory_.get(); |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 2127 | } |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 2128 | #endif |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 2129 | |
rockot | 1587e33 | 2016-07-27 17:44:14 | [diff] [blame] | 2130 | mojom::RenderFrameMessageFilter* |
| 2131 | RenderThreadImpl::render_frame_message_filter() { |
| 2132 | if (!render_frame_message_filter_) |
| 2133 | GetChannel()->GetRemoteAssociatedInterface(&render_frame_message_filter_); |
| 2134 | return render_frame_message_filter_.get(); |
| 2135 | } |
| 2136 | |
rockot | e261d211 | 2016-09-21 22:22:23 | [diff] [blame] | 2137 | mojom::RenderMessageFilter* RenderThreadImpl::render_message_filter() { |
| 2138 | if (!render_message_filter_) |
| 2139 | GetChannel()->GetRemoteAssociatedInterface(&render_message_filter_); |
| 2140 | return render_message_filter_.get(); |
| 2141 | } |
| 2142 | |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 2143 | gpu::GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 2144 | if (!gpu_channel_) |
danakj | 3873e85 | 2016-05-05 00:46:07 | [diff] [blame] | 2145 | return nullptr; |
[email protected] | 7951bfe | 2013-06-13 01:43:34 | [diff] [blame] | 2146 | if (gpu_channel_->IsLost()) |
danakj | 3873e85 | 2016-05-05 00:46:07 | [diff] [blame] | 2147 | return nullptr; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2148 | return gpu_channel_.get(); |
| 2149 | } |
| 2150 | |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 2151 | void RenderThreadImpl::CreateView(mojom::CreateViewParamsPtr params) { |
| 2152 | CompositorDependencies* compositor_deps = this; |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 2153 | is_scroll_animator_enabled_ = params->web_preferences.enable_scroll_animator; |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 2154 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 2155 | RenderViewImpl::Create(compositor_deps, *params, |
| 2156 | RenderWidget::ShowCallback()); |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 2157 | } |
| 2158 | |
rockot | 53be7caf | 2016-10-04 20:17:08 | [diff] [blame] | 2159 | void RenderThreadImpl::CreateFrame(mojom::CreateFrameParamsPtr params) { |
| 2160 | // Debug cases of https://crbug.com/626802. |
| 2161 | base::debug::SetCrashKeyValue("newframe_routing_id", |
| 2162 | base::IntToString(params->routing_id)); |
| 2163 | base::debug::SetCrashKeyValue("newframe_proxy_id", |
| 2164 | base::IntToString(params->proxy_routing_id)); |
| 2165 | base::debug::SetCrashKeyValue("newframe_opener_id", |
| 2166 | base::IntToString(params->opener_routing_id)); |
| 2167 | base::debug::SetCrashKeyValue("newframe_parent_id", |
| 2168 | base::IntToString(params->parent_routing_id)); |
| 2169 | base::debug::SetCrashKeyValue("newframe_widget_id", |
| 2170 | base::IntToString( |
| 2171 | params->widget_params->routing_id)); |
| 2172 | base::debug::SetCrashKeyValue("newframe_widget_hidden", |
| 2173 | params->widget_params->hidden ? "yes" : "no"); |
| 2174 | base::debug::SetCrashKeyValue("newframe_replicated_origin", |
| 2175 | params->replication_state.origin.Serialize()); |
| 2176 | base::debug::SetCrashKeyValue("newframe_oopifs_possible", |
| 2177 | SiteIsolationPolicy::AreCrossProcessFramesPossible() ? "yes" : "no"); |
| 2178 | CompositorDependencies* compositor_deps = this; |
| 2179 | RenderFrameImpl::CreateFrame( |
| 2180 | params->routing_id, params->proxy_routing_id, params->opener_routing_id, |
| 2181 | params->parent_routing_id, params->previous_sibling_routing_id, |
| 2182 | params->replication_state, compositor_deps, *params->widget_params, |
| 2183 | params->frame_owner_properties); |
| 2184 | } |
| 2185 | |
| 2186 | void RenderThreadImpl::CreateFrameProxy( |
| 2187 | int32_t routing_id, |
| 2188 | int32_t render_view_routing_id, |
| 2189 | int32_t opener_routing_id, |
| 2190 | int32_t parent_routing_id, |
| 2191 | const FrameReplicationState& replicated_state) { |
nick | 3b5a21f | 2016-11-22 23:07:11 | [diff] [blame] | 2192 | RenderFrameProxy::CreateFrameProxy( |
| 2193 | routing_id, render_view_routing_id, |
| 2194 | RenderFrameImpl::ResolveOpener(opener_routing_id), parent_routing_id, |
| 2195 | replicated_state); |
rockot | 53be7caf | 2016-10-04 20:17:08 | [diff] [blame] | 2196 | } |
| 2197 | |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2198 | void RenderThreadImpl::OnNetworkConnectionChanged( |
| 2199 | net::NetworkChangeNotifier::ConnectionType type, |
| 2200 | double max_bandwidth_mbps) { |
| 2201 | bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2202 | WebNetworkStateNotifier::SetOnLine(online); |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2203 | for (auto& observer : observers_) |
| 2204 | observer.NetworkStateChanged(online); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2205 | WebNetworkStateNotifier::SetWebConnection( |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2206 | NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps); |
| 2207 | } |
| 2208 | |
tbansal | 15973c3 | 2017-05-10 18:40:44 | [diff] [blame] | 2209 | void RenderThreadImpl::OnNetworkQualityChanged( |
tbansal | b612c5d | 2017-05-25 18:53:06 | [diff] [blame] | 2210 | net::EffectiveConnectionType type, |
tbansal | 99d8aeb | 2017-05-22 19:12:58 | [diff] [blame] | 2211 | base::TimeDelta http_rtt, |
| 2212 | base::TimeDelta transport_rtt, |
tbansal | 15973c3 | 2017-05-10 18:40:44 | [diff] [blame] | 2213 | double downlink_throughput_kbps) { |
| 2214 | UMA_HISTOGRAM_BOOLEAN("NQE.RenderThreadNotified", true); |
tbansal | b612c5d | 2017-05-25 18:53:06 | [diff] [blame] | 2215 | WebNetworkStateNotifier::SetNetworkQuality( |
| 2216 | EffectiveConnectionTypeToWebEffectiveConnectionType(type), http_rtt, |
| 2217 | transport_rtt, downlink_throughput_kbps); |
tbansal | 15973c3 | 2017-05-10 18:40:44 | [diff] [blame] | 2218 | } |
| 2219 | |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2220 | void RenderThreadImpl::SetWebKitSharedTimersSuspended(bool suspend) { |
| 2221 | #if defined(OS_ANDROID) |
| 2222 | if (suspend) { |
Alexander Timin | 16329088 | 2017-08-01 17:38:07 | [diff] [blame] | 2223 | renderer_scheduler_->PauseTimerQueue(); |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2224 | } else { |
| 2225 | renderer_scheduler_->ResumeTimerQueue(); |
| 2226 | } |
| 2227 | webkit_shared_timer_suspended_ = suspend; |
| 2228 | #else |
| 2229 | NOTREACHED(); |
| 2230 | #endif |
| 2231 | } |
| 2232 | |
| 2233 | void RenderThreadImpl::UpdateScrollbarTheme( |
| 2234 | mojom::UpdateScrollbarThemeParamsPtr params) { |
| 2235 | #if defined(OS_MACOSX) |
| 2236 | static_cast<WebScrollbarBehaviorImpl*>( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2237 | blink_platform_impl_->ScrollbarBehavior()) |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2238 | ->set_jump_on_track_click(params->jump_on_track_click); |
| 2239 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2240 | blink::WebScrollbarTheme::UpdateScrollbarsWithNSDefaults( |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2241 | params->initial_button_delay, params->autoscroll_button_delay, |
| 2242 | params->preferred_scroller_style, params->redraw, |
| 2243 | params->button_placement); |
Greg Kerr | a7b943b | 2017-07-24 23:17:17 | [diff] [blame] | 2244 | |
| 2245 | is_elastic_overscroll_enabled_ = params->scroll_view_rubber_banding; |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2246 | #else |
| 2247 | NOTREACHED(); |
| 2248 | #endif |
| 2249 | } |
| 2250 | |
| 2251 | void RenderThreadImpl::OnSystemColorsChanged( |
| 2252 | int32_t aqua_color_variant, |
| 2253 | const std::string& highlight_text_color, |
| 2254 | const std::string& highlight_color) { |
| 2255 | #if defined(OS_MACOSX) |
| 2256 | SystemColorsDidChange(aqua_color_variant, highlight_text_color, |
| 2257 | highlight_color); |
| 2258 | #else |
| 2259 | NOTREACHED(); |
| 2260 | #endif |
| 2261 | } |
| 2262 | |
| 2263 | void RenderThreadImpl::PurgePluginListCache(bool reload_pages) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2264 | #if BUILDFLAG(ENABLE_PLUGINS) |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2265 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 2266 | // point we already know that the browser has refreshed its list, so disable |
| 2267 | // refresh temporarily to prevent each renderer process causing the list to be |
| 2268 | // regenerated. |
| 2269 | blink_platform_impl_->set_plugin_refresh_allowed(false); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2270 | blink::ResetPluginCache(reload_pages); |
rockot | a2db0da | 2016-10-18 17:39:11 | [diff] [blame] | 2271 | blink_platform_impl_->set_plugin_refresh_allowed(true); |
| 2272 | |
| 2273 | for (auto& observer : observers_) |
| 2274 | observer.PluginListChanged(); |
| 2275 | #else |
| 2276 | NOTREACHED(); |
| 2277 | #endif |
| 2278 | } |
| 2279 | |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 2280 | void RenderThreadImpl::OnCreateNewSharedWorker( |
| 2281 | const WorkerProcessMsg_CreateWorker_Params& params) { |
| 2282 | // EmbeddedSharedWorkerStub will self-destruct. |
mkwst | cfa9893 | 2016-03-09 13:06:19 | [diff] [blame] | 2283 | new EmbeddedSharedWorkerStub( |
| 2284 | params.url, params.name, params.content_security_policy, |
| 2285 | params.security_policy_type, params.creation_address_space, |
Yuki Yamada | 68992b0 | 2017-07-31 06:13:45 | [diff] [blame] | 2286 | params.pause_on_start, params.route_id, params.data_saver_enabled, |
| 2287 | mojo::ScopedMessagePipeHandle(params.content_settings_handle)); |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 2288 | } |
| 2289 | |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 2290 | void RenderThreadImpl::OnMemoryPressure( |
| 2291 | base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2292 | TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
rmcilroy | 7fbb3bd5 | 2015-02-17 19:02:14 | [diff] [blame] | 2293 | if (blink_platform_impl_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2294 | blink::WebMemoryCoordinator::OnMemoryPressure( |
bashi | c577bfc | 2016-01-08 03:42:35 | [diff] [blame] | 2295 | static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2296 | } |
| 2297 | if (memory_pressure_level == |
| 2298 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 2299 | ReleaseFreeMemory(); |
| 2300 | ClearMemory(); |
| 2301 | } |
| 2302 | } |
rmcilroy | ab967c97 | 2015-02-17 23:15:00 | [diff] [blame] | 2303 | |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2304 | void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2305 | if (blink_platform_impl_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2306 | blink::WebMemoryCoordinator::OnMemoryStateChange( |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2307 | static_cast<blink::MemoryState>(state)); |
| 2308 | } |
bashi | 233f65e | 2017-02-09 08:36:03 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | void RenderThreadImpl::OnPurgeMemory() { |
bashi | b9058f28 | 2017-03-30 01:55:24 | [diff] [blame] | 2312 | // Record amount of purged memory after 2 seconds. 2 seconds is arbitrary |
| 2313 | // but it works most cases. |
| 2314 | RendererMemoryMetrics metrics; |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 2315 | if (!GetRendererMemoryMetrics(&metrics)) |
| 2316 | return; |
| 2317 | |
bashi | b9058f28 | 2017-03-30 01:55:24 | [diff] [blame] | 2318 | GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 2319 | FROM_HERE, |
| 2320 | base::Bind(&RenderThreadImpl::RecordPurgeMemory, base::Unretained(this), |
| 2321 | std::move(metrics)), |
| 2322 | base::TimeDelta::FromSeconds(2)); |
| 2323 | |
bashi | 233f65e | 2017-02-09 08:36:03 | [diff] [blame] | 2324 | OnTrimMemoryImmediately(); |
| 2325 | ReleaseFreeMemory(); |
| 2326 | ClearMemory(); |
| 2327 | if (blink_platform_impl_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2328 | blink::WebMemoryCoordinator::OnPurgeMemory(); |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2329 | } |
| 2330 | |
bashi | b9058f28 | 2017-03-30 01:55:24 | [diff] [blame] | 2331 | void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) { |
| 2332 | RendererMemoryMetrics after; |
bashi | a0ba0d4 | 2017-04-03 08:11:06 | [diff] [blame] | 2333 | if (!GetRendererMemoryMetrics(&after)) |
| 2334 | return; |
bashi | b9058f28 | 2017-03-30 01:55:24 | [diff] [blame] | 2335 | int64_t mbytes = static_cast<int64_t>(before.total_allocated_mb) - |
| 2336 | static_cast<int64_t>(after.total_allocated_mb); |
| 2337 | if (mbytes < 0) |
| 2338 | mbytes = 0; |
| 2339 | UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer.PurgedMemory", |
| 2340 | mbytes); |
| 2341 | } |
| 2342 | |
hajimehoshi | 7bb3958 | 2016-10-12 04:30:57 | [diff] [blame] | 2343 | void RenderThreadImpl::ClearMemory() { |
| 2344 | // Do not call into blink if it is not initialized. |
| 2345 | if (blink_platform_impl_) { |
| 2346 | // Purge Skia font cache, by setting it to 0 and then again to the |
| 2347 | // previous limit. |
| 2348 | size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2349 | SkGraphics::SetFontCacheLimit(font_cache_limit); |
rmcilroy | 7fbb3bd5 | 2015-02-17 19:02:14 | [diff] [blame] | 2350 | } |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 2351 | } |
| 2352 | |
Marijn Kruisselbrink | 8c27641 | 2017-07-29 06:11:21 | [diff] [blame] | 2353 | scoped_refptr<base::TaskRunner> RenderThreadImpl::GetFileThreadTaskRunner() { |
| 2354 | return blink_platform_impl_->BaseFileTaskRunner(); |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 2355 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2356 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 2357 | scoped_refptr<base::SingleThreadTaskRunner> |
| 2358 | RenderThreadImpl::GetMediaThreadTaskRunner() { |
fdoray | e94d864 | 2016-07-07 19:19:01 | [diff] [blame] | 2359 | DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2360 | if (!media_thread_) { |
| 2361 | media_thread_.reset(new base::Thread("Media")); |
| 2362 | media_thread_->Start(); |
| 2363 | } |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 2364 | return media_thread_->task_runner(); |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2365 | } |
| 2366 | |
dcastagna | 4517a18 | 2015-08-05 19:51:03 | [diff] [blame] | 2367 | base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() { |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 2368 | return categorized_worker_pool_.get(); |
dcastagna | b880e8f | 2015-06-30 20:16:06 | [diff] [blame] | 2369 | } |
| 2370 | |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2371 | scoped_refptr<ui::ContextProviderCommandBuffer> |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 2372 | RenderThreadImpl::SharedCompositorWorkerContextProvider() { |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2373 | DCHECK(IsMainThread()); |
| 2374 | // Try to reuse existing shared worker context provider. |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2375 | if (shared_worker_context_provider_) { |
| 2376 | // Note: If context is lost, delete reference after releasing the lock. |
Xu Xing | 3254916 | 2017-07-17 22:25:43 | [diff] [blame] | 2377 | viz::ContextProvider::ScopedContextLock lock( |
boliu | 11afa7e | 2016-04-18 18:04:14 | [diff] [blame] | 2378 | shared_worker_context_provider_.get()); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2379 | if (shared_worker_context_provider_->ContextGL() |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2380 | ->GetGraphicsResetStatusKHR() == GL_NO_ERROR) |
| 2381 | return shared_worker_context_provider_; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2382 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2383 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 2384 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 2385 | EstablishGpuChannelSync()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2386 | if (!gpu_channel_host) { |
| 2387 | shared_worker_context_provider_ = nullptr; |
| 2388 | return shared_worker_context_provider_; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2389 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2390 | |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 2391 | int32_t stream_id = kGpuStreamIdDefault; |
| 2392 | gpu::SchedulingPriority stream_priority = kGpuStreamPriorityDefault; |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 2393 | if (is_async_worker_context_enabled_) { |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 2394 | stream_id = kGpuStreamIdWorker; |
| 2395 | stream_priority = kGpuStreamPriorityWorker; |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 2396 | } |
| 2397 | |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 2398 | bool support_locking = true; |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 2399 | shared_worker_context_provider_ = CreateOffscreenContext( |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 2400 | std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking, |
sadrul | 85cc5d8 | 2016-12-20 03:37:41 | [diff] [blame] | 2401 | ui::command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id, |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 2402 | stream_priority); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2403 | if (!shared_worker_context_provider_->BindToCurrentThread()) |
| 2404 | shared_worker_context_provider_ = nullptr; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2405 | return shared_worker_context_provider_; |
| 2406 | } |
| 2407 | |
juncai | 2f298a8 | 2017-04-18 03:51:39 | [diff] [blame] | 2408 | void RenderThreadImpl::SampleGamepads(device::Gamepads* data) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2409 | blink_platform_impl_->SampleGamepads(*data); |
[email protected] | 0ff73656 | 2014-05-09 09:09:47 | [diff] [blame] | 2410 | } |
| 2411 | |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2412 | bool RenderThreadImpl::RendererIsHidden() const { |
| 2413 | return widget_count_ > 0 && hidden_widget_count_ == widget_count_; |
| 2414 | } |
| 2415 | |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2416 | void RenderThreadImpl::WidgetCreated() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2417 | bool renderer_was_hidden = RendererIsHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2418 | widget_count_++; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2419 | if (renderer_was_hidden) |
| 2420 | OnRendererVisible(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | void RenderThreadImpl::WidgetDestroyed() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2424 | // TODO(rmcilroy): Remove the restriction that destroyed widgets must be |
| 2425 | // unhidden before WidgetDestroyed is called. |
| 2426 | DCHECK_GT(widget_count_, 0); |
| 2427 | DCHECK_GT(widget_count_, hidden_widget_count_); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2428 | widget_count_--; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2429 | if (RendererIsHidden()) |
| 2430 | OnRendererHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | void RenderThreadImpl::WidgetHidden() { |
| 2434 | DCHECK_LT(hidden_widget_count_, widget_count_); |
| 2435 | hidden_widget_count_++; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2436 | if (RendererIsHidden()) |
| 2437 | OnRendererHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | void RenderThreadImpl::WidgetRestored() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2441 | bool renderer_was_hidden = RendererIsHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2442 | DCHECK_GT(hidden_widget_count_, 0); |
| 2443 | hidden_widget_count_--; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2444 | if (renderer_was_hidden) |
| 2445 | OnRendererVisible(); |
| 2446 | } |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2447 | |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2448 | void RenderThreadImpl::OnRendererHidden() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2449 | blink::MainThreadIsolate()->IsolateInBackgroundNotification(); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2450 | // TODO(rmcilroy): Remove IdleHandler and replace it with an IdleTask |
| 2451 | // scheduled by the RendererScheduler - http://crbug.com/469210. |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 2452 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
| 2453 | return; |
Alexander Timin | 771b337 | 2017-06-15 13:26:47 | [diff] [blame] | 2454 | renderer_scheduler_->SetRendererHidden(true); |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 2455 | ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | void RenderThreadImpl::OnRendererVisible() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2459 | blink::MainThreadIsolate()->IsolateInForegroundNotification(); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2460 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2461 | return; |
Alexander Timin | 771b337 | 2017-06-15 13:26:47 | [diff] [blame] | 2462 | renderer_scheduler_->SetRendererHidden(false); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2463 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 2464 | } |
| 2465 | |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 2466 | void RenderThreadImpl::ReleaseFreeMemory() { |
| 2467 | base::allocator::ReleaseFreeMemory(); |
penghuang | 342762b | 2016-12-02 21:04:58 | [diff] [blame] | 2468 | discardable_shared_memory_manager_->ReleaseFreeMemory(); |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 2469 | |
| 2470 | if (blink_platform_impl_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2471 | blink::DecommitFreeableMemory(); |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 2472 | } |
| 2473 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2474 | RenderThreadImpl::PendingFrameCreate::PendingFrameCreate( |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 2475 | const service_manager::BindSourceInfo& browser_info, |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2476 | int routing_id, |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2477 | mojom::FrameRequest frame_request, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2478 | mojom::FrameHostInterfaceBrokerPtr frame_host_interface_broker) |
ben | f28ce88 | 2017-05-02 16:15:49 | [diff] [blame] | 2479 | : browser_info_(browser_info), |
| 2480 | routing_id_(routing_id), |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2481 | frame_request_(std::move(frame_request)), |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2482 | frame_host_interface_broker_(std::move(frame_host_interface_broker)) { |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2483 | // The RenderFrame may be deleted before the CreateFrame message is received. |
| 2484 | // In that case, the RenderFrameHost should cancel the create, which is |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2485 | // detected by setting an error handler on |frame_host_interface_broker_|. |
| 2486 | frame_host_interface_broker_.set_connection_error_handler( |
| 2487 | base::Bind(&RenderThreadImpl::PendingFrameCreate::OnConnectionError, |
| 2488 | base::Unretained(this))); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2489 | } |
| 2490 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2491 | RenderThreadImpl::PendingFrameCreate::~PendingFrameCreate() { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2492 | } |
| 2493 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2494 | void RenderThreadImpl::PendingFrameCreate::OnConnectionError() { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2495 | size_t erased = |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2496 | RenderThreadImpl::current()->pending_frame_creates_.erase(routing_id_); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2497 | DCHECK_EQ(1u, erased); |
| 2498 | } |
| 2499 | |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2500 | void RenderThreadImpl::OnSyncMemoryPressure( |
| 2501 | base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2502 | if (!blink::MainThreadIsolate()) |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2503 | return; |
| 2504 | |
| 2505 | v8::MemoryPressureLevel v8_memory_pressure_level = |
| 2506 | static_cast<v8::MemoryPressureLevel>(memory_pressure_level); |
| 2507 | |
Luke Halliwell | 16136de | 2017-07-05 21:15:56 | [diff] [blame] | 2508 | #if !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND) |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2509 | // In order to reduce performance impact, translate critical level to |
Luke Halliwell | 16136de | 2017-07-05 21:15:56 | [diff] [blame] | 2510 | // moderate level for foreground renderer. |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2511 | if (!RendererIsHidden() && |
| 2512 | v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2513 | v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
Luke Halliwell | 16136de | 2017-07-05 21:15:56 | [diff] [blame] | 2514 | #endif // !BUILDFLAG(ALLOW_CRITICAL_MEMORY_PRESSURE_HANDLING_IN_FOREGROUND) |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2515 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2516 | blink::MainThreadIsolate()->MemoryPressureNotification( |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2517 | v8_memory_pressure_level); |
| 2518 | blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2519 | v8_memory_pressure_level); |
| 2520 | } |
| 2521 | |
bashi | c4b4afcb | 2016-08-23 06:37:52 | [diff] [blame] | 2522 | // Note that this would be called only when memory_coordinator is enabled. |
| 2523 | // OnSyncMemoryPressure() is never called in that case. |
| 2524 | void RenderThreadImpl::OnTrimMemoryImmediately() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2525 | if (blink::MainThreadIsolate()) { |
| 2526 | blink::MainThreadIsolate()->MemoryPressureNotification( |
bashi | c4b4afcb | 2016-08-23 06:37:52 | [diff] [blame] | 2527 | v8::MemoryPressureLevel::kCritical); |
| 2528 | blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2529 | v8::MemoryPressureLevel::kCritical); |
| 2530 | } |
| 2531 | } |
| 2532 | |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 2533 | void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2534 | mojom::RendererAssociatedRequest request) { |
| 2535 | DCHECK(!renderer_binding_.is_bound()); |
| 2536 | renderer_binding_.Bind(std::move(request)); |
| 2537 | } |
bashi | c4b4afcb | 2016-08-23 06:37:52 | [diff] [blame] | 2538 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2539 | } // namespace content |