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. |
44 IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool unique, bool multiEntry) | 46 // IDBDatabaseMetadata -> IDBObjectStoreMetadata -> IDBIndexMetadata |
45 : name(name) | 47 |
46 , id(id) | 48 class IDBIndexMetadata : public RefCounted<IDBIndexMetadata> { |
47 , keyPath(keyPath) | 49 USING_FAST_MALLOC(IDBIndexMetadata); |
48 , unique(unique) | 50 |
49 , multiEntry(multiEntry) { } | 51 public: |
52 IDBIndexMetadata(); | |
53 IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath&, bool uni que, bool multiEntry); | |
54 | |
50 String name; | 55 String name; |
51 int64_t id; | 56 int64_t id; |
52 IDBKeyPath keyPath; | 57 IDBKeyPath keyPath; |
53 bool unique; | 58 bool unique; |
54 bool multiEntry; | 59 bool multiEntry; |
55 | 60 |
56 static constexpr int64_t InvalidId = -1; | 61 static constexpr int64_t InvalidId = -1; |
57 }; | 62 }; |
58 | 63 |
59 struct IDBObjectStoreMetadata { | 64 class IDBObjectStoreMetadata : public RefCounted<IDBObjectStoreMetadata> { |
60 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 65 USING_FAST_MALLOC(IDBObjectStoreMetadata); |
61 IDBObjectStoreMetadata() { } | 66 |
62 IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath& key Path, bool autoIncrement, int64_t maxIndexId) | 67 public: |
63 : name(name) | 68 IDBObjectStoreMetadata(); |
64 , id(id) | 69 IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath&, bo ol autoIncrement, int64_t maxIndexId); |
65 , keyPath(keyPath) | 70 |
66 , autoIncrement(autoIncrement) | 71 // Creates a deep copy of the object metadata, which includes copies of inde x metadata items. |
67 , maxIndexId(maxIndexId) | 72 RefPtr<IDBObjectStoreMetadata> createCopy() const; |
68 { | 73 |
69 } | |
70 String name; | 74 String name; |
71 int64_t id; | 75 int64_t id; |
72 IDBKeyPath keyPath; | 76 IDBKeyPath keyPath; |
73 bool autoIncrement; | 77 bool autoIncrement; |
74 int64_t maxIndexId; | 78 int64_t maxIndexId; |
75 | 79 |
76 static constexpr int64_t InvalidId = -1; | 80 static constexpr int64_t InvalidId = -1; |
77 | 81 |
78 typedef HashMap<int64_t, IDBIndexMetadata> IndexMap; | 82 using IndexMap = HashMap<int64_t, RefPtr<IDBIndexMetadata>>; |
79 IndexMap indexes; | 83 IndexMap indexes; |
80 }; | 84 }; |
81 | 85 |
82 struct IDBDatabaseMetadata { | 86 struct MODULES_EXPORT IDBDatabaseMetadata { |
83 DISALLOW_NEW(); | 87 DISALLOW_NEW(); |
88 | |
89 public: | |
84 // FIXME: These can probably be collapsed into 0. | 90 // FIXME: These can probably be collapsed into 0. |
85 enum { | 91 enum { |
86 NoVersion = -1, | 92 NoVersion = -1, |
87 DefaultVersion = 0 | 93 DefaultVersion = 0 |
88 }; | 94 }; |
89 | 95 |
90 typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap; | 96 IDBDatabaseMetadata(); |
91 | 97 IDBDatabaseMetadata(const String& name, int64_t id, int64_t version, int64_t maxObjectStoreId); |
92 IDBDatabaseMetadata() | |
93 : version(NoVersion) | |
94 { | |
95 } | |
96 | |
97 IDBDatabaseMetadata(const String& name, int64_t id, int64_t version, int64_t maxObjectStoreId) | |
98 : name(name) | |
99 , id(id) | |
100 , version(version) | |
101 , maxObjectStoreId(maxObjectStoreId) | |
102 { | |
103 } | |
104 | 98 |
105 explicit IDBDatabaseMetadata(const WebIDBMetadata&); | 99 explicit IDBDatabaseMetadata(const WebIDBMetadata&); |
106 | 100 |
107 String name; | 101 String name; |
108 int64_t id; | 102 int64_t id; |
109 int64_t version; | 103 int64_t version; |
110 int64_t maxObjectStoreId; | 104 int64_t maxObjectStoreId; |
111 | 105 |
106 using ObjectStoreMap = HashMap<int64_t, RefPtr<IDBObjectStoreMetadata>>; | |
jsbell
2016/09/26 22:23:40
Nit: Per style guide (google, not overridden by ch
pwnall
2016/09/27 00:12:19
Done.
I also moved "using" in IDBObjectStore.h an
| |
112 ObjectStoreMap objectStores; | 107 ObjectStoreMap objectStores; |
113 }; | 108 }; |
114 | 109 |
115 } // namespace blink | 110 } // namespace blink |
116 | 111 |
117 #endif // IDBMetadata_h | 112 #endif // IDBMetadata_h |
OLD | NEW |