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 <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <map> | 11 #include <map> |
9 #include <set> | 12 #include <set> |
10 #include <string> | 13 #include <string> |
11 #include <utility> | 14 #include <utility> |
12 #include <vector> | 15 #include <vector> |
13 | 16 |
14 #include "base/basictypes.h" | |
15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
19 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
20 #include "base/time/time.h" | 23 #include "base/time/time.h" |
21 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
22 #include "content/browser/indexed_db/indexed_db.h" | 25 #include "content/browser/indexed_db/indexed_db.h" |
23 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" | 26 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" |
24 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 27 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
25 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 28 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 public: | 62 public: |
60 class CONTENT_EXPORT Comparator : public LevelDBComparator { | 63 class CONTENT_EXPORT Comparator : public LevelDBComparator { |
61 public: | 64 public: |
62 int Compare(const base::StringPiece& a, | 65 int Compare(const base::StringPiece& a, |
63 const base::StringPiece& b) const override; | 66 const base::StringPiece& b) const override; |
64 const char* Name() const override; | 67 const char* Name() const override; |
65 }; | 68 }; |
66 | 69 |
67 class CONTENT_EXPORT RecordIdentifier { | 70 class CONTENT_EXPORT RecordIdentifier { |
68 public: | 71 public: |
69 RecordIdentifier(const std::string& primary_key, int64 version); | 72 RecordIdentifier(const std::string& primary_key, int64_t version); |
70 RecordIdentifier(); | 73 RecordIdentifier(); |
71 ~RecordIdentifier(); | 74 ~RecordIdentifier(); |
72 | 75 |
73 const std::string& primary_key() const { return primary_key_; } | 76 const std::string& primary_key() const { return primary_key_; } |
74 int64 version() const { return version_; } | 77 int64_t version() const { return version_; } |
75 void Reset(const std::string& primary_key, int64 version) { | 78 void Reset(const std::string& primary_key, int64_t version) { |
76 primary_key_ = primary_key; | 79 primary_key_ = primary_key; |
77 version_ = version; | 80 version_ = version; |
78 } | 81 } |
79 | 82 |
80 private: | 83 private: |
81 // TODO(jsbell): Make it more clear that this is the *encoded* version of | 84 // TODO(jsbell): Make it more clear that this is the *encoded* version of |
82 // the key. | 85 // the key. |
83 std::string primary_key_; | 86 std::string primary_key_; |
84 int64 version_; | 87 int64_t version_; |
85 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | 88 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); |
86 }; | 89 }; |
87 | 90 |
88 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { | 91 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { |
89 public: | 92 public: |
90 virtual void Run(bool succeeded) = 0; | 93 virtual void Run(bool succeeded) = 0; |
91 | 94 |
92 protected: | 95 protected: |
93 friend class base::RefCounted<BlobWriteCallback>; | 96 friend class base::RefCounted<BlobWriteCallback>; |
94 virtual ~BlobWriteCallback() {} | 97 virtual ~BlobWriteCallback() {} |
95 }; | 98 }; |
96 | 99 |
97 class BlobChangeRecord { | 100 class BlobChangeRecord { |
98 public: | 101 public: |
99 BlobChangeRecord(const std::string& key, int64 object_store_id); | 102 BlobChangeRecord(const std::string& key, int64_t object_store_id); |
100 ~BlobChangeRecord(); | 103 ~BlobChangeRecord(); |
101 | 104 |
102 const std::string& key() const { return key_; } | 105 const std::string& key() const { return key_; } |
103 int64 object_store_id() const { return object_store_id_; } | 106 int64_t object_store_id() const { return object_store_id_; } |
104 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); | 107 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); |
105 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } | 108 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } |
106 const std::vector<IndexedDBBlobInfo>& blob_info() const { | 109 const std::vector<IndexedDBBlobInfo>& blob_info() const { |
107 return blob_info_; | 110 return blob_info_; |
108 } | 111 } |
109 void SetHandles(ScopedVector<storage::BlobDataHandle>* handles); | 112 void SetHandles(ScopedVector<storage::BlobDataHandle>* handles); |
110 scoped_ptr<BlobChangeRecord> Clone() const; | 113 scoped_ptr<BlobChangeRecord> Clone() const; |
111 | 114 |
112 private: | 115 private: |
113 std::string key_; | 116 std::string key_; |
114 int64 object_store_id_; | 117 int64_t object_store_id_; |
115 std::vector<IndexedDBBlobInfo> blob_info_; | 118 std::vector<IndexedDBBlobInfo> blob_info_; |
116 ScopedVector<storage::BlobDataHandle> handles_; | 119 ScopedVector<storage::BlobDataHandle> handles_; |
117 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord); | 120 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord); |
118 }; | 121 }; |
119 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; | 122 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; |
120 | 123 |
121 class CONTENT_EXPORT Transaction { | 124 class CONTENT_EXPORT Transaction { |
122 public: | 125 public: |
123 explicit Transaction(IndexedDBBackingStore* backing_store); | 126 explicit Transaction(IndexedDBBackingStore* backing_store); |
124 virtual ~Transaction(); | 127 virtual ~Transaction(); |
(...skipping 13 matching lines...) Expand all Loading... |
138 // including blob journal updates, then deletes any blob files deleted | 141 // including blob journal updates, then deletes any blob files deleted |
139 // by the transaction and not referenced by running scripts. | 142 // by the transaction and not referenced by running scripts. |
140 virtual leveldb::Status CommitPhaseTwo(); | 143 virtual leveldb::Status CommitPhaseTwo(); |
141 | 144 |
142 virtual void Rollback(); | 145 virtual void Rollback(); |
143 void Reset() { | 146 void Reset() { |
144 backing_store_ = NULL; | 147 backing_store_ = NULL; |
145 transaction_ = NULL; | 148 transaction_ = NULL; |
146 } | 149 } |
147 leveldb::Status PutBlobInfoIfNeeded( | 150 leveldb::Status PutBlobInfoIfNeeded( |
148 int64 database_id, | 151 int64_t database_id, |
149 int64 object_store_id, | 152 int64_t object_store_id, |
150 const std::string& object_store_data_key, | 153 const std::string& object_store_data_key, |
151 std::vector<IndexedDBBlobInfo>*, | 154 std::vector<IndexedDBBlobInfo>*, |
152 ScopedVector<storage::BlobDataHandle>* handles); | 155 ScopedVector<storage::BlobDataHandle>* handles); |
153 void PutBlobInfo(int64 database_id, | 156 void PutBlobInfo(int64_t database_id, |
154 int64 object_store_id, | 157 int64_t object_store_id, |
155 const std::string& object_store_data_key, | 158 const std::string& object_store_data_key, |
156 std::vector<IndexedDBBlobInfo>*, | 159 std::vector<IndexedDBBlobInfo>*, |
157 ScopedVector<storage::BlobDataHandle>* handles); | 160 ScopedVector<storage::BlobDataHandle>* handles); |
158 | 161 |
159 LevelDBTransaction* transaction() { return transaction_.get(); } | 162 LevelDBTransaction* transaction() { return transaction_.get(); } |
160 | 163 |
161 leveldb::Status GetBlobInfoForRecord( | 164 leveldb::Status GetBlobInfoForRecord( |
162 int64 database_id, | 165 int64_t database_id, |
163 const std::string& object_store_data_key, | 166 const std::string& object_store_data_key, |
164 IndexedDBValue* value); | 167 IndexedDBValue* value); |
165 | 168 |
166 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored | 169 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored |
167 // under that key. | 170 // under that key. |
168 typedef std::vector<std::pair<BlobEntryKey, std::string> > | 171 typedef std::vector<std::pair<BlobEntryKey, std::string> > |
169 BlobEntryKeyValuePairVec; | 172 BlobEntryKeyValuePairVec; |
170 | 173 |
171 class CONTENT_EXPORT WriteDescriptor { | 174 class CONTENT_EXPORT WriteDescriptor { |
172 public: | 175 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 }; | 208 }; |
206 | 209 |
207 class ChainedBlobWriter | 210 class ChainedBlobWriter |
208 : public base::RefCountedThreadSafe<ChainedBlobWriter> { | 211 : public base::RefCountedThreadSafe<ChainedBlobWriter> { |
209 public: | 212 public: |
210 virtual void set_delegate( | 213 virtual void set_delegate( |
211 scoped_ptr<storage::FileWriterDelegate> delegate) = 0; | 214 scoped_ptr<storage::FileWriterDelegate> delegate) = 0; |
212 | 215 |
213 // TODO(ericu): Add a reason in the event of failure. | 216 // TODO(ericu): Add a reason in the event of failure. |
214 virtual void ReportWriteCompletion(bool succeeded, | 217 virtual void ReportWriteCompletion(bool succeeded, |
215 int64 bytes_written) = 0; | 218 int64_t bytes_written) = 0; |
216 | 219 |
217 virtual void Abort() = 0; | 220 virtual void Abort() = 0; |
218 | 221 |
219 protected: | 222 protected: |
220 friend class base::RefCountedThreadSafe<ChainedBlobWriter>; | 223 friend class base::RefCountedThreadSafe<ChainedBlobWriter>; |
221 virtual ~ChainedBlobWriter() {} | 224 virtual ~ChainedBlobWriter() {} |
222 }; | 225 }; |
223 | 226 |
224 class ChainedBlobWriterImpl; | 227 class ChainedBlobWriterImpl; |
225 | 228 |
(...skipping 24 matching lines...) Expand all Loading... |
250 | 253 |
251 // Called by CommitPhaseTwo: Partition blob references in blobs_to_remove_ | 254 // Called by CommitPhaseTwo: Partition blob references in blobs_to_remove_ |
252 // into live (active references) and dead (no references). | 255 // into live (active references) and dead (no references). |
253 void PartitionBlobsToRemove(BlobJournalType* dead_blobs, | 256 void PartitionBlobsToRemove(BlobJournalType* dead_blobs, |
254 BlobJournalType* live_blobs) const; | 257 BlobJournalType* live_blobs) const; |
255 | 258 |
256 IndexedDBBackingStore* backing_store_; | 259 IndexedDBBackingStore* backing_store_; |
257 scoped_refptr<LevelDBTransaction> transaction_; | 260 scoped_refptr<LevelDBTransaction> transaction_; |
258 BlobChangeMap blob_change_map_; | 261 BlobChangeMap blob_change_map_; |
259 BlobChangeMap incognito_blob_map_; | 262 BlobChangeMap incognito_blob_map_; |
260 int64 database_id_; | 263 int64_t database_id_; |
261 | 264 |
262 // List of blob files being newly written as part of this transaction. | 265 // List of blob files being newly written as part of this transaction. |
263 // These will be added to the primary blob journal prior to commit, then | 266 // These will be added to the primary blob journal prior to commit, then |
264 // removed after a successful commit. | 267 // removed after a successful commit. |
265 BlobJournalType blobs_to_write_; | 268 BlobJournalType blobs_to_write_; |
266 | 269 |
267 // List of blob files being deleted as part of this transaction. These will | 270 // List of blob files being deleted as part of this transaction. These will |
268 // be added to either the primary or live blob journal as appropriate | 271 // be added to either the primary or live blob journal as appropriate |
269 // following a successful commit. | 272 // following a successful commit. |
270 BlobJournalType blobs_to_remove_; | 273 BlobJournalType blobs_to_remove_; |
271 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; | 274 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; |
272 | 275 |
273 // Set to true between CommitPhaseOne and CommitPhaseTwo/Rollback, to | 276 // Set to true between CommitPhaseOne and CommitPhaseTwo/Rollback, to |
274 // indicate that the committing_transaction_count_ on the backing store | 277 // indicate that the committing_transaction_count_ on the backing store |
275 // has been bumped, and journal cleaning should be deferred. | 278 // has been bumped, and journal cleaning should be deferred. |
276 bool committing_; | 279 bool committing_; |
277 }; | 280 }; |
278 | 281 |
279 class Cursor { | 282 class Cursor { |
280 public: | 283 public: |
281 enum IteratorState { READY = 0, SEEK }; | 284 enum IteratorState { READY = 0, SEEK }; |
282 | 285 |
283 virtual ~Cursor(); | 286 virtual ~Cursor(); |
284 | 287 |
285 struct CursorOptions { | 288 struct CursorOptions { |
286 CursorOptions(); | 289 CursorOptions(); |
287 ~CursorOptions(); | 290 ~CursorOptions(); |
288 int64 database_id; | 291 int64_t database_id; |
289 int64 object_store_id; | 292 int64_t object_store_id; |
290 int64 index_id; | 293 int64_t index_id; |
291 std::string low_key; | 294 std::string low_key; |
292 bool low_open; | 295 bool low_open; |
293 std::string high_key; | 296 std::string high_key; |
294 bool high_open; | 297 bool high_open; |
295 bool forward; | 298 bool forward; |
296 bool unique; | 299 bool unique; |
297 }; | 300 }; |
298 | 301 |
299 const IndexedDBKey& key() const { return *current_key_; } | 302 const IndexedDBKey& key() const { return *current_key_; } |
300 bool Continue(leveldb::Status* s) { return Continue(NULL, NULL, SEEK, s); } | 303 bool Continue(leveldb::Status* s) { return Continue(NULL, NULL, SEEK, s); } |
301 bool Continue(const IndexedDBKey* key, | 304 bool Continue(const IndexedDBKey* key, |
302 IteratorState state, | 305 IteratorState state, |
303 leveldb::Status* s) { | 306 leveldb::Status* s) { |
304 return Continue(key, NULL, state, s); | 307 return Continue(key, NULL, state, s); |
305 } | 308 } |
306 bool Continue(const IndexedDBKey* key, | 309 bool Continue(const IndexedDBKey* key, |
307 const IndexedDBKey* primary_key, | 310 const IndexedDBKey* primary_key, |
308 IteratorState state, | 311 IteratorState state, |
309 leveldb::Status*); | 312 leveldb::Status*); |
310 bool Advance(uint32 count, leveldb::Status*); | 313 bool Advance(uint32_t count, leveldb::Status*); |
311 bool FirstSeek(leveldb::Status*); | 314 bool FirstSeek(leveldb::Status*); |
312 | 315 |
313 virtual Cursor* Clone() = 0; | 316 virtual Cursor* Clone() = 0; |
314 virtual const IndexedDBKey& primary_key() const; | 317 virtual const IndexedDBKey& primary_key() const; |
315 virtual IndexedDBValue* value() = 0; | 318 virtual IndexedDBValue* value() = 0; |
316 virtual const RecordIdentifier& record_identifier() const; | 319 virtual const RecordIdentifier& record_identifier() const; |
317 virtual bool LoadCurrentRow(leveldb::Status* s) = 0; | 320 virtual bool LoadCurrentRow(leveldb::Status* s) = 0; |
318 | 321 |
319 protected: | 322 protected: |
320 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, | 323 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, |
321 Transaction* transaction, | 324 Transaction* transaction, |
322 int64 database_id, | 325 int64_t database_id, |
323 const CursorOptions& cursor_options); | 326 const CursorOptions& cursor_options); |
324 explicit Cursor(const IndexedDBBackingStore::Cursor* other); | 327 explicit Cursor(const IndexedDBBackingStore::Cursor* other); |
325 | 328 |
326 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; | 329 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; |
327 virtual std::string EncodeKey(const IndexedDBKey& key, | 330 virtual std::string EncodeKey(const IndexedDBKey& key, |
328 const IndexedDBKey& primary_key) = 0; | 331 const IndexedDBKey& primary_key) = 0; |
329 | 332 |
330 bool IsPastBounds() const; | 333 bool IsPastBounds() const; |
331 bool HaveEnteredRange() const; | 334 bool HaveEnteredRange() const; |
332 | 335 |
333 IndexedDBBackingStore* backing_store_; | 336 IndexedDBBackingStore* backing_store_; |
334 Transaction* transaction_; | 337 Transaction* transaction_; |
335 int64 database_id_; | 338 int64_t database_id_; |
336 const CursorOptions cursor_options_; | 339 const CursorOptions cursor_options_; |
337 scoped_ptr<LevelDBIterator> iterator_; | 340 scoped_ptr<LevelDBIterator> iterator_; |
338 scoped_ptr<IndexedDBKey> current_key_; | 341 scoped_ptr<IndexedDBKey> current_key_; |
339 IndexedDBBackingStore::RecordIdentifier record_identifier_; | 342 IndexedDBBackingStore::RecordIdentifier record_identifier_; |
340 | 343 |
341 private: | 344 private: |
342 // For cursors with direction Next or NextNoDuplicate. | 345 // For cursors with direction Next or NextNoDuplicate. |
343 bool ContinueNext(const IndexedDBKey* key, | 346 bool ContinueNext(const IndexedDBKey* key, |
344 const IndexedDBKey* primary_key, | 347 const IndexedDBKey* primary_key, |
345 IteratorState state, | 348 IteratorState state, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // Compact is public for testing. | 404 // Compact is public for testing. |
402 virtual void Compact(); | 405 virtual void Compact(); |
403 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); | 406 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); |
404 virtual leveldb::Status GetIDBDatabaseMetaData( | 407 virtual leveldb::Status GetIDBDatabaseMetaData( |
405 const base::string16& name, | 408 const base::string16& name, |
406 IndexedDBDatabaseMetadata* metadata, | 409 IndexedDBDatabaseMetadata* metadata, |
407 bool* success) WARN_UNUSED_RESULT; | 410 bool* success) WARN_UNUSED_RESULT; |
408 virtual leveldb::Status CreateIDBDatabaseMetaData( | 411 virtual leveldb::Status CreateIDBDatabaseMetaData( |
409 const base::string16& name, | 412 const base::string16& name, |
410 const base::string16& version, | 413 const base::string16& version, |
411 int64 int_version, | 414 int64_t int_version, |
412 int64* row_id); | 415 int64_t* row_id); |
413 virtual bool UpdateIDBDatabaseIntVersion( | 416 virtual bool UpdateIDBDatabaseIntVersion( |
414 IndexedDBBackingStore::Transaction* transaction, | 417 IndexedDBBackingStore::Transaction* transaction, |
415 int64 row_id, | 418 int64_t row_id, |
416 int64 int_version); | 419 int64_t int_version); |
417 virtual leveldb::Status DeleteDatabase(const base::string16& name); | 420 virtual leveldb::Status DeleteDatabase(const base::string16& name); |
418 | 421 |
419 // Assumes caller has already closed the backing store. | 422 // Assumes caller has already closed the backing store. |
420 static leveldb::Status DestroyBackingStore(const base::FilePath& path_base, | 423 static leveldb::Status DestroyBackingStore(const base::FilePath& path_base, |
421 const GURL& origin_url); | 424 const GURL& origin_url); |
422 static bool RecordCorruptionInfo(const base::FilePath& path_base, | 425 static bool RecordCorruptionInfo(const base::FilePath& path_base, |
423 const GURL& origin_url, | 426 const GURL& origin_url, |
424 const std::string& message); | 427 const std::string& message); |
425 leveldb::Status GetObjectStores( | 428 leveldb::Status GetObjectStores( |
426 int64 database_id, | 429 int64_t database_id, |
427 IndexedDBDatabaseMetadata::ObjectStoreMap* map) WARN_UNUSED_RESULT; | 430 IndexedDBDatabaseMetadata::ObjectStoreMap* map) WARN_UNUSED_RESULT; |
428 virtual leveldb::Status CreateObjectStore( | 431 virtual leveldb::Status CreateObjectStore( |
429 IndexedDBBackingStore::Transaction* transaction, | 432 IndexedDBBackingStore::Transaction* transaction, |
430 int64 database_id, | 433 int64_t database_id, |
431 int64 object_store_id, | 434 int64_t object_store_id, |
432 const base::string16& name, | 435 const base::string16& name, |
433 const IndexedDBKeyPath& key_path, | 436 const IndexedDBKeyPath& key_path, |
434 bool auto_increment); | 437 bool auto_increment); |
435 virtual leveldb::Status DeleteObjectStore( | 438 virtual leveldb::Status DeleteObjectStore( |
436 IndexedDBBackingStore::Transaction* transaction, | 439 IndexedDBBackingStore::Transaction* transaction, |
437 int64 database_id, | 440 int64_t database_id, |
438 int64 object_store_id) WARN_UNUSED_RESULT; | 441 int64_t object_store_id) WARN_UNUSED_RESULT; |
439 | 442 |
440 virtual leveldb::Status GetRecord( | 443 virtual leveldb::Status GetRecord( |
441 IndexedDBBackingStore::Transaction* transaction, | 444 IndexedDBBackingStore::Transaction* transaction, |
442 int64 database_id, | 445 int64_t database_id, |
443 int64 object_store_id, | 446 int64_t object_store_id, |
444 const IndexedDBKey& key, | 447 const IndexedDBKey& key, |
445 IndexedDBValue* record) WARN_UNUSED_RESULT; | 448 IndexedDBValue* record) WARN_UNUSED_RESULT; |
446 virtual leveldb::Status PutRecord( | 449 virtual leveldb::Status PutRecord( |
447 IndexedDBBackingStore::Transaction* transaction, | 450 IndexedDBBackingStore::Transaction* transaction, |
448 int64 database_id, | 451 int64_t database_id, |
449 int64 object_store_id, | 452 int64_t object_store_id, |
450 const IndexedDBKey& key, | 453 const IndexedDBKey& key, |
451 IndexedDBValue* value, | 454 IndexedDBValue* value, |
452 ScopedVector<storage::BlobDataHandle>* handles, | 455 ScopedVector<storage::BlobDataHandle>* handles, |
453 RecordIdentifier* record) WARN_UNUSED_RESULT; | 456 RecordIdentifier* record) WARN_UNUSED_RESULT; |
454 virtual leveldb::Status ClearObjectStore( | 457 virtual leveldb::Status ClearObjectStore( |
455 IndexedDBBackingStore::Transaction* transaction, | 458 IndexedDBBackingStore::Transaction* transaction, |
456 int64 database_id, | 459 int64_t database_id, |
457 int64 object_store_id) WARN_UNUSED_RESULT; | 460 int64_t object_store_id) WARN_UNUSED_RESULT; |
458 virtual leveldb::Status DeleteRecord( | 461 virtual leveldb::Status DeleteRecord( |
459 IndexedDBBackingStore::Transaction* transaction, | 462 IndexedDBBackingStore::Transaction* transaction, |
460 int64 database_id, | 463 int64_t database_id, |
461 int64 object_store_id, | 464 int64_t object_store_id, |
462 const RecordIdentifier& record) WARN_UNUSED_RESULT; | 465 const RecordIdentifier& record) WARN_UNUSED_RESULT; |
463 virtual leveldb::Status DeleteRange( | 466 virtual leveldb::Status DeleteRange( |
464 IndexedDBBackingStore::Transaction* transaction, | 467 IndexedDBBackingStore::Transaction* transaction, |
465 int64 database_id, | 468 int64_t database_id, |
466 int64 object_store_id, | 469 int64_t object_store_id, |
467 const IndexedDBKeyRange&) WARN_UNUSED_RESULT; | 470 const IndexedDBKeyRange&) WARN_UNUSED_RESULT; |
468 virtual leveldb::Status GetKeyGeneratorCurrentNumber( | 471 virtual leveldb::Status GetKeyGeneratorCurrentNumber( |
469 IndexedDBBackingStore::Transaction* transaction, | 472 IndexedDBBackingStore::Transaction* transaction, |
470 int64 database_id, | 473 int64_t database_id, |
471 int64 object_store_id, | 474 int64_t object_store_id, |
472 int64* current_number) WARN_UNUSED_RESULT; | 475 int64_t* current_number) WARN_UNUSED_RESULT; |
473 virtual leveldb::Status MaybeUpdateKeyGeneratorCurrentNumber( | 476 virtual leveldb::Status MaybeUpdateKeyGeneratorCurrentNumber( |
474 IndexedDBBackingStore::Transaction* transaction, | 477 IndexedDBBackingStore::Transaction* transaction, |
475 int64 database_id, | 478 int64_t database_id, |
476 int64 object_store_id, | 479 int64_t object_store_id, |
477 int64 new_state, | 480 int64_t new_state, |
478 bool check_current) WARN_UNUSED_RESULT; | 481 bool check_current) WARN_UNUSED_RESULT; |
479 virtual leveldb::Status KeyExistsInObjectStore( | 482 virtual leveldb::Status KeyExistsInObjectStore( |
480 IndexedDBBackingStore::Transaction* transaction, | 483 IndexedDBBackingStore::Transaction* transaction, |
481 int64 database_id, | 484 int64_t database_id, |
482 int64 object_store_id, | 485 int64_t object_store_id, |
483 const IndexedDBKey& key, | 486 const IndexedDBKey& key, |
484 RecordIdentifier* found_record_identifier, | 487 RecordIdentifier* found_record_identifier, |
485 bool* found) WARN_UNUSED_RESULT; | 488 bool* found) WARN_UNUSED_RESULT; |
486 | 489 |
487 virtual leveldb::Status CreateIndex( | 490 virtual leveldb::Status CreateIndex( |
488 IndexedDBBackingStore::Transaction* transaction, | 491 IndexedDBBackingStore::Transaction* transaction, |
489 int64 database_id, | 492 int64_t database_id, |
490 int64 object_store_id, | 493 int64_t object_store_id, |
491 int64 index_id, | 494 int64_t index_id, |
492 const base::string16& name, | 495 const base::string16& name, |
493 const IndexedDBKeyPath& key_path, | 496 const IndexedDBKeyPath& key_path, |
494 bool is_unique, | 497 bool is_unique, |
495 bool is_multi_entry) WARN_UNUSED_RESULT; | 498 bool is_multi_entry) WARN_UNUSED_RESULT; |
496 virtual leveldb::Status DeleteIndex( | 499 virtual leveldb::Status DeleteIndex( |
497 IndexedDBBackingStore::Transaction* transaction, | 500 IndexedDBBackingStore::Transaction* transaction, |
498 int64 database_id, | 501 int64_t database_id, |
499 int64 object_store_id, | 502 int64_t object_store_id, |
500 int64 index_id) WARN_UNUSED_RESULT; | 503 int64_t index_id) WARN_UNUSED_RESULT; |
501 virtual leveldb::Status PutIndexDataForRecord( | 504 virtual leveldb::Status PutIndexDataForRecord( |
502 IndexedDBBackingStore::Transaction* transaction, | 505 IndexedDBBackingStore::Transaction* transaction, |
503 int64 database_id, | 506 int64_t database_id, |
504 int64 object_store_id, | 507 int64_t object_store_id, |
505 int64 index_id, | 508 int64_t index_id, |
506 const IndexedDBKey& key, | 509 const IndexedDBKey& key, |
507 const RecordIdentifier& record) WARN_UNUSED_RESULT; | 510 const RecordIdentifier& record) WARN_UNUSED_RESULT; |
508 virtual leveldb::Status GetPrimaryKeyViaIndex( | 511 virtual leveldb::Status GetPrimaryKeyViaIndex( |
509 IndexedDBBackingStore::Transaction* transaction, | 512 IndexedDBBackingStore::Transaction* transaction, |
510 int64 database_id, | 513 int64_t database_id, |
511 int64 object_store_id, | 514 int64_t object_store_id, |
512 int64 index_id, | 515 int64_t index_id, |
513 const IndexedDBKey& key, | 516 const IndexedDBKey& key, |
514 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; | 517 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; |
515 virtual leveldb::Status KeyExistsInIndex( | 518 virtual leveldb::Status KeyExistsInIndex( |
516 IndexedDBBackingStore::Transaction* transaction, | 519 IndexedDBBackingStore::Transaction* transaction, |
517 int64 database_id, | 520 int64_t database_id, |
518 int64 object_store_id, | 521 int64_t object_store_id, |
519 int64 index_id, | 522 int64_t index_id, |
520 const IndexedDBKey& key, | 523 const IndexedDBKey& key, |
521 scoped_ptr<IndexedDBKey>* found_primary_key, | 524 scoped_ptr<IndexedDBKey>* found_primary_key, |
522 bool* exists) WARN_UNUSED_RESULT; | 525 bool* exists) WARN_UNUSED_RESULT; |
523 | 526 |
524 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. | 527 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. |
525 virtual void ReportBlobUnused(int64 database_id, int64 blob_key); | 528 virtual void ReportBlobUnused(int64_t database_id, int64_t blob_key); |
526 | 529 |
527 base::FilePath GetBlobFileName(int64 database_id, int64 key) const; | 530 base::FilePath GetBlobFileName(int64_t database_id, int64_t key) const; |
528 | 531 |
529 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( | 532 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( |
530 IndexedDBBackingStore::Transaction* transaction, | 533 IndexedDBBackingStore::Transaction* transaction, |
531 int64 database_id, | 534 int64_t database_id, |
532 int64 object_store_id, | 535 int64_t object_store_id, |
533 const IndexedDBKeyRange& key_range, | 536 const IndexedDBKeyRange& key_range, |
534 blink::WebIDBCursorDirection, | 537 blink::WebIDBCursorDirection, |
535 leveldb::Status*); | 538 leveldb::Status*); |
536 virtual scoped_ptr<Cursor> OpenObjectStoreCursor( | 539 virtual scoped_ptr<Cursor> OpenObjectStoreCursor( |
537 IndexedDBBackingStore::Transaction* transaction, | 540 IndexedDBBackingStore::Transaction* transaction, |
538 int64 database_id, | 541 int64_t database_id, |
539 int64 object_store_id, | 542 int64_t object_store_id, |
540 const IndexedDBKeyRange& key_range, | 543 const IndexedDBKeyRange& key_range, |
541 blink::WebIDBCursorDirection, | 544 blink::WebIDBCursorDirection, |
542 leveldb::Status*); | 545 leveldb::Status*); |
543 virtual scoped_ptr<Cursor> OpenIndexKeyCursor( | 546 virtual scoped_ptr<Cursor> OpenIndexKeyCursor( |
544 IndexedDBBackingStore::Transaction* transaction, | 547 IndexedDBBackingStore::Transaction* transaction, |
545 int64 database_id, | 548 int64_t database_id, |
546 int64 object_store_id, | 549 int64_t object_store_id, |
547 int64 index_id, | 550 int64_t index_id, |
548 const IndexedDBKeyRange& key_range, | 551 const IndexedDBKeyRange& key_range, |
549 blink::WebIDBCursorDirection, | 552 blink::WebIDBCursorDirection, |
550 leveldb::Status*); | 553 leveldb::Status*); |
551 virtual scoped_ptr<Cursor> OpenIndexCursor( | 554 virtual scoped_ptr<Cursor> OpenIndexCursor( |
552 IndexedDBBackingStore::Transaction* transaction, | 555 IndexedDBBackingStore::Transaction* transaction, |
553 int64 database_id, | 556 int64_t database_id, |
554 int64 object_store_id, | 557 int64_t object_store_id, |
555 int64 index_id, | 558 int64_t index_id, |
556 const IndexedDBKeyRange& key_range, | 559 const IndexedDBKeyRange& key_range, |
557 blink::WebIDBCursorDirection, | 560 blink::WebIDBCursorDirection, |
558 leveldb::Status*); | 561 leveldb::Status*); |
559 | 562 |
560 protected: | 563 protected: |
561 friend class base::RefCounted<IndexedDBBackingStore>; | 564 friend class base::RefCounted<IndexedDBBackingStore>; |
562 | 565 |
563 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 566 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
564 const GURL& origin_url, | 567 const GURL& origin_url, |
565 const base::FilePath& blob_path, | 568 const base::FilePath& blob_path, |
566 net::URLRequestContext* request_context, | 569 net::URLRequestContext* request_context, |
567 scoped_ptr<LevelDBDatabase> db, | 570 scoped_ptr<LevelDBDatabase> db, |
568 scoped_ptr<LevelDBComparator> comparator, | 571 scoped_ptr<LevelDBComparator> comparator, |
569 base::SequencedTaskRunner* task_runner); | 572 base::SequencedTaskRunner* task_runner); |
570 virtual ~IndexedDBBackingStore(); | 573 virtual ~IndexedDBBackingStore(); |
571 | 574 |
572 bool is_incognito() const { return !indexed_db_factory_; } | 575 bool is_incognito() const { return !indexed_db_factory_; } |
573 | 576 |
574 leveldb::Status SetUpMetadata(); | 577 leveldb::Status SetUpMetadata(); |
575 | 578 |
576 virtual bool WriteBlobFile( | 579 virtual bool WriteBlobFile( |
577 int64 database_id, | 580 int64_t database_id, |
578 const Transaction::WriteDescriptor& descriptor, | 581 const Transaction::WriteDescriptor& descriptor, |
579 Transaction::ChainedBlobWriter* chained_blob_writer); | 582 Transaction::ChainedBlobWriter* chained_blob_writer); |
580 | 583 |
581 // Remove the referenced file on disk. | 584 // Remove the referenced file on disk. |
582 virtual bool RemoveBlobFile(int64 database_id, int64 key) const; | 585 virtual bool RemoveBlobFile(int64_t database_id, int64_t key) const; |
583 | 586 |
584 // Schedule a call to CleanPrimaryJournalIgnoreReturn() via | 587 // Schedule a call to CleanPrimaryJournalIgnoreReturn() via |
585 // an owned timer. If this object is destroyed, the timer | 588 // an owned timer. If this object is destroyed, the timer |
586 // will automatically be cancelled. | 589 // will automatically be cancelled. |
587 virtual void StartJournalCleaningTimer(); | 590 virtual void StartJournalCleaningTimer(); |
588 | 591 |
589 // Attempt to clean the primary journal. This will remove | 592 // Attempt to clean the primary journal. This will remove |
590 // any referenced files and delete the journal entry. If any | 593 // any referenced files and delete the journal entry. If any |
591 // transaction is currently committing this will be deferred | 594 // transaction is currently committing this will be deferred |
592 // via StartJournalCleaningTimer(). | 595 // via StartJournalCleaningTimer(). |
593 void CleanPrimaryJournalIgnoreReturn(); | 596 void CleanPrimaryJournalIgnoreReturn(); |
594 | 597 |
595 private: | 598 private: |
596 static scoped_refptr<IndexedDBBackingStore> Create( | 599 static scoped_refptr<IndexedDBBackingStore> Create( |
597 IndexedDBFactory* indexed_db_factory, | 600 IndexedDBFactory* indexed_db_factory, |
598 const GURL& origin_url, | 601 const GURL& origin_url, |
599 const base::FilePath& blob_path, | 602 const base::FilePath& blob_path, |
600 net::URLRequestContext* request_context, | 603 net::URLRequestContext* request_context, |
601 scoped_ptr<LevelDBDatabase> db, | 604 scoped_ptr<LevelDBDatabase> db, |
602 scoped_ptr<LevelDBComparator> comparator, | 605 scoped_ptr<LevelDBComparator> comparator, |
603 base::SequencedTaskRunner* task_runner, | 606 base::SequencedTaskRunner* task_runner, |
604 leveldb::Status* status); | 607 leveldb::Status* status); |
605 | 608 |
606 static bool ReadCorruptionInfo(const base::FilePath& path_base, | 609 static bool ReadCorruptionInfo(const base::FilePath& path_base, |
607 const GURL& origin_url, | 610 const GURL& origin_url, |
608 std::string* message); | 611 std::string* message); |
609 | 612 |
610 leveldb::Status FindKeyInIndex( | 613 leveldb::Status FindKeyInIndex( |
611 IndexedDBBackingStore::Transaction* transaction, | 614 IndexedDBBackingStore::Transaction* transaction, |
612 int64 database_id, | 615 int64_t database_id, |
613 int64 object_store_id, | 616 int64_t object_store_id, |
614 int64 index_id, | 617 int64_t index_id, |
615 const IndexedDBKey& key, | 618 const IndexedDBKey& key, |
616 std::string* found_encoded_primary_key, | 619 std::string* found_encoded_primary_key, |
617 bool* found); | 620 bool* found); |
618 leveldb::Status GetIndexes(int64 database_id, | 621 leveldb::Status GetIndexes(int64_t database_id, |
619 int64 object_store_id, | 622 int64_t object_store_id, |
620 IndexedDBObjectStoreMetadata::IndexMap* map) | 623 IndexedDBObjectStoreMetadata::IndexMap* map) |
621 WARN_UNUSED_RESULT; | 624 WARN_UNUSED_RESULT; |
622 | 625 |
623 // Remove the blob directory for the specified database and all contained | 626 // Remove the blob directory for the specified database and all contained |
624 // blob files. | 627 // blob files. |
625 bool RemoveBlobDirectory(int64 database_id) const; | 628 bool RemoveBlobDirectory(int64_t database_id) const; |
626 | 629 |
627 // Synchronously read the key-specified blob journal entry from the backing | 630 // Synchronously read the key-specified blob journal entry from the backing |
628 // store, delete all referenced blob files, and erase the journal entry. | 631 // store, delete all referenced blob files, and erase the journal entry. |
629 // This must not be used while temporary entries are present e.g. during | 632 // This must not be used while temporary entries are present e.g. during |
630 // a two-stage transaction commit with blobs. | 633 // a two-stage transaction commit with blobs. |
631 leveldb::Status CleanUpBlobJournal(const std::string& level_db_key) const; | 634 leveldb::Status CleanUpBlobJournal(const std::string& level_db_key) const; |
632 | 635 |
633 // Synchronously delete the files and/or directories on disk referenced by | 636 // Synchronously delete the files and/or directories on disk referenced by |
634 // the blob journal. | 637 // the blob journal. |
635 leveldb::Status CleanUpBlobJournalEntries( | 638 leveldb::Status CleanUpBlobJournalEntries( |
(...skipping 28 matching lines...) Expand all Loading... |
664 // complete. While > 0, temporary journal entries may exist so out-of-band | 667 // complete. While > 0, temporary journal entries may exist so out-of-band |
665 // journal cleaning must be deferred. | 668 // journal cleaning must be deferred. |
666 size_t committing_transaction_count_; | 669 size_t committing_transaction_count_; |
667 | 670 |
668 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); | 671 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); |
669 }; | 672 }; |
670 | 673 |
671 } // namespace content | 674 } // namespace content |
672 | 675 |
673 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 676 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
OLD | NEW |