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

Unified Diff: content/renderer/render_thread_impl.cc

Issue 2402643002: Make RenderThreadImpl a client of memory coordinator (Closed)
Patch Set: 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
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..0b92487fa845db5a4019c575a995f7bdbcd77457 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,9 +897,12 @@ void RenderThreadImpl::Init(
#endif
is_renderer_suspended_ = false;
+
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
}
RenderThreadImpl::~RenderThreadImpl() {
+ 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.
}
void RenderThreadImpl::Shutdown() {
@@ -2132,20 +2136,46 @@ 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));
+ }
+ ClearMemory(memory_pressure_level ==
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
+}
- 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:
+ ClearMemory(false);
+ break;
+ case base::MemoryState::SUSPENDED:
+ ClearMemory(true);
+ break;
+ case base::MemoryState::UNKNOWN:
+ NOTREACHED();
+ break;
+ }
+}
+
+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.
+ ReleaseFreeMemory();
+
+ // Do not call into blink if it is not initialized.
+ if (blink_platform_impl_ && 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);
}
}

Powered by Google App Engine
This is Rietveld 408576698