OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
7 | 7 |
| 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "content/browser/indexed_db/indexed_db.h" | 16 #include "content/browser/indexed_db/indexed_db.h" |
16 #include "content/browser/indexed_db/indexed_db_metadata.h" | 17 #include "content/browser/indexed_db/indexed_db_metadata.h" |
17 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const string16& name, | 92 const string16& name, |
92 const IndexedDBKeyPath& key_path, | 93 const IndexedDBKeyPath& key_path, |
93 bool auto_increment); | 94 bool auto_increment); |
94 virtual bool DeleteObjectStore( | 95 virtual bool DeleteObjectStore( |
95 IndexedDBBackingStore::Transaction* transaction, | 96 IndexedDBBackingStore::Transaction* transaction, |
96 int64 database_id, | 97 int64 database_id, |
97 int64 object_store_id) WARN_UNUSED_RESULT; | 98 int64 object_store_id) WARN_UNUSED_RESULT; |
98 | 99 |
99 class CONTENT_EXPORT RecordIdentifier { | 100 class CONTENT_EXPORT RecordIdentifier { |
100 public: | 101 public: |
101 RecordIdentifier(const std::vector<char>& primary_key, int64 version); | 102 RecordIdentifier(const std::string& primary_key, int64 version); |
102 RecordIdentifier(); | 103 RecordIdentifier(); |
103 ~RecordIdentifier(); | 104 ~RecordIdentifier(); |
104 | 105 |
105 const std::vector<char>& primary_key() const { return primary_key_; } | 106 const std::string& primary_key() const { return primary_key_; } |
106 int64 version() const { return version_; } | 107 int64 version() const { return version_; } |
107 void Reset(const std::vector<char>& primary_key, int64 version) { | 108 void Reset(const std::string& primary_key, int64 version) { |
108 primary_key_ = primary_key; | 109 primary_key_ = primary_key; |
109 version_ = version; | 110 version_ = version; |
110 } | 111 } |
111 | 112 |
112 private: | 113 private: |
113 // TODO(jsbell): Make it more clear that this is the *encoded* version of | 114 // TODO(jsbell): Make it more clear that this is the *encoded* version of |
114 // the key. | 115 // the key. |
115 std::vector<char> primary_key_; | 116 std::string primary_key_; |
116 int64 version_; | 117 int64 version_; |
117 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | 118 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); |
118 }; | 119 }; |
119 | 120 |
120 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, | 121 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, |
121 int64 database_id, | 122 int64 database_id, |
122 int64 object_store_id, | 123 int64 object_store_id, |
123 const IndexedDBKey& key, | 124 const IndexedDBKey& key, |
124 std::vector<char>* record) WARN_UNUSED_RESULT; | 125 std::string* record) WARN_UNUSED_RESULT; |
125 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, | 126 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, |
126 int64 database_id, | 127 int64 database_id, |
127 int64 object_store_id, | 128 int64 object_store_id, |
128 const IndexedDBKey& key, | 129 const IndexedDBKey& key, |
129 const std::vector<char>& value, | 130 const std::string& value, |
130 RecordIdentifier* record) WARN_UNUSED_RESULT; | 131 RecordIdentifier* record) WARN_UNUSED_RESULT; |
131 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, | 132 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, |
132 int64 database_id, | 133 int64 database_id, |
133 int64 object_store_id) WARN_UNUSED_RESULT; | 134 int64 object_store_id) WARN_UNUSED_RESULT; |
134 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, | 135 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, |
135 int64 database_id, | 136 int64 database_id, |
136 int64 object_store_id, | 137 int64 object_store_id, |
137 const RecordIdentifier& record) WARN_UNUSED_RESULT; | 138 const RecordIdentifier& record) WARN_UNUSED_RESULT; |
138 virtual bool GetKeyGeneratorCurrentNumber( | 139 virtual bool GetKeyGeneratorCurrentNumber( |
139 IndexedDBBackingStore::Transaction* transaction, | 140 IndexedDBBackingStore::Transaction* transaction, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 READY = 0, | 197 READY = 0, |
197 SEEK | 198 SEEK |
198 }; | 199 }; |
199 | 200 |
200 struct CursorOptions { | 201 struct CursorOptions { |
201 CursorOptions(); | 202 CursorOptions(); |
202 ~CursorOptions(); | 203 ~CursorOptions(); |
203 int64 database_id; | 204 int64 database_id; |
204 int64 object_store_id; | 205 int64 object_store_id; |
205 int64 index_id; | 206 int64 index_id; |
206 std::vector<char> low_key; | 207 std::string low_key; |
207 bool low_open; | 208 bool low_open; |
208 std::vector<char> high_key; | 209 std::string high_key; |
209 bool high_open; | 210 bool high_open; |
210 bool forward; | 211 bool forward; |
211 bool unique; | 212 bool unique; |
212 }; | 213 }; |
213 | 214 |
214 const IndexedDBKey& key() const { return *current_key_; } | 215 const IndexedDBKey& key() const { return *current_key_; } |
215 bool ContinueFunction() { return ContinueFunction(NULL, SEEK); } | 216 bool ContinueFunction() { return ContinueFunction(NULL, SEEK); } |
216 bool ContinueFunction(const IndexedDBKey* key, IteratorState state); | 217 bool ContinueFunction(const IndexedDBKey* key, IteratorState state); |
217 bool Advance(uint32 count); | 218 bool Advance(uint32 count); |
218 bool FirstSeek(); | 219 bool FirstSeek(); |
219 | 220 |
220 virtual Cursor* Clone() = 0; | 221 virtual Cursor* Clone() = 0; |
221 virtual const IndexedDBKey& primary_key() const; | 222 virtual const IndexedDBKey& primary_key() const; |
222 virtual std::vector<char>* Value() = 0; | 223 virtual std::string* Value() = 0; |
223 virtual const RecordIdentifier& record_identifier() const; | 224 virtual const RecordIdentifier& record_identifier() const; |
224 virtual bool LoadCurrentRow() = 0; | 225 virtual bool LoadCurrentRow() = 0; |
225 | 226 |
226 protected: | 227 protected: |
227 Cursor(LevelDBTransaction* transaction, | 228 Cursor(LevelDBTransaction* transaction, |
228 const CursorOptions& cursor_options); | 229 const CursorOptions& cursor_options); |
229 explicit Cursor(const IndexedDBBackingStore::Cursor* other); | 230 explicit Cursor(const IndexedDBBackingStore::Cursor* other); |
230 | 231 |
231 virtual std::vector<char> EncodeKey(const IndexedDBKey& key) = 0; | 232 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; |
232 | 233 |
233 bool IsPastBounds() const; | 234 bool IsPastBounds() const; |
234 bool HaveEnteredRange() const; | 235 bool HaveEnteredRange() const; |
235 | 236 |
236 LevelDBTransaction* transaction_; | 237 LevelDBTransaction* transaction_; |
237 const CursorOptions cursor_options_; | 238 const CursorOptions cursor_options_; |
238 scoped_ptr<LevelDBIterator> iterator_; | 239 scoped_ptr<LevelDBIterator> iterator_; |
239 scoped_ptr<IndexedDBKey> current_key_; | 240 scoped_ptr<IndexedDBKey> current_key_; |
240 IndexedDBBackingStore::RecordIdentifier record_identifier_; | 241 IndexedDBBackingStore::RecordIdentifier record_identifier_; |
241 }; | 242 }; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 static scoped_refptr<IndexedDBBackingStore> Create( | 301 static scoped_refptr<IndexedDBBackingStore> Create( |
301 const std::string& identifier, | 302 const std::string& identifier, |
302 scoped_ptr<LevelDBDatabase> db, | 303 scoped_ptr<LevelDBDatabase> db, |
303 scoped_ptr<LevelDBComparator> comparator); | 304 scoped_ptr<LevelDBComparator> comparator); |
304 | 305 |
305 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, | 306 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, |
306 int64 database_id, | 307 int64 database_id, |
307 int64 object_store_id, | 308 int64 object_store_id, |
308 int64 index_id, | 309 int64 index_id, |
309 const IndexedDBKey& key, | 310 const IndexedDBKey& key, |
310 std::vector<char>* found_encoded_primary_key, | 311 std::string* found_encoded_primary_key, |
311 bool* found); | 312 bool* found); |
312 bool GetIndexes(int64 database_id, | 313 bool GetIndexes(int64 database_id, |
313 int64 object_store_id, | 314 int64 object_store_id, |
314 IndexedDBObjectStoreMetadata::IndexMap* map) | 315 IndexedDBObjectStoreMetadata::IndexMap* map) |
315 WARN_UNUSED_RESULT; | 316 WARN_UNUSED_RESULT; |
316 | 317 |
317 std::string identifier_; | 318 std::string identifier_; |
318 | 319 |
319 scoped_ptr<LevelDBDatabase> db_; | 320 scoped_ptr<LevelDBDatabase> db_; |
320 scoped_ptr<LevelDBComparator> comparator_; | 321 scoped_ptr<LevelDBComparator> comparator_; |
321 base::WeakPtrFactory<IndexedDBBackingStore> weak_factory_; | 322 base::WeakPtrFactory<IndexedDBBackingStore> weak_factory_; |
322 }; | 323 }; |
323 | 324 |
324 } // namespace content | 325 } // namespace content |
325 | 326 |
326 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 327 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
OLD | NEW |