| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/indexed_db/indexed_db_context_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/task_scheduler/post_task.h" |
| 20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 23 #include "base/values.h" | 24 #include "base/values.h" |
| 24 #include "content/browser/browser_main_loop.h" | 25 #include "content/browser/browser_main_loop.h" |
| 25 #include "content/browser/indexed_db/indexed_db_connection.h" | 26 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 26 #include "content/browser/indexed_db/indexed_db_database.h" | 27 #include "content/browser/indexed_db/indexed_db_database.h" |
| 27 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 28 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 28 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 29 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 29 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 30 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 continue; | 103 continue; |
| 103 base::DeleteFile(*file_path, true); | 104 base::DeleteFile(*file_path, true); |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace | 108 } // namespace |
| 108 | 109 |
| 109 IndexedDBContextImpl::IndexedDBContextImpl( | 110 IndexedDBContextImpl::IndexedDBContextImpl( |
| 110 const base::FilePath& data_path, | 111 const base::FilePath& data_path, |
| 111 storage::SpecialStoragePolicy* special_storage_policy, | 112 storage::SpecialStoragePolicy* special_storage_policy, |
| 112 storage::QuotaManagerProxy* quota_manager_proxy, | 113 storage::QuotaManagerProxy* quota_manager_proxy) |
| 113 scoped_refptr<base::SequencedTaskRunner> task_runner) | |
| 114 : force_keep_session_state_(false), | 114 : force_keep_session_state_(false), |
| 115 special_storage_policy_(special_storage_policy), | 115 special_storage_policy_(special_storage_policy), |
| 116 quota_manager_proxy_(quota_manager_proxy), | 116 quota_manager_proxy_(quota_manager_proxy), |
| 117 task_runner_(std::move(task_runner)) { | 117 task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
| 118 {base::MayBlock(), base::WithBaseSyncPrimitives(), |
| 119 base::TaskPriority::USER_VISIBLE, |
| 120 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) { |
| 118 IDB_TRACE("init"); | 121 IDB_TRACE("init"); |
| 119 if (!data_path.empty()) | 122 if (!data_path.empty()) |
| 120 data_path_ = data_path.Append(kIndexedDBDirectory); | 123 data_path_ = data_path.Append(kIndexedDBDirectory); |
| 121 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); | 124 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); |
| 122 } | 125 } |
| 123 | 126 |
| 124 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 127 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { |
| 125 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); | 128 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); |
| 126 if (!factory_.get()) { | 129 if (!factory_.get()) { |
| 127 // Prime our cache of origins with existing databases so we can | 130 // Prime our cache of origins with existing databases so we can |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 const GURL& origin_url) const { | 422 const GURL& origin_url) const { |
| 420 return GetFilePathForTesting(Origin(origin_url)); | 423 return GetFilePathForTesting(Origin(origin_url)); |
| 421 } | 424 } |
| 422 | 425 |
| 423 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 426 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 424 const Origin& origin) const { | 427 const Origin& origin) const { |
| 425 return GetLevelDBPath(origin); | 428 return GetLevelDBPath(origin); |
| 426 } | 429 } |
| 427 | 430 |
| 428 void IndexedDBContextImpl::SetTaskRunnerForTesting( | 431 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 429 base::SequencedTaskRunner* task_runner) { | 432 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 430 DCHECK(!task_runner_.get()); | |
| 431 task_runner_ = task_runner; | 433 task_runner_ = task_runner; |
| 432 } | 434 } |
| 433 | 435 |
| 434 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin, | 436 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin, |
| 435 IndexedDBConnection* connection) { | 437 IndexedDBConnection* connection) { |
| 436 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); | 438 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); |
| 437 quota_manager_proxy()->NotifyStorageAccessed( | 439 quota_manager_proxy()->NotifyStorageAccessed( |
| 438 storage::QuotaClient::kIndexedDatabase, origin.GetURL(), | 440 storage::QuotaClient::kIndexedDatabase, origin.GetURL(), |
| 439 storage::kStorageTypeTemporary); | 441 storage::kStorageTypeTemporary); |
| 440 if (AddToOriginSet(origin)) { | 442 if (AddToOriginSet(origin)) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 void IndexedDBContextImpl::ResetCaches() { | 565 void IndexedDBContextImpl::ResetCaches() { |
| 564 origin_set_.reset(); | 566 origin_set_.reset(); |
| 565 origin_size_map_.clear(); | 567 origin_size_map_.clear(); |
| 566 } | 568 } |
| 567 | 569 |
| 568 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 570 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 569 return task_runner_.get(); | 571 return task_runner_.get(); |
| 570 } | 572 } |
| 571 | 573 |
| 572 } // namespace content | 574 } // namespace content |
| OLD | NEW |