| 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/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "content/browser/browser_main_loop.h" | 23 #include "content/browser/browser_main_loop.h" |
| 24 #include "content/browser/indexed_db/database_factory_impl.h" |
| 24 #include "content/browser/indexed_db/indexed_db_connection.h" | 25 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 25 #include "content/browser/indexed_db/indexed_db_database.h" | 26 #include "content/browser/indexed_db/indexed_db_database.h" |
| 26 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | |
| 27 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 27 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 28 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 28 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| 29 #include "content/browser/indexed_db/indexed_db_tracing.h" | 29 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 30 #include "content/browser/indexed_db/indexed_db_transaction.h" | 30 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/indexed_db_info.h" | 32 #include "content/public/browser/indexed_db_info.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "storage/browser/database/database_util.h" | 34 #include "storage/browser/database/database_util.h" |
| 35 #include "storage/browser/quota/quota_manager_proxy.h" | 35 #include "storage/browser/quota/quota_manager_proxy.h" |
| 36 #include "storage/browser/quota/special_storage_policy.h" | 36 #include "storage/browser/quota/special_storage_policy.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 base::DeleteFile(*file_path, true); | 102 base::DeleteFile(*file_path, true); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace | 106 } // namespace |
| 107 | 107 |
| 108 IndexedDBContextImpl::IndexedDBContextImpl( | 108 IndexedDBContextImpl::IndexedDBContextImpl( |
| 109 const base::FilePath& data_path, | 109 const base::FilePath& data_path, |
| 110 storage::SpecialStoragePolicy* special_storage_policy, | 110 storage::SpecialStoragePolicy* special_storage_policy, |
| 111 storage::QuotaManagerProxy* quota_manager_proxy, | 111 storage::QuotaManagerProxy* quota_manager_proxy, |
| 112 base::SequencedTaskRunner* task_runner) | 112 base::SingleThreadTaskRunner* task_runner) |
| 113 : force_keep_session_state_(false), | 113 : mojo_factory_(nullptr), |
| 114 force_keep_session_state_(false), |
| 114 special_storage_policy_(special_storage_policy), | 115 special_storage_policy_(special_storage_policy), |
| 115 quota_manager_proxy_(quota_manager_proxy), | 116 quota_manager_proxy_(quota_manager_proxy), |
| 116 task_runner_(task_runner) { | 117 task_runner_(task_runner) { |
| 117 IDB_TRACE("init"); | 118 IDB_TRACE("init"); |
| 118 if (!data_path.empty()) | 119 if (!data_path.empty()) |
| 119 data_path_ = data_path.Append(kIndexedDBDirectory); | 120 data_path_ = data_path.Append(kIndexedDBDirectory); |
| 120 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); | 121 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 124 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { |
| 124 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 125 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 125 if (!factory_.get()) { | 126 if (!factory_.get()) { |
| 126 // Prime our cache of origins with existing databases so we can | 127 // Prime our cache of origins with existing databases so we can |
| 127 // detect when dbs are newly created. | 128 // detect when dbs are newly created. |
| 128 GetOriginSet(); | 129 GetOriginSet(); |
| 129 factory_ = new IndexedDBFactoryImpl(this); | 130 factory_ = new IndexedDBFactoryImpl(this); |
| 130 } | 131 } |
| 131 return factory_.get(); | 132 return factory_.get(); |
| 132 } | 133 } |
| 133 | 134 |
| 135 storage::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() const { |
| 136 return quota_manager_proxy_.get(); |
| 137 } |
| 138 |
| 134 std::vector<Origin> IndexedDBContextImpl::GetAllOrigins() { | 139 std::vector<Origin> IndexedDBContextImpl::GetAllOrigins() { |
| 135 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 140 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 136 std::set<Origin>* origins_set = GetOriginSet(); | 141 std::set<Origin>* origins_set = GetOriginSet(); |
| 137 return std::vector<Origin>(origins_set->begin(), origins_set->end()); | 142 return std::vector<Origin>(origins_set->begin(), origins_set->end()); |
| 138 } | 143 } |
| 139 | 144 |
| 140 bool IndexedDBContextImpl::HasOrigin(const Origin& origin) { | 145 bool IndexedDBContextImpl::HasOrigin(const Origin& origin) { |
| 141 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 146 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 142 std::set<Origin>* set = GetOriginSet(); | 147 std::set<Origin>* set = GetOriginSet(); |
| 143 return set->find(origin) != set->end(); | 148 return set->find(origin) != set->end(); |
| 144 } | 149 } |
| 145 | 150 |
| 146 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { | 151 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { |
| 147 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 152 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 148 std::vector<Origin> origins = GetAllOrigins(); | 153 std::vector<Origin> origins = GetAllOrigins(); |
| 149 std::vector<IndexedDBInfo> result; | 154 std::vector<IndexedDBInfo> result; |
| 150 for (const auto& origin : origins) { | 155 for (const auto& origin : origins) { |
| 151 size_t connection_count = GetConnectionCount(origin); | 156 size_t connection_count = GetConnectionCount(origin); |
| 152 result.push_back( | 157 result.push_back( |
| 153 IndexedDBInfo(GURL(origin.Serialize()), GetOriginDiskUsage(origin), | 158 IndexedDBInfo(GURL(origin.Serialize()), GetOriginDiskUsage(origin), |
| 154 GetOriginLastModified(origin), connection_count)); | 159 GetOriginLastModified(origin), connection_count)); |
| 155 } | 160 } |
| 156 return result; | 161 return result; |
| 157 } | 162 } |
| 158 | 163 |
| 159 static bool HostNameComparator(const Origin& i, const Origin& j) { | 164 static bool HostNameComparator(const Origin& i, const Origin& j) { |
| 160 return i.host() < j.host(); | 165 return i.host() < j.host(); |
| 161 } | 166 } |
| 162 | 167 |
| 168 #if 0 |
| 163 base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() { | 169 base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() { |
| 164 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 170 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 165 std::vector<Origin> origins = GetAllOrigins(); | 171 std::vector<Origin> origins = GetAllOrigins(); |
| 166 | 172 |
| 167 std::sort(origins.begin(), origins.end(), HostNameComparator); | 173 std::sort(origins.begin(), origins.end(), HostNameComparator); |
| 168 | 174 |
| 169 std::unique_ptr<base::ListValue> list(base::MakeUnique<base::ListValue>()); | 175 std::unique_ptr<base::ListValue> list(base::MakeUnique<base::ListValue>()); |
| 170 for (const auto& origin : origins) { | 176 for (const auto& origin : origins) { |
| 171 std::unique_ptr<base::DictionaryValue> info( | 177 std::unique_ptr<base::DictionaryValue> info( |
| 172 base::MakeUnique<base::DictionaryValue>()); | 178 base::MakeUnique<base::DictionaryValue>()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 277 |
| 272 database_list->Append(std::move(db_info)); | 278 database_list->Append(std::move(db_info)); |
| 273 } | 279 } |
| 274 info->Set("databases", database_list.release()); | 280 info->Set("databases", database_list.release()); |
| 275 } | 281 } |
| 276 | 282 |
| 277 list->Append(std::move(info)); | 283 list->Append(std::move(info)); |
| 278 } | 284 } |
| 279 return list.release(); | 285 return list.release(); |
| 280 } | 286 } |
| 287 #endif |
| 281 | 288 |
| 282 int IndexedDBContextImpl::GetOriginBlobFileCount(const Origin& origin) { | 289 int IndexedDBContextImpl::GetOriginBlobFileCount(const Origin& origin) { |
| 283 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 290 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 284 int count = 0; | 291 int count = 0; |
| 285 base::FileEnumerator file_enumerator(GetBlobStorePath(origin), true, | 292 base::FileEnumerator file_enumerator(GetBlobStorePath(origin), true, |
| 286 base::FileEnumerator::FILES); | 293 base::FileEnumerator::FILES); |
| 287 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 294 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 288 file_path = file_enumerator.Next()) { | 295 file_path = file_enumerator.Next()) { |
| 289 count++; | 296 count++; |
| 290 } | 297 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 const GURL& origin_url) const { | 430 const GURL& origin_url) const { |
| 424 return GetFilePathForTesting(Origin(origin_url)); | 431 return GetFilePathForTesting(Origin(origin_url)); |
| 425 } | 432 } |
| 426 | 433 |
| 427 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 434 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 428 const Origin& origin) const { | 435 const Origin& origin) const { |
| 429 return GetLevelDBPath(origin); | 436 return GetLevelDBPath(origin); |
| 430 } | 437 } |
| 431 | 438 |
| 432 void IndexedDBContextImpl::SetTaskRunnerForTesting( | 439 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 433 base::SequencedTaskRunner* task_runner) { | 440 base::SingleThreadTaskRunner* task_runner) { |
| 434 DCHECK(!task_runner_.get()); | 441 DCHECK(!task_runner_.get()); |
| 435 task_runner_ = task_runner; | 442 task_runner_ = task_runner; |
| 436 } | 443 } |
| 437 | 444 |
| 438 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin, | 445 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin, |
| 439 IndexedDBConnection* connection) { | 446 IndexedDBConnection* connection) { |
| 440 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 447 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 441 quota_manager_proxy()->NotifyStorageAccessed( | 448 quota_manager_proxy()->NotifyStorageAccessed( |
| 442 storage::QuotaClient::kIndexedDatabase, GURL(origin.Serialize()), | 449 storage::QuotaClient::kIndexedDatabase, GURL(origin.Serialize()), |
| 443 storage::kStorageTypeTemporary); | 450 storage::kStorageTypeTemporary); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 base::MakeUnique<std::set<Origin>>(origins.begin(), origins.end()); | 571 base::MakeUnique<std::set<Origin>>(origins.begin(), origins.end()); |
| 565 } | 572 } |
| 566 return origin_set_.get(); | 573 return origin_set_.get(); |
| 567 } | 574 } |
| 568 | 575 |
| 569 void IndexedDBContextImpl::ResetCaches() { | 576 void IndexedDBContextImpl::ResetCaches() { |
| 570 origin_set_.reset(); | 577 origin_set_.reset(); |
| 571 origin_size_map_.clear(); | 578 origin_size_map_.clear(); |
| 572 } | 579 } |
| 573 | 580 |
| 574 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 581 base::SingleThreadTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 575 return task_runner_.get(); | 582 return task_runner_.get(); |
| 576 } | 583 } |
| 577 | 584 |
| 578 } // namespace content | 585 } // namespace content |
| OLD | NEW |