OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" | 154 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" |
155 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 155 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
156 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 156 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
157 #include "third_party/WebKit/public/web/WebScriptController.h" | 157 #include "third_party/WebKit/public/web/WebScriptController.h" |
158 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 158 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
159 #include "third_party/WebKit/public/web/WebView.h" | 159 #include "third_party/WebKit/public/web/WebView.h" |
160 #include "third_party/icu/source/i18n/unicode/timezone.h" | 160 #include "third_party/icu/source/i18n/unicode/timezone.h" |
161 #include "third_party/skia/include/core/SkGraphics.h" | 161 #include "third_party/skia/include/core/SkGraphics.h" |
162 #include "ui/base/layout.h" | 162 #include "ui/base/layout.h" |
163 #include "ui/base/ui_base_switches.h" | 163 #include "ui/base/ui_base_switches.h" |
164 #include "v8/include/v8.h" | |
165 | 164 |
166 #if defined(OS_ANDROID) | 165 #if defined(OS_ANDROID) |
167 #include <cpu-features.h> | 166 #include <cpu-features.h> |
168 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s
ource.h" | 167 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s
ource.h" |
169 #include "content/renderer/android/synchronous_compositor_filter.h" | 168 #include "content/renderer/android/synchronous_compositor_filter.h" |
170 #include "content/renderer/media/android/renderer_demuxer_android.h" | 169 #include "content/renderer/media/android/renderer_demuxer_android.h" |
171 #include "content/renderer/media/android/stream_texture_factory.h" | 170 #include "content/renderer/media/android/stream_texture_factory.h" |
172 #include "media/base/android/media_codec_util.h" | 171 #include "media/base/android/media_codec_util.h" |
173 #endif | 172 #endif |
174 | 173 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // require pre-scaling. Skia will fallback to a filter that doesn't | 234 // require pre-scaling. Skia will fallback to a filter that doesn't |
236 // require pre-scaling if the default filter would require an | 235 // require pre-scaling if the default filter would require an |
237 // allocation that exceeds this limit. | 236 // allocation that exceeds this limit. |
238 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; | 237 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
239 | 238 |
240 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access | 239 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
241 // incorrectly from the wrong thread. | 240 // incorrectly from the wrong thread. |
242 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > | 241 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
243 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 242 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
244 | 243 |
| 244 // v8::MemoryPressureLevel should correspond to base::MemoryPressureListener. |
| 245 static_assert(static_cast<v8::MemoryPressureLevel>( |
| 246 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 247 v8::MemoryPressureLevel::kNone, "none level not align"); |
| 248 static_assert(static_cast<v8::MemoryPressureLevel>( |
| 249 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 250 v8::MemoryPressureLevel::kModerate, "moderate level not align"); |
| 251 static_assert(static_cast<v8::MemoryPressureLevel>( |
| 252 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 253 v8::MemoryPressureLevel::kCritical, "critical level not align"); |
| 254 |
245 class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { | 255 class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { |
246 public: | 256 public: |
247 explicit WebThreadForCompositor(base::Thread::Options options) | 257 explicit WebThreadForCompositor(base::Thread::Options options) |
248 : WebThreadImplForWorkerScheduler("Compositor", options) { | 258 : WebThreadImplForWorkerScheduler("Compositor", options) { |
249 Init(); | 259 Init(); |
250 } | 260 } |
251 ~WebThreadForCompositor() override {} | 261 ~WebThreadForCompositor() override {} |
252 | 262 |
253 private: | 263 private: |
254 // WebThreadImplForWorkerScheduler: | 264 // WebThreadImplForWorkerScheduler: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 blink::enableLogChannel(t.token().c_str()); | 306 blink::enableLogChannel(t.token().c_str()); |
297 } | 307 } |
298 | 308 |
299 void NotifyTimezoneChangeOnThisThread() { | 309 void NotifyTimezoneChangeOnThisThread() { |
300 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 310 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
301 if (!isolate) | 311 if (!isolate) |
302 return; | 312 return; |
303 v8::Date::DateTimeConfigurationChangeNotification(isolate); | 313 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
304 } | 314 } |
305 | 315 |
306 void LowMemoryNotificationOnThisThread() { | |
307 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
308 if (!isolate) | |
309 return; | |
310 isolate->LowMemoryNotification(); | |
311 } | |
312 | |
313 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { | 316 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { |
314 public: | 317 public: |
315 explicit RenderFrameSetupImpl( | 318 explicit RenderFrameSetupImpl( |
316 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) | 319 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) |
317 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} | 320 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} |
318 | 321 |
319 void ExchangeInterfaceProviders( | 322 void ExchangeInterfaceProviders( |
320 int32_t frame_routing_id, | 323 int32_t frame_routing_id, |
321 shell::mojom::InterfaceProviderRequest services, | 324 shell::mojom::InterfaceProviderRequest services, |
322 shell::mojom::InterfaceProviderPtr exposed_services) override { | 325 shell::mojom::InterfaceProviderPtr exposed_services) override { |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 media::InitializeMediaLibrary(); | 771 media::InitializeMediaLibrary(); |
769 | 772 |
770 #if defined(OS_ANDROID) | 773 #if defined(OS_ANDROID) |
771 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 774 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
772 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 775 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
773 media::EnablePlatformDecoderSupport(); | 776 media::EnablePlatformDecoderSupport(); |
774 } | 777 } |
775 #endif | 778 #endif |
776 | 779 |
777 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 780 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
778 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 781 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 782 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 783 base::Unretained(this)))); |
779 | 784 |
780 int num_raster_threads = 0; | 785 int num_raster_threads = 0; |
781 std::string string_value = | 786 std::string string_value = |
782 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 787 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
783 bool parsed_num_raster_threads = | 788 bool parsed_num_raster_threads = |
784 base::StringToInt(string_value, &num_raster_threads); | 789 base::StringToInt(string_value, &num_raster_threads); |
785 DCHECK(parsed_num_raster_threads) << string_value; | 790 DCHECK(parsed_num_raster_threads) << string_value; |
786 DCHECK_GT(num_raster_threads, 0); | 791 DCHECK_GT(num_raster_threads, 0); |
787 | 792 |
788 // TODO(vmpstr): If the flag sticks, we should clean it up and always have | 793 // TODO(vmpstr): If the flag sticks, we should clean it up and always have |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 const WorkerProcessMsg_CreateWorker_Params& params) { | 1871 const WorkerProcessMsg_CreateWorker_Params& params) { |
1867 // EmbeddedSharedWorkerStub will self-destruct. | 1872 // EmbeddedSharedWorkerStub will self-destruct. |
1868 new EmbeddedSharedWorkerStub( | 1873 new EmbeddedSharedWorkerStub( |
1869 params.url, params.name, params.content_security_policy, | 1874 params.url, params.name, params.content_security_policy, |
1870 params.security_policy_type, params.creation_address_space, | 1875 params.security_policy_type, params.creation_address_space, |
1871 params.pause_on_start, params.route_id); | 1876 params.pause_on_start, params.route_id); |
1872 } | 1877 } |
1873 | 1878 |
1874 void RenderThreadImpl::OnMemoryPressure( | 1879 void RenderThreadImpl::OnMemoryPressure( |
1875 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 1880 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 1881 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
1876 ReleaseFreeMemory(); | 1882 ReleaseFreeMemory(); |
1877 | 1883 |
1878 // Do not call into blink if it is not initialized. | 1884 // Do not call into blink if it is not initialized. |
1879 if (blink_platform_impl_) { | 1885 if (blink_platform_impl_) { |
1880 blink::WebMemoryPressureListener::onMemoryPressure( | 1886 blink::WebMemoryPressureListener::onMemoryPressure( |
1881 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 1887 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
1882 | 1888 |
1883 if (blink::mainThreadIsolate()) { | |
1884 // Trigger full v8 garbage collection on memory pressure notifications. | |
1885 // This will potentially hang the renderer for a long time, however, when | |
1886 // we receive a memory pressure notification, we might be about to be | |
1887 // killed. Because of the janky hang don't do this to foreground | |
1888 // renderers. | |
1889 if (RendererIsHidden()) { | |
1890 blink::mainThreadIsolate()->LowMemoryNotification(); | |
1891 RenderThread::Get()->PostTaskToAllWebWorkers( | |
1892 base::Bind(&LowMemoryNotificationOnThisThread)); | |
1893 } | |
1894 } | |
1895 | |
1896 if (memory_pressure_level == | 1889 if (memory_pressure_level == |
1897 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 1890 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
1898 // Purge Skia font cache, by setting it to 0 and then again to the | 1891 // Purge Skia font cache, by setting it to 0 and then again to the |
1899 // previous limit. | 1892 // previous limit. |
1900 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 1893 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
1901 SkGraphics::SetFontCacheLimit(font_cache_limit); | 1894 SkGraphics::SetFontCacheLimit(font_cache_limit); |
1902 } | 1895 } |
1903 } | 1896 } |
1904 } | 1897 } |
1905 | 1898 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2038 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
2046 } | 2039 } |
2047 | 2040 |
2048 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2041 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2049 size_t erased = | 2042 size_t erased = |
2050 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2043 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2051 routing_id_); | 2044 routing_id_); |
2052 DCHECK_EQ(1u, erased); | 2045 DCHECK_EQ(1u, erased); |
2053 } | 2046 } |
2054 | 2047 |
| 2048 void RenderThreadImpl::OnSyncMemoryPressure( |
| 2049 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2050 if (!blink::mainThreadIsolate()) |
| 2051 return; |
| 2052 |
| 2053 v8::MemoryPressureLevel v8_memory_pressure_level = |
| 2054 static_cast<v8::MemoryPressureLevel>(memory_pressure_level); |
| 2055 |
| 2056 // In order to reduce performance impact, translate critical level to |
| 2057 // moderate level for foregroud renderer. |
| 2058 if (!RendererIsHidden() && |
| 2059 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2060 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
| 2061 |
| 2062 blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2063 v8_memory_pressure_level); |
| 2064 blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2065 v8_memory_pressure_level); |
| 2066 } |
| 2067 |
2055 } // namespace content | 2068 } // namespace content |
OLD | NEW |