Chromium Code Reviews

Unified Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 2335933003: Make DOMStorageContextWrapper a client of memory coordinator (Closed)
Patch Set: Address on reviews Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: content/browser/dom_storage/dom_storage_context_wrapper.cc
diff --git a/content/browser/dom_storage/dom_storage_context_wrapper.cc b/content/browser/dom_storage/dom_storage_context_wrapper.cc
index 52e769cf72a1e7bc86c15b670d166ca0fb39e7e0..b63e618c1018938d343cceceb4d2912c0cfa8949 100644
--- a/content/browser/dom_storage/dom_storage_context_wrapper.cc
+++ b/content/browser/dom_storage/dom_storage_context_wrapper.cc
@@ -18,6 +18,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "components/filesystem/public/interfaces/directory.mojom.h"
#include "components/leveldb/public/interfaces/leveldb.mojom.h"
+#include "components/memory_coordinator/browser/memory_coordinator.h"
#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/browser/dom_storage/dom_storage_context_impl.h"
#include "content/browser/dom_storage/dom_storage_task_runner.h"
@@ -284,8 +285,12 @@ DOMStorageContextWrapper::DOMStorageContextWrapper(
worker_pool->GetNamedSequenceToken("dom_storage_commit"),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get()));
- memory_pressure_listener_.reset(new base::MemoryPressureListener(
+ if (memory_coordinator::MemoryCoordinator::GetInstance()) {
+ memory_coordinator::MemoryCoordinator::GetInstance()->RegisterClient(this);
+ } else {
+ memory_pressure_listener_.reset(new base::MemoryPressureListener(
base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this)));
+ }
}
DOMStorageContextWrapper::~DOMStorageContextWrapper() {}
@@ -365,6 +370,11 @@ void DOMStorageContextWrapper::Shutdown() {
FROM_HERE,
DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&DOMStorageContextImpl::Shutdown, context_));
+ if (memory_coordinator::MemoryCoordinator::GetInstance()) {
+ memory_coordinator::MemoryCoordinator::GetInstance()->UnregisterClient(
+ this);
+ }
+
}
void DOMStorageContextWrapper::Flush() {
@@ -384,10 +394,36 @@ void DOMStorageContextWrapper::OpenLocalStorage(
void DOMStorageContextWrapper::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
+ PurgeMemory(memory_pressure_level ==
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
+}
+
+void DOMStorageContextWrapper::OnMemoryStateChange(
+ memory_coordinator::MemoryState state) {
+ // TODO(hajimehoshi): As OnMemoryStateChange changes the state, we should
+ // adjust the limitation to the amount of cache, DomStroageContextImpl doesn't
+ // have such limitation so far though.
+ switch (state) {
+ case memory_coordinator::MemoryState::NORMAL:
michaeln 2016/09/14 19:40:49 style nit: indent cases by 2 spaces
hajimehoshi 2016/09/15 09:14:46 Done.
+ // Don't have to purge memory here.
+ break;
+ case memory_coordinator::MemoryState::THROTTLED:
+ // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we have
+ // such value, let's change the argument accroding to the value.
+ PurgeMemory(false);
+ break;
+ case memory_coordinator::MemoryState::UNKNOWN:
+ case memory_coordinator::MemoryState::SUSPENDED:
+ NOTREACHED();
michaeln 2016/09/14 19:40:49 maybe comment that SUSPENDED doesn't occur in the
hajimehoshi 2016/09/15 09:14:46 Done.
+ break;
+ }
+}
+
+void DOMStorageContextWrapper::PurgeMemory(bool aggressively)
+{
michaeln 2016/09/14 19:40:49 style nit: move { up to the end of the previous li
hajimehoshi 2016/09/15 09:14:46 Done.
DOMStorageContextImpl::PurgeOption purge_option =
DOMStorageContextImpl::PURGE_UNOPENED;
- if (memory_pressure_level ==
- base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
+ if (aggressively) {
purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE;
}
context_->task_runner()->PostTask(

Powered by Google App Engine