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 9f52d77266e9ed750370a1f307664486fef4aa47..d646ada9754a69be1e49e2209c5dc58ff3300499 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,14 @@ DOMStorageContextWrapper::DOMStorageContextWrapper( |
worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); |
- memory_pressure_listener_.reset(new base::MemoryPressureListener( |
- base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
+ auto* memory_coordinator = |
+ memory_coordinator::MemoryCoordinator::GetInstance(); |
+ if (memory_coordinator) { |
+ memory_coordinator->RegisterClient(this); |
+ } else { |
+ memory_pressure_listener_.reset(new base::MemoryPressureListener( |
+ base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
+ } |
} |
DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
@@ -395,4 +402,16 @@ void DOMStorageContextWrapper::OnMemoryPressure( |
base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
} |
+void DOMStorageContextWrapper::OnMemoryStateChange( |
+ memory_coordinator::MemoryState state) { |
+ DOMStorageContextImpl::PurgeOption purge_option = |
+ DOMStorageContextImpl::PURGE_UNOPENED; |
+ if (state == memory_coordinator::MemoryState::SUSPENDED) { |
+ purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
+ } |
+ context_->task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
+} |
+ |
} // namespace content |