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

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

Issue 261843004: More changes to support incognito mode in the IDB/Blob code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 std::string* data_loss_message, 100 std::string* data_loss_message,
101 bool* disk_full, 101 bool* disk_full,
102 LevelDBFactory* leveldb_factory, 102 LevelDBFactory* leveldb_factory,
103 base::TaskRunner* task_runner, 103 base::TaskRunner* task_runner,
104 bool clean_journal); 104 bool clean_journal);
105 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 105 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
106 const GURL& origin_url, 106 const GURL& origin_url,
107 base::TaskRunner* task_runner); 107 base::TaskRunner* task_runner);
108 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 108 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
109 const GURL& origin_url, 109 const GURL& origin_url,
110 LevelDBFactory* level_db_factory, 110 LevelDBFactory* leveldb_factory,
111 base::TaskRunner* task_runner); 111 base::TaskRunner* task_runner);
112 112
113 void GrantChildProcessPermissions(int child_process_id); 113 void GrantChildProcessPermissions(int child_process_id);
114 114
115 // Compact is public for testing. 115 // Compact is public for testing.
116 virtual void Compact(); 116 virtual void Compact();
117 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); 117 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*);
118 virtual leveldb::Status GetIDBDatabaseMetaData( 118 virtual leveldb::Status GetIDBDatabaseMetaData(
119 const base::string16& name, 119 const base::string16& name,
120 IndexedDBDatabaseMetadata* metadata, 120 IndexedDBDatabaseMetadata* metadata,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 leveldb::Status*); 350 leveldb::Status*);
351 virtual scoped_ptr<Cursor> OpenIndexCursor( 351 virtual scoped_ptr<Cursor> OpenIndexCursor(
352 IndexedDBBackingStore::Transaction* transaction, 352 IndexedDBBackingStore::Transaction* transaction,
353 int64 database_id, 353 int64 database_id,
354 int64 object_store_id, 354 int64 object_store_id,
355 int64 index_id, 355 int64 index_id,
356 const IndexedDBKeyRange& key_range, 356 const IndexedDBKeyRange& key_range,
357 indexed_db::CursorDirection, 357 indexed_db::CursorDirection,
358 leveldb::Status*); 358 leveldb::Status*);
359 359
360 class BlobChangeRecord {
361 public:
362 BlobChangeRecord(const std::string& key, int64 object_store_id);
363 ~BlobChangeRecord();
364 const std::string& key() const { return key_; }
365 int64 object_store_id() const { return object_store_id_; }
366 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info);
367 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; }
368 const std::vector<IndexedDBBlobInfo>& blob_info() const {
369 return blob_info_;
370 }
371 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles);
372 scoped_ptr<BlobChangeRecord> Copy() const;
jsbell 2014/05/05 22:21:23 Is 'Clone' more common? Dunno.
ericu 2014/05/05 23:03:20 [ericu@orevarmer src]$ git grep '\<Clone()' | wc -
373
374 private:
375 std::string key_;
376 int64 object_store_id_;
377 std::vector<IndexedDBBlobInfo> blob_info_;
378 ScopedVector<webkit_blob::BlobDataHandle> handles_;
379 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord);
380 };
381 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap;
382
360 class Transaction { 383 class Transaction {
361 public: 384 public:
362 explicit Transaction(IndexedDBBackingStore* backing_store); 385 explicit Transaction(IndexedDBBackingStore* backing_store);
363 virtual ~Transaction(); 386 virtual ~Transaction();
364 virtual void Begin(); 387 virtual void Begin();
365 virtual leveldb::Status Commit(); 388 virtual leveldb::Status Commit();
366 virtual void Rollback(); 389 virtual void Rollback();
367 void Reset() { 390 void Reset() {
368 backing_store_ = NULL; 391 backing_store_ = NULL;
369 transaction_ = NULL; 392 transaction_ = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 440
418 protected: 441 protected:
419 virtual ~ChainedBlobWriter() {} 442 virtual ~ChainedBlobWriter() {}
420 friend class base::RefCounted<ChainedBlobWriter>; 443 friend class base::RefCounted<ChainedBlobWriter>;
421 }; 444 };
422 class ChainedBlobWriterImpl; 445 class ChainedBlobWriterImpl;
423 446
424 typedef std::vector<WriteDescriptor> WriteDescriptorVec; 447 typedef std::vector<WriteDescriptor> WriteDescriptorVec;
425 448
426 private: 449 private:
427 class BlobChangeRecord {
428 public:
429 BlobChangeRecord(const std::string& key, int64 object_store_id);
430 ~BlobChangeRecord();
431 const std::string& key() const { return key_; }
432 int64 object_store_id() const { return object_store_id_; }
433 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info);
434 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; }
435 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles);
436
437 private:
438 std::string key_;
439 int64 object_store_id_;
440 std::vector<IndexedDBBlobInfo> blob_info_;
441 ScopedVector<webkit_blob::BlobDataHandle> handles_;
442 };
443 class BlobWriteCallbackWrapper; 450 class BlobWriteCallbackWrapper;
444 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap;
445 451
446 // The callback will be called eventually on success or failure. 452 // The callback will be called eventually on success or failure.
447 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries, 453 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries,
448 WriteDescriptorVec& new_files_to_write, 454 WriteDescriptorVec& new_files_to_write,
449 scoped_refptr<BlobWriteCallback> callback); 455 scoped_refptr<BlobWriteCallback> callback);
450 456
451 IndexedDBBackingStore* backing_store_; 457 IndexedDBBackingStore* backing_store_;
452 scoped_refptr<LevelDBTransaction> transaction_; 458 scoped_refptr<LevelDBTransaction> transaction_;
453 BlobChangeMap blob_change_map_; 459 BlobChangeMap blob_change_map_;
460 BlobChangeMap incognito_blob_map_;
454 int64 database_id_; 461 int64 database_id_;
455 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; 462 scoped_refptr<ChainedBlobWriter> chained_blob_writer_;
456 }; 463 };
457 464
458 protected: 465 protected:
459 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 466 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
460 const GURL& origin_url, 467 const GURL& origin_url,
461 const base::FilePath& blob_path, 468 const base::FilePath& blob_path,
462 net::URLRequestContext* request_context, 469 net::URLRequestContext* request_context,
463 scoped_ptr<LevelDBDatabase> db, 470 scoped_ptr<LevelDBDatabase> db,
464 scoped_ptr<LevelDBComparator> comparator, 471 scoped_ptr<LevelDBComparator> comparator,
465 base::TaskRunner* task_runner); 472 base::TaskRunner* task_runner);
466 virtual ~IndexedDBBackingStore(); 473 virtual ~IndexedDBBackingStore();
467 friend class base::RefCounted<IndexedDBBackingStore>; 474 friend class base::RefCounted<IndexedDBBackingStore>;
468 475
476 bool is_incognito() const { return !indexed_db_factory_; }
477
469 virtual bool WriteBlobFile( 478 virtual bool WriteBlobFile(
470 int64 database_id, 479 int64 database_id,
471 const Transaction::WriteDescriptor& descriptor, 480 const Transaction::WriteDescriptor& descriptor,
472 Transaction::ChainedBlobWriter* chained_blob_writer); 481 Transaction::ChainedBlobWriter* chained_blob_writer);
473 virtual bool RemoveBlobFile(int64 database_id, int64 key); 482 virtual bool RemoveBlobFile(int64 database_id, int64 key);
474 virtual void StartJournalCleaningTimer(); 483 virtual void StartJournalCleaningTimer();
475 void CleanPrimaryJournalIgnoreReturn(); 484 void CleanPrimaryJournalIgnoreReturn();
476 485
477 private: 486 private:
478 static scoped_refptr<IndexedDBBackingStore> Create( 487 static scoped_refptr<IndexedDBBackingStore> Create(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // leveldb backing store to partition data by origin. It is a normalized 520 // leveldb backing store to partition data by origin. It is a normalized
512 // version of the origin URL with a versioning suffix appended, e.g. 521 // version of the origin URL with a versioning suffix appended, e.g.
513 // "http_localhost_81@1" Since only one origin is stored per backing store 522 // "http_localhost_81@1" Since only one origin is stored per backing store
514 // this is redundant but necessary for backwards compatibility; the suffix 523 // this is redundant but necessary for backwards compatibility; the suffix
515 // provides for future flexibility. 524 // provides for future flexibility.
516 const std::string origin_identifier_; 525 const std::string origin_identifier_;
517 526
518 net::URLRequestContext* request_context_; 527 net::URLRequestContext* request_context_;
519 base::TaskRunner* task_runner_; 528 base::TaskRunner* task_runner_;
520 std::set<int> child_process_ids_granted_; 529 std::set<int> child_process_ids_granted_;
530 BlobChangeMap incognito_blob_map_;
521 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_; 531 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_;
522 532
523 scoped_ptr<LevelDBDatabase> db_; 533 scoped_ptr<LevelDBDatabase> db_;
524 scoped_ptr<LevelDBComparator> comparator_; 534 scoped_ptr<LevelDBComparator> comparator_;
525 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ 535 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_
526 // will hold a reference to this backing store. 536 // will hold a reference to this backing store.
527 IndexedDBActiveBlobRegistry active_blob_registry_; 537 IndexedDBActiveBlobRegistry active_blob_registry_;
528 base::OneShotTimer<IndexedDBBackingStore> close_timer_; 538 base::OneShotTimer<IndexedDBBackingStore> close_timer_;
529 }; 539 };
530 540
531 } // namespace content 541 } // namespace content
532 542
533 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ 543 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698