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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/allocator/allocator_extension.h" | 13 #include "base/allocator/allocator_extension.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug/crash_logging.h" | 15 #include "base/debug/crash_logging.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/discardable_memory_allocator.h" | 19 #include "base/memory/discardable_memory_allocator.h" |
20 #include "base/memory/memory_coordinator_client_registry.h" | |
20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
21 #include "base/memory/shared_memory.h" | 22 #include "base/memory/shared_memory.h" |
22 #include "base/metrics/field_trial.h" | 23 #include "base/metrics/field_trial.h" |
23 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
25 #include "base/run_loop.h" | 26 #include "base/run_loop.h" |
26 #include "base/strings/string16.h" | 27 #include "base/strings/string16.h" |
27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/string_split.h" | 29 #include "base/strings/string_split.h" |
29 #include "base/strings/sys_string_conversions.h" | 30 #include "base/strings/sys_string_conversions.h" |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 time_zone_monitor_binding_.CreateInterfacePtrAndBind()); | 890 time_zone_monitor_binding_.CreateInterfacePtrAndBind()); |
890 | 891 |
891 #if defined(OS_LINUX) | 892 #if defined(OS_LINUX) |
892 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); | 893 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); |
893 ChildThreadImpl::current()->SetThreadPriority( | 894 ChildThreadImpl::current()->SetThreadPriority( |
894 categorized_worker_pool_->background_worker_thread_id(), | 895 categorized_worker_pool_->background_worker_thread_id(), |
895 base::ThreadPriority::BACKGROUND); | 896 base::ThreadPriority::BACKGROUND); |
896 #endif | 897 #endif |
897 | 898 |
898 is_renderer_suspended_ = false; | 899 is_renderer_suspended_ = false; |
900 | |
901 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | |
899 } | 902 } |
900 | 903 |
901 RenderThreadImpl::~RenderThreadImpl() { | 904 RenderThreadImpl::~RenderThreadImpl() { |
905 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); | |
haraken
2016/10/07 11:45:30
I'd call this in Shutdown().
hajimehoshi
2016/10/11 07:05:32
Done.
| |
902 } | 906 } |
903 | 907 |
904 void RenderThreadImpl::Shutdown() { | 908 void RenderThreadImpl::Shutdown() { |
905 FOR_EACH_OBSERVER( | 909 FOR_EACH_OBSERVER( |
906 RenderThreadObserver, observers_, OnRenderProcessShutdown()); | 910 RenderThreadObserver, observers_, OnRenderProcessShutdown()); |
907 | 911 |
908 if (memory_observer_) { | 912 if (memory_observer_) { |
909 message_loop()->RemoveTaskObserver(memory_observer_.get()); | 913 message_loop()->RemoveTaskObserver(memory_observer_.get()); |
910 memory_observer_.reset(); | 914 memory_observer_.reset(); |
911 } | 915 } |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2125 // EmbeddedSharedWorkerStub will self-destruct. | 2129 // EmbeddedSharedWorkerStub will self-destruct. |
2126 new EmbeddedSharedWorkerStub( | 2130 new EmbeddedSharedWorkerStub( |
2127 params.url, params.name, params.content_security_policy, | 2131 params.url, params.name, params.content_security_policy, |
2128 params.security_policy_type, params.creation_address_space, | 2132 params.security_policy_type, params.creation_address_space, |
2129 params.pause_on_start, params.route_id); | 2133 params.pause_on_start, params.route_id); |
2130 } | 2134 } |
2131 | 2135 |
2132 void RenderThreadImpl::OnMemoryPressure( | 2136 void RenderThreadImpl::OnMemoryPressure( |
2133 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 2137 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
2134 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); | 2138 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); |
2139 if (blink_platform_impl_) { | |
2140 blink::WebMemoryCoordinator::onMemoryPressure( | |
2141 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | |
2142 } | |
2143 ClearMemory(memory_pressure_level == | |
2144 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
2145 } | |
2146 | |
2147 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | |
2148 // TODO(hajimehoshi): Adjust the size of this memory usage according to | |
2149 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | |
2150 // present. | |
2151 if (blink_platform_impl_) { | |
2152 blink::WebMemoryCoordinator::onMemoryStateChange( | |
2153 static_cast<blink::MemoryState>(state)); | |
2154 } | |
2155 switch (state) { | |
2156 case base::MemoryState::NORMAL: | |
2157 break; | |
2158 case base::MemoryState::THROTTLED: | |
2159 ClearMemory(false); | |
2160 break; | |
2161 case base::MemoryState::SUSPENDED: | |
2162 ClearMemory(true); | |
2163 break; | |
2164 case base::MemoryState::UNKNOWN: | |
2165 NOTREACHED(); | |
2166 break; | |
2167 } | |
2168 } | |
2169 | |
2170 void RenderThreadImpl::ClearMemory(bool critical) { | |
haraken
2016/10/07 11:45:30
I'd avoid introducing the boolean flag. Alternatel
hajimehoshi
2016/10/11 07:05:32
Done.
| |
2135 ReleaseFreeMemory(); | 2171 ReleaseFreeMemory(); |
2136 | 2172 |
2137 // Do not call into blink if it is not initialized. | 2173 // Do not call into blink if it is not initialized. |
2138 if (blink_platform_impl_) { | 2174 if (blink_platform_impl_ && critical) { |
2139 blink::WebMemoryCoordinator::onMemoryPressure( | 2175 // Purge Skia font cache, by setting it to 0 and then again to the |
2140 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 2176 // previous limit. |
2141 | 2177 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2142 if (memory_pressure_level == | 2178 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2143 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | |
2144 // Purge Skia font cache, by setting it to 0 and then again to the | |
2145 // previous limit. | |
2146 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | |
2147 SkGraphics::SetFontCacheLimit(font_cache_limit); | |
2148 } | |
2149 } | 2179 } |
2150 } | 2180 } |
2151 | 2181 |
2152 scoped_refptr<base::SingleThreadTaskRunner> | 2182 scoped_refptr<base::SingleThreadTaskRunner> |
2153 RenderThreadImpl::GetFileThreadTaskRunner() { | 2183 RenderThreadImpl::GetFileThreadTaskRunner() { |
2154 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); | 2184 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); |
2155 if (!file_thread_) { | 2185 if (!file_thread_) { |
2156 file_thread_.reset(new base::Thread("Renderer::FILE")); | 2186 file_thread_.reset(new base::Thread("Renderer::FILE")); |
2157 file_thread_->Start(); | 2187 file_thread_->Start(); |
2158 } | 2188 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2329 } | 2359 } |
2330 } | 2360 } |
2331 | 2361 |
2332 void RenderThreadImpl::OnRendererInterfaceRequest( | 2362 void RenderThreadImpl::OnRendererInterfaceRequest( |
2333 mojom::RendererAssociatedRequest request) { | 2363 mojom::RendererAssociatedRequest request) { |
2334 DCHECK(!renderer_binding_.is_bound()); | 2364 DCHECK(!renderer_binding_.is_bound()); |
2335 renderer_binding_.Bind(std::move(request)); | 2365 renderer_binding_.Bind(std::move(request)); |
2336 } | 2366 } |
2337 | 2367 |
2338 } // namespace content | 2368 } // namespace content |
OLD | NEW |