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/memory_coordinator_client_registry.h" | |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "components/filesystem/public/interfaces/directory.mojom.h" | 20 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 20 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 21 #include "components/leveldb/public/interfaces/leveldb.mojom.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" |
| 27 #include "content/browser/memory/memory_coordinator.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/local_storage_usage_info.h" | 29 #include "content/public/browser/local_storage_usage_info.h" |
| 28 #include "content/public/browser/session_storage_usage_info.h" | 30 #include "content/public/browser/session_storage_usage_info.h" |
| 29 #include "mojo/common/common_type_converters.h" | 31 #include "mojo/common/common_type_converters.h" |
| 30 #include "services/file/public/cpp/constants.h" | 32 #include "services/file/public/cpp/constants.h" |
| 31 #include "services/file/public/interfaces/file_system.mojom.h" | 33 #include "services/file/public/interfaces/file_system.mojom.h" |
| 32 #include "services/shell/public/cpp/connection.h" | 34 #include "services/shell/public/cpp/connection.h" |
| 33 #include "services/shell/public/cpp/connector.h" | 35 #include "services/shell/public/cpp/connector.h" |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 : data_path.AppendASCII(kLocalStorageDirectory), | 279 : data_path.AppendASCII(kLocalStorageDirectory), |
| 278 data_path.empty() ? data_path | 280 data_path.empty() ? data_path |
| 279 : data_path.AppendASCII(kSessionStorageDirectory), | 281 : data_path.AppendASCII(kSessionStorageDirectory), |
| 280 special_storage_policy, | 282 special_storage_policy, |
| 281 new DOMStorageWorkerPoolTaskRunner( | 283 new DOMStorageWorkerPoolTaskRunner( |
| 282 worker_pool, | 284 worker_pool, |
| 283 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 285 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 284 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 286 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 285 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | 287 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); |
| 286 | 288 |
| 287 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 289 if (MemoryCoordinator::GetInstance()) { |
|
hajimehoshi
2016/09/15 09:14:46
bashi: Is this a correct usage to check whether Me
| |
| 288 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | 290 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 291 } else { | |
| 292 memory_pressure_listener_.reset(new base::MemoryPressureListener( | |
| 293 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | |
| 294 } | |
| 289 } | 295 } |
| 290 | 296 |
| 291 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} | 297 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
| 292 | 298 |
| 293 void DOMStorageContextWrapper::GetLocalStorageUsage( | 299 void DOMStorageContextWrapper::GetLocalStorageUsage( |
| 294 const GetLocalStorageUsageCallback& callback) { | 300 const GetLocalStorageUsageCallback& callback) { |
| 295 DCHECK(context_.get()); | 301 DCHECK(context_.get()); |
| 296 context_->task_runner()->PostShutdownBlockingTask( | 302 context_->task_runner()->PostShutdownBlockingTask( |
| 297 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 303 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 298 base::Bind(&GetLocalStorageUsageHelper, | 304 base::Bind(&GetLocalStorageUsageHelper, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 364 } |
| 359 | 365 |
| 360 void DOMStorageContextWrapper::Shutdown() { | 366 void DOMStorageContextWrapper::Shutdown() { |
| 361 DCHECK(context_.get()); | 367 DCHECK(context_.get()); |
| 362 mojo_state_.reset(); | 368 mojo_state_.reset(); |
| 363 memory_pressure_listener_.reset(); | 369 memory_pressure_listener_.reset(); |
| 364 context_->task_runner()->PostShutdownBlockingTask( | 370 context_->task_runner()->PostShutdownBlockingTask( |
| 365 FROM_HERE, | 371 FROM_HERE, |
| 366 DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 372 DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 367 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); | 373 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); |
| 374 if (MemoryCoordinator::GetInstance()) { | |
| 375 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(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) { |
| 387 DOMStorageContextImpl::PurgeOption purge_option = | 397 DOMStorageContextImpl::PurgeOption purge_option = |
| 388 DOMStorageContextImpl::PURGE_UNOPENED; | 398 DOMStorageContextImpl::PURGE_UNOPENED; |
| 389 if (memory_pressure_level == | 399 if (memory_pressure_level == |
| 390 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 400 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 391 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; | 401 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 392 } | 402 } |
| 403 PurgeMemory(purge_option); | |
| 404 } | |
| 405 | |
| 406 void DOMStorageContextWrapper::OnMemoryStateChange(base::MemoryState state) { | |
| 407 // TODO(hajimehoshi): As OnMemoryStateChange changes the state, we should | |
| 408 // adjust the limitation to the amount of cache, DomStroageContextImpl doesn't | |
| 409 // have such limitation so far though. | |
| 410 switch (state) { | |
| 411 case base::MemoryState::NORMAL: | |
| 412 // Don't have to purge memory here. | |
| 413 break; | |
| 414 case base::MemoryState::THROTTLED: | |
| 415 // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we | |
| 416 // have such value, let's change the argument accroding to the value. | |
| 417 PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED); | |
| 418 break; | |
| 419 case base::MemoryState::SUSPENDED: | |
| 420 // Note that SUSPENDED never occurs in the main browser process so far. | |
| 421 // Fall through. | |
| 422 case base::MemoryState::UNKNOWN: | |
| 423 NOTREACHED(); | |
| 424 break; | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption | |
| 429 purge_option) { | |
| 393 context_->task_runner()->PostTask( | 430 context_->task_runner()->PostTask( |
| 394 FROM_HERE, | 431 FROM_HERE, |
| 395 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 432 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 396 } | 433 } |
| 397 | 434 |
| 398 } // namespace content | 435 } // namespace content |
| OLD | NEW |