Chromium Code Reviews| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 blink::enableLogChannel(t.token().c_str()); | 340 blink::enableLogChannel(t.token().c_str()); |
| 342 } | 341 } |
| 343 | 342 |
| 344 void NotifyTimezoneChangeOnThisThread() { | 343 void NotifyTimezoneChangeOnThisThread() { |
| 345 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 344 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 346 if (!isolate) | 345 if (!isolate) |
| 347 return; | 346 return; |
| 348 v8::Date::DateTimeConfigurationChangeNotification(isolate); | 347 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
| 349 } | 348 } |
| 350 | 349 |
| 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 { | 350 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { |
| 359 public: | 351 public: |
| 360 explicit RenderFrameSetupImpl( | 352 explicit RenderFrameSetupImpl( |
| 361 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) | 353 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) |
| 362 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} | 354 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} |
| 363 | 355 |
| 364 void ExchangeInterfaceProviders( | 356 void ExchangeInterfaceProviders( |
| 365 int32_t frame_routing_id, | 357 int32_t frame_routing_id, |
| 366 shell::mojom::InterfaceProviderRequest services, | 358 shell::mojom::InterfaceProviderRequest services, |
| 367 shell::mojom::InterfaceProviderPtr exposed_services) override { | 359 shell::mojom::InterfaceProviderPtr exposed_services) override { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 media::InitializeMediaLibrary(); | 787 media::InitializeMediaLibrary(); |
| 796 | 788 |
| 797 #if defined(OS_ANDROID) | 789 #if defined(OS_ANDROID) |
| 798 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 790 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
| 799 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 791 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
| 800 media::EnablePlatformDecoderSupport(); | 792 media::EnablePlatformDecoderSupport(); |
| 801 } | 793 } |
| 802 #endif | 794 #endif |
| 803 | 795 |
| 804 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 796 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 805 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 797 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 798 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, | |
| 799 base::Unretained(this)))); | |
| 806 | 800 |
| 807 int num_raster_threads = 0; | 801 int num_raster_threads = 0; |
| 808 std::string string_value = | 802 std::string string_value = |
| 809 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 803 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 810 bool parsed_num_raster_threads = | 804 bool parsed_num_raster_threads = |
| 811 base::StringToInt(string_value, &num_raster_threads); | 805 base::StringToInt(string_value, &num_raster_threads); |
| 812 DCHECK(parsed_num_raster_threads) << string_value; | 806 DCHECK(parsed_num_raster_threads) << string_value; |
| 813 DCHECK_GT(num_raster_threads, 0); | 807 DCHECK_GT(num_raster_threads, 0); |
| 814 | 808 |
| 815 #if defined(OS_ANDROID) | 809 #if defined(OS_ANDROID) |
| (...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1971 const WorkerProcessMsg_CreateWorker_Params& params) { | 1965 const WorkerProcessMsg_CreateWorker_Params& params) { |
| 1972 // EmbeddedSharedWorkerStub will self-destruct. | 1966 // EmbeddedSharedWorkerStub will self-destruct. |
| 1973 new EmbeddedSharedWorkerStub( | 1967 new EmbeddedSharedWorkerStub( |
| 1974 params.url, params.name, params.content_security_policy, | 1968 params.url, params.name, params.content_security_policy, |
| 1975 params.security_policy_type, params.creation_address_space, | 1969 params.security_policy_type, params.creation_address_space, |
| 1976 params.pause_on_start, params.route_id); | 1970 params.pause_on_start, params.route_id); |
| 1977 } | 1971 } |
| 1978 | 1972 |
| 1979 void RenderThreadImpl::OnMemoryPressure( | 1973 void RenderThreadImpl::OnMemoryPressure( |
| 1980 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 1974 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 1975 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); | |
| 1981 ReleaseFreeMemory(); | 1976 ReleaseFreeMemory(); |
| 1982 | 1977 |
| 1983 // Do not call into blink if it is not initialized. | 1978 // Do not call into blink if it is not initialized. |
| 1984 if (blink_platform_impl_) { | 1979 if (blink_platform_impl_) { |
| 1985 blink::WebMemoryPressureListener::onMemoryPressure( | 1980 blink::WebMemoryPressureListener::onMemoryPressure( |
| 1986 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 1981 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
| 1987 | 1982 |
| 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 == | 1983 if (memory_pressure_level == |
| 2002 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 1984 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 2003 // Purge Skia font cache, by setting it to 0 and then again to the | 1985 // Purge Skia font cache, by setting it to 0 and then again to the |
| 2004 // previous limit. | 1986 // previous limit. |
| 2005 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 1987 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2006 SkGraphics::SetFontCacheLimit(font_cache_limit); | 1988 SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2007 } | 1989 } |
| 2008 } | 1990 } |
| 2009 } | 1991 } |
| 2010 | 1992 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2127 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
| 2146 } | 2128 } |
| 2147 | 2129 |
| 2148 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2130 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
| 2149 size_t erased = | 2131 size_t erased = |
| 2150 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2132 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
| 2151 routing_id_); | 2133 routing_id_); |
| 2152 DCHECK_EQ(1u, erased); | 2134 DCHECK_EQ(1u, erased); |
| 2153 } | 2135 } |
| 2154 | 2136 |
| 2137 void RenderThreadImpl::OnSyncMemoryPressure( | |
| 2138 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
| 2139 if (blink::mainThreadIsolate()) { | |
|
esprehn
2016/04/18 21:57:59
early return instead of indenting the entire funct
hong.zheng
2016/04/19 06:27:43
Done.
| |
| 2140 static_assert( | |
| 2141 static_cast<v8::MemoryPressureLevel>( | |
| 2142 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) == | |
|
esprehn
2016/04/18 21:57:59
these static_asserts should just be in a block at
hong.zheng
2016/04/19 06:27:43
Done.
| |
| 2143 v8::MemoryPressureLevel::kNone, "none level not align"); | |
| 2144 static_assert( | |
| 2145 static_cast<v8::MemoryPressureLevel>( | |
| 2146 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) == | |
| 2147 v8::MemoryPressureLevel::kModerate, "moderate level not align"); | |
| 2148 static_assert( | |
| 2149 static_cast<v8::MemoryPressureLevel>( | |
| 2150 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) == | |
| 2151 v8::MemoryPressureLevel::kCritical, "critical level not align"); | |
| 2152 | |
| 2153 v8::MemoryPressureLevel v8_memory_pressure_level = | |
| 2154 static_cast<v8::MemoryPressureLevel>(memory_pressure_level); | |
| 2155 | |
| 2156 if (!RendererIsHidden()) { | |
| 2157 if (v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) | |
|
esprehn
2016/04/18 21:57:58
combine the if statements, doing:
if (x) {
if (
hong.zheng
2016/04/19 06:27:43
Done.
| |
| 2158 // In order to reduce performance impact, translate critical level to | |
| 2159 // moderate level for foregroud renderer. | |
| 2160 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; | |
| 2161 } | |
| 2162 | |
| 2163 blink::mainThreadIsolate()->MemoryPressureNotification( | |
| 2164 v8_memory_pressure_level); | |
| 2165 blink::MemoryPressureNotificationToWorkerThreadIsolates( | |
| 2166 v8_memory_pressure_level); | |
| 2167 } | |
| 2168 } | |
| 2169 | |
| 2155 } // namespace content | 2170 } // namespace content |
| OLD | NEW |