| 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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 static const base::FilePath::CharType kLevelDBExtension[] = | 57 static const base::FilePath::CharType kLevelDBExtension[] = |
| 58 FILE_PATH_LITERAL(".leveldb"); | 58 FILE_PATH_LITERAL(".leveldb"); |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 // This may be called after the IndexedDBContext is destroyed. | 62 // This may be called after the IndexedDBContext is destroyed. |
| 63 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, | 63 void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path, |
| 64 std::vector<Origin>* origins, | 64 std::vector<Origin>* origins, |
| 65 std::vector<base::FilePath>* file_paths) { | 65 std::vector<base::FilePath>* file_paths) { |
| 66 // TODO(jsbell): DCHECK that this is running on an IndexedDB thread, | 66 // TODO(jsbell): DCHECK that this is running on an IndexedDB sequence, |
| 67 // if a global handle to it is ever available. | 67 // if a global handle to it is ever available. |
| 68 if (indexeddb_path.empty()) | 68 if (indexeddb_path.empty()) |
| 69 return; | 69 return; |
| 70 base::FileEnumerator file_enumerator( | 70 base::FileEnumerator file_enumerator( |
| 71 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); | 71 indexeddb_path, false, base::FileEnumerator::DIRECTORIES); |
| 72 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 72 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 73 file_path = file_enumerator.Next()) { | 73 file_path = file_enumerator.Next()) { |
| 74 if (file_path.Extension() == kLevelDBExtension && | 74 if (file_path.Extension() == kLevelDBExtension && |
| 75 file_path.RemoveExtension().Extension() == kIndexedDBExtension) { | 75 file_path.RemoveExtension().Extension() == kIndexedDBExtension) { |
| 76 std::string origin_id = file_path.BaseName().RemoveExtension() | 76 std::string origin_id = file_path.BaseName().RemoveExtension() |
| 77 .RemoveExtension().MaybeAsASCII(); | 77 .RemoveExtension().MaybeAsASCII(); |
| 78 origins->push_back(Origin(storage::GetOriginFromIdentifier(origin_id))); | 78 origins->push_back(Origin(storage::GetOriginFromIdentifier(origin_id))); |
| 79 if (file_paths) | 79 if (file_paths) |
| 80 file_paths->push_back(file_path); | 80 file_paths->push_back(file_path); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 // This will be called after the IndexedDBContext is destroyed. | 85 // This will be called after the IndexedDBContext is destroyed. |
| 86 void ClearSessionOnlyOrigins( | 86 void ClearSessionOnlyOrigins( |
| 87 const base::FilePath& indexeddb_path, | 87 const base::FilePath& indexeddb_path, |
| 88 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy) { | 88 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy) { |
| 89 // TODO(jsbell): DCHECK that this is running on an IndexedDB thread, | 89 // TODO(jsbell): DCHECK that this is running on an IndexedDB sequence, |
| 90 // if a global handle to it is ever available. | 90 // if a global handle to it is ever available. |
| 91 std::vector<Origin> origins; | 91 std::vector<Origin> origins; |
| 92 std::vector<base::FilePath> file_paths; | 92 std::vector<base::FilePath> file_paths; |
| 93 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); | 93 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); |
| 94 DCHECK_EQ(origins.size(), file_paths.size()); | 94 DCHECK_EQ(origins.size(), file_paths.size()); |
| 95 auto file_path = file_paths.cbegin(); | 95 auto file_path = file_paths.cbegin(); |
| 96 auto origin = origins.cbegin(); | 96 auto origin = origins.cbegin(); |
| 97 for (; origin != origins.cend(); ++origin, ++file_path) { | 97 for (; origin != origins.cend(); ++origin, ++file_path) { |
| 98 const GURL origin_url = GURL(origin->Serialize()); | 98 const GURL origin_url = GURL(origin->Serialize()); |
| 99 if (!special_storage_policy->IsStorageSessionOnly(origin_url)) | 99 if (!special_storage_policy->IsStorageSessionOnly(origin_url)) |
| 100 continue; | 100 continue; |
| 101 if (special_storage_policy->IsStorageProtected(origin_url)) | 101 if (special_storage_policy->IsStorageProtected(origin_url)) |
| 102 continue; | 102 continue; |
| 103 base::DeleteFile(*file_path, true); | 103 base::DeleteFile(*file_path, true); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 IndexedDBContextImpl::IndexedDBContextImpl( | 109 IndexedDBContextImpl::IndexedDBContextImpl( |
| 110 const base::FilePath& data_path, | 110 const base::FilePath& data_path, |
| 111 storage::SpecialStoragePolicy* special_storage_policy, | 111 storage::SpecialStoragePolicy* special_storage_policy, |
| 112 storage::QuotaManagerProxy* quota_manager_proxy, | 112 storage::QuotaManagerProxy* quota_manager_proxy, |
| 113 base::SequencedTaskRunner* task_runner) | 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_(task_runner) { | 117 task_runner_(std::move(task_runner)) { |
| 118 IDB_TRACE("init"); | 118 IDB_TRACE("init"); |
| 119 if (!data_path.empty()) | 119 if (!data_path.empty()) |
| 120 data_path_ = data_path.Append(kIndexedDBDirectory); | 120 data_path_ = data_path.Append(kIndexedDBDirectory); |
| 121 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); | 121 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { | 124 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { |
| 125 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); | 125 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); |
| 126 if (!factory_.get()) { | 126 if (!factory_.get()) { |
| 127 // Prime our cache of origins with existing databases so we can | 127 // Prime our cache of origins with existing databases so we can |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 void IndexedDBContextImpl::ResetCaches() { | 563 void IndexedDBContextImpl::ResetCaches() { |
| 564 origin_set_.reset(); | 564 origin_set_.reset(); |
| 565 origin_size_map_.clear(); | 565 origin_size_map_.clear(); |
| 566 } | 566 } |
| 567 | 567 |
| 568 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 568 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 569 return task_runner_.get(); | 569 return task_runner_.get(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 } // namespace content | 572 } // namespace content |
| OLD | NEW |