Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h

Issue 2349413002: Minor IndexedDB refactorings. (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, p ublic ScriptWrappable { 52 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, p ublic ScriptWrappable {
53 DEFINE_WRAPPERTYPEINFO(); 53 DEFINE_WRAPPERTYPEINFO();
54 public: 54 public:
55 static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTra nsaction* transaction) 55 static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTra nsaction* transaction)
56 { 56 {
57 return new IDBObjectStore(metadata, transaction); 57 return new IDBObjectStore(metadata, transaction);
58 } 58 }
59 ~IDBObjectStore() { } 59 ~IDBObjectStore() { }
60 DECLARE_TRACE(); 60 DECLARE_TRACE();
61 61
62 const IDBObjectStoreMetadata& metadata() const { return m_metadata; }
63 const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; }
64
62 // Implement the IDBObjectStore IDL 65 // Implement the IDBObjectStore IDL
63 int64_t id() const { return m_metadata.id; } 66 int64_t id() const { return metadata().id; }
64 const String& name() const { return m_metadata.name; } 67 const String& name() const { return metadata().name; }
65 void setName(const String& name, ExceptionState&); 68 void setName(const String& name, ExceptionState&);
66 ScriptValue keyPath(ScriptState*) const; 69 ScriptValue keyPath(ScriptState*) const;
67 DOMStringList* indexNames() const; 70 DOMStringList* indexNames() const;
68 IDBTransaction* transaction() const { return m_transaction.get(); } 71 IDBTransaction* transaction() const { return m_transaction.get(); }
69 bool autoIncrement() const { return m_metadata.autoIncrement; } 72 bool autoIncrement() const { return metadata().autoIncrement; }
70 73
71 IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&); 74 IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&);
72 IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const Stri ng& direction, ExceptionState&); 75 IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const Stri ng& direction, ExceptionState&);
73 IDBRequest* get(ScriptState*, const ScriptValue& key, ExceptionState&); 76 IDBRequest* get(ScriptState*, const ScriptValue& key, ExceptionState&);
74 IDBRequest* getKey(ScriptState*, const ScriptValue& key, ExceptionState&); 77 IDBRequest* getKey(ScriptState*, const ScriptValue& key, ExceptionState&);
75 IDBRequest* getAll(ScriptState*, const ScriptValue& range, unsigned long max Count, ExceptionState&); 78 IDBRequest* getAll(ScriptState*, const ScriptValue& range, unsigned long max Count, ExceptionState&);
76 IDBRequest* getAll(ScriptState*, const ScriptValue& range, ExceptionState&); 79 IDBRequest* getAll(ScriptState*, const ScriptValue& range, ExceptionState&);
77 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, unsigned long maxCount, ExceptionState&); 80 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, unsigned long maxCount, ExceptionState&);
78 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, ExceptionStat e&); 81 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, ExceptionStat e&);
79 IDBRequest* add(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex ceptionState&); 82 IDBRequest* add(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex ceptionState&);
80 IDBRequest* put(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex ceptionState&); 83 IDBRequest* put(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex ceptionState&);
81 IDBRequest* deleteFunction(ScriptState*, const ScriptValue& key, ExceptionSt ate&); 84 IDBRequest* deleteFunction(ScriptState*, const ScriptValue& key, ExceptionSt ate&);
82 IDBRequest* clear(ScriptState*, ExceptionState&); 85 IDBRequest* clear(ScriptState*, ExceptionState&);
83 86
84 IDBIndex* createIndex(ScriptState* scriptState, const String& name, const St ringOrStringSequence& keyPath, const IDBIndexParameters& options, ExceptionState & exceptionState) 87 IDBIndex* createIndex(ScriptState* scriptState, const String& name, const St ringOrStringSequence& keyPath, const IDBIndexParameters& options, ExceptionState & exceptionState)
85 { 88 {
86 return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exce ptionState); 89 return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exce ptionState);
87 } 90 }
88 IDBIndex* index(const String& name, ExceptionState&); 91 IDBIndex* index(const String& name, ExceptionState&);
89 void deleteIndex(const String& name, ExceptionState&); 92 void deleteIndex(const String& name, ExceptionState&);
90 93
91 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&); 94 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&);
92 95
93 // Used by IDBCursor::update(): 96 // Used by IDBCursor::update():
94 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, IDBKey*, ExceptionState&); 97 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, IDBKey*, ExceptionState&);
95 98
96 // Used internally and by InspectorIndexedDBAgent: 99 // Used internally and by InspectorIndexedDBAgent:
97 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We bIDBTaskType = WebIDBTaskTypeNormal); 100 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We bIDBTaskType = WebIDBTaskTypeNormal);
98 101
99 void markDeleted() { m_deleted = true; } 102 void markDeleted();
100 bool isDeleted() const { return m_deleted; } 103 bool isDeleted() const { return m_deleted; }
101 void abort(); 104 void abort();
102 void transactionFinished(); 105 void transactionFinished();
103 106
104 const IDBObjectStoreMetadata& metadata() const { return m_metadata; }
105 void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = meta data; } 107 void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = meta data; }
106 108
107 typedef HeapVector<Member<IDBKey>> IndexKeys;
108
109 // Used by IDBIndex::setName: 109 // Used by IDBIndex::setName:
110 bool containsIndex(const String& name) const 110 bool containsIndex(const String& name) const
111 { 111 {
112 return findIndexId(name) != IDBIndexMetadata::InvalidId; 112 return findIndexId(name) != IDBIndexMetadata::InvalidId;
113 } 113 }
114 void indexRenamed(int64_t indexId, const String& newName); 114 void indexRenamed(int64_t indexId, const String& newName);
115 115
116 WebIDBDatabase* backendDB() const; 116 WebIDBDatabase* backendDB() const;
117 117
118 private: 118 private:
119 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*); 119 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*);
120 120
121 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c onst IDBIndexParameters&, ExceptionState&); 121 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c onst IDBIndexParameters&, ExceptionState&);
122 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, const ScriptValue& key, ExceptionState&); 122 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, const ScriptValue& key, ExceptionState&);
123 123
124 int64_t findIndexId(const String& name) const; 124 int64_t findIndexId(const String& name) const;
125 125
126 IDBObjectStoreMetadata m_metadata; 126 IDBObjectStoreMetadata m_metadata;
127 Member<IDBTransaction> m_transaction; 127 Member<IDBTransaction> m_transaction;
128 bool m_deleted = false; 128 bool m_deleted = false;
129 129
130 typedef HeapHashMap<String, Member<IDBIndex>> IDBIndexMap; 130 // Caches the IDBIndex instances returned by the index() method.
131 // The spec requires that an object store's index() returns the same
132 // IDBIndex instance for a specific index, so this cache is necessary
133 // for correctness.
134 //
135 // index() throws for completed/aborted transactions, so this is not used
136 // after a transaction is finished, and can be cleared.
137 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>;
131 IDBIndexMap m_indexMap; 138 IDBIndexMap m_indexMap;
132 139
133 // Used to mark indexes created in an aborted upgrade transaction as 140 // Used to mark indexes created in an aborted upgrade transaction as
134 // deleted. 141 // deleted.
135 HeapHashSet<Member<IDBIndex>> m_createdIndexes; 142 HeapHashSet<Member<IDBIndex>> m_createdIndexes;
136 }; 143 };
137 144
138 } // namespace blink 145 } // namespace blink
139 146
140 #endif // IDBObjectStore_h 147 #endif // IDBObjectStore_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698