Chromium Code Reviews| 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..35932cb123a61a06dfb1c6315a1a3107f9d4261d 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,11 +285,20 @@ 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() {} |
| +DOMStorageContextWrapper::~DOMStorageContextWrapper() { |
| + if (memory_coordinator::MemoryCoordinator::GetInstance()) { |
|
michaeln
2016/09/14 01:34:41
Register() / Unregister() need to be called on the
hajimehoshi
2016/09/14 11:49:47
Done.
|
| + memory_coordinator::MemoryCoordinator::GetInstance()->UnregisterClient( |
| + this); |
| + } |
| +} |
| void DOMStorageContextWrapper::GetLocalStorageUsage( |
| const GetLocalStorageUsageCallback& callback) { |
| @@ -384,10 +394,19 @@ void DOMStorageContextWrapper::OpenLocalStorage( |
| void DOMStorageContextWrapper::OnMemoryPressure( |
| base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| + PurgeMemory(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
|
ssid
2016/09/13 18:29:23
Why are we always purging aggressively here? shoul
hajimehoshi
2016/09/14 11:49:48
Done.
|
| +} |
| + |
| +void DOMStorageContextWrapper::OnMemoryStateChange( |
| + memory_coordinator::MemoryState state) { |
|
michaeln
2016/09/14 01:34:41
enum class MemoryState : int32_t {
UNKNOWN = -1,
bashi
2016/09/14 03:33:13
Sorry for lack of explanation. I'll add comments i
|
| + PurgeMemory(state == memory_coordinator::MemoryState::SUSPENDED); |
|
ssid
2016/09/13 18:29:23
The memory coordinator document states that the "s
hajimehoshi
2016/09/14 11:49:47
I realized 'suspended' state can't come to browser
|
| +} |
| + |
| +void DOMStorageContextWrapper::PurgeMemory(bool aggressively) |
|
michaeln
2016/09/14 01:34:41
might be cleaner to have the helper take a DOMStor
hajimehoshi
2016/09/14 11:49:48
I don't think that is possible since DOMStorageCon
michaeln
2016/09/14 19:40:48
Maybe i'm missing something? This method is a pri
hajimehoshi
2016/09/15 09:14:46
Sorry but I was misunderstanding. Instead of addin
michaeln
2016/09/15 20:46:27
Thnx, that's exactly what i was suggesting :) The
|
| +{ |
| 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( |