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. |
cmumford
2016/10/05 21:15:27
typo
pwnall
2016/10/05 23:15:45
Done.
Thank you!
| |
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; |
66 }; | |
67 | |
68 class IDBObjectStoreMetadata : public RefCounted<IDBObjectStoreMetadata> { | |
69 USING_FAST_MALLOC(IDBObjectStoreMetadata); | |
70 | |
71 public: | |
72 using IndexMap = HashMap<int64_t, RefPtr<IDBIndexMetadata>>; | |
59 | 73 |
60 static constexpr int64_t InvalidId = -1; | 74 static constexpr int64_t InvalidId = -1; |
61 }; | |
62 | 75 |
63 struct IDBObjectStoreMetadata { | 76 IDBObjectStoreMetadata(); |
64 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
65 IDBObjectStoreMetadata() {} | |
66 IDBObjectStoreMetadata(const String& name, | 77 IDBObjectStoreMetadata(const String& name, |
67 int64_t id, | 78 int64_t id, |
68 const IDBKeyPath& keyPath, | 79 const IDBKeyPath&, |
69 bool autoIncrement, | 80 bool autoIncrement, |
70 int64_t maxIndexId) | 81 int64_t maxIndexId); |
71 : name(name), | 82 |
72 id(id), | 83 // Creates a deep copy of the object store's metadata, which includes copies |
73 keyPath(keyPath), | 84 // of the metadata for all indexes. |
74 autoIncrement(autoIncrement), | 85 RefPtr<IDBObjectStoreMetadata> createCopy() const; |
75 maxIndexId(maxIndexId) {} | 86 |
76 String name; | 87 String name; |
77 int64_t id; | 88 int64_t id; |
78 IDBKeyPath keyPath; | 89 IDBKeyPath keyPath; |
79 bool autoIncrement; | 90 bool autoIncrement; |
80 int64_t maxIndexId; | 91 int64_t maxIndexId; |
81 | |
82 static constexpr int64_t InvalidId = -1; | |
83 | |
84 typedef HashMap<int64_t, IDBIndexMetadata> IndexMap; | |
85 IndexMap indexes; | 92 IndexMap indexes; |
86 }; | 93 }; |
87 | 94 |
88 struct IDBDatabaseMetadata { | 95 struct MODULES_EXPORT IDBDatabaseMetadata { |
89 DISALLOW_NEW(); | 96 DISALLOW_NEW(); |
97 | |
98 public: | |
cmumford
2016/10/05 21:15:26
public not needed - in a struct.
pwnall
2016/10/05 23:15:45
Done.
| |
99 using ObjectStoreMap = HashMap<int64_t, RefPtr<IDBObjectStoreMetadata>>; | |
cmumford
2016/10/05 21:15:26
My preference is to not declare ObjectStoreMap. Ju
pwnall
2016/10/05 23:15:45
Done.
Also removed IDBObjectStoreMetadata::IndexMa
| |
100 | |
90 // FIXME: These can probably be collapsed into 0. | 101 // FIXME: These can probably be collapsed into 0. |
91 enum { NoVersion = -1, DefaultVersion = 0 }; | 102 enum { NoVersion = -1, DefaultVersion = 0 }; |
92 | 103 |
93 typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap; | 104 IDBDatabaseMetadata(); |
94 | |
95 IDBDatabaseMetadata() : version(NoVersion) {} | |
96 | |
97 IDBDatabaseMetadata(const String& name, | 105 IDBDatabaseMetadata(const String& name, |
98 int64_t id, | 106 int64_t id, |
99 int64_t version, | 107 int64_t version, |
100 int64_t maxObjectStoreId) | 108 int64_t maxObjectStoreId); |
101 : name(name), | |
102 id(id), | |
103 version(version), | |
104 maxObjectStoreId(maxObjectStoreId) {} | |
105 | 109 |
106 explicit IDBDatabaseMetadata(const WebIDBMetadata&); | 110 explicit IDBDatabaseMetadata(const WebIDBMetadata&); |
107 | 111 |
108 String name; | 112 String name; |
109 int64_t id; | 113 int64_t id; |
110 int64_t version; | 114 int64_t version; |
111 int64_t maxObjectStoreId; | 115 int64_t maxObjectStoreId; |
112 | |
113 ObjectStoreMap objectStores; | 116 ObjectStoreMap objectStores; |
114 }; | 117 }; |
115 | 118 |
116 } // namespace blink | 119 } // namespace blink |
117 | 120 |
118 #endif // IDBMetadata_h | 121 #endif // IDBMetadata_h |
OLD | NEW |