| 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 auto* memory_coordinator = |
| 288 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | 289 memory_coordinator::MemoryCoordinator::GetInstance(); |
| 290 if (memory_coordinator) { |
| 291 memory_coordinator->RegisterClient(this); |
| 292 } else { |
| 293 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 294 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
| 295 } |
| 289 } | 296 } |
| 290 | 297 |
| 291 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} | 298 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
| 292 | 299 |
| 293 void DOMStorageContextWrapper::GetLocalStorageUsage( | 300 void DOMStorageContextWrapper::GetLocalStorageUsage( |
| 294 const GetLocalStorageUsageCallback& callback) { | 301 const GetLocalStorageUsageCallback& callback) { |
| 295 DCHECK(context_.get()); | 302 DCHECK(context_.get()); |
| 296 context_->task_runner()->PostShutdownBlockingTask( | 303 context_->task_runner()->PostShutdownBlockingTask( |
| 297 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 304 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 298 base::Bind(&GetLocalStorageUsageHelper, | 305 base::Bind(&GetLocalStorageUsageHelper, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 DOMStorageContextImpl::PURGE_UNOPENED; | 395 DOMStorageContextImpl::PURGE_UNOPENED; |
| 389 if (memory_pressure_level == | 396 if (memory_pressure_level == |
| 390 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 397 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 391 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; | 398 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 392 } | 399 } |
| 393 context_->task_runner()->PostTask( | 400 context_->task_runner()->PostTask( |
| 394 FROM_HERE, | 401 FROM_HERE, |
| 395 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 402 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 396 } | 403 } |
| 397 | 404 |
| 405 void DOMStorageContextWrapper::OnMemoryStateChange( |
| 406 memory_coordinator::MemoryState state) { |
| 407 DOMStorageContextImpl::PurgeOption purge_option = |
| 408 DOMStorageContextImpl::PURGE_UNOPENED; |
| 409 if (state == memory_coordinator::MemoryState::SUSPENDED) { |
| 410 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 411 } |
| 412 context_->task_runner()->PostTask( |
| 413 FROM_HERE, |
| 414 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 415 } |
| 416 |
| 398 } // namespace content | 417 } // namespace content |
| OLD | NEW |