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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_thread_impl.cc
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index d1545473645b206b6758af47ee6a20a28bd2df17..afeb6be3898ff93e3fbde9506ae31604d3f11b72 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -17,6 +17,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/discardable_memory_allocator.h"
+#include "base/memory/memory_coordinator_client_registry.h"
#include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h"
#include "base/metrics/field_trial.h"
@@ -896,6 +897,8 @@ void RenderThreadImpl::Init(
#endif
is_renderer_suspended_ = false;
+
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
}
RenderThreadImpl::~RenderThreadImpl() {
@@ -1027,6 +1030,8 @@ void RenderThreadImpl::Shutdown() {
main_message_loop_.reset();
lazy_tls.Pointer()->Set(nullptr);
+
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
}
bool RenderThreadImpl::Send(IPC::Message* msg) {
@@ -2132,20 +2137,48 @@ void RenderThreadImpl::OnCreateNewSharedWorker(
void RenderThreadImpl::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
- ReleaseFreeMemory();
-
- // Do not call into blink if it is not initialized.
if (blink_platform_impl_) {
blink::WebMemoryCoordinator::onMemoryPressure(
static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
+ }
+ if (memory_pressure_level ==
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
+ ReleaseFreeMemory();
+ ClearMemory();
+ }
+}
- if (memory_pressure_level ==
- base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
- // Purge Skia font cache, by setting it to 0 and then again to the
- // previous limit.
- size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
- SkGraphics::SetFontCacheLimit(font_cache_limit);
- }
+void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
+ // TODO(hajimehoshi): Adjust the size of this memory usage according to
+ // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at
+ // present.
+ if (blink_platform_impl_) {
+ blink::WebMemoryCoordinator::onMemoryStateChange(
+ static_cast<blink::MemoryState>(state));
+ }
+ switch (state) {
+ case base::MemoryState::NORMAL:
+ break;
+ case base::MemoryState::THROTTLED:
+ ReleaseFreeMemory();
+ break;
+ case base::MemoryState::SUSPENDED:
+ ReleaseFreeMemory();
+ ClearMemory();
+ break;
+ case base::MemoryState::UNKNOWN:
+ NOTREACHED();
+ break;
+ }
+}
+
+void RenderThreadImpl::ClearMemory() {
+ // Do not call into blink if it is not initialized.
+ if (blink_platform_impl_) {
+ // Purge Skia font cache, by setting it to 0 and then again to the
+ // previous limit.
+ size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
+ SkGraphics::SetFontCacheLimit(font_cache_limit);
}
}
« 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