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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" | 156 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" |
157 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 157 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
158 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 158 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
159 #include "third_party/WebKit/public/web/WebScriptController.h" | 159 #include "third_party/WebKit/public/web/WebScriptController.h" |
160 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 160 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
161 #include "third_party/WebKit/public/web/WebView.h" | 161 #include "third_party/WebKit/public/web/WebView.h" |
162 #include "third_party/icu/source/i18n/unicode/timezone.h" | 162 #include "third_party/icu/source/i18n/unicode/timezone.h" |
163 #include "third_party/skia/include/core/SkGraphics.h" | 163 #include "third_party/skia/include/core/SkGraphics.h" |
164 #include "ui/base/layout.h" | 164 #include "ui/base/layout.h" |
165 #include "ui/base/ui_base_switches.h" | 165 #include "ui/base/ui_base_switches.h" |
166 #include "v8/include/v8.h" | |
167 | 166 |
168 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
169 #include <cpu-features.h> | 168 #include <cpu-features.h> |
170 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" | 169 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" |
171 #include "content/renderer/android/synchronous_compositor_factory.h" | 170 #include "content/renderer/android/synchronous_compositor_factory.h" |
172 #include "content/renderer/android/synchronous_compositor_filter.h" | 171 #include "content/renderer/android/synchronous_compositor_filter.h" |
173 #include "content/renderer/media/android/renderer_demuxer_android.h" | 172 #include "content/renderer/media/android/renderer_demuxer_android.h" |
174 #include "content/renderer/media/android/stream_texture_factory_impl.h" | 173 #include "content/renderer/media/android/stream_texture_factory_impl.h" |
175 #include "media/base/android/media_codec_util.h" | 174 #include "media/base/android/media_codec_util.h" |
176 #endif | 175 #endif |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 media::InitializeMediaLibrary(); | 806 media::InitializeMediaLibrary(); |
808 | 807 |
809 #if defined(OS_ANDROID) | 808 #if defined(OS_ANDROID) |
810 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 809 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
811 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 810 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
812 media::EnablePlatformDecoderSupport(); | 811 media::EnablePlatformDecoderSupport(); |
813 } | 812 } |
814 #endif | 813 #endif |
815 | 814 |
816 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 815 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
817 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 816 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
817 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, | |
818 base::Unretained(this)))); | |
818 | 819 |
819 int num_raster_threads = 0; | 820 int num_raster_threads = 0; |
820 std::string string_value = | 821 std::string string_value = |
821 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 822 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
822 bool parsed_num_raster_threads = | 823 bool parsed_num_raster_threads = |
823 base::StringToInt(string_value, &num_raster_threads); | 824 base::StringToInt(string_value, &num_raster_threads); |
824 DCHECK(parsed_num_raster_threads) << string_value; | 825 DCHECK(parsed_num_raster_threads) << string_value; |
825 DCHECK_GT(num_raster_threads, 0); | 826 DCHECK_GT(num_raster_threads, 0); |
826 | 827 |
827 // TODO(vmpstr): If the flag sticks, we should clean it up and always have | 828 // TODO(vmpstr): If the flag sticks, we should clean it up and always have |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1998 new EmbeddedSharedWorkerStub(params.url, | 1999 new EmbeddedSharedWorkerStub(params.url, |
1999 params.name, | 2000 params.name, |
2000 params.content_security_policy, | 2001 params.content_security_policy, |
2001 params.security_policy_type, | 2002 params.security_policy_type, |
2002 params.pause_on_start, | 2003 params.pause_on_start, |
2003 params.route_id); | 2004 params.route_id); |
2004 } | 2005 } |
2005 | 2006 |
2006 void RenderThreadImpl::OnMemoryPressure( | 2007 void RenderThreadImpl::OnMemoryPressure( |
2007 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 2008 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
2009 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); | |
2008 ReleaseFreeMemory(); | 2010 ReleaseFreeMemory(); |
2009 | 2011 |
2010 // Do not call into blink if it is not initialized. | 2012 // Do not call into blink if it is not initialized. |
2011 if (blink_platform_impl_) { | 2013 if (blink_platform_impl_) { |
2012 blink::WebMemoryPressureListener::onMemoryPressure( | 2014 blink::WebMemoryPressureListener::onMemoryPressure( |
2013 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 2015 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
2014 | 2016 |
2015 if (blink::mainThreadIsolate()) { | 2017 if (blink::mainThreadIsolate()) { |
2016 // Trigger full v8 garbage collection on memory pressure notifications. | |
2017 // This will potentially hang the renderer for a long time, however, when | |
2018 // we receive a memory pressure notification, we might be about to be | |
2019 // killed. | |
2020 blink::mainThreadIsolate()->LowMemoryNotification(); | |
2021 RenderThread::Get()->PostTaskToAllWebWorkers( | 2018 RenderThread::Get()->PostTaskToAllWebWorkers( |
2022 base::Bind(&LowMemoryNotificationOnThisThread)); | 2019 base::Bind(&LowMemoryNotificationOnThisThread)); |
2023 } | 2020 } |
2024 | 2021 |
2025 if (memory_pressure_level == | 2022 if (memory_pressure_level == |
2026 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 2023 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
2027 // Purge Skia font cache, by setting it to 0 and then again to the | 2024 // Purge Skia font cache, by setting it to 0 and then again to the |
2028 // previous limit. | 2025 // previous limit. |
2029 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2026 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2030 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2027 SkGraphics::SetFontCacheLimit(font_cache_limit); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2169 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2166 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
2170 } | 2167 } |
2171 | 2168 |
2172 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2169 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2173 size_t erased = | 2170 size_t erased = |
2174 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2171 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2175 routing_id_); | 2172 routing_id_); |
2176 DCHECK_EQ(1u, erased); | 2173 DCHECK_EQ(1u, erased); |
2177 } | 2174 } |
2178 | 2175 |
2176 void RenderThreadImpl::OnSyncMemoryPressure( | |
2177 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
2178 v8::MemoryPressureLevel memoryPressureLevel = | |
esprehn
2016/03/25 09:20:35
v8_memory_pressure_level or something of that natu
hong.zheng
2016/04/01 09:22:34
Done.
| |
2179 v8::MemoryPressureLevel::kNone; | |
2180 switch (memory_pressure_level) { | |
jochen (gone - plz use gerrit)
2016/03/30 16:23:01
this should probably also take into account whethe
hong.zheng
2016/04/01 09:22:34
The CL can deliver memory pressure notification to
jochen (gone - plz use gerrit)
2016/04/03 11:21:35
V8 doesn't look at whether the renderer is in the
hong.zheng
2016/04/05 09:09:17
It is a problem about how to balance OOM risk and
hong.zheng
2016/04/07 10:55:49
Done.
| |
2181 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: | |
2182 memoryPressureLevel = v8::MemoryPressureLevel::kNone; | |
esprehn
2016/03/25 09:20:35
Sigh, not having base in v8 makes for really silly
hong.zheng
2016/04/01 09:22:34
Done.
| |
2183 break; | |
2184 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: | |
2185 memoryPressureLevel = v8::MemoryPressureLevel::kModerate; | |
2186 break; | |
2187 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: | |
2188 memoryPressureLevel = v8::MemoryPressureLevel::kCritical; | |
2189 break; | |
2190 default: | |
2191 NOTREACHED(); | |
2192 } | |
2193 blink::mainThreadIsolate()->MemoryPressureNotification(memoryPressureLevel); | |
jochen (gone - plz use gerrit)
2016/03/30 16:22:23
since this API is threadsafe, why not notify the w
hong.zheng
2016/04/01 09:22:34
Done.
| |
2194 } | |
2195 | |
2179 } // namespace content | 2196 } // namespace content |
OLD | NEW |