[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" |
[email protected] | 06533c0b | 2009-03-05 21:39:11 | [diff] [blame] | 14 | #include "base/command_line.h" |
creis | 9f7248b | 2016-01-27 20:27:39 | [diff] [blame] | 15 | #include "base/debug/crash_logging.h" |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 16 | #include "base/lazy_instance.h" |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 17 | #include "base/logging.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 18 | #include "base/macros.h" |
reveman | 1af05cb3 | 2015-03-17 23:18:16 | [diff] [blame] | 19 | #include "base/memory/discardable_memory_allocator.h" |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 20 | #include "base/memory/ptr_util.h" |
[email protected] | 8bac37b | 2013-07-18 19:13:56 | [diff] [blame] | 21 | #include "base/memory/shared_memory.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 22 | #include "base/metrics/field_trial.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 23 | #include "base/metrics/histogram_macros.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 24 | #include "base/path_service.h" |
fdoray | 2df4a9e | 2016-07-18 23:47:16 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 26 | #include "base/strings/string16.h" |
[email protected] | 1e1d1e1 | 2014-01-17 16:14:29 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 28 | #include "base/strings/string_split.h" |
ccameron | 6728bae3 | 2015-01-09 20:18:06 | [diff] [blame] | 29 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 30 | #include "base/strings/utf_string_conversions.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 31 | #include "base/threading/simple_thread.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 32 | #include "base/threading/thread_local.h" |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 33 | #include "base/threading/thread_restrictions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 34 | #include "base/threading/thread_task_runner_handle.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 35 | #include "base/trace_event/trace_event.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 36 | #include "base/values.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 37 | #include "build/build_config.h" |
jbroman | 0d30216 | 2015-09-05 05:46:23 | [diff] [blame] | 38 | #include "cc/base/histograms.h" |
[email protected] | d7249315 | 2014-01-08 17:37:45 | [diff] [blame] | 39 | #include "cc/base/switches.h" |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 40 | #include "cc/blink/web_layer_impl.h" |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 41 | #include "cc/output/buffer_to_texture_target_map.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 42 | #include "cc/output/compositor_frame_sink.h" |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 43 | #include "cc/output/copy_output_request.h" |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 44 | #include "cc/output/vulkan_in_process_context_provider.h" |
danakj | 92015685 | 2015-05-18 20:22:29 | [diff] [blame] | 45 | #include "cc/raster/task_graph_runner.h" |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 46 | #include "cc/trees/layer_tree_host_common.h" |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 47 | #include "cc/trees/layer_tree_settings.h" |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 48 | #include "content/child/appcache/appcache_dispatcher.h" |
| 49 | #include "content/child/appcache/appcache_frontend_impl.h" |
dmurph | 1fb9848 | 2016-03-30 21:14:26 | [diff] [blame] | 50 | #include "content/child/blob_storage/blob_message_filter.h" |
reveman | cb5a66af | 2014-10-25 00:34:39 | [diff] [blame] | 51 | #include "content/child/child_discardable_shared_memory_manager.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 52 | #include "content/child/child_gpu_memory_buffer_manager.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 53 | #include "content/child/child_histogram_message_filter.h" |
alexclarke | 0bc36e8d3 | 2014-12-17 17:29:20 | [diff] [blame] | 54 | #include "content/child/child_resource_message_filter.h" |
jbauman | 2f5c194 | 2014-12-06 03:28:24 | [diff] [blame] | 55 | #include "content/child/child_shared_bitmap_manager.h" |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 56 | #include "content/child/content_child_helpers.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 57 | #include "content/child/db_message_filter.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 58 | #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 59 | #include "content/child/indexed_db/indexed_db_message_filter.h" |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 60 | #include "content/child/memory/child_memory_coordinator_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 61 | #include "content/child/resource_dispatcher.h" |
alexclarke | 0bc36e8d3 | 2014-12-17 17:29:20 | [diff] [blame] | 62 | #include "content/child/resource_scheduling_filter.h" |
[email protected] | 643255da | 2013-06-12 20:55:13 | [diff] [blame] | 63 | #include "content/child/runtime_features.h" |
[email protected] | 57cf9788 | 2013-06-26 20:39:01 | [diff] [blame] | 64 | #include "content/child/thread_safe_sender.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 65 | #include "content/child/web_database_observer_impl.h" |
kinuko | ef64741 | 2015-12-23 06:10:43 | [diff] [blame] | 66 | #include "content/child/worker_thread_registry.h" |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 67 | #include "content/common/child_process_messages.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 68 | #include "content/common/content_constants_internal.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 69 | #include "content/common/dom_storage/dom_storage_messages.h" |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 70 | #include "content/common/frame_messages.h" |
raymes | bba82b3 | 2016-07-19 00:41:38 | [diff] [blame] | 71 | #include "content/common/frame_owner_properties.h" |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 72 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
avi | a7c3f51c | 2015-09-16 00:30:31 | [diff] [blame] | 73 | #include "content/common/render_process_messages.h" |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 74 | #include "content/common/resource_messages.h" |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 75 | #include "content/common/service_worker/embedded_worker_setup.mojom.h" |
alexmos | 6873421 | 2016-08-27 00:06:31 | [diff] [blame] | 76 | #include "content/common/site_isolation_policy.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 77 | #include "content/common/view_messages.h" |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 78 | #include "content/common/worker_messages.h" |
[email protected] | a458504b | 2012-07-23 19:57:06 | [diff] [blame] | 79 | #include "content/public/common/content_constants.h" |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 80 | #include "content/public/common/content_features.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 81 | #include "content/public/common/content_paths.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 82 | #include "content/public/common/content_switches.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 83 | #include "content/public/common/renderer_preferences.h" |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 84 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 85 | #include "content/public/renderer/content_renderer_client.h" |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 86 | #include "content/public/renderer/render_thread_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 87 | #include "content/public/renderer/render_view_visitor.h" |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 88 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
jsbell | 279efb4 | 2015-03-31 17:02:46 | [diff] [blame] | 89 | #include "content/renderer/cache_storage/cache_storage_dispatcher.h" |
| 90 | #include "content/renderer/cache_storage/cache_storage_message_filter.h" |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 91 | #include "content/renderer/categorized_worker_pool.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 92 | #include "content/renderer/devtools/devtools_agent_filter.h" |
alph | 666f80f | 2014-12-08 15:52:11 | [diff] [blame] | 93 | #include "content/renderer/devtools/v8_sampling_profiler.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 94 | #include "content/renderer/dom_storage/dom_storage_dispatcher.h" |
| 95 | #include "content/renderer/dom_storage/webstoragearea_impl.h" |
| 96 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 97 | #include "content/renderer/gpu/compositor_external_begin_frame_source.h" |
| 98 | #include "content/renderer/gpu/compositor_forwarding_message_filter.h" |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 99 | #include "content/renderer/gpu/frame_swap_message_queue.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 100 | #include "content/renderer/gpu/renderer_compositor_frame_sink.h" |
[email protected] | 7a72d45 | 2013-12-13 10:01:13 | [diff] [blame] | 101 | #include "content/renderer/input/input_event_filter.h" |
| 102 | #include "content/renderer/input/input_handler_manager.h" |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 103 | #include "content/renderer/input/main_thread_input_event_filter.h" |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 104 | #include "content/renderer/media/audio_input_message_filter.h" |
| 105 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 106 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 107 | #include "content/renderer/media/media_stream_center.h" |
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 108 | #include "content/renderer/media/midi_message_filter.h" |
xhwang | 194acae | 2014-11-12 22:46:33 | [diff] [blame] | 109 | #include "content/renderer/media/render_media_client.h" |
[email protected] | 2329bfc7 | 2014-02-28 02:03:21 | [diff] [blame] | 110 | #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 111 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | ba164c91 | 2011-06-14 22:07:34 | [diff] [blame] | 112 | #include "content/renderer/media/video_capture_message_filter.h" |
[email protected] | d7ff5fb | 2014-05-29 19:50:25 | [diff] [blame] | 113 | #include "content/renderer/net_info_helper.h" |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 114 | #include "content/renderer/p2p/socket_dispatcher.h" |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 115 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 116 | #include "content/renderer/render_process_impl.h" |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 117 | #include "content/renderer/render_view_impl.h" |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 118 | #include "content/renderer/renderer_blink_platform_impl.h" |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 119 | #include "content/renderer/scheduler/resource_dispatch_throttler.h" |
[email protected] | 7670d433 | 2013-11-29 04:35:00 | [diff] [blame] | 120 | #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 121 | #include "content/renderer/service_worker/service_worker_context_client.h" |
kinuko | 5af4ffe | 2015-06-09 03:38:46 | [diff] [blame] | 122 | #include "content/renderer/service_worker/service_worker_context_message_filter.h" |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 123 | #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 124 | #include "gin/public/debug.h" |
dongseong.hwang | 72183b0 | 2014-12-08 10:41:55 | [diff] [blame] | 125 | #include "gpu/GLES2/gl2extchromium.h" |
danakj | 6f4e1e2 | 2016-04-20 03:27:34 | [diff] [blame] | 126 | #include "gpu/command_buffer/client/shared_memory_limits.h" |
danakj | 870925d4 | 2016-05-03 20:07:38 | [diff] [blame] | 127 | #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 128 | #include "gpu/ipc/client/gpu_channel_host.h" |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 129 | #include "ipc/ipc_channel_handle.h" |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 130 | #include "ipc/ipc_channel_mojo.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 131 | #include "ipc/ipc_platform_file.h" |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 132 | #include "media/base/media.h" |
servolk | 8b3b39b | 2015-03-03 19:08:18 | [diff] [blame] | 133 | #include "media/renderers/gpu_video_accelerator_factories.h" |
[email protected] | f68c146 | 2014-04-24 18:17:53 | [diff] [blame] | 134 | #include "mojo/common/common_type_converters.h" |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 135 | #include "mojo/public/cpp/bindings/strong_binding.h" |
[email protected] | 620161e | 2011-03-07 18:05:26 | [diff] [blame] | 136 | #include "net/base/net_errors.h" |
eroman | 9ab6484 | 2015-07-21 05:07:52 | [diff] [blame] | 137 | #include "net/base/port_util.h" |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 138 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
tfarina | 7a4a7fd | 2016-01-20 14:23:44 | [diff] [blame] | 139 | #include "net/base/url_util.h" |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 140 | #include "services/shell/public/cpp/interface_provider.h" |
| 141 | #include "services/shell/public/cpp/interface_registry.h" |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 142 | #include "skia/ext/event_tracer_impl.h" |
ssid | 59c96916 | 2015-07-28 13:02:58 | [diff] [blame] | 143 | #include "skia/ext/skia_memory_dump_provider.h" |
reed | 6e5a7222 | 2015-08-06 20:37:16 | [diff] [blame] | 144 | #include "third_party/WebKit/public/platform/WebImageGenerator.h" |
bashi | 5f4c7892 | 2016-08-18 23:06:08 | [diff] [blame] | 145 | #include "third_party/WebKit/public/platform/WebMemoryCoordinator.h" |
[email protected] | 89c36f8 | 2013-07-17 06:23:27 | [diff] [blame] | 146 | #include "third_party/WebKit/public/platform/WebString.h" |
skyostil | 457b0a1 | 2014-09-09 10:12:07 | [diff] [blame] | 147 | #include "third_party/WebKit/public/platform/WebThread.h" |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 148 | #include "third_party/WebKit/public/platform/scheduler/child/compositor_worker_scheduler.h" |
| 149 | #include "third_party/WebKit/public/platform/scheduler/child/webthread_impl_for_worker_scheduler.h" |
| 150 | #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h" |
hong.zheng | a35a480d | 2014-12-25 17:11:09 | [diff] [blame] | 151 | #include "third_party/WebKit/public/web/WebCache.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 152 | #include "third_party/WebKit/public/web/WebDatabase.h" |
| 153 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 154 | #include "third_party/WebKit/public/web/WebFrame.h" |
| 155 | #include "third_party/WebKit/public/web/WebKit.h" |
| 156 | #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 157 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 158 | #include "third_party/WebKit/public/web/WebScriptController.h" |
| 159 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 160 | #include "third_party/WebKit/public/web/WebView.h" |
jshin | 0a9aa63 | 2015-04-29 18:35:29 | [diff] [blame] | 161 | #include "third_party/icu/source/i18n/unicode/timezone.h" |
[email protected] | ddbb5334 | 2014-01-06 10:59:47 | [diff] [blame] | 162 | #include "third_party/skia/include/core/SkGraphics.h" |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 163 | #include "ui/base/layout.h" |
[email protected] | 18ad677 | 2011-09-20 21:51:32 | [diff] [blame] | 164 | #include "ui/base/ui_base_switches.h" |
enne | e292bdc | 2016-09-15 19:57:15 | [diff] [blame] | 165 | #include "ui/gl/gl_switches.h" |
[email protected] | 2c62b56 | 2009-01-27 19:04:50 | [diff] [blame] | 166 | |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 167 | #if defined(OS_ANDROID) |
| 168 | #include <cpu-features.h> |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 169 | #include "content/renderer/android/synchronous_compositor_filter.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 170 | #include "content/renderer/android/synchronous_compositor_frame_sink.h" |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 171 | #include "content/renderer/media/android/renderer_demuxer_android.h" |
boliu | e81d1613 | 2016-04-26 00:54:41 | [diff] [blame] | 172 | #include "content/renderer/media/android/stream_texture_factory.h" |
dalecurtis | 88af393 | 2016-02-20 00:12:20 | [diff] [blame] | 173 | #include "media/base/android/media_codec_util.h" |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 174 | #endif |
| 175 | |
| 176 | #if defined(OS_MACOSX) |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 177 | #include "base/mac/mac_util.h" |
rsesek | 1efb3c3 | 2015-09-29 15:39:50 | [diff] [blame] | 178 | #include "content/renderer/theme_helper_mac.h" |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 179 | #include "content/renderer/webscrollbarbehavior_impl_mac.h" |
| 180 | #endif |
| 181 | |
| 182 | #if defined(OS_POSIX) |
| 183 | #include "ipc/ipc_channel_posix.h" |
| 184 | #endif |
| 185 | |
[email protected] | da00a288 | 2009-03-09 17:51:19 | [diff] [blame] | 186 | #if defined(OS_WIN) |
| 187 | #include <windows.h> |
| 188 | #include <objbase.h> |
| 189 | #endif |
| 190 | |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 191 | #if defined(ENABLE_WEBRTC) |
liushouqun | 517b129 | 2016-09-14 05:58:59 | [diff] [blame] | 192 | #include "content/renderer/media/aec_dump_message_filter.h" |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 193 | #include "content/renderer/media/peer_connection_tracker.h" |
| 194 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 195 | #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 196 | #endif |
| 197 | |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 198 | #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 199 | #include "v8/src/third_party/vtune/v8-vtune.h" |
| 200 | #endif |
| 201 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 202 | #if defined(USE_AURA) |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 203 | #include "content/public/common/mojo_shell_connection.h" |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 204 | #include "content/renderer/mus/render_widget_mus_connection.h" |
fsamuel | 2545ecc | 2015-12-05 00:44:46 | [diff] [blame] | 205 | #include "content/renderer/mus/render_widget_window_tree_client_factory.h" |
sadrul | 9909744 | 2016-08-11 16:10:12 | [diff] [blame] | 206 | #include "services/ui/public/cpp/gpu_service.h" |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 207 | #endif |
| 208 | |
ochang | dd89a1e | 2016-06-08 16:39:01 | [diff] [blame] | 209 | #if defined(ENABLE_IPC_FUZZER) |
| 210 | #include "content/common/external_ipc_dumper.h" |
| 211 | #endif |
| 212 | |
[email protected] | d293572a | 2013-05-23 18:50:45 | [diff] [blame] | 213 | using base::ThreadRestrictions; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 214 | using blink::WebDocument; |
| 215 | using blink::WebFrame; |
| 216 | using blink::WebNetworkStateNotifier; |
| 217 | using blink::WebRuntimeFeatures; |
| 218 | using blink::WebScriptController; |
| 219 | using blink::WebSecurityPolicy; |
| 220 | using blink::WebString; |
| 221 | using blink::WebView; |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 222 | using blink::scheduler::WebThreadImplForWorkerScheduler; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 223 | |
| 224 | namespace content { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 226 | namespace { |
[email protected] | da9ccfb | 2012-01-28 00:34:40 | [diff] [blame] | 227 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 228 | const int64_t kInitialIdleHandlerDelayMs = 1000; |
| 229 | const int64_t kLongIdleHandlerDelayMs = 30 * 1000; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 230 | |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 231 | #if defined(OS_ANDROID) |
| 232 | // On Android, resource messages can each take ~1.5ms to dispatch on the browser |
| 233 | // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the |
| 234 | // induced work takes but a fraction (~1/4) of the overall frame budget. |
| 235 | const int kMaxResourceRequestsPerFlushWhenThrottled = 3; |
| 236 | #else |
| 237 | const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
| 238 | #endif |
| 239 | const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
| 240 | |
[email protected] | dd2c102 | 2014-07-22 23:13:57 | [diff] [blame] | 241 | // Maximum allocation size allowed for image scaling filters that |
| 242 | // require pre-scaling. Skia will fallback to a filter that doesn't |
| 243 | // require pre-scaling if the default filter would require an |
| 244 | // allocation that exceeds this limit. |
| 245 | const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 246 | |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 247 | // Unique identifier for each output surface created. |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 248 | uint32_t g_next_compositor_frame_sink_id = 1; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 249 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 250 | // 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] | 251 | // incorrectly from the wrong thread. |
[email protected] | da9ccfb | 2012-01-28 00:34:40 | [diff] [blame] | 252 | base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 253 | lazy_tls = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 254 | |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 255 | // v8::MemoryPressureLevel should correspond to base::MemoryPressureListener. |
| 256 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 257 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 258 | v8::MemoryPressureLevel::kNone, "none level not align"); |
| 259 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 260 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 261 | v8::MemoryPressureLevel::kModerate, "moderate level not align"); |
| 262 | static_assert(static_cast<v8::MemoryPressureLevel>( |
| 263 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 264 | v8::MemoryPressureLevel::kCritical, "critical level not align"); |
| 265 | |
hong.zheng | 2e296f82 | 2016-06-29 02:47:44 | [diff] [blame] | 266 | // WebMemoryPressureLevel should correspond to base::MemoryPressureListener. |
| 267 | static_assert(static_cast<blink::WebMemoryPressureLevel>( |
| 268 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 269 | blink::WebMemoryPressureLevelNone, |
| 270 | "blink::WebMemoryPressureLevelNone not align"); |
| 271 | static_assert(static_cast<blink::WebMemoryPressureLevel>( |
| 272 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 273 | blink::WebMemoryPressureLevelModerate, |
| 274 | "blink::WebMemoryPressureLevelModerate not align"); |
| 275 | static_assert(static_cast<blink::WebMemoryPressureLevel>( |
| 276 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 277 | blink::WebMemoryPressureLevelCritical, |
| 278 | "blink::WebMemoryPressureLevelCritical not align"); |
| 279 | |
sadrul | ff12c00 | 2016-01-14 20:52:20 | [diff] [blame] | 280 | class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { |
| 281 | public: |
| 282 | explicit WebThreadForCompositor(base::Thread::Options options) |
| 283 | : WebThreadImplForWorkerScheduler("Compositor", options) { |
| 284 | Init(); |
| 285 | } |
| 286 | ~WebThreadForCompositor() override {} |
| 287 | |
| 288 | private: |
| 289 | // WebThreadImplForWorkerScheduler: |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 290 | std::unique_ptr<blink::scheduler::WorkerScheduler> CreateWorkerScheduler() |
| 291 | override { |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 292 | return base::MakeUnique<blink::scheduler::CompositorWorkerScheduler>( |
| 293 | thread()); |
sadrul | ff12c00 | 2016-01-14 20:52:20 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | DISALLOW_COPY_AND_ASSIGN(WebThreadForCompositor); |
| 297 | }; |
| 298 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 299 | void* CreateHistogram( |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 300 | const char *name, int min, int max, size_t buckets) { |
| 301 | if (min <= 0) |
| 302 | min = 1; |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 303 | std::string histogram_name; |
| 304 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 305 | if (render_thread_impl) { // Can be null in tests. |
| 306 | histogram_name = render_thread_impl-> |
| 307 | histogram_customizer()->ConvertToCustomHistogramName(name); |
| 308 | } else { |
| 309 | histogram_name = std::string(name); |
| 310 | } |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 311 | base::HistogramBase* histogram = base::Histogram::FactoryGet( |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 312 | histogram_name, min, max, buckets, |
| 313 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 314 | return histogram; |
| 315 | } |
| 316 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 317 | void AddHistogramSample(void* hist, int sample) { |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 318 | base::Histogram* histogram = static_cast<base::Histogram*>(hist); |
| 319 | histogram->Add(sample); |
| 320 | } |
| 321 | |
[email protected] | df9accd | 2014-03-13 18:18:30 | [diff] [blame] | 322 | void NotifyTimezoneChangeOnThisThread() { |
| 323 | v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 324 | if (!isolate) |
| 325 | return; |
| 326 | v8::Date::DateTimeConfigurationChangeNotification(isolate); |
| 327 | } |
| 328 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 329 | class FrameFactoryImpl : public mojom::FrameFactory { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 330 | public: |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 331 | FrameFactoryImpl() : routing_id_highmark_(-1) {} |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 332 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 333 | private: |
| 334 | // mojom::FrameFactory: |
| 335 | void CreateFrame(int32_t frame_routing_id, |
| 336 | mojom::FrameRequest frame_request, |
| 337 | mojom::FrameHostPtr frame_host) override { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 338 | // TODO(morrita): This is for investigating http://crbug.com/415059 and |
| 339 | // should be removed once it is fixed. |
| 340 | CHECK_LT(routing_id_highmark_, frame_routing_id); |
| 341 | routing_id_highmark_ = frame_routing_id; |
| 342 | |
| 343 | RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id); |
| 344 | // We can receive a GetServiceProviderForFrame message for a frame not yet |
| 345 | // created due to a race between the message and a ViewMsg_New IPC that |
| 346 | // triggers creation of the RenderFrame we want. |
| 347 | if (!frame) { |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 348 | RenderThreadImpl::current()->RegisterPendingFrameCreate( |
| 349 | frame_routing_id, std::move(frame_request), std::move(frame_host)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 350 | return; |
| 351 | } |
| 352 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 353 | frame->Bind(std::move(frame_request), std::move(frame_host)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | private: |
| 357 | int32_t routing_id_highmark_; |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 358 | }; |
| 359 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 360 | void CreateFrameFactory(mojom::FrameFactoryRequest request) { |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 361 | mojo::MakeStrongBinding(base::MakeUnique<FrameFactoryImpl>(), |
| 362 | std::move(request)); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 363 | } |
| 364 | |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 365 | void SetupEmbeddedWorkerOnWorkerThread( |
ben | 13be608 | 2016-06-29 15:08:58 | [diff] [blame] | 366 | shell::mojom::InterfaceProviderRequest request, |
| 367 | shell::mojom::InterfaceProviderPtrInfo remote_interfaces) { |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 368 | ServiceWorkerContextClient* client = |
| 369 | ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 370 | // It is possible for client to be null if for some reason the worker died |
| 371 | // before this call made it to the worker thread. In that case just do |
| 372 | // nothing and let mojo close the connection. |
| 373 | if (!client) |
| 374 | return; |
ben | 13be608 | 2016-06-29 15:08:58 | [diff] [blame] | 375 | client->BindInterfaceProviders(std::move(request), |
| 376 | mojo::MakeProxy(std::move(remote_interfaces))); |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 377 | } |
| 378 | |
leon.han | be782c4 | 2016-03-22 05:05:22 | [diff] [blame] | 379 | class EmbeddedWorkerSetupImpl : public mojom::EmbeddedWorkerSetup { |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 380 | public: |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 381 | EmbeddedWorkerSetupImpl() = default; |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 382 | |
ben | 9578795 | 2016-02-10 07:46:20 | [diff] [blame] | 383 | void ExchangeInterfaceProviders( |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 384 | int32_t thread_id, |
ben | 13be608 | 2016-06-29 15:08:58 | [diff] [blame] | 385 | shell::mojom::InterfaceProviderRequest request, |
| 386 | shell::mojom::InterfaceProviderPtr remote_interfaces) override { |
kinuko | ef64741 | 2015-12-23 06:10:43 | [diff] [blame] | 387 | WorkerThreadRegistry::Instance()->GetTaskRunnerFor(thread_id)->PostTask( |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 388 | FROM_HERE, |
ben | 13be608 | 2016-06-29 15:08:58 | [diff] [blame] | 389 | base::Bind(&SetupEmbeddedWorkerOnWorkerThread, base::Passed(&request), |
| 390 | base::Passed(remote_interfaces.PassInterface()))); |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 391 | } |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 392 | }; |
| 393 | |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 394 | void CreateEmbeddedWorkerSetup(mojom::EmbeddedWorkerSetupRequest request) { |
| 395 | mojo::MakeStrongBinding(base::MakeUnique<EmbeddedWorkerSetupImpl>(), |
| 396 | std::move(request)); |
mek | 27c9d74 | 2015-07-16 18:30:18 | [diff] [blame] | 397 | } |
| 398 | |
danakj | c398355 | 2016-05-03 00:04:35 | [diff] [blame] | 399 | scoped_refptr<ContextProviderCommandBuffer> CreateOffscreenContext( |
| 400 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 401 | const gpu::SharedMemoryLimits& limits, |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 402 | bool support_locking, |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 403 | command_buffer_metrics::ContextType type, |
| 404 | int32_t stream_id, |
| 405 | gpu::GpuStreamPriority stream_priority) { |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 406 | DCHECK(gpu_channel_host); |
| 407 | // This is used to create a few different offscreen contexts: |
| 408 | // - The shared main thread context (offscreen) used by blink for canvas. |
| 409 | // - The worker context (offscreen) used for GPU raster and video decoding. |
| 410 | // This is for an offscreen context, so the default framebuffer doesn't need |
| 411 | // alpha, depth, stencil, antialiasing. |
| 412 | gpu::gles2::ContextCreationAttribHelper attributes; |
| 413 | attributes.alpha_size = -1; |
| 414 | attributes.depth_size = 0; |
| 415 | attributes.stencil_size = 0; |
| 416 | attributes.samples = 0; |
| 417 | attributes.sample_buffers = 0; |
| 418 | attributes.bind_generates_resource = false; |
| 419 | attributes.lose_context_when_out_of_memory = true; |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 420 | const bool automatic_flushes = false; |
danakj | c398355 | 2016-05-03 00:04:35 | [diff] [blame] | 421 | return make_scoped_refptr(new ContextProviderCommandBuffer( |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 422 | std::move(gpu_channel_host), stream_id, stream_priority, |
| 423 | gpu::kNullSurfaceHandle, |
danakj | ba37f81 | 2016-05-03 03:58:03 | [diff] [blame] | 424 | GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext"), |
piman | d488e8b4 | 2016-06-30 19:06:59 | [diff] [blame] | 425 | automatic_flushes, support_locking, limits, attributes, nullptr, type)); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 426 | } |
| 427 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 428 | bool IsRunningInMash() { |
| 429 | const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 430 | return cmdline->HasSwitch(switches::kIsRunningInMash); |
| 431 | } |
| 432 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 433 | } // namespace |
| 434 | |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 435 | // For measuring memory usage after each task. Behind a command line flag. |
| 436 | class MemoryObserver : public base::MessageLoop::TaskObserver { |
| 437 | public: |
| 438 | MemoryObserver() {} |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 439 | ~MemoryObserver() override {} |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 440 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 441 | void WillProcessTask(const base::PendingTask& pending_task) override {} |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 442 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 443 | void DidProcessTask(const base::PendingTask& pending_task) override { |
asvitkine | c0fb802 | 2014-08-26 04:39:35 | [diff] [blame] | 444 | LOCAL_HISTOGRAM_MEMORY_KB("Memory.RendererUsed", GetMemoryUsageKB()); |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | private: |
| 448 | DISALLOW_COPY_AND_ASSIGN(MemoryObserver); |
| 449 | }; |
| 450 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 451 | RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { |
| 452 | custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); |
| 453 | custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted"); |
| 454 | custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed"); |
hablich | 4598ddc | 2015-11-07 18:37:28 | [diff] [blame] | 455 | custom_histograms_.insert("V8.MemoryHeapUsed"); |
| 456 | custom_histograms_.insert("V8.MemoryHeapCommitted"); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} |
| 460 | |
| 461 | void RenderThreadImpl::HistogramCustomizer::RenderViewNavigatedToHost( |
| 462 | const std::string& host, size_t view_count) { |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 463 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 464 | switches::kDisableHistogramCustomizer)) { |
[email protected] | 9baee83 | 2012-12-10 11:07:15 | [diff] [blame] | 465 | return; |
| 466 | } |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 467 | // Check if all RenderViews are displaying a page from the same host. If there |
| 468 | // is only one RenderView, the common host is this view's host. If there are |
| 469 | // many, check if this one shares the common host of the other |
| 470 | // RenderViews. It's ok to not detect some cases where the RenderViews share a |
| 471 | // common host. This information is only used for producing custom histograms. |
| 472 | if (view_count == 1) |
| 473 | SetCommonHost(host); |
| 474 | else if (host != common_host_) |
| 475 | SetCommonHost(std::string()); |
| 476 | } |
| 477 | |
| 478 | std::string RenderThreadImpl::HistogramCustomizer::ConvertToCustomHistogramName( |
| 479 | const char* histogram_name) const { |
| 480 | std::string name(histogram_name); |
| 481 | if (!common_host_histogram_suffix_.empty() && |
| 482 | custom_histograms_.find(name) != custom_histograms_.end()) |
| 483 | name += common_host_histogram_suffix_; |
| 484 | return name; |
| 485 | } |
| 486 | |
| 487 | void RenderThreadImpl::HistogramCustomizer::SetCommonHost( |
| 488 | const std::string& host) { |
| 489 | if (host != common_host_) { |
| 490 | common_host_ = host; |
| 491 | common_host_histogram_suffix_ = HostToCustomHistogramSuffix(host); |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 492 | blink::mainThreadIsolate()->SetCreateHistogramFunction(CreateHistogram); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 496 | std::string RenderThreadImpl::HistogramCustomizer::HostToCustomHistogramSuffix( |
| 497 | const std::string& host) { |
| 498 | if (host == "mail.google.com") |
| 499 | return ".gmail"; |
| 500 | if (host == "docs.google.com" || host == "drive.google.com") |
| 501 | return ".docs"; |
| 502 | if (host == "plus.google.com") |
| 503 | return ".plus"; |
| 504 | if (host == "inbox.google.com") |
| 505 | return ".inbox"; |
hpayer | dd4def05 | 2016-02-06 19:06:10 | [diff] [blame] | 506 | if (host == "calendar.google.com") |
| 507 | return ".calendar"; |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 508 | if (host == "www.youtube.com") |
| 509 | return ".youtube"; |
| 510 | if (IsAlexaTop10NonGoogleSite(host)) |
| 511 | return ".top10"; |
| 512 | |
| 513 | return std::string(); |
| 514 | } |
| 515 | |
| 516 | bool RenderThreadImpl::HistogramCustomizer::IsAlexaTop10NonGoogleSite( |
| 517 | const std::string& host) { |
| 518 | // The Top10 sites have different TLD and/or subdomains depending on the |
| 519 | // localization. |
| 520 | if (host == "sina.com.cn") |
| 521 | return true; |
| 522 | |
| 523 | std::string sanitized_host = |
| 524 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 525 | host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 526 | |
| 527 | if (sanitized_host == "facebook.com") |
| 528 | return true; |
| 529 | if (sanitized_host == "baidu.com") |
| 530 | return true; |
| 531 | if (sanitized_host == "qq.com") |
| 532 | return true; |
| 533 | if (sanitized_host == "twitter.com") |
| 534 | return true; |
| 535 | if (sanitized_host == "taobao.com") |
| 536 | return true; |
| 537 | if (sanitized_host == "live.com") |
| 538 | return true; |
| 539 | |
| 540 | if (!sanitized_host.empty()) { |
| 541 | std::vector<base::StringPiece> host_tokens = base::SplitStringPiece( |
| 542 | sanitized_host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 543 | |
| 544 | if (host_tokens.size() >= 2) { |
| 545 | if ((host_tokens[0] == "yahoo") || (host_tokens[0] == "amazon") || |
| 546 | (host_tokens[0] == "wikipedia")) { |
| 547 | return true; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | return false; |
| 552 | } |
| 553 | |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 554 | // static |
| 555 | RenderThreadImpl* RenderThreadImpl::Create( |
| 556 | const InProcessChildThreadParams& params) { |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 557 | std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler = |
| 558 | blink::scheduler::RendererScheduler::Create(); |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 559 | scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; |
| 560 | return new RenderThreadImpl( |
| 561 | params, std::move(renderer_scheduler), test_task_counter); |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // static |
| 565 | RenderThreadImpl* RenderThreadImpl::Create( |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 566 | std::unique_ptr<base::MessageLoop> main_message_loop, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 567 | std::unique_ptr<blink::scheduler::RendererScheduler> renderer_scheduler) { |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 568 | return new RenderThreadImpl(std::move(main_message_loop), |
| 569 | std::move(renderer_scheduler)); |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 572 | RenderThreadImpl* RenderThreadImpl::current() { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 573 | return lazy_tls.Pointer()->Get(); |
| 574 | } |
| 575 | |
leon.han | 2c0f9f1 | 2015-07-11 02:01:19 | [diff] [blame] | 576 | RenderThreadImpl::RenderThreadImpl( |
| 577 | const InProcessChildThreadParams& params, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 578 | std::unique_ptr<blink::scheduler::RendererScheduler> scheduler, |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 579 | scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 580 | : ChildThreadImpl(Options::Builder() |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 581 | .InBrowserProcess(params) |
| 582 | .UseMojoChannel(true) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 583 | .AutoStartMojoShellConnection(false) |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 584 | .ConnectToBrowser(true) |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 585 | .Build()), |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 586 | renderer_scheduler_(std::move(scheduler)), |
blundell | c00adf44 | 2016-09-16 10:43:41 | [diff] [blame^] | 587 | time_zone_monitor_binding_(this), |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 588 | categorized_worker_pool_(new CategorizedWorkerPool()) { |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 589 | Init(resource_task_queue); |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 590 | } |
| 591 | |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 592 | // When we run plugins in process, we actually run them on the render thread, |
| 593 | // which means that we need to make the render thread pump UI events. |
haraken | 53f081d | 2014-11-11 01:03:40 | [diff] [blame] | 594 | RenderThreadImpl::RenderThreadImpl( |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 595 | std::unique_ptr<base::MessageLoop> main_message_loop, |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 596 | std::unique_ptr<blink::scheduler::RendererScheduler> scheduler) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 597 | : ChildThreadImpl(Options::Builder() |
| 598 | .UseMojoChannel(true) |
| 599 | .AutoStartMojoShellConnection(false) |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 600 | .ConnectToBrowser(true) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 601 | .Build()), |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 602 | renderer_scheduler_(std::move(scheduler)), |
blundell | c00adf44 | 2016-09-16 10:43:41 | [diff] [blame^] | 603 | time_zone_monitor_binding_(this), |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 604 | main_message_loop_(std::move(main_message_loop)), |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 605 | categorized_worker_pool_(new CategorizedWorkerPool()) { |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 606 | scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; |
| 607 | Init(test_task_counter); |
haraken | 53f081d | 2014-11-11 01:03:40 | [diff] [blame] | 608 | } |
| 609 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 610 | void RenderThreadImpl::Init( |
| 611 | scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { |
fdoray | f6d8624 | 2015-10-08 16:49:53 | [diff] [blame] | 612 | TRACE_EVENT0("startup", "RenderThreadImpl::Init"); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 613 | |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 614 | base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex( |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 615 | base::PlatformThread::CurrentId(), |
| 616 | kTraceEventRendererMainThreadSortIndex); |
| 617 | |
haibinlu | c643d33c | 2016-06-03 02:22:34 | [diff] [blame] | 618 | #if defined(USE_EXTERNAL_POPUP_MENU) |
sievers | 9dff7205 | 2015-11-16 18:35:57 | [diff] [blame] | 619 | // On Mac and Android Java UI, the select popups are rendered by the browser. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 620 | blink::WebView::setUseExternalPopupMenus(true); |
[email protected] | 53c607c | 2011-03-21 23:19:04 | [diff] [blame] | 621 | #endif |
| 622 | |
[email protected] | 94f9a0f68 | 2009-06-15 18:30:30 | [diff] [blame] | 623 | lazy_tls.Pointer()->Set(this); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 624 | |
[email protected] | 06c694d | 2012-02-01 22:26:16 | [diff] [blame] | 625 | // Register this object as the main thread. |
| 626 | ChildProcess::current()->set_main_thread(this); |
| 627 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 628 | #if defined(USE_AURA) |
sadrul | 62c3113 | 2016-08-11 04:13:17 | [diff] [blame] | 629 | if (IsRunningInMash()) { |
sadrul | 9e0bb1d | 2016-08-04 20:18:39 | [diff] [blame] | 630 | gpu_service_ = |
sadrul | 75f7dde | 2016-08-22 23:37:24 | [diff] [blame] | 631 | ui::GpuService::Create(GetMojoShellConnection()->GetConnector(), |
| 632 | ChildProcess::current()->io_task_runner()); |
sadrul | 62c3113 | 2016-08-11 04:13:17 | [diff] [blame] | 633 | } |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 634 | #endif |
| 635 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 636 | InitializeWebKit(resource_task_queue); |
| 637 | |
[email protected] | 31f8713 | 2010-04-21 23:36:21 | [diff] [blame] | 638 | // In single process the single process is all there is. |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 639 | webkit_shared_timer_suspended_ = false; |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 640 | widget_count_ = 0; |
| 641 | hidden_widget_count_ = 0; |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 642 | idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 643 | idle_notifications_to_skip_ = 0; |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 644 | |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 645 | appcache_dispatcher_.reset( |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 646 | new AppCacheDispatcher(Get(), new AppCacheFrontendImpl())); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 647 | dom_storage_dispatcher_.reset(new DomStorageDispatcher()); |
[email protected] | 1e8d91e | 2013-06-27 00:12:43 | [diff] [blame] | 648 | main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher( |
| 649 | thread_safe_sender())); |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 650 | main_thread_cache_storage_dispatcher_.reset( |
jsbell | 279efb4 | 2015-03-31 17:02:46 | [diff] [blame] | 651 | new CacheStorageDispatcher(thread_safe_sender())); |
[email protected] | 7670d433 | 2013-11-29 04:35:00 | [diff] [blame] | 652 | embedded_worker_dispatcher_.reset(new EmbeddedWorkerDispatcher()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 653 | |
jdduke | 94ae1f3 | 2015-02-05 06:27:13 | [diff] [blame] | 654 | // Note: This may reorder messages from the ResourceDispatcher with respect to |
| 655 | // other subsystems. |
| 656 | resource_dispatch_throttler_.reset(new ResourceDispatchThrottler( |
| 657 | static_cast<RenderThread*>(this), renderer_scheduler_.get(), |
| 658 | base::TimeDelta::FromSecondsD(kThrottledResourceRequestFlushPeriodS), |
| 659 | kMaxResourceRequestsPerFlushWhenThrottled)); |
| 660 | resource_dispatcher()->set_message_sender(resource_dispatch_throttler_.get()); |
| 661 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 662 | media_stream_center_ = nullptr; |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 663 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 664 | blob_message_filter_ = new BlobMessageFilter(GetFileThreadTaskRunner()); |
dmurph | 1fb9848 | 2016-03-30 21:14:26 | [diff] [blame] | 665 | AddFilter(blob_message_filter_.get()); |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 666 | db_message_filter_ = new DBMessageFilter(); |
| 667 | AddFilter(db_message_filter_.get()); |
[email protected] | dd924193 | 2010-02-24 19:23:13 | [diff] [blame] | 668 | |
[email protected] | 4504807 | 2014-01-14 13:51:29 | [diff] [blame] | 669 | vc_manager_.reset(new VideoCaptureImplManager()); |
[email protected] | c9c43a0 | 2013-12-17 08:59:54 | [diff] [blame] | 670 | AddFilter(vc_manager_->video_capture_message_filter()); |
| 671 | |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 672 | browser_plugin_manager_.reset(new BrowserPluginManager()); |
| 673 | AddObserver(browser_plugin_manager_.get()); |
| 674 | |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 675 | #if defined(ENABLE_WEBRTC) |
[email protected] | af08997 | 2013-01-10 04:04:40 | [diff] [blame] | 676 | peer_connection_tracker_.reset(new PeerConnectionTracker()); |
| 677 | AddObserver(peer_connection_tracker_.get()); |
| 678 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 679 | p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOTaskRunner().get()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 680 | AddFilter(p2p_socket_dispatcher_.get()); |
[email protected] | 921480f6 | 2013-07-20 03:42:57 | [diff] [blame] | 681 | |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 682 | peer_connection_factory_.reset( |
| 683 | new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get())); |
| 684 | |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 685 | aec_dump_message_filter_ = new AecDumpMessageFilter( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 686 | GetIOTaskRunner(), message_loop()->task_runner()); |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 687 | |
[email protected] | da9f30a | 2014-06-18 19:39:04 | [diff] [blame] | 688 | AddFilter(aec_dump_message_filter_.get()); |
| 689 | |
[email protected] | 4761cf1 | 2012-09-12 10:37:55 | [diff] [blame] | 690 | #endif // defined(ENABLE_WEBRTC) |
[email protected] | e25f4d7 | 2011-06-08 20:58:46 | [diff] [blame] | 691 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 692 | audio_input_message_filter_ = new AudioInputMessageFilter(GetIOTaskRunner()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 693 | AddFilter(audio_input_message_filter_.get()); |
| 694 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 695 | audio_message_filter_ = new AudioMessageFilter(GetIOTaskRunner()); |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 696 | AddFilter(audio_message_filter_.get()); |
| 697 | |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 698 | midi_message_filter_ = new MidiMessageFilter(GetIOTaskRunner()); |
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 699 | AddFilter(midi_message_filter_.get()); |
| 700 | |
[email protected] | ce944c6 | 2013-11-19 16:34:36 | [diff] [blame] | 701 | AddFilter((new IndexedDBMessageFilter(thread_safe_sender()))->GetFilter()); |
[email protected] | 31bfae7 | 2011-12-16 02:04:38 | [diff] [blame] | 702 | |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 703 | AddFilter((new CacheStorageMessageFilter(thread_safe_sender()))->GetFilter()); |
| 704 | |
kinuko | 5af4ffe | 2015-06-09 03:38:46 | [diff] [blame] | 705 | AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter()); |
[email protected] | ddbb5334 | 2014-01-06 10:59:47 | [diff] [blame] | 706 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 707 | #if defined(USE_AURA) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 708 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 709 | switches::kUseMusInRenderer)) { |
| 710 | CreateRenderWidgetWindowTreeClientFactory(GetMojoShellConnection()); |
| 711 | } |
| 712 | #endif |
| 713 | |
| 714 | // Must be called before RenderThreadStarted() below. |
| 715 | StartMojoShellConnection(); |
| 716 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 717 | GetContentClient()->renderer()->RenderThreadStarted(); |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 718 | |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 719 | InitSkiaEventTracer(); |
ssid | 59c96916 | 2015-07-28 13:02:58 | [diff] [blame] | 720 | base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
primiano | 186d6bfe | 2015-10-30 13:21:40 | [diff] [blame] | 721 | skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr); |
[email protected] | b48c53ad | 2014-02-05 21:59:18 | [diff] [blame] | 722 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 723 | const base::CommandLine& command_line = |
| 724 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | e54ab49 | 2012-06-12 19:40:01 | [diff] [blame] | 725 | |
ochang | dd89a1e | 2016-06-08 16:39:01 | [diff] [blame] | 726 | #if defined(ENABLE_IPC_FUZZER) |
| 727 | if (command_line.HasSwitch(switches::kIpcDumpDirectory)) { |
| 728 | base::FilePath dump_directory = |
| 729 | command_line.GetSwitchValuePath(switches::kIpcDumpDirectory); |
| 730 | IPC::ChannelProxy::OutgoingMessageFilter* filter = |
| 731 | LoadExternalIPCDumper(dump_directory); |
| 732 | GetChannel()->set_outgoing_message_filter(filter); |
| 733 | } |
| 734 | #endif |
| 735 | |
jbroman | 0d30216 | 2015-09-05 05:46:23 | [diff] [blame] | 736 | cc::SetClientNameForMetrics("Renderer"); |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 737 | |
loyso | 65c93c60 | 2015-08-11 05:15:57 | [diff] [blame] | 738 | is_threaded_animation_enabled_ = |
| 739 | !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation); |
| 740 | |
reveman | 91a0a87 | 2014-11-04 03:40:32 | [diff] [blame] | 741 | is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy); |
ericrk | 1d17f75 | 2015-10-20 03:03:07 | [diff] [blame] | 742 | is_partial_raster_enabled_ = |
dongseong.hwang | 23db47f | 2016-03-08 07:50:02 | [diff] [blame] | 743 | !command_line.HasSwitch(switches::kDisablePartialRaster); |
ccameron | c7fcd13 | 2015-11-03 20:14:31 | [diff] [blame] | 744 | is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch( |
| 745 | switches::kEnableGpuMemoryBufferCompositorResources); |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 746 | |
jam | e1f453c | 2016-03-21 15:51:34 | [diff] [blame] | 747 | #if defined(OS_MACOSX) |
thakis | 114a1ef | 2016-04-26 16:02:59 | [diff] [blame] | 748 | base::ScopedCFTypeRef<CFStringRef> key( |
| 749 | base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding")); |
| 750 | Boolean key_exists = false; |
| 751 | Boolean value = CFPreferencesGetAppBooleanValue( |
| 752 | key, kCFPreferencesCurrentApplication, &key_exists); |
| 753 | is_elastic_overscroll_enabled_ = !key_exists || value; |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 754 | #else |
| 755 | is_elastic_overscroll_enabled_ = false; |
| 756 | #endif |
| 757 | |
danakj | e6eb185c | 2015-02-27 23:52:05 | [diff] [blame] | 758 | std::string image_texture_target_string = |
dcastagna | 7f2f719 | 2015-06-16 18:44:35 | [diff] [blame] | 759 | command_line.GetSwitchValueASCII(switches::kContentImageTextureTarget); |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 760 | buffer_to_texture_target_map_ = |
| 761 | cc::StringToBufferToTextureTargetMap(image_texture_target_string); |
reveman | 44b807f1 | 2014-11-26 02:44:50 | [diff] [blame] | 762 | |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 763 | if (command_line.HasSwitch(switches::kDisableLCDText)) { |
| 764 | is_lcd_text_enabled_ = false; |
| 765 | } else if (command_line.HasSwitch(switches::kEnableLCDText)) { |
| 766 | is_lcd_text_enabled_ = true; |
| 767 | } else { |
| 768 | #if defined(OS_ANDROID) |
| 769 | is_lcd_text_enabled_ = false; |
| 770 | #else |
| 771 | is_lcd_text_enabled_ = true; |
| 772 | #endif |
| 773 | } |
| 774 | |
[email protected] | b8d82c2 | 2014-03-31 20:12:46 | [diff] [blame] | 775 | is_gpu_rasterization_enabled_ = |
| 776 | command_line.HasSwitch(switches::kEnableGpuRasterization); |
| 777 | is_gpu_rasterization_forced_ = |
| 778 | command_line.HasSwitch(switches::kForceGpuRasterization); |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 779 | is_async_worker_context_enabled_ = |
| 780 | command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext); |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 781 | |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 782 | if (command_line.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) { |
| 783 | std::string string_value = command_line.GetSwitchValueASCII( |
| 784 | switches::kGpuRasterizationMSAASampleCount); |
| 785 | bool parsed_msaa_sample_count = |
| 786 | base::StringToInt(string_value, &gpu_rasterization_msaa_sample_count_); |
| 787 | DCHECK(parsed_msaa_sample_count) << string_value; |
| 788 | DCHECK_GE(gpu_rasterization_msaa_sample_count_, 0); |
| 789 | } else { |
senorblanco | 2a5b0e1 | 2015-08-14 21:55:37 | [diff] [blame] | 790 | gpu_rasterization_msaa_sample_count_ = -1; |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | b242b14 | 2014-05-07 14:48:49 | [diff] [blame] | 793 | if (command_line.HasSwitch(switches::kDisableDistanceFieldText)) { |
| 794 | is_distance_field_text_enabled_ = false; |
| 795 | } else if (command_line.HasSwitch(switches::kEnableDistanceFieldText)) { |
| 796 | is_distance_field_text_enabled_ = true; |
| 797 | } else { |
| 798 | is_distance_field_text_enabled_ = false; |
| 799 | } |
| 800 | |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 801 | // Note that under Linux, the media library will normally already have |
| 802 | // been initialized by the Zygote before this instance became a Renderer. |
chcunningham | fd11b3c | 2015-06-09 02:09:42 | [diff] [blame] | 803 | media::InitializeMediaLibrary(); |
[email protected] | 433df47 | 2012-03-07 20:33:39 | [diff] [blame] | 804 | |
dalecurtis | 88af393 | 2016-02-20 00:12:20 | [diff] [blame] | 805 | #if defined(OS_ANDROID) |
| 806 | if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
| 807 | media::MediaCodecUtil::IsMediaCodecAvailable()) { |
| 808 | media::EnablePlatformDecoderSupport(); |
| 809 | } |
| 810 | #endif |
| 811 | |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 812 | memory_pressure_listener_.reset(new base::MemoryPressureListener( |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 813 | base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 814 | base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 815 | base::Unretained(this)))); |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 816 | |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 817 | if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
bashi | 77f19b3 | 2016-07-19 11:19:43 | [diff] [blame] | 818 | // TODO(bashi): Revisit how to manage the lifetime of |
| 819 | // ChildMemoryCoordinatorImpl. |
| 820 | // https://codereview.chromium.org/2094583002/#msg52 |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 821 | mojom::MemoryCoordinatorHandlePtr parent_coordinator; |
bashi | 77f19b3 | 2016-07-19 11:19:43 | [diff] [blame] | 822 | GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&parent_coordinator)); |
bashi | a626404 | 2016-09-15 04:49:51 | [diff] [blame] | 823 | memory_coordinator_ = CreateChildMemoryCoordinator( |
bashi | c4b4afcb | 2016-08-23 06:37:52 | [diff] [blame] | 824 | std::move(parent_coordinator), this); |
bashi | 77f19b3 | 2016-07-19 11:19:43 | [diff] [blame] | 825 | } |
| 826 | |
danakj | 16275d4c | 2015-06-11 19:23:51 | [diff] [blame] | 827 | int num_raster_threads = 0; |
| 828 | std::string string_value = |
| 829 | command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 830 | bool parsed_num_raster_threads = |
| 831 | base::StringToInt(string_value, &num_raster_threads); |
| 832 | DCHECK(parsed_num_raster_threads) << string_value; |
| 833 | DCHECK_GT(num_raster_threads, 0); |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 834 | |
vmpstr | 6c0b511 | 2016-04-25 22:12:14 | [diff] [blame] | 835 | // TODO(vmpstr): If the flag sticks, we should clean it up and always have |
| 836 | // image decode tasks. |
vmpstr | 9dd810a | 2016-01-19 21:16:10 | [diff] [blame] | 837 | are_image_decode_tasks_enabled_ = true; |
halliwell | 4b3deee | 2014-12-19 19:57:49 | [diff] [blame] | 838 | |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 839 | categorized_worker_pool_->Start(num_raster_threads); |
[email protected] | 1e1d1e1 | 2014-01-17 16:14:29 | [diff] [blame] | 840 | |
boliu | 9760e21 | 2015-06-23 22:49:06 | [diff] [blame] | 841 | // TODO(boliu): In single process, browser main loop should set up the |
| 842 | // discardable memory manager, and should skip this if kSingleProcess. |
| 843 | // See crbug.com/503724. |
| 844 | base::DiscardableMemoryAllocator::SetInstance( |
| 845 | ChildThreadImpl::discardable_shared_memory_manager()); |
reveman | cb5a66af | 2014-10-25 00:34:39 | [diff] [blame] | 846 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 847 | GetContentClient()->renderer()->ExposeInterfacesToBrowser( |
| 848 | GetInterfaceRegistry()); |
rockot | 229fb28e | 2016-06-16 04:46:16 | [diff] [blame] | 849 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 850 | GetInterfaceRegistry()->AddInterface(base::Bind(CreateFrameFactory)); |
| 851 | GetInterfaceRegistry()->AddInterface(base::Bind(CreateEmbeddedWorkerSetup)); |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 852 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 853 | GetRemoteInterfaces()->GetInterface( |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 854 | mojo::GetProxy(&storage_partition_service_)); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 855 | |
blundell | c00adf44 | 2016-09-16 10:43:41 | [diff] [blame^] | 856 | device::mojom::TimeZoneMonitorPtr time_zone_monitor; |
| 857 | GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&time_zone_monitor)); |
| 858 | time_zone_monitor->AddClient( |
| 859 | time_zone_monitor_binding_.CreateInterfacePtrAndBind()); |
| 860 | |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 861 | is_renderer_suspended_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 862 | } |
| 863 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 864 | RenderThreadImpl::~RenderThreadImpl() { |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void RenderThreadImpl::Shutdown() { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 868 | FOR_EACH_OBSERVER( |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 869 | RenderThreadObserver, observers_, OnRenderProcessShutdown()); |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 870 | |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 871 | if (memory_observer_) { |
| 872 | message_loop()->RemoveTaskObserver(memory_observer_.get()); |
| 873 | memory_observer_.reset(); |
| 874 | } |
| 875 | |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 876 | // Wait for all databases to be closed. |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 877 | if (blink_platform_impl_) { |
michaeln | b1502854 | 2015-10-29 03:33:24 | [diff] [blame] | 878 | // Crash the process if they fail to close after a generous amount of time. |
| 879 | bool all_closed = blink_platform_impl_->web_database_observer_impl() |
| 880 | ->WaitForAllDatabasesToClose(base::TimeDelta::FromSeconds(60)); |
| 881 | CHECK(all_closed); |
[email protected] | 1406f89 | 2013-11-12 19:38:19 | [diff] [blame] | 882 | } |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 883 | |
[email protected] | 8d86fce | 2009-02-26 23:37:55 | [diff] [blame] | 884 | // Shutdown in reverse of the initialization order. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 885 | if (devtools_agent_message_filter_.get()) { |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 886 | RemoveFilter(devtools_agent_message_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 887 | devtools_agent_message_filter_ = nullptr; |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 888 | } |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 889 | |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 890 | RemoveFilter(audio_input_message_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 891 | audio_input_message_filter_ = nullptr; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 892 | |
[email protected] | 4504807 | 2014-01-14 13:51:29 | [diff] [blame] | 893 | #if defined(ENABLE_WEBRTC) |
[email protected] | 51c7985e | 2014-05-23 22:00:08 | [diff] [blame] | 894 | RTCPeerConnectionHandler::DestructAllHandlers(); |
tommi | 6c33f25 | 2014-11-24 12:29:51 | [diff] [blame] | 895 | // |peer_connection_factory_| cannot be deleted until after the main message |
| 896 | // loop has been destroyed. This is because there may be pending tasks that |
| 897 | // hold on to objects produced by the PC factory that depend on threads owned |
| 898 | // by the PC factory. Once those tasks have been freed, the factory can be |
| 899 | // deleted. |
[email protected] | 4504807 | 2014-01-14 13:51:29 | [diff] [blame] | 900 | #endif |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 901 | RemoveFilter(vc_manager_->video_capture_message_filter()); |
[email protected] | 4504807 | 2014-01-14 13:51:29 | [diff] [blame] | 902 | vc_manager_.reset(); |
[email protected] | 80b161a | 2011-06-27 17:42:11 | [diff] [blame] | 903 | |
[email protected] | 017022b | 2009-07-27 23:06:34 | [diff] [blame] | 904 | RemoveFilter(db_message_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 905 | db_message_filter_ = nullptr; |
[email protected] | 12cbfda3 | 2010-01-30 01:04:25 | [diff] [blame] | 906 | |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 907 | // Shutdown the file thread if it's running. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 908 | if (file_thread_) |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 909 | file_thread_->Stop(); |
| 910 | |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 911 | if (compositor_message_filter_.get()) { |
| 912 | RemoveFilter(compositor_message_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 913 | compositor_message_filter_ = nullptr; |
[email protected] | 23d2b7e | 2012-08-14 00:34:09 | [diff] [blame] | 914 | } |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 915 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 916 | #if defined(OS_ANDROID) |
| 917 | if (sync_compositor_message_filter_) { |
| 918 | RemoveFilter(sync_compositor_message_filter_.get()); |
| 919 | sync_compositor_message_filter_ = nullptr; |
| 920 | } |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 921 | stream_texture_factory_ = nullptr; |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 922 | #endif |
| 923 | |
[email protected] | b4ef774 | 2014-03-19 06:12:56 | [diff] [blame] | 924 | media_thread_.reset(); |
dalecurtis | 3ba0480e | 2014-09-09 20:21:30 | [diff] [blame] | 925 | |
sadrul | ff12c00 | 2016-01-14 20:52:20 | [diff] [blame] | 926 | blink_platform_impl_->SetCompositorThread(nullptr); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 927 | |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 928 | compositor_thread_.reset(); |
| 929 | |
dalecurtis | 3ba0480e | 2014-09-09 20:21:30 | [diff] [blame] | 930 | // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. |
| 931 | RemoveFilter(audio_message_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 932 | audio_message_filter_ = nullptr; |
dalecurtis | 3ba0480e | 2014-09-09 20:21:30 | [diff] [blame] | 933 | |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 934 | categorized_worker_pool_->Shutdown(); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 935 | |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 936 | main_input_callback_.Cancel(); |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 937 | input_handler_manager_.reset(); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 938 | if (input_event_filter_.get()) { |
[email protected] | b025568 | 2013-06-07 21:24:08 | [diff] [blame] | 939 | RemoveFilter(input_event_filter_.get()); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 940 | input_event_filter_ = nullptr; |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 941 | } |
| 942 | |
[email protected] | 51f82b0 | 2014-05-27 00:02:57 | [diff] [blame] | 943 | // RemoveEmbeddedWorkerRoute may be called while deleting |
| 944 | // EmbeddedWorkerDispatcher. So it must be deleted before deleting |
| 945 | // RenderThreadImpl. |
| 946 | embedded_worker_dispatcher_.reset(); |
| 947 | |
[email protected] | c5739b9e | 2013-11-07 06:30:22 | [diff] [blame] | 948 | // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might |
| 949 | // hold pointers to V8 objects (e.g., via pending requests). |
| 950 | main_thread_indexed_db_dispatcher_.reset(); |
| 951 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 952 | main_thread_compositor_task_runner_ = nullptr; |
skyostil | 457b0a1 | 2014-09-09 10:12:07 | [diff] [blame] | 953 | |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 954 | gpu_factories_.clear(); |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 955 | |
vmiura | eeb9177 | 2015-04-15 01:00:51 | [diff] [blame] | 956 | // Context providers must be released prior to destroying the GPU channel. |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 957 | shared_worker_context_provider_ = nullptr; |
piman | 765e528 | 2015-05-08 03:43:01 | [diff] [blame] | 958 | shared_main_thread_contexts_ = nullptr; |
vmiura | eeb9177 | 2015-04-15 01:00:51 | [diff] [blame] | 959 | |
haraken | 53f081d | 2014-11-11 01:03:40 | [diff] [blame] | 960 | if (gpu_channel_.get()) |
| 961 | gpu_channel_->DestroyChannel(); |
[email protected] | 8fd8de9 | 2008-08-12 23:50:30 | [diff] [blame] | 962 | |
reveman | 413413fb | 2016-01-14 00:43:07 | [diff] [blame] | 963 | ChildThreadImpl::Shutdown(); |
| 964 | |
fdoray | 2df4a9e | 2016-07-18 23:47:16 | [diff] [blame] | 965 | // Shut down the message loop (if provided when the RenderThreadImpl was |
| 966 | // constructed) and the renderer scheduler before shutting down Blink. This |
| 967 | // prevents a scenario where a pending task in the message loop accesses Blink |
| 968 | // objects after Blink shuts down. |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 969 | renderer_scheduler_->SetRAILModeObserver(nullptr); |
rmcilroy | 168f3dc | 2015-03-17 13:09:15 | [diff] [blame] | 970 | renderer_scheduler_->Shutdown(); |
haraken | 6e79a75 | 2016-09-05 01:33:50 | [diff] [blame] | 971 | if (main_message_loop_) |
| 972 | base::RunLoop().RunUntilIdle(); |
| 973 | |
haraken | 19a7c51a | 2016-09-05 04:19:50 | [diff] [blame] | 974 | if (blink_platform_impl_) { |
| 975 | blink_platform_impl_->Shutdown(); |
| 976 | // This must be at the very end of the shutdown sequence. |
| 977 | // blink::shutdown() must be called after all strong references from |
| 978 | // Chromium to Blink are cleared. |
| 979 | blink::shutdown(); |
| 980 | } |
| 981 | |
| 982 | // Delay shutting down DiscardableSharedMemoryManager until blink::shutdown |
| 983 | // is complete, because blink::shutdown destructs Blink Resources and they |
| 984 | // may try to unlock their underlying discardable memory. |
| 985 | ChildThreadImpl::ShutdownDiscardableSharedMemoryManager(); |
| 986 | |
| 987 | // The message loop must be cleared after shutting down |
| 988 | // the DiscardableSharedMemoryManager, which needs to send messages |
| 989 | // to the browser process. |
haraken | 6e79a75 | 2016-09-05 01:33:50 | [diff] [blame] | 990 | main_message_loop_.reset(); |
| 991 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 992 | lazy_tls.Pointer()->Set(nullptr); |
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) { |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 1009 | renderer_scheduler_->SuspendTimerQueue(); |
changwan | 6ed4d43 | 2016-05-19 22:03: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) { |
changwan | 6ed4d43 | 2016-05-19 22:03: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 | |
skyostil | 12262cf | 2015-05-21 14:49:31 | [diff] [blame] | 1042 | scoped_refptr<base::SingleThreadTaskRunner> |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 1043 | RenderThreadImpl::GetIOTaskRunner() { |
skyostil | 12262cf | 2015-05-21 14:49:31 | [diff] [blame] | 1044 | return ChildProcess::current()->io_task_runner(); |
[email protected] | 96191d5 | 2012-05-17 01:37:11 | [diff] [blame] | 1045 | } |
| 1046 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1047 | void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) { |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 1048 | ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener); |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1049 | auto it = pending_frame_creates_.find(routing_id); |
| 1050 | if (it == pending_frame_creates_.end()) |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1051 | return; |
| 1052 | |
| 1053 | RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
| 1054 | if (!frame) |
| 1055 | return; |
| 1056 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1057 | scoped_refptr<PendingFrameCreate> create(it->second); |
| 1058 | frame->Bind(it->second->TakeFrameRequest(), it->second->TakeFrameHost()); |
| 1059 | pending_frame_creates_.erase(it); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1060 | } |
| 1061 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1062 | void RenderThreadImpl::RemoveRoute(int32_t routing_id) { |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 1063 | ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1064 | } |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 1065 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1066 | void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id, |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1067 | IPC::Listener* listener) { |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1068 | AddRoute(routing_id, listener); |
| 1069 | if (devtools_agent_message_filter_.get()) { |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1070 | devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1071 | routing_id); |
| 1072 | } |
| 1073 | } |
| 1074 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1075 | void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) { |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1076 | RemoveRoute(routing_id); |
| 1077 | if (devtools_agent_message_filter_.get()) { |
[email protected] | a620b13 | 2014-04-30 22:39:17 | [diff] [blame] | 1078 | devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( |
[email protected] | 48e52e4 | 2014-03-20 06:58:07 | [diff] [blame] | 1079 | routing_id); |
| 1080 | } |
| 1081 | } |
| 1082 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1083 | void RenderThreadImpl::RegisterPendingFrameCreate( |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1084 | int routing_id, |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1085 | mojom::FrameRequest frame_request, |
| 1086 | mojom::FrameHostPtr frame_host) { |
| 1087 | std::pair<PendingFrameCreateMap::iterator, bool> result = |
| 1088 | pending_frame_creates_.insert(std::make_pair( |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1089 | routing_id, |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 1090 | make_scoped_refptr(new PendingFrameCreate( |
| 1091 | routing_id, std::move(frame_request), std::move(frame_host))))); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 1092 | CHECK(result.second) << "Inserting a duplicate item."; |
| 1093 | } |
| 1094 | |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 1095 | mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() { |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 1096 | return storage_partition_service_.get(); |
| 1097 | } |
| 1098 | |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 1099 | int RenderThreadImpl::GenerateRoutingID() { |
| 1100 | int routing_id = MSG_ROUTING_NONE; |
| 1101 | Send(new ViewHostMsg_GenerateRoutingID(&routing_id)); |
| 1102 | return routing_id; |
| 1103 | } |
| 1104 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 1105 | void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 1106 | channel()->AddFilter(filter); |
| 1107 | } |
| 1108 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 1109 | void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) { |
[email protected] | 42f1d782 | 2009-07-23 18:17:55 | [diff] [blame] | 1110 | channel()->RemoveFilter(filter); |
| 1111 | } |
| 1112 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1113 | void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1114 | observers_.AddObserver(observer); |
| 1115 | } |
| 1116 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1117 | void RenderThreadImpl::RemoveObserver(RenderThreadObserver* observer) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1118 | observers_.RemoveObserver(observer); |
| 1119 | } |
| 1120 | |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 1121 | void RenderThreadImpl::SetResourceDispatcherDelegate( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1122 | ResourceDispatcherDelegate* delegate) { |
[email protected] | 359dfa3 | 2011-10-12 01:10:15 | [diff] [blame] | 1123 | resource_dispatcher()->set_delegate(delegate); |
| 1124 | } |
| 1125 | |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1126 | void RenderThreadImpl::InitializeCompositorThread() { |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1127 | base::Thread::Options options; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1128 | #if defined(OS_ANDROID) |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1129 | options.priority = base::ThreadPriority::DISPLAY; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1130 | #endif |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1131 | compositor_thread_.reset(new WebThreadForCompositor(options)); |
| 1132 | blink_platform_impl_->SetCompositorThread(compositor_thread_.get()); |
| 1133 | compositor_task_runner_ = compositor_thread_->GetTaskRunner(); |
| 1134 | compositor_task_runner_->PostTask( |
| 1135 | FROM_HERE, |
| 1136 | base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), false)); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1137 | |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1138 | SynchronousInputHandlerProxyClient* synchronous_input_handler_proxy_client = |
| 1139 | nullptr; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1140 | #if defined(OS_ANDROID) |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 1141 | if (GetContentClient()->UsingSynchronousCompositing()) { |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1142 | sync_compositor_message_filter_ = |
| 1143 | new SynchronousCompositorFilter(compositor_task_runner_); |
| 1144 | AddFilter(sync_compositor_message_filter_.get()); |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1145 | synchronous_input_handler_proxy_client = |
| 1146 | sync_compositor_message_filter_.get(); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1147 | } |
| 1148 | #endif |
boliu | b2768db | 2016-06-03 23:35:16 | [diff] [blame] | 1149 | scoped_refptr<InputEventFilter> compositor_input_event_filter( |
| 1150 | new InputEventFilter(main_input_callback_.callback(), |
| 1151 | main_thread_compositor_task_runner_, |
| 1152 | compositor_task_runner_)); |
| 1153 | InputHandlerManagerClient* input_handler_manager_client = |
| 1154 | compositor_input_event_filter.get(); |
| 1155 | input_event_filter_ = compositor_input_event_filter; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1156 | input_handler_manager_.reset(new InputHandlerManager( |
| 1157 | compositor_task_runner_, input_handler_manager_client, |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 1158 | synchronous_input_handler_proxy_client, renderer_scheduler_.get())); |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1159 | } |
| 1160 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1161 | void RenderThreadImpl::InitializeWebKit( |
| 1162 | scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { |
| 1163 | DCHECK(!blink_platform_impl_); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1164 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1165 | const base::CommandLine& command_line = |
| 1166 | *base::CommandLine::ForCurrentProcess(); |
chunyang.dai | be874c5 | 2014-11-14 06:45:05 | [diff] [blame] | 1167 | |
| 1168 | #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 1169 | if (command_line.HasSwitch(switches::kEnableVtune)) |
| 1170 | gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler()); |
| 1171 | #endif |
| 1172 | |
rmcilroy | 4073ae1 | 2015-01-08 13:08:10 | [diff] [blame] | 1173 | SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line); |
| 1174 | |
sammc | bebeb60 | 2016-04-06 06:42:55 | [diff] [blame] | 1175 | blink_platform_impl_.reset(new RendererBlinkPlatformImpl( |
| 1176 | renderer_scheduler_.get(), |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 1177 | GetRemoteInterfaces()->GetWeakPtr())); |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 1178 | blink::initialize(blink_platform_impl_.get()); |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1179 | |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 1180 | v8::Isolate* isolate = blink::mainThreadIsolate(); |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 1181 | isolate->SetCreateHistogramFunction(CreateHistogram); |
| 1182 | isolate->SetAddHistogramSampleFunction(AddHistogramSample); |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 1183 | renderer_scheduler_->SetRAILModeObserver(this); |
[email protected] | 4b534028 | 2014-07-08 11:37:34 | [diff] [blame] | 1184 | |
rmcilroy | 321f924d | 2014-11-06 00:56:00 | [diff] [blame] | 1185 | main_thread_compositor_task_runner_ = |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1186 | renderer_scheduler_->CompositorTaskRunner(); |
skyostil | c30aa40 | 2014-10-10 13:49:09 | [diff] [blame] | 1187 | |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 1188 | main_input_callback_.Reset( |
| 1189 | base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived), |
| 1190 | base::Unretained(this))); |
| 1191 | |
jam | 75c4422 | 2016-03-23 05:34:24 | [diff] [blame] | 1192 | scoped_refptr<base::SingleThreadTaskRunner> resource_task_queue2; |
| 1193 | if (resource_task_queue) { |
| 1194 | resource_task_queue2 = resource_task_queue; |
| 1195 | } else { |
| 1196 | resource_task_queue2 = renderer_scheduler_->LoadingTaskRunner(); |
| 1197 | } |
| 1198 | // Add a filter that forces resource messages to be dispatched via a |
| 1199 | // particular task runner. |
| 1200 | scoped_refptr<ResourceSchedulingFilter> filter( |
| 1201 | new ResourceSchedulingFilter( |
| 1202 | resource_task_queue2, resource_dispatcher())); |
| 1203 | channel()->AddFilter(filter.get()); |
| 1204 | resource_dispatcher()->SetResourceSchedulingFilter(filter); |
| 1205 | |
| 1206 | // The ChildResourceMessageFilter and the ResourceDispatcher need to use the |
| 1207 | // same queue to ensure tasks are executed in the expected order. |
| 1208 | child_resource_message_filter()->SetMainThreadTaskRunner( |
| 1209 | resource_task_queue2); |
| 1210 | resource_dispatcher()->SetMainThreadTaskRunner(resource_task_queue2); |
| 1211 | |
khushalsagar | a5b15d7 | 2016-01-07 06:15:40 | [diff] [blame] | 1212 | if (!command_line.HasSwitch(switches::kDisableThreadedCompositing) && |
| 1213 | !command_line.HasSwitch(switches::kUseRemoteCompositing)) |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1214 | InitializeCompositorThread(); |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 1215 | |
jdduke | 691dd57 | 2014-12-02 20:47:52 | [diff] [blame] | 1216 | if (!input_event_filter_.get()) { |
| 1217 | // Always provide an input event filter implementation to ensure consistent |
| 1218 | // input event scheduling and prioritization. |
| 1219 | // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and |
| 1220 | // MainThreadInputEventFilter, crbug.com/436057. |
| 1221 | input_event_filter_ = new MainThreadInputEventFilter( |
| 1222 | main_input_callback_.callback(), main_thread_compositor_task_runner_); |
| 1223 | } |
| 1224 | AddFilter(input_event_filter_.get()); |
| 1225 | |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1226 | scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner; |
vollick | 1050cc6 | 2015-12-03 07:04:54 | [diff] [blame] | 1227 | if (compositor_task_runner_) |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1228 | compositor_impl_side_task_runner = compositor_task_runner_; |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 1229 | else |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1230 | compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get(); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1231 | |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 1232 | compositor_message_filter_ = new CompositorForwardingMessageFilter( |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1233 | compositor_impl_side_task_runner.get()); |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 1234 | AddFilter(compositor_message_filter_.get()); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1235 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1236 | RenderThreadImpl::RegisterSchemes(); |
| 1237 | |
xhwang | 194acae | 2014-11-12 22:46:33 | [diff] [blame] | 1238 | RenderMediaClient::Initialize(); |
| 1239 | |
[email protected] | b146d6d | 2012-09-11 10:20:05 | [diff] [blame] | 1240 | devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 1241 | AddFilter(devtools_agent_message_filter_.get()); |
| 1242 | |
alph | 666f80f | 2014-12-08 15:52:11 | [diff] [blame] | 1243 | v8_sampling_profiler_.reset(new V8SamplingProfiler()); |
| 1244 | |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 1245 | if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1246 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 1247 | } else { |
| 1248 | // If we do not track widget visibility, then assume conservatively that |
| 1249 | // the isolate is in background. This reduces memory usage. |
| 1250 | isolate->IsolateInBackgroundNotification(); |
| 1251 | } |
[email protected] | 2541d1a | 2013-07-10 07:33:27 | [diff] [blame] | 1252 | |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1253 | renderer_scheduler_->SetTimerQueueSuspensionWhenBackgroundedEnabled( |
| 1254 | GetContentClient() |
| 1255 | ->renderer() |
| 1256 | ->AllowTimerSuspensionWhenProcessBackgrounded()); |
| 1257 | |
reed | ccf98c5 | 2014-10-03 16:40:38 | [diff] [blame] | 1258 | SkGraphics::SetResourceCacheSingleAllocationByteLimit( |
[email protected] | dd2c102 | 2014-07-22 23:13:57 | [diff] [blame] | 1259 | kImageCacheSingleAllocationByteLimit); |
| 1260 | |
reed | 6e5a7222 | 2015-08-06 20:37:16 | [diff] [blame] | 1261 | // Hook up blink's codecs so skia can call them |
| 1262 | SkGraphics::SetImageGeneratorFromEncodedFactory( |
| 1263 | blink::WebImageGenerator::create); |
| 1264 | |
[email protected] | fdeac26 | 2014-07-10 12:52:51 | [diff] [blame] | 1265 | if (command_line.HasSwitch(switches::kMemoryMetrics)) { |
| 1266 | memory_observer_.reset(new MemoryObserver()); |
| 1267 | message_loop()->AddTaskObserver(memory_observer_.get()); |
| 1268 | } |
paritosh.in | 7e30c90 | 2015-04-15 17:04:07 | [diff] [blame] | 1269 | |
| 1270 | if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { |
| 1271 | std::string allowed_ports = |
| 1272 | command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); |
| 1273 | net::SetExplicitlyAllowedPorts(allowed_ports); |
| 1274 | } |
[email protected] | d1b8fccc | 2011-08-03 01:20:13 | [diff] [blame] | 1275 | } |
| 1276 | |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1277 | void RenderThreadImpl::RegisterSchemes() { |
mkwst | 8e94fb3 | 2015-05-20 05:05:14 | [diff] [blame] | 1278 | // chrome: |
| 1279 | WebString chrome_scheme(base::ASCIIToUTF16(kChromeUIScheme)); |
| 1280 | WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_scheme); |
| 1281 | WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( |
| 1282 | chrome_scheme); |
| 1283 | WebSecurityPolicy::registerURLSchemeAsSecure(chrome_scheme); |
| 1284 | WebSecurityPolicy::registerURLSchemeAsCORSEnabled(chrome_scheme); |
| 1285 | |
| 1286 | // chrome-devtools: |
| 1287 | WebString devtools_scheme(base::ASCIIToUTF16(kChromeDevToolsScheme)); |
| 1288 | WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(devtools_scheme); |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 1289 | |
| 1290 | // view-source: |
| 1291 | WebString view_source_scheme(base::ASCIIToUTF16(kViewSourceScheme)); |
| 1292 | WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(view_source_scheme); |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 1293 | } |
| 1294 | |
[email protected] | df9accd | 2014-03-13 18:18:30 | [diff] [blame] | 1295 | void RenderThreadImpl::NotifyTimezoneChange() { |
| 1296 | NotifyTimezoneChangeOnThisThread(); |
| 1297 | RenderThread::Get()->PostTaskToAllWebWorkers( |
| 1298 | base::Bind(&NotifyTimezoneChangeOnThisThread)); |
| 1299 | } |
| 1300 | |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 1301 | void RenderThreadImpl::RecordAction(const base::UserMetricsAction& action) { |
[email protected] | 97880c8 | 2013-12-04 07:09:21 | [diff] [blame] | 1302 | Send(new ViewHostMsg_UserMetricsRecordAction(action.str_)); |
| 1303 | } |
| 1304 | |
| 1305 | void RenderThreadImpl::RecordComputedAction(const std::string& action) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1306 | Send(new ViewHostMsg_UserMetricsRecordAction(action)); |
| 1307 | } |
| 1308 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1309 | std::unique_ptr<base::SharedMemory> |
| 1310 | RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) { |
erikchen | 4e01cbe | 2016-05-25 22:00:05 | [diff] [blame] | 1311 | return ChildThreadImpl::AllocateSharedMemory(size, thread_safe_sender(), |
| 1312 | nullptr); |
[email protected] | 00614a8 | 2011-10-07 22:39:31 | [diff] [blame] | 1313 | } |
| 1314 | |
jbauman | 2f5c194 | 2014-12-06 03:28:24 | [diff] [blame] | 1315 | cc::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() { |
| 1316 | return shared_bitmap_manager(); |
| 1317 | } |
| 1318 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1319 | void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1320 | WebScriptController::registerExtension(extension); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1321 | } |
| 1322 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1323 | void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1324 | idle_notification_delay_in_ms_ = initial_delay_ms; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1325 | idle_timer_.Stop(); |
| 1326 | idle_timer_.Start(FROM_HERE, |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1327 | base::TimeDelta::FromMilliseconds(initial_delay_ms), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1328 | this, &RenderThreadImpl::IdleHandler); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1329 | } |
| 1330 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1331 | void RenderThreadImpl::IdleHandler() { |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1332 | bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1333 | GetContentClient()->renderer()-> |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1334 | RunIdleHandlerWhenWidgetsHidden(); |
| 1335 | if (run_in_foreground_tab) { |
jochen | 5a32aaf | 2014-09-26 20:37:43 | [diff] [blame] | 1336 | if (idle_notifications_to_skip_ > 0) { |
| 1337 | --idle_notifications_to_skip_; |
| 1338 | } else { |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 1339 | ReleaseFreeMemory(); |
jochen | 5a32aaf | 2014-09-26 20:37:43 | [diff] [blame] | 1340 | } |
| 1341 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1342 | return; |
| 1343 | } |
[email protected] | 237a1485 | 2012-04-28 02:56:38 | [diff] [blame] | 1344 | |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 1345 | ReleaseFreeMemory(); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1346 | |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1347 | // Continue the idle timer if the webkit shared timer is not suspended or |
| 1348 | // something is left to do. |
| 1349 | bool continue_timer = !webkit_shared_timer_suspended_; |
| 1350 | |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1351 | // Schedule next invocation. When the tab is originally hidden, an invocation |
| 1352 | // is scheduled for kInitialIdleHandlerDelayMs in |
| 1353 | // RenderThreadImpl::WidgetHidden in order to race to a minimal heap. |
| 1354 | // After that, idle calls can be much less frequent, so run at a maximum of |
| 1355 | // once every kLongIdleHandlerDelayMs. |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1356 | // Dampen the delay using the algorithm (if delay is in seconds): |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1357 | // delay = delay + 1 / (delay + 2) |
| 1358 | // Using floor(delay) has a dampening effect such as: |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1359 | // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ... |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1360 | // If the delay is in milliseconds, the above formula is equivalent to: |
| 1361 | // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
| 1362 | // which is equivalent to |
| 1363 | // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1364 | if (continue_timer) { |
sullivan | cd45a3e | 2014-09-19 14:39:18 | [diff] [blame] | 1365 | ScheduleIdleHandler( |
| 1366 | std::max(kLongIdleHandlerDelayMs, |
| 1367 | idle_notification_delay_in_ms_ + |
| 1368 | 1000000 / (idle_notification_delay_in_ms_ + 2000))); |
[email protected] | 26e8232 | 2014-01-20 14:18:22 | [diff] [blame] | 1369 | |
| 1370 | } else { |
| 1371 | idle_timer_.Stop(); |
| 1372 | } |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1373 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1374 | FOR_EACH_OBSERVER(RenderThreadObserver, observers_, IdleNotification()); |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1375 | } |
| 1376 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1377 | int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1378 | return idle_notification_delay_in_ms_; |
[email protected] | 52647690 | 2011-10-06 20:34:06 | [diff] [blame] | 1379 | } |
| 1380 | |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1381 | void RenderThreadImpl::SetIdleNotificationDelayInMs( |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 1382 | int64_t idle_notification_delay_in_ms) { |
[email protected] | 6593ae1 | 2011-11-14 12:09:44 | [diff] [blame] | 1383 | idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1384 | } |
| 1385 | |
[email protected] | a1a7ff3 | 2012-07-19 14:03:51 | [diff] [blame] | 1386 | void RenderThreadImpl::UpdateHistograms(int sequence_number) { |
| 1387 | child_histogram_message_filter()->SendHistograms(sequence_number); |
| 1388 | } |
| 1389 | |
[email protected] | 5b1840636 | 2013-06-18 18:46:43 | [diff] [blame] | 1390 | int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) { |
kinuko | ef64741 | 2015-12-23 06:10:43 | [diff] [blame] | 1391 | return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure); |
[email protected] | a9bd323d | 2013-06-17 20:27:56 | [diff] [blame] | 1392 | } |
| 1393 | |
[email protected] | b02f590 | 2012-12-19 07:33:00 | [diff] [blame] | 1394 | bool RenderThreadImpl::ResolveProxy(const GURL& url, std::string* proxy_list) { |
| 1395 | bool result = false; |
| 1396 | Send(new ViewHostMsg_ResolveProxy(url, &result, proxy_list)); |
| 1397 | return result; |
| 1398 | } |
| 1399 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1400 | void RenderThreadImpl::PostponeIdleNotification() { |
| 1401 | idle_notifications_to_skip_ = 2; |
| 1402 | } |
| 1403 | |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 1404 | media::GpuVideoAcceleratorFactories* RenderThreadImpl::GetGpuFactories() { |
[email protected] | 3bb8bb3 | 2013-07-11 13:13:03 | [diff] [blame] | 1405 | DCHECK(IsMainThread()); |
| 1406 | |
dcastagna | 09bd6b3 | 2016-02-01 21:54:28 | [diff] [blame] | 1407 | if (!gpu_factories_.empty()) { |
| 1408 | scoped_refptr<ContextProviderCommandBuffer> shared_context_provider = |
| 1409 | gpu_factories_.back()->ContextProviderMainThread(); |
| 1410 | if (shared_context_provider) { |
| 1411 | cc::ContextProvider::ScopedContextLock lock( |
| 1412 | shared_context_provider.get()); |
| 1413 | if (lock.ContextGL()->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
| 1414 | return gpu_factories_.back(); |
| 1415 | } else { |
| 1416 | scoped_refptr<base::SingleThreadTaskRunner> media_task_runner = |
| 1417 | GetMediaThreadTaskRunner(); |
| 1418 | media_task_runner->PostTask( |
| 1419 | FROM_HERE, |
| 1420 | base::Bind( |
| 1421 | base::IgnoreResult( |
| 1422 | &RendererGpuVideoAcceleratorFactories::CheckContextLost), |
| 1423 | base::Unretained(gpu_factories_.back()))); |
| 1424 | } |
| 1425 | } |
| 1426 | } |
dcastagna | 7f45dada | 2015-10-19 20:17:35 | [diff] [blame] | 1427 | |
tobiasjs | ca238b3b | 2015-06-24 22:53:54 | [diff] [blame] | 1428 | const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 1429 | |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1430 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1431 | EstablishGpuChannelSync(); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1432 | if (!gpu_channel_host) |
| 1433 | return nullptr; |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 1434 | // This context is only used to create textures and mailbox them, so |
| 1435 | // use lower limits than the default. |
| 1436 | gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext(); |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1437 | bool support_locking = true; |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1438 | scoped_refptr<ContextProviderCommandBuffer> media_context_provider = |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1439 | CreateOffscreenContext(gpu_channel_host, limits, support_locking, |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 1440 | command_buffer_metrics::RENDER_WORKER_CONTEXT, |
| 1441 | gpu::GPU_STREAM_DEFAULT, |
| 1442 | gpu::GpuStreamPriority::NORMAL); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1443 | if (!media_context_provider->BindToCurrentThread()) |
| 1444 | return nullptr; |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1445 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1446 | scoped_refptr<base::SingleThreadTaskRunner> media_task_runner = |
| 1447 | GetMediaThreadTaskRunner(); |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1448 | const bool enable_video_accelerator = |
| 1449 | !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode); |
| 1450 | const bool enable_gpu_memory_buffer_video_frames = |
dcastagna | 43c3a86a | 2016-02-02 21:16:38 | [diff] [blame] | 1451 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
dcastagna | a82ed96a | 2016-05-12 02:52:47 | [diff] [blame] | 1452 | !cmd_line->HasSwitch(switches::kDisableGpuMemoryBufferVideoFrames) && |
| 1453 | !cmd_line->HasSwitch(switches::kDisableGpuCompositing) && |
| 1454 | !gpu_channel_host->gpu_info().software_rendering; |
dcastagna | b65e607 | 2015-09-05 07:18:42 | [diff] [blame] | 1455 | #else |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1456 | cmd_line->HasSwitch(switches::kEnableGpuMemoryBufferVideoFrames); |
dcastagna | b65e607 | 2015-09-05 07:18:42 | [diff] [blame] | 1457 | #endif |
dcastagna | 5077d6d | 2016-01-27 00:07:05 | [diff] [blame] | 1458 | |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1459 | gpu_factories_.push_back(RendererGpuVideoAcceleratorFactories::Create( |
| 1460 | std::move(gpu_channel_host), base::ThreadTaskRunnerHandle::Get(), |
| 1461 | media_task_runner, std::move(media_context_provider), |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 1462 | enable_gpu_memory_buffer_video_frames, buffer_to_texture_target_map_, |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 1463 | enable_video_accelerator)); |
| 1464 | return gpu_factories_.back(); |
[email protected] | 3bb8bb3 | 2013-07-11 13:13:03 | [diff] [blame] | 1465 | } |
| 1466 | |
danakj | 615aac2 | 2016-04-29 21:28:16 | [diff] [blame] | 1467 | scoped_refptr<ContextProviderCommandBuffer> |
[email protected] | f10dc47 | 2013-09-27 03:31:59 | [diff] [blame] | 1468 | RenderThreadImpl::SharedMainThreadContextProvider() { |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 1469 | DCHECK(IsMainThread()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1470 | if (shared_main_thread_contexts_ && |
| 1471 | shared_main_thread_contexts_->ContextGL()->GetGraphicsResetStatusKHR() == |
| 1472 | GL_NO_ERROR) |
| 1473 | return shared_main_thread_contexts_; |
| 1474 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1475 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 1476 | EstablishGpuChannelSync()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1477 | if (!gpu_channel_host) { |
| 1478 | shared_main_thread_contexts_ = nullptr; |
| 1479 | return nullptr; |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1480 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1481 | |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1482 | bool support_locking = false; |
danakj | c398355 | 2016-05-03 00:04:35 | [diff] [blame] | 1483 | shared_main_thread_contexts_ = CreateOffscreenContext( |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 1484 | std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking, |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 1485 | command_buffer_metrics::RENDERER_MAINTHREAD_CONTEXT, |
| 1486 | gpu::GPU_STREAM_DEFAULT, gpu::GpuStreamPriority::NORMAL); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 1487 | if (!shared_main_thread_contexts_->BindToCurrentThread()) |
| 1488 | shared_main_thread_contexts_ = nullptr; |
[email protected] | f10dc47 | 2013-09-27 03:31:59 | [diff] [blame] | 1489 | return shared_main_thread_contexts_; |
[email protected] | c29b7ff | 2013-03-06 03:51:04 | [diff] [blame] | 1490 | } |
| 1491 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1492 | #if defined(OS_ANDROID) |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1493 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1494 | scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() { |
| 1495 | DCHECK(IsMainThread()); |
boliu | 30f1b26 | 2016-04-19 00:12:33 | [diff] [blame] | 1496 | if (!stream_texture_factory_.get() || |
| 1497 | stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() != |
| 1498 | GL_NO_ERROR) { |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1499 | scoped_refptr<ContextProviderCommandBuffer> shared_context_provider = |
| 1500 | SharedMainThreadContextProvider(); |
| 1501 | if (!shared_context_provider) { |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1502 | stream_texture_factory_ = nullptr; |
| 1503 | return nullptr; |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1504 | } |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1505 | DCHECK(shared_context_provider->GetCommandBufferProxy()); |
| 1506 | DCHECK(shared_context_provider->GetCommandBufferProxy()->channel()); |
| 1507 | stream_texture_factory_ = |
| 1508 | StreamTextureFactory::Create(std::move(shared_context_provider)); |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1509 | } |
| 1510 | return stream_texture_factory_; |
| 1511 | } |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1512 | |
| 1513 | bool RenderThreadImpl::EnableStreamTextureCopy() { |
boliu | 30f1b26 | 2016-04-19 00:12:33 | [diff] [blame] | 1514 | return sync_compositor_message_filter_.get(); |
boliu | f8753bf6 | 2016-02-11 20:09:42 | [diff] [blame] | 1515 | } |
| 1516 | |
siva.gunturi | 5d4feb05 | 2015-11-15 16:15:31 | [diff] [blame] | 1517 | #endif |
| 1518 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1519 | AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1520 | if (!audio_renderer_mixer_manager_) { |
olka | 7a467939 | 2016-05-27 15:32:58 | [diff] [blame] | 1521 | audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create(); |
[email protected] | 3958e97 | 2012-07-17 00:25:41 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | return audio_renderer_mixer_manager_.get(); |
| 1525 | } |
| 1526 | |
[email protected] | 73429ca | 2014-03-06 06:07:47 | [diff] [blame] | 1527 | base::WaitableEvent* RenderThreadImpl::GetShutdownEvent() { |
| 1528 | return ChildProcess::current()->GetShutDownEvent(); |
| 1529 | } |
| 1530 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1531 | bool RenderThreadImpl::IsGpuRasterizationForced() { |
| 1532 | return is_gpu_rasterization_forced_; |
| 1533 | } |
| 1534 | |
| 1535 | bool RenderThreadImpl::IsGpuRasterizationEnabled() { |
| 1536 | return is_gpu_rasterization_enabled_; |
| 1537 | } |
| 1538 | |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 1539 | bool RenderThreadImpl::IsAsyncWorkerContextEnabled() { |
| 1540 | return is_async_worker_context_enabled_; |
| 1541 | } |
| 1542 | |
senorblanco | b60ba95 | 2015-01-27 19:12:36 | [diff] [blame] | 1543 | int RenderThreadImpl::GetGpuRasterizationMSAASampleCount() { |
| 1544 | return gpu_rasterization_msaa_sample_count_; |
| 1545 | } |
| 1546 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1547 | bool RenderThreadImpl::IsLcdTextEnabled() { |
| 1548 | return is_lcd_text_enabled_; |
| 1549 | } |
| 1550 | |
| 1551 | bool RenderThreadImpl::IsDistanceFieldTextEnabled() { |
| 1552 | return is_distance_field_text_enabled_; |
| 1553 | } |
| 1554 | |
| 1555 | bool RenderThreadImpl::IsZeroCopyEnabled() { |
| 1556 | return is_zero_copy_enabled_; |
| 1557 | } |
| 1558 | |
ericrk | 1d17f75 | 2015-10-20 03:03:07 | [diff] [blame] | 1559 | bool RenderThreadImpl::IsPartialRasterEnabled() { |
| 1560 | return is_partial_raster_enabled_; |
jbroman | 5f7f7193 | 2015-08-18 16:24:46 | [diff] [blame] | 1561 | } |
| 1562 | |
ccameron | c7fcd13 | 2015-11-03 20:14:31 | [diff] [blame] | 1563 | bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() { |
| 1564 | return is_gpu_memory_buffer_compositor_resources_enabled_; |
| 1565 | } |
| 1566 | |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 1567 | bool RenderThreadImpl::IsElasticOverscrollEnabled() { |
| 1568 | return is_elastic_overscroll_enabled_; |
| 1569 | } |
| 1570 | |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 1571 | const cc::BufferToTextureTargetMap& |
| 1572 | RenderThreadImpl::GetBufferToTextureTargetMap() { |
| 1573 | return buffer_to_texture_target_map_; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1574 | } |
vmiura | 9084b34 | 2015-02-03 22:19:57 | [diff] [blame] | 1575 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1576 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1577 | RenderThreadImpl::GetCompositorMainThreadTaskRunner() { |
| 1578 | return main_thread_compositor_task_runner_; |
| 1579 | } |
| 1580 | |
| 1581 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1582 | RenderThreadImpl::GetCompositorImplThreadTaskRunner() { |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 1583 | return compositor_task_runner_; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() { |
sadrul | a78e33d | 2016-08-16 20:11:21 | [diff] [blame] | 1587 | #if defined(USE_AURA) |
| 1588 | if (gpu_service_) |
| 1589 | return gpu_service_->gpu_memory_buffer_manager(); |
| 1590 | #endif |
| 1591 | return gpu_memory_buffer_manager(); |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1592 | } |
| 1593 | |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 1594 | blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() { |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1595 | return renderer_scheduler_.get(); |
| 1596 | } |
| 1597 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1598 | std::unique_ptr<cc::BeginFrameSource> |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1599 | RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) { |
enne | e292bdc | 2016-09-15 19:57:15 | [diff] [blame] | 1600 | const base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 1601 | if (cmd->HasSwitch(switches::kDisableGpuVsync)) { |
| 1602 | std::string display_vsync_string = |
| 1603 | cmd->GetSwitchValueASCII(switches::kDisableGpuVsync); |
| 1604 | if (display_vsync_string != "gpu") { |
| 1605 | // In disable gpu vsync mode, also let the renderer tick as fast as it |
| 1606 | // can. The top level begin frame source will also be running as a back |
| 1607 | // to back begin frame source, but using a synthetic begin frame source |
| 1608 | // here reduces latency when in this mode (at least for frames |
| 1609 | // starting--it potentially increases it for input on the other hand.) |
| 1610 | base::SingleThreadTaskRunner* compositor_impl_side_task_runner = |
| 1611 | compositor_task_runner_ ? compositor_task_runner_.get() |
| 1612 | : base::ThreadTaskRunnerHandle::Get().get(); |
| 1613 | return base::MakeUnique<cc::BackToBackBeginFrameSource>( |
| 1614 | base::MakeUnique<cc::DelayBasedTimeSource>( |
| 1615 | compositor_impl_side_task_runner)); |
| 1616 | } |
| 1617 | } |
| 1618 | |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 1619 | return base::MakeUnique<CompositorExternalBeginFrameSource>( |
| 1620 | compositor_message_filter_.get(), sync_message_filter(), routing_id); |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1621 | } |
| 1622 | |
nyquist | 16febb4 | 2016-02-12 00:15:04 | [diff] [blame] | 1623 | cc::ImageSerializationProcessor* |
| 1624 | RenderThreadImpl::GetImageSerializationProcessor() { |
| 1625 | return GetContentClient()->renderer()->GetImageSerializationProcessor(); |
| 1626 | } |
| 1627 | |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 1628 | cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() { |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 1629 | return categorized_worker_pool_->GetTaskGraphRunner(); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 1630 | } |
| 1631 | |
vmpstr | dfd2286 | 2015-09-25 17:42:41 | [diff] [blame] | 1632 | bool RenderThreadImpl::AreImageDecodeTasksEnabled() { |
| 1633 | return are_image_decode_tasks_enabled_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 1634 | } |
| 1635 | |
loyso | 65c93c60 | 2015-08-11 05:15:57 | [diff] [blame] | 1636 | bool RenderThreadImpl::IsThreadedAnimationEnabled() { |
| 1637 | return is_threaded_animation_enabled_; |
| 1638 | } |
| 1639 | |
skyostil | a37c2a7 | 2016-06-29 17:30:07 | [diff] [blame] | 1640 | void RenderThreadImpl::OnRAILModeChanged(v8::RAILMode rail_mode) { |
| 1641 | blink::mainThreadIsolate()->SetRAILMode(rail_mode); |
| 1642 | blink::setRAILModeOnWorkerThreadIsolates(rail_mode); |
| 1643 | } |
| 1644 | |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1645 | bool RenderThreadImpl::IsMainThread() { |
| 1646 | return !!current(); |
| 1647 | } |
| 1648 | |
skyostil | d445291 | 2015-05-14 14:41:53 | [diff] [blame] | 1649 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1650 | RenderThreadImpl::GetIOThreadTaskRunner() { |
| 1651 | return io_thread_task_runner_; |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1652 | } |
| 1653 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1654 | std::unique_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( |
[email protected] | 3f89283 | 2013-01-11 03:23:59 | [diff] [blame] | 1655 | size_t size) { |
piman | 08f7553 | 2015-10-05 18:58:01 | [diff] [blame] | 1656 | return HostAllocateSharedMemoryBuffer(size); |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1657 | } |
| 1658 | |
torne | 88b6645 | 2016-05-03 13:22:14 | [diff] [blame] | 1659 | void RenderThreadImpl::OnChannelError() { |
| 1660 | // In single-process mode, the renderer can't be restarted after shutdown. |
| 1661 | // So, if we get a channel error, crash the whole process right now to get a |
| 1662 | // more informative stack, since we will otherwise just crash later when we |
| 1663 | // try to restart it. |
| 1664 | CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1665 | switches::kSingleProcess)); |
| 1666 | ChildThreadImpl::OnChannelError(); |
| 1667 | } |
| 1668 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1669 | bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 1670 | base::ObserverListBase<RenderThreadObserver>::Iterator it(&observers_); |
| 1671 | RenderThreadObserver* observer; |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1672 | while ((observer = it.GetNext()) != nullptr) { |
[email protected] | 1223d6ef | 2011-03-28 16:47:50 | [diff] [blame] | 1673 | if (observer->OnControlMessageReceived(msg)) |
| 1674 | return true; |
| 1675 | } |
| 1676 | |
[email protected] | 70c19a93 | 2010-05-14 12:59:11 | [diff] [blame] | 1677 | // Some messages are handled by delegates. |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1678 | if (appcache_dispatcher_->OnMessageReceived(msg) || |
[email protected] | 7670d433 | 2013-11-29 04:35:00 | [diff] [blame] | 1679 | dom_storage_dispatcher_->OnMessageReceived(msg) || |
| 1680 | embedded_worker_dispatcher_->OnMessageReceived(msg)) { |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1681 | return true; |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1682 | } |
[email protected] | 1edc16b8 | 2009-04-07 17:45:54 | [diff] [blame] | 1683 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1684 | bool handled = true; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1685 | IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 1686 | IPC_MESSAGE_HANDLER(FrameMsg_NewFrame, OnCreateNewFrame) |
| 1687 | IPC_MESSAGE_HANDLER(FrameMsg_NewFrameProxy, OnCreateNewFrameProxy) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1688 | // TODO(port): removed from render_messages_internal.h; |
| 1689 | // is there a new non-windows message I should add here? |
| 1690 | IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |
jkarlin | 300a1d2 | 2015-09-18 19:32:52 | [diff] [blame] | 1691 | IPC_MESSAGE_HANDLER(ViewMsg_NetworkConnectionChanged, |
| 1692 | OnNetworkConnectionChanged) |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 1693 | IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateNewSharedWorker) |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 1694 | #if defined(OS_ANDROID) |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 1695 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebKitSharedTimersSuspended, |
| 1696 | OnSetWebKitSharedTimersSuspended) |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 1697 | #endif |
| 1698 | #if defined(OS_MACOSX) |
| 1699 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateScrollbarTheme, OnUpdateScrollbarTheme) |
rsesek | 1efb3c3 | 2015-09-29 15:39:50 | [diff] [blame] | 1700 | IPC_MESSAGE_HANDLER(ViewMsg_SystemColorsChanged, OnSystemColorsChanged) |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 1701 | #endif |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 1702 | #if defined(ENABLE_PLUGINS) |
| 1703 | IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |
| 1704 | #endif |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1705 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1706 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1707 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1708 | } |
| 1709 | |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1710 | void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1711 | ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1712 | |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1713 | if (backgrounded) { |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1714 | renderer_scheduler_->OnRendererBackgrounded(); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1715 | } else { |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1716 | renderer_scheduler_->OnRendererForegrounded(); |
hajimehoshi | 6909327 | 2016-05-13 08:30:58 | [diff] [blame] | 1717 | is_renderer_suspended_ = false; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1722 | ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1723 | if (is_renderer_suspended_) |
| 1724 | return; |
| 1725 | // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) |
| 1726 | is_renderer_suspended_ = true; |
| 1727 | renderer_scheduler_->SuspendRenderer(); |
jdduke | 73220f0 | 2015-09-04 17:03:51 | [diff] [blame] | 1728 | } |
| 1729 | |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 1730 | void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { |
alexmos | 6873421 | 2016-08-27 00:06:31 | [diff] [blame] | 1731 | // Debug cases of https://crbug.com/626802. |
| 1732 | base::debug::SetCrashKeyValue("newframe_routing_id", |
| 1733 | base::IntToString(params.routing_id)); |
| 1734 | base::debug::SetCrashKeyValue("newframe_proxy_id", |
| 1735 | base::IntToString(params.proxy_routing_id)); |
| 1736 | base::debug::SetCrashKeyValue("newframe_opener_id", |
| 1737 | base::IntToString(params.opener_routing_id)); |
| 1738 | base::debug::SetCrashKeyValue("newframe_parent_id", |
| 1739 | base::IntToString(params.parent_routing_id)); |
| 1740 | base::debug::SetCrashKeyValue("newframe_widget_id", |
| 1741 | base::IntToString( |
| 1742 | params.widget_params.routing_id)); |
| 1743 | base::debug::SetCrashKeyValue("newframe_widget_hidden", |
| 1744 | params.widget_params.hidden ? "yes" : "no"); |
| 1745 | base::debug::SetCrashKeyValue("newframe_replicated_origin", |
| 1746 | params.replication_state.origin.Serialize()); |
| 1747 | base::debug::SetCrashKeyValue("newframe_oopifs_possible", |
| 1748 | SiteIsolationPolicy::AreCrossProcessFramesPossible() ? "yes" : "no"); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 1749 | CompositorDependencies* compositor_deps = this; |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 1750 | RenderFrameImpl::CreateFrame( |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 1751 | params.routing_id, params.proxy_routing_id, params.opener_routing_id, |
| 1752 | params.parent_routing_id, params.previous_sibling_routing_id, |
lazyboy | 70605c3 | 2015-11-03 01:27:31 | [diff] [blame] | 1753 | params.replication_state, compositor_deps, params.widget_params, |
raymes | 3145780 | 2016-07-20 06:08:09 | [diff] [blame] | 1754 | params.frame_owner_properties); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 1755 | } |
| 1756 | |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 1757 | void RenderThreadImpl::OnCreateNewFrameProxy( |
| 1758 | int routing_id, |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 1759 | int render_view_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 1760 | int opener_routing_id, |
| 1761 | int parent_routing_id, |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 1762 | const FrameReplicationState& replicated_state) { |
creis | 9f7248b | 2016-01-27 20:27:39 | [diff] [blame] | 1763 | // Debug cases of https://crbug.com/575245. |
| 1764 | base::debug::SetCrashKeyValue("newproxy_proxy_id", |
| 1765 | base::IntToString(routing_id)); |
| 1766 | base::debug::SetCrashKeyValue("newproxy_view_id", |
| 1767 | base::IntToString(render_view_routing_id)); |
| 1768 | base::debug::SetCrashKeyValue("newproxy_opener_id", |
| 1769 | base::IntToString(opener_routing_id)); |
| 1770 | base::debug::SetCrashKeyValue("newproxy_parent_id", |
| 1771 | base::IntToString(parent_routing_id)); |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 1772 | RenderFrameProxy::CreateFrameProxy(routing_id, render_view_routing_id, |
| 1773 | opener_routing_id, parent_routing_id, |
| 1774 | replicated_state); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1777 | void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) { |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1778 | CompositorDependencies* compositor_deps = this; |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 1779 | // When bringing in render_view, also bring in webkit's glue and jsbindings. |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 1780 | RenderViewImpl::Create(compositor_deps, params, false); |
[email protected] | 7f874dec | 2009-02-06 01:48:27 | [diff] [blame] | 1781 | } |
[email protected] | 4274e58 | 2009-01-27 22:09:56 | [diff] [blame] | 1782 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1783 | scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 1784 | TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1785 | |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1786 | if (gpu_channel_) { |
[email protected] | 1082b1d | 2010-03-30 00:31:22 | [diff] [blame] | 1787 | // Do nothing if we already have a GPU channel or are already |
| 1788 | // establishing one. |
[email protected] | 7951bfe | 2013-06-13 01:43:34 | [diff] [blame] | 1789 | if (!gpu_channel_->IsLost()) |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1790 | return gpu_channel_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1791 | |
| 1792 | // Recreate the channel if it has been lost. |
piman | 765e528 | 2015-05-08 03:43:01 | [diff] [blame] | 1793 | gpu_channel_->DestroyChannel(); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1794 | gpu_channel_ = nullptr; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1795 | } |
| 1796 | |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1797 | if (!IsRunningInMash()) { |
| 1798 | int client_id = 0; |
| 1799 | IPC::ChannelHandle channel_handle; |
| 1800 | gpu::GPUInfo gpu_info; |
| 1801 | // Ask the browser for the channel name. |
| 1802 | if (!Send(new ChildProcessHostMsg_EstablishGpuChannel( |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1803 | &client_id, &channel_handle, &gpu_info)) || |
amistry | cef5cfa | 2016-07-21 00:09:32 | [diff] [blame] | 1804 | !channel_handle.mojo_handle.is_valid()) { |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1805 | // Otherwise cancel the connection. |
| 1806 | return nullptr; |
| 1807 | } |
| 1808 | GetContentClient()->SetGpuInfo(gpu_info); |
| 1809 | |
| 1810 | // Cache some variables that are needed on the compositor thread for our |
| 1811 | // implementation of GpuChannelHostFactory. |
| 1812 | io_thread_task_runner_ = ChildProcess::current()->io_task_runner(); |
| 1813 | |
| 1814 | gpu_channel_ = |
| 1815 | gpu::GpuChannelHost::Create(this, client_id, gpu_info, channel_handle, |
| 1816 | ChildProcess::current()->GetShutDownEvent(), |
| 1817 | gpu_memory_buffer_manager()); |
| 1818 | } else { |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 1819 | #if defined(USE_AURA) |
sadrul | 9e0bb1d | 2016-08-04 20:18:39 | [diff] [blame] | 1820 | gpu_channel_ = gpu_service_->EstablishGpuChannelSync(); |
penghuang | e1d8651 | 2016-07-08 18:15:00 | [diff] [blame] | 1821 | #else |
| 1822 | NOTREACHED(); |
| 1823 | #endif |
[email protected] | b42a9f6 | 2011-06-08 20:36:04 | [diff] [blame] | 1824 | } |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1825 | return gpu_channel_; |
[email protected] | 3bf4d53 | 2010-03-27 00:23:34 | [diff] [blame] | 1826 | } |
| 1827 | |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1828 | std::unique_ptr<cc::CompositorFrameSink> |
| 1829 | RenderThreadImpl::CreateCompositorFrameSink( |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1830 | bool use_software, |
| 1831 | int routing_id, |
| 1832 | scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue, |
| 1833 | const GURL& url) { |
| 1834 | const base::CommandLine& command_line = |
| 1835 | *base::CommandLine::ForCurrentProcess(); |
| 1836 | if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
| 1837 | use_software = true; |
| 1838 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 1839 | #if defined(USE_AURA) |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 1840 | if (GetMojoShellConnection() && !use_software && |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1841 | command_line.HasSwitch(switches::kUseMusInRenderer)) { |
| 1842 | RenderWidgetMusConnection* connection = |
| 1843 | RenderWidgetMusConnection::GetOrCreate(routing_id); |
sadrul | 12e259d | 2016-08-19 01:36:58 | [diff] [blame] | 1844 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = |
| 1845 | EstablishGpuChannelSync(); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1846 | return connection->CreateCompositorFrameSink(std::move(gpu_channel_host)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1847 | } |
| 1848 | #endif |
| 1849 | |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1850 | uint32_t compositor_frame_sink_id = g_next_compositor_frame_sink_id++; |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1851 | |
| 1852 | if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 1853 | scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 1854 | cc::VulkanInProcessContextProvider::Create(); |
| 1855 | if (vulkan_context_provider) { |
| 1856 | DCHECK(!layout_test_mode()); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1857 | return base::MakeUnique<RendererCompositorFrameSink>( |
| 1858 | routing_id, compositor_frame_sink_id, |
enne | 077ba486 | 2016-09-12 20:59:53 | [diff] [blame] | 1859 | CreateExternalBeginFrameSource(routing_id), |
| 1860 | std::move(vulkan_context_provider), |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 1861 | std::move(frame_swap_message_queue)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | // Create a gpu process channel and verify we want to use GPU compositing |
| 1866 | // before creating any context providers. |
| 1867 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
| 1868 | if (!use_software) { |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 1869 | gpu_channel_host = EstablishGpuChannelSync(); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1870 | if (!gpu_channel_host) { |
| 1871 | // Cause the compositor to wait and try again. |
| 1872 | return nullptr; |
| 1873 | } |
| 1874 | // We may get a valid channel, but with a software renderer. In that case, |
| 1875 | // disable GPU compositing. |
| 1876 | if (gpu_channel_host->gpu_info().software_rendering) |
| 1877 | use_software = true; |
| 1878 | } |
| 1879 | |
| 1880 | if (use_software) { |
| 1881 | DCHECK(!layout_test_mode()); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1882 | return base::MakeUnique<RendererCompositorFrameSink>( |
| 1883 | routing_id, compositor_frame_sink_id, |
enne | 077ba486 | 2016-09-12 20:59:53 | [diff] [blame] | 1884 | CreateExternalBeginFrameSource(routing_id), nullptr, nullptr, |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 1885 | std::move(frame_swap_message_queue)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | scoped_refptr<ContextProviderCommandBuffer> worker_context_provider = |
| 1889 | SharedCompositorWorkerContextProvider(); |
| 1890 | if (!worker_context_provider) { |
| 1891 | // Cause the compositor to wait and try again. |
| 1892 | return nullptr; |
| 1893 | } |
| 1894 | |
| 1895 | // The renderer compositor context doesn't do a lot of stuff, so we don't |
| 1896 | // expect it to need a lot of space for commands or transfer. Raster and |
| 1897 | // uploads happen on the worker context instead. |
| 1898 | gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext(); |
| 1899 | |
| 1900 | // This is for an offscreen context for the compositor. So the default |
| 1901 | // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
| 1902 | gpu::gles2::ContextCreationAttribHelper attributes; |
| 1903 | attributes.alpha_size = -1; |
| 1904 | attributes.depth_size = 0; |
| 1905 | attributes.stencil_size = 0; |
| 1906 | attributes.samples = 0; |
| 1907 | attributes.sample_buffers = 0; |
| 1908 | attributes.bind_generates_resource = false; |
| 1909 | attributes.lose_context_when_out_of_memory = true; |
| 1910 | |
| 1911 | constexpr bool automatic_flushes = false; |
| 1912 | constexpr bool support_locking = false; |
| 1913 | |
| 1914 | // The compositor context shares resources with the worker context unless |
| 1915 | // the worker is async. |
| 1916 | ContextProviderCommandBuffer* share_context = worker_context_provider.get(); |
| 1917 | if (IsAsyncWorkerContextEnabled()) |
| 1918 | share_context = nullptr; |
| 1919 | |
| 1920 | scoped_refptr<ContextProviderCommandBuffer> context_provider( |
| 1921 | new ContextProviderCommandBuffer( |
danakj | a40dd448 | 2016-06-28 01:14:10 | [diff] [blame] | 1922 | gpu_channel_host, gpu::GPU_STREAM_DEFAULT, |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1923 | gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, url, |
piman | d488e8b4 | 2016-06-30 19:06:59 | [diff] [blame] | 1924 | automatic_flushes, support_locking, limits, attributes, share_context, |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1925 | command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT)); |
| 1926 | |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1927 | if (layout_test_deps_) { |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1928 | return layout_test_deps_->CreateCompositorFrameSink( |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1929 | routing_id, std::move(gpu_channel_host), std::move(context_provider), |
danakj | a40dd448 | 2016-06-28 01:14:10 | [diff] [blame] | 1930 | std::move(worker_context_provider), this); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | #if defined(OS_ANDROID) |
| 1934 | if (sync_compositor_message_filter_) { |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1935 | return base::MakeUnique<SynchronousCompositorFrameSink>( |
danakj | a40dd448 | 2016-06-28 01:14:10 | [diff] [blame] | 1936 | std::move(context_provider), std::move(worker_context_provider), |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1937 | routing_id, compositor_frame_sink_id, |
enne | 077ba486 | 2016-09-12 20:59:53 | [diff] [blame] | 1938 | CreateExternalBeginFrameSource(routing_id), |
| 1939 | sync_compositor_message_filter_.get(), |
ricea | 29649b9 | 2016-08-31 09:30:21 | [diff] [blame] | 1940 | std::move(frame_swap_message_queue)); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1941 | } |
| 1942 | #endif |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 1943 | return base::WrapUnique(new RendererCompositorFrameSink( |
| 1944 | routing_id, compositor_frame_sink_id, |
| 1945 | CreateExternalBeginFrameSource(routing_id), std::move(context_provider), |
| 1946 | std::move(worker_context_provider), std::move(frame_swap_message_queue))); |
danakj | 83066a3 | 2016-06-21 02:34:49 | [diff] [blame] | 1947 | } |
| 1948 | |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1949 | std::unique_ptr<cc::SwapPromise> |
| 1950 | RenderThreadImpl::RequestCopyOfOutputForLayoutTest( |
| 1951 | int32_t routing_id, |
| 1952 | std::unique_ptr<cc::CopyOutputRequest> request) { |
| 1953 | DCHECK(layout_test_deps_); |
| 1954 | return layout_test_deps_->RequestCopyOfOutput(routing_id, std::move(request)); |
| 1955 | } |
| 1956 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1957 | blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter( |
| 1958 | blink::WebMediaStreamCenterClient* client) { |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 1959 | #if defined(ENABLE_WEBRTC) |
[email protected] | 68e5fee | 2013-02-18 10:04:22 | [diff] [blame] | 1960 | if (!media_stream_center_) { |
| 1961 | media_stream_center_ = GetContentClient()->renderer() |
| 1962 | ->OverrideCreateWebMediaStreamCenter(client); |
| 1963 | if (!media_stream_center_) { |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1964 | std::unique_ptr<MediaStreamCenter> media_stream_center( |
[email protected] | 0107d8a | 2014-05-16 10:20:34 | [diff] [blame] | 1965 | new MediaStreamCenter(client, GetPeerConnectionDependencyFactory())); |
[email protected] | c129874 | 2013-07-17 04:06:32 | [diff] [blame] | 1966 | media_stream_center_ = media_stream_center.release(); |
[email protected] | 68e5fee | 2013-02-18 10:04:22 | [diff] [blame] | 1967 | } |
| 1968 | } |
[email protected] | d8cd837 | 2012-03-09 10:49:51 | [diff] [blame] | 1969 | #endif |
| 1970 | return media_stream_center_; |
| 1971 | } |
| 1972 | |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 1973 | #if defined(ENABLE_WEBRTC) |
[email protected] | 0107d8a | 2014-05-16 10:20:34 | [diff] [blame] | 1974 | PeerConnectionDependencyFactory* |
| 1975 | RenderThreadImpl::GetPeerConnectionDependencyFactory() { |
[email protected] | 83e0a48 | 2014-05-22 18:07:18 | [diff] [blame] | 1976 | return peer_connection_factory_.get(); |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 1977 | } |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 1978 | #endif |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 1979 | |
rockot | 1587e33 | 2016-07-27 17:44:14 | [diff] [blame] | 1980 | mojom::RenderFrameMessageFilter* |
| 1981 | RenderThreadImpl::render_frame_message_filter() { |
| 1982 | if (!render_frame_message_filter_) |
| 1983 | GetChannel()->GetRemoteAssociatedInterface(&render_frame_message_filter_); |
| 1984 | return render_frame_message_filter_.get(); |
| 1985 | } |
| 1986 | |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 1987 | gpu::GpuChannelHost* RenderThreadImpl::GetGpuChannel() { |
piman | 9fc22f3 | 2016-05-02 22:21:22 | [diff] [blame] | 1988 | if (!gpu_channel_) |
danakj | 3873e85 | 2016-05-05 00:46:07 | [diff] [blame] | 1989 | return nullptr; |
[email protected] | 7951bfe | 2013-06-13 01:43:34 | [diff] [blame] | 1990 | if (gpu_channel_->IsLost()) |
danakj | 3873e85 | 2016-05-05 00:46:07 | [diff] [blame] | 1991 | return nullptr; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1992 | return gpu_channel_.get(); |
| 1993 | } |
| 1994 | |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 1995 | #if defined(ENABLE_PLUGINS) |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1996 | void RenderThreadImpl::OnPurgePluginListCache(bool reload_pages) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 1997 | // The call below will cause a GetPlugins call with refresh=true, but at this |
| 1998 | // point we already know that the browser has refreshed its list, so disable |
| 1999 | // refresh temporarily to prevent each renderer process causing the list to be |
| 2000 | // regenerated. |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 2001 | blink_platform_impl_->set_plugin_refresh_allowed(false); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2002 | blink::resetPluginCache(reload_pages); |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 2003 | blink_platform_impl_->set_plugin_refresh_allowed(true); |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 2004 | |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 2005 | FOR_EACH_OBSERVER(RenderThreadObserver, observers_, PluginListChanged()); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 2006 | } |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 2007 | #endif |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 2008 | |
jkarlin | 300a1d2 | 2015-09-18 19:32:52 | [diff] [blame] | 2009 | void RenderThreadImpl::OnNetworkConnectionChanged( |
| 2010 | net::NetworkChangeNotifier::ConnectionType type, |
| 2011 | double max_bandwidth_mbps) { |
[email protected] | 8c2a34b | 2014-06-10 16:27:27 | [diff] [blame] | 2012 | bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE; |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 2013 | WebNetworkStateNotifier::setOnLine(online); |
[email protected] | d7ff5fb | 2014-05-29 19:50:25 | [diff] [blame] | 2014 | FOR_EACH_OBSERVER( |
tyoshino | 832a58a | 2016-04-18 08:14:08 | [diff] [blame] | 2015 | RenderThreadObserver, observers_, NetworkStateChanged(online)); |
jkarlin | 300a1d2 | 2015-09-18 19:32:52 | [diff] [blame] | 2016 | WebNetworkStateNotifier::setWebConnection( |
| 2017 | NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps); |
[email protected] | 6eac57a | 2011-07-12 21:15:09 | [diff] [blame] | 2018 | } |
| 2019 | |
blundell | c00adf44 | 2016-09-16 10:43:41 | [diff] [blame^] | 2020 | void RenderThreadImpl::OnTimeZoneChange(const std::string& zone_id) { |
jochen | 22b6f9a | 2014-11-26 11:30:56 | [diff] [blame] | 2021 | if (!blink_platform_impl_) |
| 2022 | return; |
jshin | 0a9aa63 | 2015-04-29 18:35:29 | [diff] [blame] | 2023 | if (!zone_id.empty()) { |
| 2024 | icu::TimeZone *new_zone = icu::TimeZone::createTimeZone( |
| 2025 | icu::UnicodeString::fromUTF8(zone_id)); |
| 2026 | icu::TimeZone::adoptDefault(new_zone); |
| 2027 | VLOG(1) << "ICU default timezone is set to " << zone_id; |
| 2028 | } |
[email protected] | df9accd | 2014-03-13 18:18:30 | [diff] [blame] | 2029 | NotifyTimezoneChange(); |
| 2030 | } |
| 2031 | |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 2032 | #if defined(OS_ANDROID) |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 2033 | void RenderThreadImpl::OnSetWebKitSharedTimersSuspended(bool suspend) { |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 2034 | if (suspend) { |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 2035 | renderer_scheduler_->SuspendTimerQueue(); |
| 2036 | } else { |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 2037 | renderer_scheduler_->ResumeTimerQueue(); |
[email protected] | 3b96b7b5 | 2014-01-13 18:36:07 | [diff] [blame] | 2038 | } |
jdduke | d73ae541 | 2015-05-11 20:07:16 | [diff] [blame] | 2039 | webkit_shared_timer_suspended_ = suspend; |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 2040 | } |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 2041 | #endif |
| 2042 | |
| 2043 | #if defined(OS_MACOSX) |
[email protected] | 291857a | 2014-01-23 17:49:11 | [diff] [blame] | 2044 | void RenderThreadImpl::OnUpdateScrollbarTheme( |
kerrnel | c39eeb7 | 2015-06-25 21:11:48 | [diff] [blame] | 2045 | const ViewMsg_UpdateScrollbarTheme_Params& params) { |
[email protected] | 33b0299 | 2014-03-01 01:06:29 | [diff] [blame] | 2046 | static_cast<WebScrollbarBehaviorImpl*>( |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 2047 | blink_platform_impl_->scrollbarBehavior()) |
kerrnel | c39eeb7 | 2015-06-25 21:11:48 | [diff] [blame] | 2048 | ->set_jump_on_track_click(params.jump_on_track_click); |
| 2049 | |
kerrnel | a84d95e | 2015-07-31 17:34:21 | [diff] [blame] | 2050 | blink::WebScrollbarTheme::updateScrollbarsWithNSDefaults( |
kerrnel | c39eeb7 | 2015-06-25 21:11:48 | [diff] [blame] | 2051 | params.initial_button_delay, params.autoscroll_button_delay, |
kerrnel | a84d95e | 2015-07-31 17:34:21 | [diff] [blame] | 2052 | params.preferred_scroller_style, params.redraw, |
bokan | b9c00426 | 2016-02-17 23:22:10 | [diff] [blame] | 2053 | params.button_placement); |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 2054 | } |
rsesek | 1efb3c3 | 2015-09-29 15:39:50 | [diff] [blame] | 2055 | |
| 2056 | void RenderThreadImpl::OnSystemColorsChanged( |
| 2057 | int aqua_color_variant, |
| 2058 | const std::string& highlight_text_color, |
| 2059 | const std::string& highlight_color) { |
| 2060 | SystemColorsDidChange(aqua_color_variant, highlight_text_color, |
| 2061 | highlight_color); |
| 2062 | } |
[email protected] | b0988b2 | 2013-11-08 08:25:58 | [diff] [blame] | 2063 | #endif |
[email protected] | 4436338 | 2013-03-12 07:22:47 | [diff] [blame] | 2064 | |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 2065 | void RenderThreadImpl::OnCreateNewSharedWorker( |
| 2066 | const WorkerProcessMsg_CreateWorker_Params& params) { |
| 2067 | // EmbeddedSharedWorkerStub will self-destruct. |
mkwst | cfa9893 | 2016-03-09 13:06:19 | [diff] [blame] | 2068 | new EmbeddedSharedWorkerStub( |
| 2069 | params.url, params.name, params.content_security_policy, |
| 2070 | params.security_policy_type, params.creation_address_space, |
| 2071 | params.pause_on_start, params.route_id); |
[email protected] | 0ec90d52 | 2014-03-12 16:28:19 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 2074 | void RenderThreadImpl::OnMemoryPressure( |
| 2075 | base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2076 | TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
ssid | dda2ba02 | 2015-06-18 21:12:39 | [diff] [blame] | 2077 | ReleaseFreeMemory(); |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 2078 | |
rmcilroy | ab967c97 | 2015-02-17 23:15:00 | [diff] [blame] | 2079 | // Do not call into blink if it is not initialized. |
rmcilroy | 7fbb3bd5 | 2015-02-17 19:02:14 | [diff] [blame] | 2080 | if (blink_platform_impl_) { |
bashi | 5e843ac | 2016-06-17 07:44:35 | [diff] [blame] | 2081 | blink::WebMemoryCoordinator::onMemoryPressure( |
bashi | c577bfc | 2016-01-08 03:42:35 | [diff] [blame] | 2082 | static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
rmcilroy | ab967c97 | 2015-02-17 23:15:00 | [diff] [blame] | 2083 | |
rmcilroy | ab967c97 | 2015-02-17 23:15:00 | [diff] [blame] | 2084 | if (memory_pressure_level == |
| 2085 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
rmcilroy | ab967c97 | 2015-02-17 23:15:00 | [diff] [blame] | 2086 | // Purge Skia font cache, by setting it to 0 and then again to the |
| 2087 | // previous limit. |
| 2088 | size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2089 | SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2090 | } |
rmcilroy | 7fbb3bd5 | 2015-02-17 19:02:14 | [diff] [blame] | 2091 | } |
[email protected] | 5071cb2 | 2013-07-10 02:19:06 | [diff] [blame] | 2092 | } |
| 2093 | |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 2094 | scoped_refptr<base::SingleThreadTaskRunner> |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 2095 | RenderThreadImpl::GetFileThreadTaskRunner() { |
fdoray | e94d864 | 2016-07-07 19:19:01 | [diff] [blame] | 2096 | DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 2097 | if (!file_thread_) { |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 2098 | file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 2099 | file_thread_->Start(); |
| 2100 | } |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 2101 | return file_thread_->task_runner(); |
[email protected] | c6a7b86 | 2010-08-20 22:19:38 | [diff] [blame] | 2102 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2103 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 2104 | scoped_refptr<base::SingleThreadTaskRunner> |
| 2105 | RenderThreadImpl::GetMediaThreadTaskRunner() { |
fdoray | e94d864 | 2016-07-07 19:19:01 | [diff] [blame] | 2106 | DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2107 | if (!media_thread_) { |
| 2108 | media_thread_.reset(new base::Thread("Media")); |
| 2109 | media_thread_->Start(); |
[email protected] | 6ca6a08 | 2013-09-22 20:10:05 | [diff] [blame] | 2110 | |
| 2111 | #if defined(OS_ANDROID) |
| 2112 | renderer_demuxer_ = new RendererDemuxerAndroid(); |
| 2113 | AddFilter(renderer_demuxer_.get()); |
| 2114 | #endif |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2115 | } |
skyostil | 2d3b5bd | 2015-05-27 15:40:59 | [diff] [blame] | 2116 | return media_thread_->task_runner(); |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2117 | } |
| 2118 | |
dcastagna | 4517a18 | 2015-08-05 19:51:03 | [diff] [blame] | 2119 | base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() { |
prashant.n | fad657e | 2016-06-01 07:52:17 | [diff] [blame] | 2120 | return categorized_worker_pool_.get(); |
dcastagna | b880e8f | 2015-06-30 20:16:06 | [diff] [blame] | 2121 | } |
| 2122 | |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2123 | scoped_refptr<ContextProviderCommandBuffer> |
danakj | 0b4b94e3 | 2016-05-10 22:33:01 | [diff] [blame] | 2124 | RenderThreadImpl::SharedCompositorWorkerContextProvider() { |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2125 | DCHECK(IsMainThread()); |
| 2126 | // Try to reuse existing shared worker context provider. |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2127 | if (shared_worker_context_provider_) { |
| 2128 | // Note: If context is lost, delete reference after releasing the lock. |
boliu | 11afa7e | 2016-04-18 18:04:14 | [diff] [blame] | 2129 | cc::ContextProvider::ScopedContextLock lock( |
| 2130 | shared_worker_context_provider_.get()); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2131 | if (shared_worker_context_provider_->ContextGL() |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2132 | ->GetGraphicsResetStatusKHR() == GL_NO_ERROR) |
| 2133 | return shared_worker_context_provider_; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2134 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2135 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 2136 | scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 2137 | EstablishGpuChannelSync()); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2138 | if (!gpu_channel_host) { |
| 2139 | shared_worker_context_provider_ = nullptr; |
| 2140 | return shared_worker_context_provider_; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2141 | } |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2142 | |
sunnyps | d8ce1c2 | 2016-05-10 18:02:40 | [diff] [blame] | 2143 | int32_t stream_id = gpu::GPU_STREAM_DEFAULT; |
| 2144 | gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL; |
| 2145 | if (is_async_worker_context_enabled_) { |
| 2146 | stream_id = gpu_channel_host->GenerateStreamID(); |
| 2147 | stream_priority = gpu::GpuStreamPriority::LOW; |
| 2148 | } |
| 2149 | |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 2150 | bool support_locking = true; |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 2151 | shared_worker_context_provider_ = CreateOffscreenContext( |
danakj | 9a04adc | 2016-05-16 22:45:07 | [diff] [blame] | 2152 | std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking, |
danakj | 0dd9e1e | 2016-05-11 22:15:09 | [diff] [blame] | 2153 | command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id, |
| 2154 | stream_priority); |
danakj | e8ec797e | 2016-04-19 04:08:43 | [diff] [blame] | 2155 | if (!shared_worker_context_provider_->BindToCurrentThread()) |
| 2156 | shared_worker_context_provider_ = nullptr; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2157 | return shared_worker_context_provider_; |
| 2158 | } |
| 2159 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2160 | void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 2161 | blink_platform_impl_->sampleGamepads(*data); |
[email protected] | 0ff73656 | 2014-05-09 09:09:47 | [diff] [blame] | 2162 | } |
| 2163 | |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2164 | bool RenderThreadImpl::RendererIsHidden() const { |
| 2165 | return widget_count_ > 0 && hidden_widget_count_ == widget_count_; |
| 2166 | } |
| 2167 | |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2168 | void RenderThreadImpl::WidgetCreated() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2169 | bool renderer_was_hidden = RendererIsHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2170 | widget_count_++; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2171 | if (renderer_was_hidden) |
| 2172 | OnRendererVisible(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | void RenderThreadImpl::WidgetDestroyed() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2176 | // TODO(rmcilroy): Remove the restriction that destroyed widgets must be |
| 2177 | // unhidden before WidgetDestroyed is called. |
| 2178 | DCHECK_GT(widget_count_, 0); |
| 2179 | DCHECK_GT(widget_count_, hidden_widget_count_); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2180 | widget_count_--; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2181 | if (RendererIsHidden()) |
| 2182 | OnRendererHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | void RenderThreadImpl::WidgetHidden() { |
| 2186 | DCHECK_LT(hidden_widget_count_, widget_count_); |
| 2187 | hidden_widget_count_++; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2188 | if (RendererIsHidden()) |
| 2189 | OnRendererHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | void RenderThreadImpl::WidgetRestored() { |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2193 | bool renderer_was_hidden = RendererIsHidden(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2194 | DCHECK_GT(hidden_widget_count_, 0); |
| 2195 | hidden_widget_count_--; |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2196 | if (renderer_was_hidden) |
| 2197 | OnRendererVisible(); |
| 2198 | } |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2199 | |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2200 | void RenderThreadImpl::OnRendererHidden() { |
ulan | 432cd6e4 | 2016-03-01 15:59:14 | [diff] [blame] | 2201 | blink::mainThreadIsolate()->IsolateInBackgroundNotification(); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2202 | // TODO(rmcilroy): Remove IdleHandler and replace it with an IdleTask |
| 2203 | // scheduled by the RendererScheduler - http://crbug.com/469210. |
ulan | 4a38519 | 2015-11-11 10:59:18 | [diff] [blame] | 2204 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
| 2205 | return; |
| 2206 | ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | void RenderThreadImpl::OnRendererVisible() { |
ulan | 432cd6e4 | 2016-03-01 15:59:14 | [diff] [blame] | 2210 | blink::mainThreadIsolate()->IsolateInForegroundNotification(); |
rmcilroy | aa29605 | 2015-04-14 15:35:27 | [diff] [blame] | 2211 | if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2212 | return; |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 2213 | ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 2214 | } |
| 2215 | |
ssid | 0603ca9f | 2015-06-09 16:48:08 | [diff] [blame] | 2216 | void RenderThreadImpl::ReleaseFreeMemory() { |
| 2217 | base::allocator::ReleaseFreeMemory(); |
| 2218 | discardable_shared_memory_manager()->ReleaseFreeMemory(); |
| 2219 | |
| 2220 | if (blink_platform_impl_) |
| 2221 | blink::decommitFreeableMemory(); |
| 2222 | } |
| 2223 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2224 | RenderThreadImpl::PendingFrameCreate::PendingFrameCreate( |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2225 | int routing_id, |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2226 | mojom::FrameRequest frame_request, |
| 2227 | mojom::FrameHostPtr frame_host) |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2228 | : routing_id_(routing_id), |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2229 | frame_request_(std::move(frame_request)), |
| 2230 | frame_host_(std::move(frame_host)) { |
| 2231 | // The RenderFrame may be deleted before the CreateFrame message is received. |
| 2232 | // In that case, the RenderFrameHost should cancel the create, which is |
| 2233 | // detected by setting an error handler on |frame_host_|. |
| 2234 | frame_host_.set_connection_error_handler(base::Bind( |
| 2235 | &RenderThreadImpl::PendingFrameCreate::OnConnectionError, |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2236 | base::Unretained(this))); |
| 2237 | } |
| 2238 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2239 | RenderThreadImpl::PendingFrameCreate::~PendingFrameCreate() { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2240 | } |
| 2241 | |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2242 | void RenderThreadImpl::PendingFrameCreate::OnConnectionError() { |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2243 | size_t erased = |
ben | 76f52b24 | 2016-06-18 05:42:48 | [diff] [blame] | 2244 | RenderThreadImpl::current()->pending_frame_creates_.erase(routing_id_); |
rockot | f8fdd9b | 2015-12-16 22:22:35 | [diff] [blame] | 2245 | DCHECK_EQ(1u, erased); |
| 2246 | } |
| 2247 | |
hong.zheng | b28b533 | 2016-05-11 02:33:39 | [diff] [blame] | 2248 | void RenderThreadImpl::OnSyncMemoryPressure( |
| 2249 | base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2250 | if (!blink::mainThreadIsolate()) |
| 2251 | return; |
| 2252 | |
| 2253 | v8::MemoryPressureLevel v8_memory_pressure_level = |
| 2254 | static_cast<v8::MemoryPressureLevel>(memory_pressure_level); |
| 2255 | |
| 2256 | // In order to reduce performance impact, translate critical level to |
| 2257 | // moderate level for foregroud renderer. |
| 2258 | if (!RendererIsHidden() && |
| 2259 | v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2260 | v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
| 2261 | |
| 2262 | blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2263 | v8_memory_pressure_level); |
| 2264 | blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2265 | v8_memory_pressure_level); |
| 2266 | } |
| 2267 | |
bashi | c4b4afcb | 2016-08-23 06:37:52 | [diff] [blame] | 2268 | // Note that this would be called only when memory_coordinator is enabled. |
| 2269 | // OnSyncMemoryPressure() is never called in that case. |
| 2270 | void RenderThreadImpl::OnTrimMemoryImmediately() { |
| 2271 | if (blink::mainThreadIsolate()) { |
| 2272 | blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2273 | v8::MemoryPressureLevel::kCritical); |
| 2274 | blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2275 | v8::MemoryPressureLevel::kCritical); |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2280 | } // namespace content |