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..b42e20d6925ed2e52e5d8162c034145b294e3135 100644 |
| --- a/content/browser/dom_storage/dom_storage_context_wrapper.cc |
| +++ b/content/browser/dom_storage/dom_storage_context_wrapper.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/bind_helpers.h" |
| #include "base/files/file_path.h" |
| #include "base/location.h" |
| +#include "base/memory/memory_coordinator_client_registry.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/single_thread_task_runner.h" |
| @@ -23,6 +24,7 @@ |
| #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| #include "content/browser/leveldb_wrapper_impl.h" |
| +#include "content/browser/memory/memory_coordinator.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/local_storage_usage_info.h" |
| #include "content/public/browser/session_storage_usage_info.h" |
| @@ -284,8 +286,12 @@ 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))); |
| + if (MemoryCoordinator::GetInstance()) { |
|
hajimehoshi
2016/09/15 09:14:46
bashi: Is this a correct usage to check whether Me
|
| + base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| + } else { |
| + memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| + base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
| + } |
| } |
| DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
| @@ -365,6 +371,10 @@ void DOMStorageContextWrapper::Shutdown() { |
| FROM_HERE, |
| DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| base::Bind(&DOMStorageContextImpl::Shutdown, context_)); |
| + if (MemoryCoordinator::GetInstance()) { |
| + base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
| + } |
| + |
| } |
| void DOMStorageContextWrapper::Flush() { |
| @@ -390,6 +400,33 @@ void DOMStorageContextWrapper::OnMemoryPressure( |
| base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| } |
| + PurgeMemory(purge_option); |
| +} |
| + |
| +void DOMStorageContextWrapper::OnMemoryStateChange(base::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 base::MemoryState::NORMAL: |
| + // Don't have to purge memory here. |
| + break; |
| + case base::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(DOMStorageContextImpl::PURGE_UNOPENED); |
| + break; |
| + case base::MemoryState::SUSPENDED: |
| + // Note that SUSPENDED never occurs in the main browser process so far. |
| + // Fall through. |
| + case base::MemoryState::UNKNOWN: |
| + NOTREACHED(); |
| + break; |
| + } |
| +} |
| + |
| +void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption |
| + purge_option) { |
| context_->task_runner()->PostTask( |
| FROM_HERE, |
| base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |