Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2402643002: Make RenderThreadImpl a client of memory coordinator (Closed)
Patch Set: Address on haraken's review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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() {
902 } 905 }
903 906
904 void RenderThreadImpl::Shutdown() { 907 void RenderThreadImpl::Shutdown() {
905 FOR_EACH_OBSERVER( 908 FOR_EACH_OBSERVER(
906 RenderThreadObserver, observers_, OnRenderProcessShutdown()); 909 RenderThreadObserver, observers_, OnRenderProcessShutdown());
907 910
908 if (memory_observer_) { 911 if (memory_observer_) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 // is complete, because blink::shutdown destructs Blink Resources and they 1023 // is complete, because blink::shutdown destructs Blink Resources and they
1021 // may try to unlock their underlying discardable memory. 1024 // may try to unlock their underlying discardable memory.
1022 ChildThreadImpl::ShutdownDiscardableSharedMemoryManager(); 1025 ChildThreadImpl::ShutdownDiscardableSharedMemoryManager();
1023 1026
1024 // The message loop must be cleared after shutting down 1027 // The message loop must be cleared after shutting down
1025 // the DiscardableSharedMemoryManager, which needs to send messages 1028 // the DiscardableSharedMemoryManager, which needs to send messages
1026 // to the browser process. 1029 // to the browser process.
1027 main_message_loop_.reset(); 1030 main_message_loop_.reset();
1028 1031
1029 lazy_tls.Pointer()->Set(nullptr); 1032 lazy_tls.Pointer()->Set(nullptr);
1033
1034 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
1030 } 1035 }
1031 1036
1032 bool RenderThreadImpl::Send(IPC::Message* msg) { 1037 bool RenderThreadImpl::Send(IPC::Message* msg) {
1033 // There are cases where we want to pump asynchronous messages while waiting 1038 // There are cases where we want to pump asynchronous messages while waiting
1034 // synchronously for the replies to the message to be sent here. However, this 1039 // synchronously for the replies to the message to be sent here. However, this
1035 // may create an opportunity for re-entrancy into WebKit and other subsystems, 1040 // may create an opportunity for re-entrancy into WebKit and other subsystems,
1036 // so we need to take care to disable callbacks, timers, and pending network 1041 // so we need to take care to disable callbacks, timers, and pending network
1037 // loads that could trigger such callbacks. 1042 // loads that could trigger such callbacks.
1038 bool pumping_events = false; 1043 bool pumping_events = false;
1039 if (msg->is_sync()) { 1044 if (msg->is_sync()) {
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 // EmbeddedSharedWorkerStub will self-destruct. 2130 // EmbeddedSharedWorkerStub will self-destruct.
2126 new EmbeddedSharedWorkerStub( 2131 new EmbeddedSharedWorkerStub(
2127 params.url, params.name, params.content_security_policy, 2132 params.url, params.name, params.content_security_policy,
2128 params.security_policy_type, params.creation_address_space, 2133 params.security_policy_type, params.creation_address_space,
2129 params.pause_on_start, params.route_id); 2134 params.pause_on_start, params.route_id);
2130 } 2135 }
2131 2136
2132 void RenderThreadImpl::OnMemoryPressure( 2137 void RenderThreadImpl::OnMemoryPressure(
2133 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 2138 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2134 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure"); 2139 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
2135 ReleaseFreeMemory();
2136
2137 // Do not call into blink if it is not initialized.
2138 if (blink_platform_impl_) { 2140 if (blink_platform_impl_) {
2139 blink::WebMemoryCoordinator::onMemoryPressure( 2141 blink::WebMemoryCoordinator::onMemoryPressure(
2140 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); 2142 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
2141 2143 }
2142 if (memory_pressure_level == 2144 if (memory_pressure_level ==
2143 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 2145 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
2144 // Purge Skia font cache, by setting it to 0 and then again to the 2146 ReleaseFreeMemory();
2145 // previous limit. 2147 ClearMemory();
2146 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2147 SkGraphics::SetFontCacheLimit(font_cache_limit);
2148 }
2149 } 2148 }
2150 } 2149 }
2151 2150
2151 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
2152 // TODO(hajimehoshi): Adjust the size of this memory usage according to
2153 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at
2154 // present.
2155 if (blink_platform_impl_) {
2156 blink::WebMemoryCoordinator::onMemoryStateChange(
2157 static_cast<blink::MemoryState>(state));
2158 }
2159 switch (state) {
2160 case base::MemoryState::NORMAL:
2161 break;
2162 case base::MemoryState::THROTTLED:
2163 ReleaseFreeMemory();
2164 break;
2165 case base::MemoryState::SUSPENDED:
2166 ReleaseFreeMemory();
2167 ClearMemory();
2168 break;
2169 case base::MemoryState::UNKNOWN:
2170 NOTREACHED();
2171 break;
2172 }
2173 }
2174
2175 void RenderThreadImpl::ClearMemory() {
2176 // Do not call into blink if it is not initialized.
2177 if (blink_platform_impl_) {
2178 // Purge Skia font cache, by setting it to 0 and then again to the
2179 // previous limit.
2180 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2181 SkGraphics::SetFontCacheLimit(font_cache_limit);
2182 }
2183 }
2184
2152 scoped_refptr<base::SingleThreadTaskRunner> 2185 scoped_refptr<base::SingleThreadTaskRunner>
2153 RenderThreadImpl::GetFileThreadTaskRunner() { 2186 RenderThreadImpl::GetFileThreadTaskRunner() {
2154 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread()); 2187 DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
2155 if (!file_thread_) { 2188 if (!file_thread_) {
2156 file_thread_.reset(new base::Thread("Renderer::FILE")); 2189 file_thread_.reset(new base::Thread("Renderer::FILE"));
2157 file_thread_->Start(); 2190 file_thread_->Start();
2158 } 2191 }
2159 return file_thread_->task_runner(); 2192 return file_thread_->task_runner();
2160 } 2193 }
2161 2194
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 } 2362 }
2330 } 2363 }
2331 2364
2332 void RenderThreadImpl::OnRendererInterfaceRequest( 2365 void RenderThreadImpl::OnRendererInterfaceRequest(
2333 mojom::RendererAssociatedRequest request) { 2366 mojom::RendererAssociatedRequest request) {
2334 DCHECK(!renderer_binding_.is_bound()); 2367 DCHECK(!renderer_binding_.is_bound());
2335 renderer_binding_.Bind(std::move(request)); 2368 renderer_binding_.Bind(std::move(request));
2336 } 2369 }
2337 2370
2338 } // namespace content 2371 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | third_party/WebKit/Source/platform/MemoryCoordinator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698