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