OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/indexeddb/IDBMetadata.h" | 5 #include "modules/indexeddb/IDBMetadata.h" |
6 | 6 |
7 #include "public/platform/modules/indexeddb/WebIDBMetadata.h" | 7 #include "public/platform/modules/indexeddb/WebIDBMetadata.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 constexpr int64_t IDBIndexMetadata::InvalidId; | 11 constexpr int64_t IDBIndexMetadata::InvalidId; |
12 | 12 |
13 constexpr int64_t IDBObjectStoreMetadata::InvalidId; | 13 constexpr int64_t IDBObjectStoreMetadata::InvalidId; |
14 | 14 |
| 15 IDBIndexMetadata::IDBIndexMetadata() = default; |
| 16 |
| 17 IDBIndexMetadata::IDBIndexMetadata(const String& name, int64_t id, const IDBKeyP
ath& keyPath, bool unique, bool multiEntry) |
| 18 : name(name) |
| 19 , id(id) |
| 20 , keyPath(keyPath) |
| 21 , unique(unique) |
| 22 , multiEntry(multiEntry) |
| 23 { |
| 24 } |
| 25 |
| 26 IDBObjectStoreMetadata::IDBObjectStoreMetadata() = default; |
| 27 |
| 28 IDBObjectStoreMetadata::IDBObjectStoreMetadata(const String& name, int64_t id, c
onst IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId) |
| 29 : name(name) |
| 30 , id(id) |
| 31 , keyPath(keyPath) |
| 32 , autoIncrement(autoIncrement) |
| 33 , maxIndexId(maxIndexId) |
| 34 { |
| 35 } |
| 36 |
| 37 RefPtr<IDBObjectStoreMetadata> IDBObjectStoreMetadata::createCopy() const |
| 38 { |
| 39 RefPtr<IDBObjectStoreMetadata> copy = adoptRef(new IDBObjectStoreMetadata( |
| 40 name, id, keyPath, autoIncrement, maxIndexId)); |
| 41 |
| 42 for (const auto& it : indexes) { |
| 43 IDBIndexMetadata* index = it.value.get(); |
| 44 RefPtr<IDBIndexMetadata> indexCopy = adoptRef(new IDBIndexMetadata( |
| 45 index->name, index->id, index->keyPath, index->unique, index->multiE
ntry)); |
| 46 copy->indexes.add(it.key, std::move(indexCopy)); |
| 47 } |
| 48 return copy; |
| 49 } |
| 50 |
| 51 IDBDatabaseMetadata::IDBDatabaseMetadata() |
| 52 : version(IDBDatabaseMetadata::NoVersion) |
| 53 { |
| 54 } |
| 55 |
| 56 IDBDatabaseMetadata::IDBDatabaseMetadata(const String& name, int64_t id, int64_t
version, int64_t maxObjectStoreId) |
| 57 : name(name) |
| 58 , id(id) |
| 59 , version(version) |
| 60 , maxObjectStoreId(maxObjectStoreId) |
| 61 { |
| 62 } |
| 63 |
15 IDBDatabaseMetadata::IDBDatabaseMetadata(const WebIDBMetadata& webMetadata) | 64 IDBDatabaseMetadata::IDBDatabaseMetadata(const WebIDBMetadata& webMetadata) |
16 : name(webMetadata.name) | 65 : name(webMetadata.name) |
17 , id(webMetadata.id) | 66 , id(webMetadata.id) |
18 , version(webMetadata.version) | 67 , version(webMetadata.version) |
19 , maxObjectStoreId(webMetadata.maxObjectStoreId) | 68 , maxObjectStoreId(webMetadata.maxObjectStoreId) |
20 { | 69 { |
21 for (size_t i = 0; i < webMetadata.objectStores.size(); ++i) { | 70 for (size_t i = 0; i < webMetadata.objectStores.size(); ++i) { |
22 const WebIDBMetadata::ObjectStore webObjectStore = webMetadata.objectSto
res[i]; | 71 const WebIDBMetadata::ObjectStore& webObjectStore = webMetadata.objectSt
ores[i]; |
23 IDBObjectStoreMetadata objectStore(webObjectStore.name, webObjectStore.i
d, IDBKeyPath(webObjectStore.keyPath), webObjectStore.autoIncrement, webObjectSt
ore.maxIndexId); | 72 RefPtr<IDBObjectStoreMetadata> objectStore = adoptRef(new IDBObjectStore
Metadata( |
| 73 webObjectStore.name, webObjectStore.id, IDBKeyPath(webObjectStore.ke
yPath), webObjectStore.autoIncrement, webObjectStore.maxIndexId)); |
24 | 74 |
25 for (size_t j = 0; j < webObjectStore.indexes.size(); ++j) { | 75 for (size_t j = 0; j < webObjectStore.indexes.size(); ++j) { |
26 const WebIDBMetadata::Index webIndex = webObjectStore.indexes[j]; | 76 const WebIDBMetadata::Index& webIndex = webObjectStore.indexes[j]; |
27 IDBIndexMetadata index(webIndex.name, webIndex.id, IDBKeyPath(webInd
ex.keyPath), webIndex.unique, webIndex.multiEntry); | 77 RefPtr<IDBIndexMetadata> index = adoptRef(new IDBIndexMetadata( |
28 objectStore.indexes.set(index.id, index); | 78 webIndex.name, webIndex.id, IDBKeyPath(webIndex.keyPath), webInd
ex.unique, webIndex.multiEntry)); |
| 79 objectStore->indexes.set(webIndex.id, std::move(index)); |
29 } | 80 } |
30 objectStores.set(objectStore.id, objectStore); | 81 objectStores.set(webObjectStore.id, std::move(objectStore)); |
31 } | 82 } |
32 } | 83 } |
33 | 84 |
34 } // namespace blink | 85 } // namespace blink |
OLD | NEW |