OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 15 matching lines...) Expand all Loading... | |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef IDBMetadata_h | 29 #ifndef IDBMetadata_h |
30 #define IDBMetadata_h | 30 #define IDBMetadata_h |
31 | 31 |
32 #include "modules/indexeddb/IDBKeyPath.h" | 32 #include "modules/indexeddb/IDBKeyPath.h" |
33 #include "public/platform/modules/indexeddb/WebIDBMetadata.h" | 33 #include "public/platform/modules/indexeddb/WebIDBMetadata.h" |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
36 #include "wtf/RefCounted.h" | |
37 #include "wtf/RefPtr.h" | |
36 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
37 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
38 | 40 |
39 namespace blink { | 41 namespace blink { |
40 | 42 |
41 struct IDBIndexMetadata { | 43 // The lifecycle of the IndexedDB metadata objects defined below is managed by |
42 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 44 // reference counting (RefPtr). We don't have to worry about cycles because |
43 IDBIndexMetadata() {} | 45 // these objects form a tree with the hierarch shown below. |
jsbell
2016/10/06 20:01:31
typo: hierarchy
pwnall
2016/10/06 22:15:22
Done.
Gah... I swore I fixed this when addressing
| |
46 // IDBDatabaseMetadata -> IDBObjectStoreMetadata -> IDBIndexMetadata | |
47 | |
48 class IDBIndexMetadata : public RefCounted<IDBIndexMetadata> { | |
49 USING_FAST_MALLOC(IDBIndexMetadata); | |
50 | |
51 public: | |
52 static constexpr int64_t InvalidId = -1; | |
53 | |
54 IDBIndexMetadata(); | |
44 IDBIndexMetadata(const String& name, | 55 IDBIndexMetadata(const String& name, |
45 int64_t id, | 56 int64_t id, |
46 const IDBKeyPath& keyPath, | 57 const IDBKeyPath&, |
47 bool unique, | 58 bool unique, |
48 bool multiEntry) | 59 bool multiEntry); |
49 : name(name), | 60 |
50 id(id), | |
51 keyPath(keyPath), | |
52 unique(unique), | |
53 multiEntry(multiEntry) {} | |
54 String name; | 61 String name; |
55 int64_t id; | 62 int64_t id; |
56 IDBKeyPath keyPath; | 63 IDBKeyPath keyPath; |
57 bool unique; | 64 bool unique; |
58 bool multiEntry; | 65 bool multiEntry; |
59 | |
60 static constexpr int64_t InvalidId = -1; | |
61 }; | 66 }; |
62 | 67 |
63 struct IDBObjectStoreMetadata { | 68 class IDBObjectStoreMetadata : public RefCounted<IDBObjectStoreMetadata> { |
64 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 69 USING_FAST_MALLOC(IDBObjectStoreMetadata); |
65 IDBObjectStoreMetadata() {} | 70 |
71 public: | |
72 static constexpr int64_t InvalidId = -1; | |
73 | |
74 IDBObjectStoreMetadata(); | |
66 IDBObjectStoreMetadata(const String& name, | 75 IDBObjectStoreMetadata(const String& name, |
67 int64_t id, | 76 int64_t id, |
68 const IDBKeyPath& keyPath, | 77 const IDBKeyPath&, |
69 bool autoIncrement, | 78 bool autoIncrement, |
70 int64_t maxIndexId) | 79 int64_t maxIndexId); |
71 : name(name), | 80 |
72 id(id), | 81 // Creates a deep copy of the object metadata, which includes copies of index |
73 keyPath(keyPath), | 82 // metadata items. |
74 autoIncrement(autoIncrement), | 83 RefPtr<IDBObjectStoreMetadata> createCopy() const; |
75 maxIndexId(maxIndexId) {} | 84 |
76 String name; | 85 String name; |
77 int64_t id; | 86 int64_t id; |
78 IDBKeyPath keyPath; | 87 IDBKeyPath keyPath; |
79 bool autoIncrement; | 88 bool autoIncrement; |
80 int64_t maxIndexId; | 89 int64_t maxIndexId; |
81 | 90 HashMap<int64_t, RefPtr<IDBIndexMetadata>> indexes; |
82 static constexpr int64_t InvalidId = -1; | |
83 | |
84 typedef HashMap<int64_t, IDBIndexMetadata> IndexMap; | |
85 IndexMap indexes; | |
86 }; | 91 }; |
87 | 92 |
88 struct IDBDatabaseMetadata { | 93 struct MODULES_EXPORT IDBDatabaseMetadata { |
89 DISALLOW_NEW(); | 94 DISALLOW_NEW(); |
95 | |
90 // FIXME: These can probably be collapsed into 0. | 96 // FIXME: These can probably be collapsed into 0. |
91 enum { NoVersion = -1, DefaultVersion = 0 }; | 97 enum { NoVersion = -1, DefaultVersion = 0 }; |
92 | 98 |
93 typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap; | 99 IDBDatabaseMetadata(); |
94 | |
95 IDBDatabaseMetadata() : version(NoVersion) {} | |
96 | |
97 IDBDatabaseMetadata(const String& name, | 100 IDBDatabaseMetadata(const String& name, |
98 int64_t id, | 101 int64_t id, |
99 int64_t version, | 102 int64_t version, |
100 int64_t maxObjectStoreId) | 103 int64_t maxObjectStoreId); |
101 : name(name), | |
102 id(id), | |
103 version(version), | |
104 maxObjectStoreId(maxObjectStoreId) {} | |
105 | 104 |
106 explicit IDBDatabaseMetadata(const WebIDBMetadata&); | 105 explicit IDBDatabaseMetadata(const WebIDBMetadata&); |
107 | 106 |
107 // Overwrites the database metadata, but does not change the object store and | |
108 // index metadata. | |
109 void copyDatabaseMetadataFrom(const IDBDatabaseMetadata&); | |
jsbell
2016/10/06 20:01:31
Simplify to just 'copyFrom' ?
pwnall
2016/10/06 22:15:22
Done.
FWIW, I think that copyFrom is a bit of a li
| |
110 | |
108 String name; | 111 String name; |
109 int64_t id; | 112 int64_t id; |
110 int64_t version; | 113 int64_t version; |
111 int64_t maxObjectStoreId; | 114 int64_t maxObjectStoreId; |
112 | 115 HashMap<int64_t, RefPtr<IDBObjectStoreMetadata>> objectStores; |
113 ObjectStoreMap objectStores; | |
114 }; | 116 }; |
115 | 117 |
116 } // namespace blink | 118 } // namespace blink |
117 | 119 |
118 #endif // IDBMetadata_h | 120 #endif // IDBMetadata_h |
OLD | NEW |