OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ | |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ | |
7 | |
8 #include <list> | |
9 #include <map> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" | |
14 #include "content/browser/indexed_db/indexed_db_metadata.h" | |
15 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | |
16 #include "content/browser/indexed_db/list_set.h" | |
17 | |
18 namespace content { | |
19 | |
20 class IndexedDBBackingStore; | |
21 class IndexedDBDatabase; | |
22 class IndexedDBFactoryImpl; | |
23 class IndexedDBTransaction; | |
24 | |
25 class CONTENT_EXPORT IndexedDBDatabaseImpl | |
26 : NON_EXPORTED_BASE(public IndexedDBDatabase) { | |
27 public: | |
28 static scoped_refptr<IndexedDBDatabaseImpl> Create( | |
29 const string16& name, | |
30 IndexedDBBackingStore* database, | |
31 IndexedDBFactoryImpl* factory, | |
32 const string16& unique_identifier); | |
33 scoped_refptr<IndexedDBBackingStore> BackingStore() const; | |
34 | |
35 static const int64 kInvalidId = 0; | |
36 int64 id() const { return metadata_.id; } | |
37 void AddObjectStore(const IndexedDBObjectStoreMetadata& metadata, | |
38 int64 new_max_object_store_id); | |
39 void RemoveObjectStore(int64 object_store_id); | |
40 void AddIndex(int64 object_store_id, | |
41 const IndexedDBIndexMetadata& metadata, | |
42 int64 new_max_index_id); | |
43 void RemoveIndex(int64 object_store_id, int64 index_id); | |
44 | |
45 void OpenConnection( | |
46 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
47 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | |
48 int64 transaction_id, | |
49 int64 version); | |
50 void DeleteDatabase(scoped_refptr<IndexedDBCallbacksWrapper> callbacks); | |
51 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; } | |
52 | |
53 // IndexedDBDatabase | |
54 virtual void CreateObjectStore(int64 transaction_id, | |
55 int64 object_store_id, | |
56 const string16& name, | |
57 const IndexedDBKeyPath& key_path, | |
58 bool auto_increment) OVERRIDE; | |
59 virtual void DeleteObjectStore(int64 transaction_id, int64 object_store_id) | |
60 OVERRIDE; | |
61 virtual void CreateTransaction( | |
62 int64 transaction_id, | |
63 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks, | |
64 const std::vector<int64>& object_store_ids, | |
65 uint16 mode) OVERRIDE; | |
66 virtual void Close(scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks) | |
67 OVERRIDE; | |
68 | |
69 virtual void Commit(int64 transaction_id) OVERRIDE; | |
70 virtual void Abort(int64 transaction_id) OVERRIDE; | |
71 virtual void Abort(int64 transaction_id, const IndexedDBDatabaseError& error) | |
72 OVERRIDE; | |
73 | |
74 virtual void CreateIndex(int64 transaction_id, | |
75 int64 object_store_id, | |
76 int64 index_id, | |
77 const string16& name, | |
78 const IndexedDBKeyPath& key_path, | |
79 bool unique, | |
80 bool multi_entry) OVERRIDE; | |
81 virtual void DeleteIndex(int64 transaction_id, | |
82 int64 object_store_id, | |
83 int64 index_id) OVERRIDE; | |
84 | |
85 IndexedDBTransactionCoordinator& transaction_coordinator() { | |
86 return transaction_coordinator_; | |
87 } | |
88 | |
89 void TransactionStarted(IndexedDBTransaction* transaction); | |
90 void TransactionFinished(IndexedDBTransaction* transaction); | |
91 void TransactionFinishedAndCompleteFired(IndexedDBTransaction* transaction); | |
92 void TransactionFinishedAndAbortFired(IndexedDBTransaction* transaction); | |
93 | |
94 virtual void Get(int64 transaction_id, | |
95 int64 object_store_id, | |
96 int64 index_id, | |
97 scoped_ptr<IndexedDBKeyRange> key_range, | |
98 bool key_only, | |
99 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) OVERRIDE; | |
100 virtual void Put(int64 transaction_id, | |
101 int64 object_store_id, | |
102 std::vector<char>* value, | |
103 scoped_ptr<IndexedDBKey> key, | |
104 PutMode mode, | |
105 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
106 const std::vector<int64>& index_ids, | |
107 const std::vector<IndexKeys>& index_keys) OVERRIDE; | |
108 virtual void SetIndexKeys(int64 transaction_id, | |
109 int64 object_store_id, | |
110 scoped_ptr<IndexedDBKey> primary_key, | |
111 const std::vector<int64>& index_ids, | |
112 const std::vector<IndexKeys>& index_keys) OVERRIDE; | |
113 virtual void SetIndexesReady(int64 transaction_id, | |
114 int64 object_store_id, | |
115 const std::vector<int64>& index_ids) OVERRIDE; | |
116 virtual void OpenCursor(int64 transaction_id, | |
117 int64 object_store_id, | |
118 int64 index_id, | |
119 scoped_ptr<IndexedDBKeyRange> key_range, | |
120 indexed_db::CursorDirection, | |
121 bool key_only, | |
122 TaskType task_type, | |
123 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) | |
124 OVERRIDE; | |
125 virtual void Count(int64 transaction_id, | |
126 int64 object_store_id, | |
127 int64 index_id, | |
128 scoped_ptr<IndexedDBKeyRange> key_range, | |
129 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) | |
130 OVERRIDE; | |
131 virtual void DeleteRange(int64 transaction_id, | |
132 int64 object_store_id, | |
133 scoped_ptr<IndexedDBKeyRange> key_range, | |
134 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) | |
135 OVERRIDE; | |
136 virtual void Clear(int64 transaction_id, | |
137 int64 object_store_id, | |
138 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) | |
139 OVERRIDE; | |
140 | |
141 private: | |
142 IndexedDBDatabaseImpl(const string16& name, | |
143 IndexedDBBackingStore* database, | |
144 IndexedDBFactoryImpl* factory, | |
145 const string16& unique_identifier); | |
146 virtual ~IndexedDBDatabaseImpl(); | |
147 | |
148 bool IsOpenConnectionBlocked() const; | |
149 bool OpenInternal(); | |
150 void RunVersionChangeTransaction( | |
151 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
152 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | |
153 int64 transaction_id, | |
154 int64 requested_version); | |
155 void RunVersionChangeTransactionFinal( | |
156 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
157 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | |
158 int64 transaction_id, | |
159 int64 requested_version); | |
160 size_t ConnectionCount() const; | |
161 void ProcessPendingCalls(); | |
162 | |
163 bool IsDeleteDatabaseBlocked() const; | |
164 void DeleteDatabaseFinal(scoped_refptr<IndexedDBCallbacksWrapper> callbacks); | |
165 | |
166 class VersionChangeOperation; | |
167 | |
168 // When a "versionchange" transaction aborts, these restore the back-end | |
169 // object hierarchy. | |
170 class VersionChangeAbortOperation; | |
171 | |
172 scoped_refptr<IndexedDBBackingStore> backing_store_; | |
173 IndexedDBDatabaseMetadata metadata_; | |
174 | |
175 string16 identifier_; | |
176 // This might not need to be a scoped_refptr since the factory's lifetime is | |
177 // that of the page group, but it's better to be conservitive than sorry. | |
178 scoped_refptr<IndexedDBFactoryImpl> factory_; | |
179 | |
180 IndexedDBTransactionCoordinator transaction_coordinator_; | |
181 IndexedDBTransaction* running_version_change_transaction_; | |
182 | |
183 typedef std::map<int64, IndexedDBTransaction*> TransactionMap; | |
184 TransactionMap transactions_; | |
185 | |
186 class PendingOpenCall; | |
187 typedef std::list<PendingOpenCall*> PendingOpenCallList; | |
188 PendingOpenCallList pending_open_calls_; | |
189 scoped_ptr<PendingOpenCall> pending_run_version_change_transaction_call_; | |
190 scoped_ptr<PendingOpenCall> pending_second_half_open_; | |
191 | |
192 class PendingDeleteCall; | |
193 typedef std::list<PendingDeleteCall*> PendingDeleteCallList; | |
194 PendingDeleteCallList pending_delete_calls_; | |
195 | |
196 typedef list_set<scoped_refptr<IndexedDBDatabaseCallbacksWrapper> > | |
197 DatabaseCallbacksSet; | |
198 DatabaseCallbacksSet database_callbacks_set_; | |
199 | |
200 bool closing_connection_; | |
201 }; | |
202 | |
203 } // namespace content | |
204 | |
205 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ | |
OLD | NEW |