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() {} |
| 292 | 297 |
| 293 void DOMStorageContextWrapper::GetLocalStorageUsage( | 298 void DOMStorageContextWrapper::GetLocalStorageUsage( |
| 294 const GetLocalStorageUsageCallback& callback) { | 299 const GetLocalStorageUsageCallback& callback) { |
| 295 DCHECK(context_.get()); | 300 DCHECK(context_.get()); |
| 296 context_->task_runner()->PostShutdownBlockingTask( | 301 context_->task_runner()->PostShutdownBlockingTask( |
| 297 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 302 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 298 base::Bind(&GetLocalStorageUsageHelper, | 303 base::Bind(&GetLocalStorageUsageHelper, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 363 } |
| 359 | 364 |
| 360 void DOMStorageContextWrapper::Shutdown() { | 365 void DOMStorageContextWrapper::Shutdown() { |
| 361 DCHECK(context_.get()); | 366 DCHECK(context_.get()); |
| 362 mojo_state_.reset(); | 367 mojo_state_.reset(); |
| 363 memory_pressure_listener_.reset(); | 368 memory_pressure_listener_.reset(); |
| 364 context_->task_runner()->PostShutdownBlockingTask( | 369 context_->task_runner()->PostShutdownBlockingTask( |
| 365 FROM_HERE, | 370 FROM_HERE, |
| 366 DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 371 DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 367 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); | 372 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); |
| 373 if (memory_coordinator::MemoryCoordinator::GetInstance()) { | |
| 374 memory_coordinator::MemoryCoordinator::GetInstance()->UnregisterClient( | |
| 375 this); | |
| 376 } | |
| 377 | |
| 368 } | 378 } |
| 369 | 379 |
| 370 void DOMStorageContextWrapper::Flush() { | 380 void DOMStorageContextWrapper::Flush() { |
| 371 DCHECK(context_.get()); | 381 DCHECK(context_.get()); |
| 372 context_->task_runner()->PostShutdownBlockingTask( | 382 context_->task_runner()->PostShutdownBlockingTask( |
| 373 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 383 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 374 base::Bind(&DOMStorageContextImpl::Flush, context_)); | 384 base::Bind(&DOMStorageContextImpl::Flush, context_)); |
| 375 } | 385 } |
| 376 | 386 |
| 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(memory_pressure_level == | |
| 398 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 399 } | |
| 400 | |
| 401 void DOMStorageContextWrapper::OnMemoryStateChange( | |
| 402 memory_coordinator::MemoryState state) { | |
| 403 // TODO(hajimehoshi): As OnMemoryStateChange changes the state, we should | |
| 404 // adjust the limitation to the amount of cache, DomStroageContextImpl doesn't | |
| 405 // have such limitation so far though. | |
| 406 switch (state) { | |
| 407 case memory_coordinator::MemoryState::NORMAL: | |
|
michaeln
2016/09/14 19:40:49
style nit: indent cases by 2 spaces
hajimehoshi
2016/09/15 09:14:46
Done.
| |
| 408 // Don't have to purge memory here. | |
| 409 break; | |
| 410 case memory_coordinator::MemoryState::THROTTLED: | |
| 411 // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we have | |
| 412 // such value, let's change the argument accroding to the value. | |
| 413 PurgeMemory(false); | |
| 414 break; | |
| 415 case memory_coordinator::MemoryState::UNKNOWN: | |
| 416 case memory_coordinator::MemoryState::SUSPENDED: | |
| 417 NOTREACHED(); | |
|
michaeln
2016/09/14 19:40:49
maybe comment that SUSPENDED doesn't occur in the
hajimehoshi
2016/09/15 09:14:46
Done.
| |
| 418 break; | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 void DOMStorageContextWrapper::PurgeMemory(bool aggressively) | |
| 423 { | |
|
michaeln
2016/09/14 19:40:49
style nit: move { up to the end of the previous li
hajimehoshi
2016/09/15 09:14:46
Done.
| |
| 387 DOMStorageContextImpl::PurgeOption purge_option = | 424 DOMStorageContextImpl::PurgeOption purge_option = |
| 388 DOMStorageContextImpl::PURGE_UNOPENED; | 425 DOMStorageContextImpl::PURGE_UNOPENED; |
| 389 if (memory_pressure_level == | 426 if (aggressively) { |
| 390 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | |
| 391 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; | 427 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 392 } | 428 } |
| 393 context_->task_runner()->PostTask( | 429 context_->task_runner()->PostTask( |
| 394 FROM_HERE, | 430 FROM_HERE, |
| 395 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 431 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 396 } | 432 } |
| 397 | 433 |
| 398 } // namespace content | 434 } // namespace content |
| OLD | NEW |