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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" | 153 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" |
154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
155 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 155 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
156 #include "third_party/WebKit/public/web/WebScriptController.h" | 156 #include "third_party/WebKit/public/web/WebScriptController.h" |
157 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 157 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
158 #include "third_party/WebKit/public/web/WebView.h" | 158 #include "third_party/WebKit/public/web/WebView.h" |
159 #include "third_party/icu/source/i18n/unicode/timezone.h" | 159 #include "third_party/icu/source/i18n/unicode/timezone.h" |
160 #include "third_party/skia/include/core/SkGraphics.h" | 160 #include "third_party/skia/include/core/SkGraphics.h" |
161 #include "ui/base/layout.h" | 161 #include "ui/base/layout.h" |
162 #include "ui/base/ui_base_switches.h" | 162 #include "ui/base/ui_base_switches.h" |
163 #include "v8/include/v8.h" | |
164 | 163 |
165 #if defined(OS_ANDROID) | 164 #if defined(OS_ANDROID) |
166 #include <cpu-features.h> | 165 #include <cpu-features.h> |
167 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" | 166 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" |
168 #include "content/renderer/android/synchronous_compositor_factory.h" | 167 #include "content/renderer/android/synchronous_compositor_factory.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_impl.h" | 170 #include "content/renderer/media/android/stream_texture_factory_impl.h" |
172 #include "media/base/android/media_codec_util.h" | 171 #include "media/base/android/media_codec_util.h" |
173 #endif | 172 #endif |
(...skipping 61 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 blink::enableLogChannel(t.token().c_str()); | 351 blink::enableLogChannel(t.token().c_str()); |
342 } | 352 } |
343 | 353 |
344 void NotifyTimezoneChangeOnThisThread() { | 354 void NotifyTimezoneChangeOnThisThread() { |
345 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 355 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
346 if (!isolate) | 356 if (!isolate) |
347 return; | 357 return; |
348 v8::Date::DateTimeConfigurationChangeNotification(isolate); | 358 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
349 } | 359 } |
350 | 360 |
351 void LowMemoryNotificationOnThisThread() { | |
352 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
353 if (!isolate) | |
354 return; | |
355 isolate->LowMemoryNotification(); | |
356 } | |
357 | |
358 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { | 361 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { |
359 public: | 362 public: |
360 explicit RenderFrameSetupImpl( | 363 explicit RenderFrameSetupImpl( |
361 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) | 364 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) |
362 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} | 365 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} |
363 | 366 |
364 void ExchangeInterfaceProviders( | 367 void ExchangeInterfaceProviders( |
365 int32_t frame_routing_id, | 368 int32_t frame_routing_id, |
366 shell::mojom::InterfaceProviderRequest services, | 369 shell::mojom::InterfaceProviderRequest services, |
367 shell::mojom::InterfaceProviderPtr exposed_services) override { | 370 shell::mojom::InterfaceProviderPtr exposed_services) override { |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 media::InitializeMediaLibrary(); | 798 media::InitializeMediaLibrary(); |
796 | 799 |
797 #if defined(OS_ANDROID) | 800 #if defined(OS_ANDROID) |
798 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 801 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
799 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 802 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
800 media::EnablePlatformDecoderSupport(); | 803 media::EnablePlatformDecoderSupport(); |
801 } | 804 } |
802 #endif | 805 #endif |
803 | 806 |
804 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 807 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
805 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 808 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
809 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, | |
810 base::Unretained(this)))); | |
806 | 811 |
807 int num_raster_threads = 0; | 812 int num_raster_threads = 0; |
808 std::string string_value = | 813 std::string string_value = |
809 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 814 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
810 bool parsed_num_raster_threads = | 815 bool parsed_num_raster_threads = |
811 base::StringToInt(string_value, &num_raster_threads); | 816 base::StringToInt(string_value, &num_raster_threads); |
812 DCHECK(parsed_num_raster_threads) << string_value; | 817 DCHECK(parsed_num_raster_threads) << string_value; |
813 DCHECK_GT(num_raster_threads, 0); | 818 DCHECK_GT(num_raster_threads, 0); |
814 | 819 |
815 #if defined(OS_ANDROID) | 820 #if defined(OS_ANDROID) |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1971 const WorkerProcessMsg_CreateWorker_Params& params) { | 1976 const WorkerProcessMsg_CreateWorker_Params& params) { |
1972 // EmbeddedSharedWorkerStub will self-destruct. | 1977 // EmbeddedSharedWorkerStub will self-destruct. |
1973 new EmbeddedSharedWorkerStub( | 1978 new EmbeddedSharedWorkerStub( |
1974 params.url, params.name, params.content_security_policy, | 1979 params.url, params.name, params.content_security_policy, |
1975 params.security_policy_type, params.creation_address_space, | 1980 params.security_policy_type, params.creation_address_space, |
1976 params.pause_on_start, params.route_id); | 1981 params.pause_on_start, params.route_id); |
1977 } | 1982 } |
1978 | 1983 |
1979 void RenderThreadImpl::OnMemoryPressure( | 1984 void RenderThreadImpl::OnMemoryPressure( |
1980 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 1985 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
1986 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); | |
1981 ReleaseFreeMemory(); | 1987 ReleaseFreeMemory(); |
1982 | 1988 |
1983 // Do not call into blink if it is not initialized. | 1989 // Do not call into blink if it is not initialized. |
1984 if (blink_platform_impl_) { | 1990 if (blink_platform_impl_) { |
1985 blink::WebMemoryPressureListener::onMemoryPressure( | 1991 blink::WebMemoryPressureListener::onMemoryPressure( |
1986 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 1992 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
1987 | 1993 |
1988 if (blink::mainThreadIsolate()) { | |
1989 // Trigger full v8 garbage collection on memory pressure notifications. | |
1990 // This will potentially hang the renderer for a long time, however, when | |
1991 // we receive a memory pressure notification, we might be about to be | |
1992 // killed. Because of the janky hang don't do this to foreground | |
1993 // renderers. | |
1994 if (RendererIsHidden()) { | |
1995 blink::mainThreadIsolate()->LowMemoryNotification(); | |
1996 RenderThread::Get()->PostTaskToAllWebWorkers( | |
1997 base::Bind(&LowMemoryNotificationOnThisThread)); | |
1998 } | |
1999 } | |
2000 | |
2001 if (memory_pressure_level == | 1994 if (memory_pressure_level == |
2002 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 1995 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
2003 // Purge Skia font cache, by setting it to 0 and then again to the | 1996 // Purge Skia font cache, by setting it to 0 and then again to the |
2004 // previous limit. | 1997 // previous limit. |
2005 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 1998 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2006 SkGraphics::SetFontCacheLimit(font_cache_limit); | 1999 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2007 } | 2000 } |
2008 } | 2001 } |
2009 } | 2002 } |
2010 | 2003 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2145 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2138 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
2146 } | 2139 } |
2147 | 2140 |
2148 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2141 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2149 size_t erased = | 2142 size_t erased = |
2150 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2143 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2151 routing_id_); | 2144 routing_id_); |
2152 DCHECK_EQ(1u, erased); | 2145 DCHECK_EQ(1u, erased); |
2153 } | 2146 } |
2154 | 2147 |
2148 void RenderThreadImpl::OnSyncMemoryPressure( | |
2149 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
2150 if (!blink::mainThreadIsolate()) | |
2151 return; | |
2152 | |
2153 v8::MemoryPressureLevel v8_memory_pressure_level = | |
2154 static_cast<v8::MemoryPressureLevel>(memory_pressure_level); | |
2155 | |
2156 // In order to reduce performance impact, translate critical level to | |
2157 // moderate level for foregroud renderer. | |
jochen (gone - plz use gerrit)
2016/04/20 12:46:35
foregrou*n*d
hong.zheng
2016/04/21 12:18:04
Done.
| |
2158 if (!RendererIsHidden() && | |
2159 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) | |
jochen (gone - plz use gerrit)
2016/04/20 12:46:35
please add { }
hong.zheng
2016/04/21 12:18:04
Done.
| |
2160 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; | |
2161 | |
2162 blink::mainThreadIsolate()->MemoryPressureNotification( | |
2163 v8_memory_pressure_level); | |
2164 blink::MemoryPressureNotificationToWorkerThreadIsolates( | |
2165 v8_memory_pressure_level); | |
2166 } | |
2167 | |
2155 } // namespace content | 2168 } // namespace content |
OLD | NEW |