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

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

Issue 417573004: indexeddb: Removed use of dangling ptr in writeBlobToFileOnIOThread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also scoped LocalWriteClosure::task_runner_ Created 6 years, 5 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
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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 16 matching lines...) Expand all
27 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 27 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
28 #include "content/common/content_export.h" 28 #include "content/common/content_export.h"
29 #include "content/common/indexed_db/indexed_db_key.h" 29 #include "content/common/indexed_db/indexed_db_key.h"
30 #include "content/common/indexed_db/indexed_db_key_path.h" 30 #include "content/common/indexed_db/indexed_db_key_path.h"
31 #include "content/common/indexed_db/indexed_db_key_range.h" 31 #include "content/common/indexed_db/indexed_db_key_range.h"
32 #include "third_party/leveldatabase/src/include/leveldb/status.h" 32 #include "third_party/leveldatabase/src/include/leveldb/status.h"
33 #include "url/gurl.h" 33 #include "url/gurl.h"
34 #include "webkit/browser/blob/blob_data_handle.h" 34 #include "webkit/browser/blob/blob_data_handle.h"
35 35
36 namespace base { 36 namespace base {
37 class TaskRunner; 37 class SequencedTaskRunner;
38 } 38 }
39 39
40 namespace fileapi { 40 namespace fileapi {
41 class FileWriterDelegate; 41 class FileWriterDelegate;
42 } 42 }
43 43
44 namespace net { 44 namespace net {
45 class URLRequestContext; 45 class URLRequestContext;
46 } 46 }
47 47
(...skipping 12 matching lines...) Expand all
60 60
61 class CONTENT_EXPORT Comparator : public LevelDBComparator { 61 class CONTENT_EXPORT Comparator : public LevelDBComparator {
62 public: 62 public:
63 virtual int Compare(const base::StringPiece& a, 63 virtual int Compare(const base::StringPiece& a,
64 const base::StringPiece& b) const OVERRIDE; 64 const base::StringPiece& b) const OVERRIDE;
65 virtual const char* Name() const OVERRIDE; 65 virtual const char* Name() const OVERRIDE;
66 }; 66 };
67 67
68 const GURL& origin_url() const { return origin_url_; } 68 const GURL& origin_url() const { return origin_url_; }
69 IndexedDBFactory* factory() const { return indexed_db_factory_; } 69 IndexedDBFactory* factory() const { return indexed_db_factory_; }
70 base::TaskRunner* task_runner() const { return task_runner_; } 70 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); }
71 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { 71 base::OneShotTimer<IndexedDBBackingStore>* close_timer() {
72 return &close_timer_; 72 return &close_timer_;
73 } 73 }
74 IndexedDBActiveBlobRegistry* active_blob_registry() { 74 IndexedDBActiveBlobRegistry* active_blob_registry() {
75 return &active_blob_registry_; 75 return &active_blob_registry_;
76 } 76 }
77 77
78 static scoped_refptr<IndexedDBBackingStore> Open( 78 static scoped_refptr<IndexedDBBackingStore> Open(
79 IndexedDBFactory* indexed_db_factory, 79 IndexedDBFactory* indexed_db_factory,
80 const GURL& origin_url, 80 const GURL& origin_url,
81 const base::FilePath& path_base, 81 const base::FilePath& path_base,
82 net::URLRequestContext* request_context, 82 net::URLRequestContext* request_context,
83 blink::WebIDBDataLoss* data_loss, 83 blink::WebIDBDataLoss* data_loss,
84 std::string* data_loss_message, 84 std::string* data_loss_message,
85 bool* disk_full, 85 bool* disk_full,
86 base::TaskRunner* task_runner, 86 base::SequencedTaskRunner* task_runner,
87 bool clean_journal, 87 bool clean_journal,
88 leveldb::Status* status); 88 leveldb::Status* status);
89 static scoped_refptr<IndexedDBBackingStore> Open( 89 static scoped_refptr<IndexedDBBackingStore> Open(
90 IndexedDBFactory* indexed_db_factory, 90 IndexedDBFactory* indexed_db_factory,
91 const GURL& origin_url, 91 const GURL& origin_url,
92 const base::FilePath& path_base, 92 const base::FilePath& path_base,
93 net::URLRequestContext* request_context, 93 net::URLRequestContext* request_context,
94 blink::WebIDBDataLoss* data_loss, 94 blink::WebIDBDataLoss* data_loss,
95 std::string* data_loss_message, 95 std::string* data_loss_message,
96 bool* disk_full, 96 bool* disk_full,
97 LevelDBFactory* leveldb_factory, 97 LevelDBFactory* leveldb_factory,
98 base::TaskRunner* task_runner, 98 base::SequencedTaskRunner* task_runner,
99 bool clean_journal, 99 bool clean_journal,
100 leveldb::Status* status); 100 leveldb::Status* status);
101 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 101 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
102 const GURL& origin_url, 102 const GURL& origin_url,
103 base::TaskRunner* task_runner, 103 base::SequencedTaskRunner* task_runner,
104 leveldb::Status* status); 104 leveldb::Status* status);
105 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 105 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
106 const GURL& origin_url, 106 const GURL& origin_url,
107 LevelDBFactory* leveldb_factory, 107 LevelDBFactory* leveldb_factory,
108 base::TaskRunner* task_runner, 108 base::SequencedTaskRunner* task_runner,
109 leveldb::Status* status); 109 leveldb::Status* status);
110 110
111 void GrantChildProcessPermissions(int child_process_id); 111 void GrantChildProcessPermissions(int child_process_id);
112 112
113 // Compact is public for testing. 113 // Compact is public for testing.
114 virtual void Compact(); 114 virtual void Compact();
115 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); 115 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*);
116 virtual leveldb::Status GetIDBDatabaseMetaData( 116 virtual leveldb::Status GetIDBDatabaseMetaData(
117 const base::string16& name, 117 const base::string16& name,
118 IndexedDBDatabaseMetadata* metadata, 118 IndexedDBDatabaseMetadata* metadata,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::string primary_key_; 168 std::string primary_key_;
169 int64 version_; 169 int64 version_;
170 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); 170 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier);
171 }; 171 };
172 172
173 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { 173 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> {
174 public: 174 public:
175 virtual void Run(bool succeeded) = 0; 175 virtual void Run(bool succeeded) = 0;
176 176
177 protected: 177 protected:
178 friend class base::RefCounted<BlobWriteCallback>;
178 virtual ~BlobWriteCallback() {} 179 virtual ~BlobWriteCallback() {}
179 friend class base::RefCounted<BlobWriteCallback>;
180 }; 180 };
181 181
182 virtual leveldb::Status GetRecord( 182 virtual leveldb::Status GetRecord(
183 IndexedDBBackingStore::Transaction* transaction, 183 IndexedDBBackingStore::Transaction* transaction,
184 int64 database_id, 184 int64 database_id,
185 int64 object_store_id, 185 int64 object_store_id,
186 const IndexedDBKey& key, 186 const IndexedDBKey& key,
187 IndexedDBValue* record) WARN_UNUSED_RESULT; 187 IndexedDBValue* record) WARN_UNUSED_RESULT;
188 virtual leveldb::Status PutRecord( 188 virtual leveldb::Status PutRecord(
189 IndexedDBBackingStore::Transaction* transaction, 189 IndexedDBBackingStore::Transaction* transaction,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 private: 453 private:
454 bool is_file_; 454 bool is_file_;
455 GURL url_; 455 GURL url_;
456 base::FilePath file_path_; 456 base::FilePath file_path_;
457 int64_t key_; 457 int64_t key_;
458 int64_t size_; 458 int64_t size_;
459 base::Time last_modified_; 459 base::Time last_modified_;
460 }; 460 };
461 461
462 class ChainedBlobWriter : public base::RefCounted<ChainedBlobWriter> { 462 class ChainedBlobWriter
463 : public base::RefCountedThreadSafe<ChainedBlobWriter> {
463 public: 464 public:
464 virtual void set_delegate( 465 virtual void set_delegate(
465 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; 466 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0;
466 467
467 // TODO(ericu): Add a reason in the event of failure. 468 // TODO(ericu): Add a reason in the event of failure.
468 virtual void ReportWriteCompletion(bool succeeded, 469 virtual void ReportWriteCompletion(bool succeeded,
469 int64 bytes_written) = 0; 470 int64 bytes_written) = 0;
470 471
471 virtual void Abort() = 0; 472 virtual void Abort() = 0;
472 473
473 protected: 474 protected:
475 friend class base::RefCountedThreadSafe<ChainedBlobWriter>;
474 virtual ~ChainedBlobWriter() {} 476 virtual ~ChainedBlobWriter() {}
475 friend class base::RefCounted<ChainedBlobWriter>;
476 }; 477 };
477 478
478 class ChainedBlobWriterImpl; 479 class ChainedBlobWriterImpl;
479 480
480 typedef std::vector<WriteDescriptor> WriteDescriptorVec; 481 typedef std::vector<WriteDescriptor> WriteDescriptorVec;
481 482
482 private: 483 private:
483 class BlobWriteCallbackWrapper; 484 class BlobWriteCallbackWrapper;
484 485
485 leveldb::Status HandleBlobPreTransaction( 486 leveldb::Status HandleBlobPreTransaction(
(...skipping 10 matching lines...) Expand all
496 IndexedDBBackingStore* backing_store_; 497 IndexedDBBackingStore* backing_store_;
497 scoped_refptr<LevelDBTransaction> transaction_; 498 scoped_refptr<LevelDBTransaction> transaction_;
498 BlobChangeMap blob_change_map_; 499 BlobChangeMap blob_change_map_;
499 BlobChangeMap incognito_blob_map_; 500 BlobChangeMap incognito_blob_map_;
500 int64 database_id_; 501 int64 database_id_;
501 BlobJournalType blobs_to_remove_; 502 BlobJournalType blobs_to_remove_;
502 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; 503 scoped_refptr<ChainedBlobWriter> chained_blob_writer_;
503 }; 504 };
504 505
505 protected: 506 protected:
507 friend class base::RefCounted<IndexedDBBackingStore>;
506 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 508 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
507 const GURL& origin_url, 509 const GURL& origin_url,
508 const base::FilePath& blob_path, 510 const base::FilePath& blob_path,
509 net::URLRequestContext* request_context, 511 net::URLRequestContext* request_context,
510 scoped_ptr<LevelDBDatabase> db, 512 scoped_ptr<LevelDBDatabase> db,
511 scoped_ptr<LevelDBComparator> comparator, 513 scoped_ptr<LevelDBComparator> comparator,
512 base::TaskRunner* task_runner); 514 base::SequencedTaskRunner* task_runner);
513 virtual ~IndexedDBBackingStore(); 515 virtual ~IndexedDBBackingStore();
514 friend class base::RefCounted<IndexedDBBackingStore>;
515 516
516 bool is_incognito() const { return !indexed_db_factory_; } 517 bool is_incognito() const { return !indexed_db_factory_; }
517 518
518 leveldb::Status SetUpMetadata(); 519 leveldb::Status SetUpMetadata();
519 520
520 virtual bool WriteBlobFile( 521 virtual bool WriteBlobFile(
521 int64 database_id, 522 int64 database_id,
522 const Transaction::WriteDescriptor& descriptor, 523 const Transaction::WriteDescriptor& descriptor,
523 Transaction::ChainedBlobWriter* chained_blob_writer); 524 Transaction::ChainedBlobWriter* chained_blob_writer);
524 virtual bool RemoveBlobFile(int64 database_id, int64 key); 525 virtual bool RemoveBlobFile(int64 database_id, int64 key);
525 virtual void StartJournalCleaningTimer(); 526 virtual void StartJournalCleaningTimer();
526 void CleanPrimaryJournalIgnoreReturn(); 527 void CleanPrimaryJournalIgnoreReturn();
527 528
528 private: 529 private:
529 static scoped_refptr<IndexedDBBackingStore> Create( 530 static scoped_refptr<IndexedDBBackingStore> Create(
530 IndexedDBFactory* indexed_db_factory, 531 IndexedDBFactory* indexed_db_factory,
531 const GURL& origin_url, 532 const GURL& origin_url,
532 const base::FilePath& blob_path, 533 const base::FilePath& blob_path,
533 net::URLRequestContext* request_context, 534 net::URLRequestContext* request_context,
534 scoped_ptr<LevelDBDatabase> db, 535 scoped_ptr<LevelDBDatabase> db,
535 scoped_ptr<LevelDBComparator> comparator, 536 scoped_ptr<LevelDBComparator> comparator,
536 base::TaskRunner* task_runner, 537 base::SequencedTaskRunner* task_runner,
537 leveldb::Status* status); 538 leveldb::Status* status);
538 539
539 static bool ReadCorruptionInfo(const base::FilePath& path_base, 540 static bool ReadCorruptionInfo(const base::FilePath& path_base,
540 const GURL& origin_url, 541 const GURL& origin_url,
541 std::string* message); 542 std::string* message);
542 543
543 leveldb::Status FindKeyInIndex( 544 leveldb::Status FindKeyInIndex(
544 IndexedDBBackingStore::Transaction* transaction, 545 IndexedDBBackingStore::Transaction* transaction,
545 int64 database_id, 546 int64 database_id,
546 int64 object_store_id, 547 int64 object_store_id,
(...skipping 14 matching lines...) Expand all
561 562
562 // The origin identifier is a key prefix unique to the origin used in the 563 // The origin identifier is a key prefix unique to the origin used in the
563 // leveldb backing store to partition data by origin. It is a normalized 564 // leveldb backing store to partition data by origin. It is a normalized
564 // version of the origin URL with a versioning suffix appended, e.g. 565 // version of the origin URL with a versioning suffix appended, e.g.
565 // "http_localhost_81@1" Since only one origin is stored per backing store 566 // "http_localhost_81@1" Since only one origin is stored per backing store
566 // this is redundant but necessary for backwards compatibility; the suffix 567 // this is redundant but necessary for backwards compatibility; the suffix
567 // provides for future flexibility. 568 // provides for future flexibility.
568 const std::string origin_identifier_; 569 const std::string origin_identifier_;
569 570
570 net::URLRequestContext* request_context_; 571 net::URLRequestContext* request_context_;
571 base::TaskRunner* task_runner_; 572 scoped_refptr<base::SequencedTaskRunner> task_runner_;
572 std::set<int> child_process_ids_granted_; 573 std::set<int> child_process_ids_granted_;
573 BlobChangeMap incognito_blob_map_; 574 BlobChangeMap incognito_blob_map_;
574 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_; 575 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_;
575 576
576 scoped_ptr<LevelDBDatabase> db_; 577 scoped_ptr<LevelDBDatabase> db_;
577 scoped_ptr<LevelDBComparator> comparator_; 578 scoped_ptr<LevelDBComparator> comparator_;
578 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ 579 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_
579 // will hold a reference to this backing store. 580 // will hold a reference to this backing store.
580 IndexedDBActiveBlobRegistry active_blob_registry_; 581 IndexedDBActiveBlobRegistry active_blob_registry_;
581 base::OneShotTimer<IndexedDBBackingStore> close_timer_; 582 base::OneShotTimer<IndexedDBBackingStore> close_timer_;
582 583
583 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); 584 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore);
584 }; 585 };
585 586
586 } // namespace content 587 } // namespace content
587 588
588 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ 589 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698