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

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store.h

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DeleteRange now seems to work. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 RecordIdentifier* record) WARN_UNUSED_RESULT; 196 RecordIdentifier* record) WARN_UNUSED_RESULT;
197 virtual leveldb::Status ClearObjectStore( 197 virtual leveldb::Status ClearObjectStore(
198 IndexedDBBackingStore::Transaction* transaction, 198 IndexedDBBackingStore::Transaction* transaction,
199 int64 database_id, 199 int64 database_id,
200 int64 object_store_id) WARN_UNUSED_RESULT; 200 int64 object_store_id) WARN_UNUSED_RESULT;
201 virtual leveldb::Status DeleteRecord( 201 virtual leveldb::Status DeleteRecord(
202 IndexedDBBackingStore::Transaction* transaction, 202 IndexedDBBackingStore::Transaction* transaction,
203 int64 database_id, 203 int64 database_id,
204 int64 object_store_id, 204 int64 object_store_id,
205 const RecordIdentifier& record) WARN_UNUSED_RESULT; 205 const RecordIdentifier& record) WARN_UNUSED_RESULT;
206 virtual leveldb::Status DeleteRange(
207 IndexedDBBackingStore::Transaction* transaction,
208 int64 database_id,
209 int64 object_store_id,
210 const IndexedDBKeyRange&) WARN_UNUSED_RESULT;
206 virtual leveldb::Status GetKeyGeneratorCurrentNumber( 211 virtual leveldb::Status GetKeyGeneratorCurrentNumber(
207 IndexedDBBackingStore::Transaction* transaction, 212 IndexedDBBackingStore::Transaction* transaction,
208 int64 database_id, 213 int64 database_id,
209 int64 object_store_id, 214 int64 object_store_id,
210 int64* current_number) WARN_UNUSED_RESULT; 215 int64* current_number) WARN_UNUSED_RESULT;
211 virtual leveldb::Status MaybeUpdateKeyGeneratorCurrentNumber( 216 virtual leveldb::Status MaybeUpdateKeyGeneratorCurrentNumber(
212 IndexedDBBackingStore::Transaction* transaction, 217 IndexedDBBackingStore::Transaction* transaction,
213 int64 database_id, 218 int64 database_id,
214 int64 object_store_id, 219 int64 object_store_id,
215 int64 new_state, 220 int64 new_state,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 int64 index_id, 262 int64 index_id,
258 const IndexedDBKey& key, 263 const IndexedDBKey& key,
259 scoped_ptr<IndexedDBKey>* found_primary_key, 264 scoped_ptr<IndexedDBKey>* found_primary_key,
260 bool* exists) WARN_UNUSED_RESULT; 265 bool* exists) WARN_UNUSED_RESULT;
261 266
262 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. 267 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef.
263 virtual void ReportBlobUnused(int64 database_id, int64 blob_key); 268 virtual void ReportBlobUnused(int64 database_id, int64 blob_key);
264 269
265 base::FilePath GetBlobFileName(int64 database_id, int64 key); 270 base::FilePath GetBlobFileName(int64 database_id, int64 key);
266 271
272 class Transaction;
273
267 class Cursor { 274 class Cursor {
268 public: 275 public:
269 virtual ~Cursor(); 276 virtual ~Cursor();
270 277
271 enum IteratorState { 278 enum IteratorState {
272 READY = 0, 279 READY = 0,
273 SEEK 280 SEEK
274 }; 281 };
275 282
276 struct CursorOptions { 283 struct CursorOptions {
(...skipping 24 matching lines...) Expand all
301 bool Advance(uint32 count, leveldb::Status*); 308 bool Advance(uint32 count, leveldb::Status*);
302 bool FirstSeek(leveldb::Status*); 309 bool FirstSeek(leveldb::Status*);
303 310
304 virtual Cursor* Clone() = 0; 311 virtual Cursor* Clone() = 0;
305 virtual const IndexedDBKey& primary_key() const; 312 virtual const IndexedDBKey& primary_key() const;
306 virtual IndexedDBValue* value() = 0; 313 virtual IndexedDBValue* value() = 0;
307 virtual const RecordIdentifier& record_identifier() const; 314 virtual const RecordIdentifier& record_identifier() const;
308 virtual bool LoadCurrentRow() = 0; 315 virtual bool LoadCurrentRow() = 0;
309 316
310 protected: 317 protected:
311 Cursor(LevelDBTransaction* transaction, 318 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store,
319 Transaction* transaction,
320 int64 database_id,
312 const CursorOptions& cursor_options); 321 const CursorOptions& cursor_options);
313 explicit Cursor(const IndexedDBBackingStore::Cursor* other); 322 explicit Cursor(const IndexedDBBackingStore::Cursor* other);
314 323
315 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; 324 virtual std::string EncodeKey(const IndexedDBKey& key) = 0;
316 virtual std::string EncodeKey(const IndexedDBKey& key, 325 virtual std::string EncodeKey(const IndexedDBKey& key,
317 const IndexedDBKey& primary_key) = 0; 326 const IndexedDBKey& primary_key) = 0;
318 327
319 bool IsPastBounds() const; 328 bool IsPastBounds() const;
320 bool HaveEnteredRange() const; 329 bool HaveEnteredRange() const;
321 330
322 LevelDBTransaction* transaction_; 331 IndexedDBBackingStore* backing_store_;
332 Transaction* transaction_;
333 int64 database_id_;
323 const CursorOptions cursor_options_; 334 const CursorOptions cursor_options_;
324 scoped_ptr<LevelDBIterator> iterator_; 335 scoped_ptr<LevelDBIterator> iterator_;
325 scoped_ptr<IndexedDBKey> current_key_; 336 scoped_ptr<IndexedDBKey> current_key_;
326 IndexedDBBackingStore::RecordIdentifier record_identifier_; 337 IndexedDBBackingStore::RecordIdentifier record_identifier_;
327 }; 338 };
328 339
329 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( 340 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor(
330 IndexedDBBackingStore::Transaction* transaction, 341 IndexedDBBackingStore::Transaction* transaction,
331 int64 database_id, 342 int64 database_id,
332 int64 object_store_id, 343 int64 object_store_id,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 ScopedVector<webkit_blob::BlobDataHandle> handles_; 389 ScopedVector<webkit_blob::BlobDataHandle> handles_;
379 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord); 390 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord);
380 }; 391 };
381 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; 392 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap;
382 393
383 class Transaction { 394 class Transaction {
384 public: 395 public:
385 explicit Transaction(IndexedDBBackingStore* backing_store); 396 explicit Transaction(IndexedDBBackingStore* backing_store);
386 virtual ~Transaction(); 397 virtual ~Transaction();
387 virtual void Begin(); 398 virtual void Begin();
388 virtual leveldb::Status Commit(); 399 // The callback will be called eventually on success or failure, or
400 // immediately if phase one is complete due to lack of any blobs to write.
401 virtual leveldb::Status CommitPhaseOne(scoped_refptr<BlobWriteCallback>);
402 virtual leveldb::Status CommitPhaseTwo();
389 virtual void Rollback(); 403 virtual void Rollback();
390 void Reset() { 404 void Reset() {
391 backing_store_ = NULL; 405 backing_store_ = NULL;
392 transaction_ = NULL; 406 transaction_ = NULL;
393 } 407 }
394 void PutBlobInfo(int64 database_id, 408 void PutBlobInfo(int64 database_id,
395 int64 object_store_id, 409 int64 object_store_id,
396 const std::string& object_store_data_key, 410 const std::string& object_store_data_key,
397 std::vector<IndexedDBBlobInfo>*, 411 std::vector<IndexedDBBlobInfo>*,
398 ScopedVector<webkit_blob::BlobDataHandle>* handles); 412 ScopedVector<webkit_blob::BlobDataHandle>* handles);
399 413
400 LevelDBTransaction* transaction() { return transaction_; } 414 LevelDBTransaction* transaction() { return transaction_; }
401 415
416 leveldb::Status GetBlobInfoForRecord(
417 int64 database_id,
418 const std::string& object_store_data_key,
419 IndexedDBValue* value);
420
402 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored 421 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored
403 // under that key. 422 // under that key.
404 typedef std::vector<std::pair<BlobEntryKey, std::string> > 423 typedef std::vector<std::pair<BlobEntryKey, std::string> >
405 BlobEntryKeyValuePairVec; 424 BlobEntryKeyValuePairVec;
406 425
407 class WriteDescriptor { 426 class WriteDescriptor {
408 public: 427 public:
409 WriteDescriptor(const GURL& url, int64_t key); 428 WriteDescriptor(const GURL& url, int64_t key);
410 WriteDescriptor(const base::FilePath& path, int64_t key); 429 WriteDescriptor(const base::FilePath& path, int64_t key);
411 430
(...skipping 30 matching lines...) Expand all
442 virtual ~ChainedBlobWriter() {} 461 virtual ~ChainedBlobWriter() {}
443 friend class base::RefCounted<ChainedBlobWriter>; 462 friend class base::RefCounted<ChainedBlobWriter>;
444 }; 463 };
445 class ChainedBlobWriterImpl; 464 class ChainedBlobWriterImpl;
446 465
447 typedef std::vector<WriteDescriptor> WriteDescriptorVec; 466 typedef std::vector<WriteDescriptor> WriteDescriptorVec;
448 467
449 private: 468 private:
450 class BlobWriteCallbackWrapper; 469 class BlobWriteCallbackWrapper;
451 470
471 // These return true on success, false on failure.
472 leveldb::Status HandleBlobPreTransaction(
473 BlobEntryKeyValuePairVec* new_blob_entries,
474 WriteDescriptorVec* new_files_to_write);
475 bool CollectBlobFilesToRemove();
452 // The callback will be called eventually on success or failure. 476 // The callback will be called eventually on success or failure.
453 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries, 477 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries,
454 WriteDescriptorVec& new_files_to_write, 478 WriteDescriptorVec& new_files_to_write,
455 scoped_refptr<BlobWriteCallback> callback); 479 scoped_refptr<BlobWriteCallback> callback);
480 leveldb::Status SortBlobsToRemove();
456 481
457 IndexedDBBackingStore* backing_store_; 482 IndexedDBBackingStore* backing_store_;
458 scoped_refptr<LevelDBTransaction> transaction_; 483 scoped_refptr<LevelDBTransaction> transaction_;
459 BlobChangeMap blob_change_map_; 484 BlobChangeMap blob_change_map_;
460 BlobChangeMap incognito_blob_map_; 485 BlobChangeMap incognito_blob_map_;
461 int64 database_id_; 486 int64 database_id_;
487 BlobJournalType blobs_to_remove_;
462 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; 488 scoped_refptr<ChainedBlobWriter> chained_blob_writer_;
463 }; 489 };
464 490
465 protected: 491 protected:
466 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 492 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
467 const GURL& origin_url, 493 const GURL& origin_url,
468 const base::FilePath& blob_path, 494 const base::FilePath& blob_path,
469 net::URLRequestContext* request_context, 495 net::URLRequestContext* request_context,
470 scoped_ptr<LevelDBDatabase> db, 496 scoped_ptr<LevelDBDatabase> db,
471 scoped_ptr<LevelDBComparator> comparator, 497 scoped_ptr<LevelDBComparator> comparator,
472 base::TaskRunner* task_runner); 498 base::TaskRunner* task_runner);
473 virtual ~IndexedDBBackingStore(); 499 virtual ~IndexedDBBackingStore();
474 friend class base::RefCounted<IndexedDBBackingStore>; 500 friend class base::RefCounted<IndexedDBBackingStore>;
475 501
476 bool is_incognito() const { return !indexed_db_factory_; } 502 bool is_incognito() const { return !indexed_db_factory_; }
477 503
504 bool SetUpMetadata();
505
478 virtual bool WriteBlobFile( 506 virtual bool WriteBlobFile(
479 int64 database_id, 507 int64 database_id,
480 const Transaction::WriteDescriptor& descriptor, 508 const Transaction::WriteDescriptor& descriptor,
481 Transaction::ChainedBlobWriter* chained_blob_writer); 509 Transaction::ChainedBlobWriter* chained_blob_writer);
482 virtual bool RemoveBlobFile(int64 database_id, int64 key); 510 virtual bool RemoveBlobFile(int64 database_id, int64 key);
483 virtual void StartJournalCleaningTimer(); 511 virtual void StartJournalCleaningTimer();
484 void CleanPrimaryJournalIgnoreReturn(); 512 void CleanPrimaryJournalIgnoreReturn();
485 513
486 private: 514 private:
487 static scoped_refptr<IndexedDBBackingStore> Create( 515 static scoped_refptr<IndexedDBBackingStore> Create(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 scoped_ptr<LevelDBComparator> comparator_; 562 scoped_ptr<LevelDBComparator> comparator_;
535 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ 563 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_
536 // will hold a reference to this backing store. 564 // will hold a reference to this backing store.
537 IndexedDBActiveBlobRegistry active_blob_registry_; 565 IndexedDBActiveBlobRegistry active_blob_registry_;
538 base::OneShotTimer<IndexedDBBackingStore> close_timer_; 566 base::OneShotTimer<IndexedDBBackingStore> close_timer_;
539 }; 567 };
540 568
541 } // namespace content 569 } // namespace content
542 570
543 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ 571 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698