| 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/base_features.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/memory/memory_coordinator_client_registry.h" | 16 #include "base/memory/memory_coordinator_client_registry.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/task_scheduler/post_task.h" | 22 #include "base/task_scheduler/post_task.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "content/browser/dom_storage/dom_storage_area.h" | 25 #include "content/browser/dom_storage/dom_storage_area.h" |
| 25 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 26 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 26 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 27 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 27 #include "content/browser/dom_storage/local_storage_context_mojo.h" | 28 #include "content/browser/dom_storage/local_storage_context_mojo.h" |
| 28 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 29 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/local_storage_usage_info.h" | 32 #include "content/public/browser/local_storage_usage_info.h" |
| 32 #include "content/public/browser/session_storage_usage_info.h" | 33 #include "content/public/browser/session_storage_usage_info.h" |
| 33 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
| 34 #include "content/public/common/content_features.h" | |
| 35 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 36 | 36 |
| 37 namespace content { | 37 namespace content { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const char kLocalStorageDirectory[] = "Local Storage"; | 40 const char kLocalStorageDirectory[] = "Local Storage"; |
| 41 const char kSessionStorageDirectory[] = "Session Storage"; | 41 const char kSessionStorageDirectory[] = "Session Storage"; |
| 42 | 42 |
| 43 void InvokeLocalStorageUsageCallbackHelper( | 43 void InvokeLocalStorageUsageCallbackHelper( |
| 44 const DOMStorageContext::GetLocalStorageUsageCallback& callback, | 44 const DOMStorageContext::GetLocalStorageUsageCallback& callback, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // TODO(michaeln): Enable writing to disk when db is versioned, | 131 // TODO(michaeln): Enable writing to disk when db is versioned, |
| 132 // for now using an empty subdirectory to use an in-memory db. | 132 // for now using an empty subdirectory to use an in-memory db. |
| 133 // subdirectory_(subdirectory), | 133 // subdirectory_(subdirectory), |
| 134 mojo_state_.reset(new LocalStorageContextMojo( | 134 mojo_state_.reset(new LocalStorageContextMojo( |
| 135 connector, context_->task_runner(), | 135 connector, context_->task_runner(), |
| 136 data_path.empty() ? data_path | 136 data_path.empty() ? data_path |
| 137 : data_path.AppendASCII(kLocalStorageDirectory), | 137 : data_path.AppendASCII(kLocalStorageDirectory), |
| 138 storage_dir)); | 138 storage_dir)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 141 if (base::FeatureList::IsEnabled(base::features::kMemoryCoordinator)) { |
| 142 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 142 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 143 } else { | 143 } else { |
| 144 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 144 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 145 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | 145 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} | 149 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
| 150 | 150 |
| 151 void DOMStorageContextWrapper::GetLocalStorageUsage( | 151 void DOMStorageContextWrapper::GetLocalStorageUsage( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 235 } |
| 236 | 236 |
| 237 void DOMStorageContextWrapper::Shutdown() { | 237 void DOMStorageContextWrapper::Shutdown() { |
| 238 DCHECK(context_.get()); | 238 DCHECK(context_.get()); |
| 239 mojo_state_.reset(); | 239 mojo_state_.reset(); |
| 240 memory_pressure_listener_.reset(); | 240 memory_pressure_listener_.reset(); |
| 241 context_->task_runner()->PostShutdownBlockingTask( | 241 context_->task_runner()->PostShutdownBlockingTask( |
| 242 FROM_HERE, | 242 FROM_HERE, |
| 243 DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 243 DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 244 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); | 244 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); |
| 245 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 245 if (base::FeatureList::IsEnabled(base::features::kMemoryCoordinator)) { |
| 246 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); | 246 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } | 249 } |
| 250 | 250 |
| 251 void DOMStorageContextWrapper::Flush() { | 251 void DOMStorageContextWrapper::Flush() { |
| 252 DCHECK(context_.get()); | 252 DCHECK(context_.get()); |
| 253 context_->task_runner()->PostShutdownBlockingTask( | 253 context_->task_runner()->PostShutdownBlockingTask( |
| 254 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 254 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 255 base::Bind(&DOMStorageContextImpl::Flush, context_)); | 255 base::Bind(&DOMStorageContextImpl::Flush, context_)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 GetLocalStorageUsageCallback callback, | 293 GetLocalStorageUsageCallback callback, |
| 294 std::vector<LocalStorageUsageInfo> usage) { | 294 std::vector<LocalStorageUsageInfo> usage) { |
| 295 context_->task_runner()->PostShutdownBlockingTask( | 295 context_->task_runner()->PostShutdownBlockingTask( |
| 296 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 296 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 297 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage), | 297 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage), |
| 298 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), | 298 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), |
| 299 base::RetainedRef(context_), callback)); | 299 base::RetainedRef(context_), callback)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace content | 302 } // namespace content |
| OLD | NEW |