Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "components/filesystem/public/interfaces/directory.mojom.h" | 19 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 20 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 20 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 21 #include "components/memory_coordinator/browser/memory_coordinator.h" | |
| 21 #include "content/browser/dom_storage/dom_storage_area.h" | 22 #include "content/browser/dom_storage/dom_storage_area.h" |
| 22 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 23 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 23 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 24 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 25 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 25 #include "content/browser/leveldb_wrapper_impl.h" | 26 #include "content/browser/leveldb_wrapper_impl.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/local_storage_usage_info.h" | 28 #include "content/public/browser/local_storage_usage_info.h" |
| 28 #include "content/public/browser/session_storage_usage_info.h" | 29 #include "content/public/browser/session_storage_usage_info.h" |
| 29 #include "mojo/common/common_type_converters.h" | 30 #include "mojo/common/common_type_converters.h" |
| 30 #include "services/file/public/cpp/constants.h" | 31 #include "services/file/public/cpp/constants.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 : data_path.AppendASCII(kLocalStorageDirectory), | 278 : data_path.AppendASCII(kLocalStorageDirectory), |
| 278 data_path.empty() ? data_path | 279 data_path.empty() ? data_path |
| 279 : data_path.AppendASCII(kSessionStorageDirectory), | 280 : data_path.AppendASCII(kSessionStorageDirectory), |
| 280 special_storage_policy, | 281 special_storage_policy, |
| 281 new DOMStorageWorkerPoolTaskRunner( | 282 new DOMStorageWorkerPoolTaskRunner( |
| 282 worker_pool, | 283 worker_pool, |
| 283 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 284 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 284 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 285 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 285 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | 286 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); |
| 286 | 287 |
| 287 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 288 if (memory_coordinator::MemoryCoordinator::GetInstance()) { |
| 289 memory_coordinator::MemoryCoordinator::GetInstance()->RegisterClient(this); | |
| 290 } else { | |
| 291 memory_pressure_listener_.reset(new base::MemoryPressureListener( | |
| 288 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | 292 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
| 293 } | |
| 289 } | 294 } |
| 290 | 295 |
| 291 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} | 296 DOMStorageContextWrapper::~DOMStorageContextWrapper() { |
| 297 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.
| |
| 298 memory_coordinator::MemoryCoordinator::GetInstance()->UnregisterClient( | |
| 299 this); | |
| 300 } | |
| 301 } | |
| 292 | 302 |
| 293 void DOMStorageContextWrapper::GetLocalStorageUsage( | 303 void DOMStorageContextWrapper::GetLocalStorageUsage( |
| 294 const GetLocalStorageUsageCallback& callback) { | 304 const GetLocalStorageUsageCallback& callback) { |
| 295 DCHECK(context_.get()); | 305 DCHECK(context_.get()); |
| 296 context_->task_runner()->PostShutdownBlockingTask( | 306 context_->task_runner()->PostShutdownBlockingTask( |
| 297 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 307 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 298 base::Bind(&GetLocalStorageUsageHelper, | 308 base::Bind(&GetLocalStorageUsageHelper, |
| 299 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), | 309 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), |
| 300 base::RetainedRef(context_), callback)); | 310 base::RetainedRef(context_), callback)); |
| 301 } | 311 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 void DOMStorageContextWrapper::OpenLocalStorage( | 387 void DOMStorageContextWrapper::OpenLocalStorage( |
| 378 const url::Origin& origin, | 388 const url::Origin& origin, |
| 379 mojom::LevelDBObserverPtr observer, | 389 mojom::LevelDBObserverPtr observer, |
| 380 mojom::LevelDBWrapperRequest request) { | 390 mojom::LevelDBWrapperRequest request) { |
| 381 mojo_state_->OpenLocalStorage( | 391 mojo_state_->OpenLocalStorage( |
| 382 origin, std::move(observer), std::move(request)); | 392 origin, std::move(observer), std::move(request)); |
| 383 } | 393 } |
| 384 | 394 |
| 385 void DOMStorageContextWrapper::OnMemoryPressure( | 395 void DOMStorageContextWrapper::OnMemoryPressure( |
| 386 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 396 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 397 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.
| |
| 398 } | |
| 399 | |
| 400 void DOMStorageContextWrapper::OnMemoryStateChange( | |
| 401 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
| |
| 402 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
| |
| 403 } | |
| 404 | |
| 405 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
| |
| 406 { | |
| 387 DOMStorageContextImpl::PurgeOption purge_option = | 407 DOMStorageContextImpl::PurgeOption purge_option = |
| 388 DOMStorageContextImpl::PURGE_UNOPENED; | 408 DOMStorageContextImpl::PURGE_UNOPENED; |
| 389 if (memory_pressure_level == | 409 if (aggressively) { |
| 390 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | |
| 391 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; | 410 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 392 } | 411 } |
| 393 context_->task_runner()->PostTask( | 412 context_->task_runner()->PostTask( |
| 394 FROM_HERE, | 413 FROM_HERE, |
| 395 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 414 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 396 } | 415 } |
| 397 | 416 |
| 398 } // namespace content | 417 } // namespace content |
| OLD | NEW |