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 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 media::InitializeMediaLibrary(); | 819 media::InitializeMediaLibrary(); |
817 | 820 |
818 #if defined(OS_ANDROID) | 821 #if defined(OS_ANDROID) |
819 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && | 822 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && |
820 media::MediaCodecUtil::IsMediaCodecAvailable()) { | 823 media::MediaCodecUtil::IsMediaCodecAvailable()) { |
821 media::EnablePlatformDecoderSupport(); | 824 media::EnablePlatformDecoderSupport(); |
822 } | 825 } |
823 #endif | 826 #endif |
824 | 827 |
825 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 828 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
826 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 829 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 830 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 831 base::Unretained(this)))); |
827 | 832 |
828 int num_raster_threads = 0; | 833 int num_raster_threads = 0; |
829 std::string string_value = | 834 std::string string_value = |
830 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 835 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
831 bool parsed_num_raster_threads = | 836 bool parsed_num_raster_threads = |
832 base::StringToInt(string_value, &num_raster_threads); | 837 base::StringToInt(string_value, &num_raster_threads); |
833 DCHECK(parsed_num_raster_threads) << string_value; | 838 DCHECK(parsed_num_raster_threads) << string_value; |
834 DCHECK_GT(num_raster_threads, 0); | 839 DCHECK_GT(num_raster_threads, 0); |
835 | 840 |
836 // TODO(vmpstr): If the flag sticks, we should clean it up and always have | 841 // TODO(vmpstr): If the flag sticks, we should clean it up and always have |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 const WorkerProcessMsg_CreateWorker_Params& params) { | 1929 const WorkerProcessMsg_CreateWorker_Params& params) { |
1925 // EmbeddedSharedWorkerStub will self-destruct. | 1930 // EmbeddedSharedWorkerStub will self-destruct. |
1926 new EmbeddedSharedWorkerStub( | 1931 new EmbeddedSharedWorkerStub( |
1927 params.url, params.name, params.content_security_policy, | 1932 params.url, params.name, params.content_security_policy, |
1928 params.security_policy_type, params.creation_address_space, | 1933 params.security_policy_type, params.creation_address_space, |
1929 params.pause_on_start, params.route_id); | 1934 params.pause_on_start, params.route_id); |
1930 } | 1935 } |
1931 | 1936 |
1932 void RenderThreadImpl::OnMemoryPressure( | 1937 void RenderThreadImpl::OnMemoryPressure( |
1933 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 1938 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 1939 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
1934 ReleaseFreeMemory(); | 1940 ReleaseFreeMemory(); |
1935 | 1941 |
1936 // Do not call into blink if it is not initialized. | 1942 // Do not call into blink if it is not initialized. |
1937 if (blink_platform_impl_) { | 1943 if (blink_platform_impl_) { |
1938 blink::WebMemoryPressureListener::onMemoryPressure( | 1944 blink::WebMemoryPressureListener::onMemoryPressure( |
1939 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 1945 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
1940 | 1946 |
1941 if (blink::mainThreadIsolate()) { | |
1942 // Trigger full v8 garbage collection on memory pressure notifications. | |
1943 // This will potentially hang the renderer for a long time, however, when | |
1944 // we receive a memory pressure notification, we might be about to be | |
1945 // killed. Because of the janky hang don't do this to foreground | |
1946 // renderers. | |
1947 if (RendererIsHidden()) { | |
1948 blink::mainThreadIsolate()->LowMemoryNotification(); | |
1949 RenderThread::Get()->PostTaskToAllWebWorkers( | |
1950 base::Bind(&LowMemoryNotificationOnThisThread)); | |
1951 } | |
1952 } | |
1953 | |
1954 if (memory_pressure_level == | 1947 if (memory_pressure_level == |
1955 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 1948 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
1956 // Purge Skia font cache, by setting it to 0 and then again to the | 1949 // Purge Skia font cache, by setting it to 0 and then again to the |
1957 // previous limit. | 1950 // previous limit. |
1958 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 1951 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
1959 SkGraphics::SetFontCacheLimit(font_cache_limit); | 1952 SkGraphics::SetFontCacheLimit(font_cache_limit); |
1960 } | 1953 } |
1961 } | 1954 } |
1962 } | 1955 } |
1963 | 1956 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2104 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2097 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
2105 } | 2098 } |
2106 | 2099 |
2107 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2100 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2108 size_t erased = | 2101 size_t erased = |
2109 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2102 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2110 routing_id_); | 2103 routing_id_); |
2111 DCHECK_EQ(1u, erased); | 2104 DCHECK_EQ(1u, erased); |
2112 } | 2105 } |
2113 | 2106 |
| 2107 void RenderThreadImpl::OnSyncMemoryPressure( |
| 2108 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2109 if (!blink::mainThreadIsolate()) |
| 2110 return; |
| 2111 |
| 2112 v8::MemoryPressureLevel v8_memory_pressure_level = |
| 2113 static_cast<v8::MemoryPressureLevel>(memory_pressure_level); |
| 2114 |
| 2115 // In order to reduce performance impact, translate critical level to |
| 2116 // moderate level for foregroud renderer. |
| 2117 if (!RendererIsHidden() && |
| 2118 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2119 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
| 2120 |
| 2121 blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2122 v8_memory_pressure_level); |
| 2123 blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2124 v8_memory_pressure_level); |
| 2125 } |
| 2126 |
2114 } // namespace content | 2127 } // namespace content |
OLD | NEW |