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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 blink::enableLogChannel(t.token().c_str()); | 347 blink::enableLogChannel(t.token().c_str()); |
349 } | 348 } |
350 | 349 |
351 void NotifyTimezoneChangeOnThisThread() { | 350 void NotifyTimezoneChangeOnThisThread() { |
352 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 351 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
353 if (!isolate) | 352 if (!isolate) |
354 return; | 353 return; |
355 v8::Date::DateTimeConfigurationChangeNotification(isolate); | 354 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
356 } | 355 } |
357 | 356 |
358 void LowMemoryNotificationOnThisThread() { | |
359 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
360 if (!isolate) | |
361 return; | |
362 isolate->LowMemoryNotification(); | |
363 } | |
364 | |
365 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { | 357 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { |
366 public: | 358 public: |
367 explicit RenderFrameSetupImpl( | 359 explicit RenderFrameSetupImpl( |
368 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) | 360 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) |
369 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} | 361 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} |
370 | 362 |
371 void ExchangeInterfaceProviders( | 363 void ExchangeInterfaceProviders( |
372 int32_t frame_routing_id, | 364 int32_t frame_routing_id, |
373 mojo::shell::mojom::InterfaceProviderRequest services, | 365 mojo::shell::mojom::InterfaceProviderRequest services, |
374 mojo::shell::mojom::InterfaceProviderPtr exposed_services) | 366 mojo::shell::mojom::InterfaceProviderPtr exposed_services) |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 media::InitializeMediaLibrary(); | 796 media::InitializeMediaLibrary(); |
805 | 797 |
806 #if defined(OS_ANDROID) | 798 #if defined(OS_ANDROID) |
807 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 799 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
808 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 800 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
809 media::EnablePlatformDecoderSupport(); | 801 media::EnablePlatformDecoderSupport(); |
810 } | 802 } |
811 #endif | 803 #endif |
812 | 804 |
813 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 805 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
814 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 806 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 807 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 808 base::Unretained(this)))); |
815 | 809 |
816 int num_raster_threads = 0; | 810 int num_raster_threads = 0; |
817 std::string string_value = | 811 std::string string_value = |
818 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 812 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
819 bool parsed_num_raster_threads = | 813 bool parsed_num_raster_threads = |
820 base::StringToInt(string_value, &num_raster_threads); | 814 base::StringToInt(string_value, &num_raster_threads); |
821 DCHECK(parsed_num_raster_threads) << string_value; | 815 DCHECK(parsed_num_raster_threads) << string_value; |
822 DCHECK_GT(num_raster_threads, 0); | 816 DCHECK_GT(num_raster_threads, 0); |
823 | 817 |
824 // TODO(vmpstr): If the flag sticks, we should clean it up and always have | 818 // TODO(vmpstr): If the flag sticks, we should clean it up and always have |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 const WorkerProcessMsg_CreateWorker_Params& params) { | 1993 const WorkerProcessMsg_CreateWorker_Params& params) { |
2000 // EmbeddedSharedWorkerStub will self-destruct. | 1994 // EmbeddedSharedWorkerStub will self-destruct. |
2001 new EmbeddedSharedWorkerStub( | 1995 new EmbeddedSharedWorkerStub( |
2002 params.url, params.name, params.content_security_policy, | 1996 params.url, params.name, params.content_security_policy, |
2003 params.security_policy_type, params.creation_address_space, | 1997 params.security_policy_type, params.creation_address_space, |
2004 params.pause_on_start, params.route_id); | 1998 params.pause_on_start, params.route_id); |
2005 } | 1999 } |
2006 | 2000 |
2007 void RenderThreadImpl::OnMemoryPressure( | 2001 void RenderThreadImpl::OnMemoryPressure( |
2008 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 2002 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2003 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
2009 ReleaseFreeMemory(); | 2004 ReleaseFreeMemory(); |
2010 | 2005 |
2011 // Do not call into blink if it is not initialized. | 2006 // Do not call into blink if it is not initialized. |
2012 if (blink_platform_impl_) { | 2007 if (blink_platform_impl_) { |
2013 blink::WebMemoryPressureListener::onMemoryPressure( | 2008 blink::WebMemoryPressureListener::onMemoryPressure( |
2014 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 2009 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
2015 | 2010 |
2016 if (blink::mainThreadIsolate()) { | |
2017 // Trigger full v8 garbage collection on memory pressure notifications. | |
2018 // This will potentially hang the renderer for a long time, however, when | |
2019 // we receive a memory pressure notification, we might be about to be | |
2020 // killed. Because of the janky hang don't do this to foreground | |
2021 // renderers. | |
2022 if (RendererIsHidden()) { | |
2023 blink::mainThreadIsolate()->LowMemoryNotification(); | |
2024 RenderThread::Get()->PostTaskToAllWebWorkers( | |
2025 base::Bind(&LowMemoryNotificationOnThisThread)); | |
2026 } | |
2027 } | |
2028 | |
2029 if (memory_pressure_level == | 2011 if (memory_pressure_level == |
2030 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 2012 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
2031 // Purge Skia font cache, by setting it to 0 and then again to the | 2013 // Purge Skia font cache, by setting it to 0 and then again to the |
2032 // previous limit. | 2014 // previous limit. |
2033 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2015 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2034 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2016 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2035 } | 2017 } |
2036 } | 2018 } |
2037 } | 2019 } |
2038 | 2020 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2173 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2155 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
2174 } | 2156 } |
2175 | 2157 |
2176 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2158 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2177 size_t erased = | 2159 size_t erased = |
2178 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2160 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2179 routing_id_); | 2161 routing_id_); |
2180 DCHECK_EQ(1u, erased); | 2162 DCHECK_EQ(1u, erased); |
2181 } | 2163 } |
2182 | 2164 |
| 2165 void RenderThreadImpl::OnSyncMemoryPressure( |
| 2166 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2167 if (blink::mainThreadIsolate()) { |
| 2168 static_assert( |
| 2169 static_cast<v8::MemoryPressureLevel>( |
| 2170 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == |
| 2171 v8::MemoryPressureLevel::kNone, "none level not align"); |
| 2172 static_assert( |
| 2173 static_cast<v8::MemoryPressureLevel>( |
| 2174 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == |
| 2175 v8::MemoryPressureLevel::kModerate, "moderate level not align"); |
| 2176 static_assert( |
| 2177 static_cast<v8::MemoryPressureLevel>( |
| 2178 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == |
| 2179 v8::MemoryPressureLevel::kCritical, "critical level not align"); |
| 2180 |
| 2181 v8::MemoryPressureLevel v8_memory_pressure_level = |
| 2182 static_cast<v8::MemoryPressureLevel>(memory_pressure_level); |
| 2183 |
| 2184 if (!RendererIsHidden()) { |
| 2185 if (v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2186 // In order to reduce performance impact, translate critical level to |
| 2187 // moderate level for foregroud renderer. |
| 2188 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
| 2189 } |
| 2190 |
| 2191 blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2192 v8_memory_pressure_level); |
| 2193 std::set<v8::Isolate*>* worker_thread_isolates = |
| 2194 blink::workerThreadIsolates(); |
| 2195 if (worker_thread_isolates) { |
| 2196 for (std::set<v8::Isolate*>::iterator it = |
| 2197 worker_thread_isolates->begin(); |
| 2198 it != worker_thread_isolates->end(); ++it) { |
| 2199 v8::Isolate* isolate = *it; |
| 2200 isolate->MemoryPressureNotification(v8_memory_pressure_level); |
| 2201 } |
| 2202 } |
| 2203 } |
| 2204 } |
| 2205 |
2183 } // namespace content | 2206 } // namespace content |
OLD | NEW |