| 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/memory_coordinator_client_registry.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/task_scheduler/post_task.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "components/filesystem/public/interfaces/directory.mojom.h" | 22 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 21 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 23 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 22 #include "content/browser/dom_storage/dom_storage_area.h" | 24 #include "content/browser/dom_storage/dom_storage_area.h" |
| 23 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 25 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 24 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 26 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 25 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 27 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 26 #include "content/browser/leveldb_wrapper_impl.h" | 28 #include "content/browser/leveldb_wrapper_impl.h" |
| 27 #include "content/browser/memory/memory_coordinator.h" | 29 #include "content/browser/memory/memory_coordinator.h" |
| 28 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/content_browser_client.h" |
| 29 #include "content/public/browser/local_storage_usage_info.h" | 32 #include "content/public/browser/local_storage_usage_info.h" |
| 30 #include "content/public/browser/session_storage_usage_info.h" | 33 #include "content/public/browser/session_storage_usage_info.h" |
| 34 #include "content/public/common/content_client.h" |
| 31 #include "content/public/common/content_features.h" | 35 #include "content/public/common/content_features.h" |
| 32 #include "mojo/common/common_type_converters.h" | 36 #include "mojo/common/common_type_converters.h" |
| 33 #include "services/file/public/interfaces/constants.mojom.h" | 37 #include "services/file/public/interfaces/constants.mojom.h" |
| 34 #include "services/file/public/interfaces/file_system.mojom.h" | 38 #include "services/file/public/interfaces/file_system.mojom.h" |
| 35 #include "services/service_manager/public/cpp/connection.h" | 39 #include "services/service_manager/public/cpp/connection.h" |
| 36 #include "services/service_manager/public/cpp/connector.h" | 40 #include "services/service_manager/public/cpp/connector.h" |
| 37 | 41 |
| 38 namespace content { | 42 namespace content { |
| 39 namespace { | 43 namespace { |
| 40 | 44 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const base::FilePath& local_partition_path, | 271 const base::FilePath& local_partition_path, |
| 268 storage::SpecialStoragePolicy* special_storage_policy) { | 272 storage::SpecialStoragePolicy* special_storage_policy) { |
| 269 base::FilePath storage_dir; | 273 base::FilePath storage_dir; |
| 270 if (!profile_path.empty()) | 274 if (!profile_path.empty()) |
| 271 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory); | 275 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory); |
| 272 mojo_state_.reset(new MojoState(connector, storage_dir)); | 276 mojo_state_.reset(new MojoState(connector, storage_dir)); |
| 273 | 277 |
| 274 base::FilePath data_path; | 278 base::FilePath data_path; |
| 275 if (!profile_path.empty()) | 279 if (!profile_path.empty()) |
| 276 data_path = profile_path.Append(local_partition_path); | 280 data_path = profile_path.Append(local_partition_path); |
| 277 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 281 |
| 282 scoped_refptr<base::SequencedTaskRunner> primary_sequence; |
| 283 scoped_refptr<base::SequencedTaskRunner> commit_sequence; |
| 284 if (GetContentClient()->browser()->ShouldRedirectDOMStorageTaskRunner()) { |
| 285 // TaskPriority::USER_BLOCKING as an experiment because this is currently |
| 286 // believed to be blocking synchronous IPCs from the renderers: |
| 287 // http://crbug.com/665588 (yes we want to fix that bug, but are taking it |
| 288 // as an opportunity to experiment with the scheduler). |
| 289 base::TaskTraits dom_storage_traits = |
| 290 base::TaskTraits() |
| 291 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN) |
| 292 .WithFileIO() |
| 293 .WithPriority(base::TaskPriority::USER_BLOCKING); |
| 294 primary_sequence = |
| 295 base::CreateSequencedTaskRunnerWithTraits(dom_storage_traits); |
| 296 commit_sequence = |
| 297 base::CreateSequencedTaskRunnerWithTraits(dom_storage_traits); |
| 298 } else { |
| 299 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
| 300 primary_sequence = worker_pool->GetSequencedTaskRunner( |
| 301 worker_pool->GetNamedSequenceToken("dom_storage_primary")); |
| 302 commit_sequence = worker_pool->GetSequencedTaskRunner( |
| 303 worker_pool->GetNamedSequenceToken("dom_storage_commit")); |
| 304 } |
| 305 DCHECK(primary_sequence); |
| 306 DCHECK(commit_sequence); |
| 307 |
| 278 context_ = new DOMStorageContextImpl( | 308 context_ = new DOMStorageContextImpl( |
| 279 data_path.empty() ? data_path | 309 data_path.empty() ? data_path |
| 280 : data_path.AppendASCII(kLocalStorageDirectory), | 310 : data_path.AppendASCII(kLocalStorageDirectory), |
| 281 data_path.empty() ? data_path | 311 data_path.empty() ? data_path |
| 282 : data_path.AppendASCII(kSessionStorageDirectory), | 312 : data_path.AppendASCII(kSessionStorageDirectory), |
| 283 special_storage_policy, | 313 special_storage_policy, |
| 284 new DOMStorageWorkerPoolTaskRunner( | 314 new DOMStorageWorkerPoolTaskRunner(std::move(primary_sequence), |
| 285 worker_pool, | 315 std::move(commit_sequence))); |
| 286 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | |
| 287 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | |
| 288 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | |
| 289 | 316 |
| 290 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 317 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 291 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 318 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 292 } else { | 319 } else { |
| 293 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 320 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 294 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); | 321 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); |
| 295 } | 322 } |
| 296 } | 323 } |
| 297 | 324 |
| 298 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} | 325 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 463 } |
| 437 | 464 |
| 438 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption | 465 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption |
| 439 purge_option) { | 466 purge_option) { |
| 440 context_->task_runner()->PostTask( | 467 context_->task_runner()->PostTask( |
| 441 FROM_HERE, | 468 FROM_HERE, |
| 442 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 469 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 443 } | 470 } |
| 444 | 471 |
| 445 } // namespace content | 472 } // namespace content |
| OLD | NEW |