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 417573004: indexeddb: Removed use of dangling ptr in writeBlobToFileOnIOThread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Including <string> to make "git cl lint" happy 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>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/sequenced_task_runner.h"
michaeln 2014/07/24 00:20:23 would a fwrd decl work in here?
cmumford 2014/07/24 18:18:26 If I change task_runner() to return a SequencedTas
18 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "base/timer/timer.h" 21 #include "base/timer/timer.h"
21 #include "content/browser/indexed_db/indexed_db.h" 22 #include "content/browser/indexed_db/indexed_db.h"
22 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" 23 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
23 #include "content/browser/indexed_db/indexed_db_blob_info.h" 24 #include "content/browser/indexed_db/indexed_db_blob_info.h"
24 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" 25 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
25 #include "content/browser/indexed_db/indexed_db_metadata.h" 26 #include "content/browser/indexed_db/indexed_db_metadata.h"
26 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 27 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
27 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 28 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
28 #include "content/common/content_export.h" 29 #include "content/common/content_export.h"
29 #include "content/common/indexed_db/indexed_db_key.h" 30 #include "content/common/indexed_db/indexed_db_key.h"
30 #include "content/common/indexed_db/indexed_db_key_path.h" 31 #include "content/common/indexed_db/indexed_db_key_path.h"
31 #include "content/common/indexed_db/indexed_db_key_range.h" 32 #include "content/common/indexed_db/indexed_db_key_range.h"
32 #include "third_party/leveldatabase/src/include/leveldb/status.h" 33 #include "third_party/leveldatabase/src/include/leveldb/status.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 #include "webkit/browser/blob/blob_data_handle.h" 35 #include "webkit/browser/blob/blob_data_handle.h"
35 36
36 namespace base {
37 class TaskRunner;
38 }
39
40 namespace fileapi { 37 namespace fileapi {
41 class FileWriterDelegate; 38 class FileWriterDelegate;
42 } 39 }
43 40
44 namespace net { 41 namespace net {
45 class URLRequestContext; 42 class URLRequestContext;
46 } 43 }
47 44
48 namespace content { 45 namespace content {
49 46
(...skipping 26 matching lines...) Expand all
76 } 73 }
77 74
78 static scoped_refptr<IndexedDBBackingStore> Open( 75 static scoped_refptr<IndexedDBBackingStore> Open(
79 IndexedDBFactory* indexed_db_factory, 76 IndexedDBFactory* indexed_db_factory,
80 const GURL& origin_url, 77 const GURL& origin_url,
81 const base::FilePath& path_base, 78 const base::FilePath& path_base,
82 net::URLRequestContext* request_context, 79 net::URLRequestContext* request_context,
83 blink::WebIDBDataLoss* data_loss, 80 blink::WebIDBDataLoss* data_loss,
84 std::string* data_loss_message, 81 std::string* data_loss_message,
85 bool* disk_full, 82 bool* disk_full,
86 base::TaskRunner* task_runner, 83 base::SequencedTaskRunner* task_runner,
87 bool clean_journal, 84 bool clean_journal,
88 leveldb::Status* status); 85 leveldb::Status* status);
89 static scoped_refptr<IndexedDBBackingStore> Open( 86 static scoped_refptr<IndexedDBBackingStore> Open(
90 IndexedDBFactory* indexed_db_factory, 87 IndexedDBFactory* indexed_db_factory,
91 const GURL& origin_url, 88 const GURL& origin_url,
92 const base::FilePath& path_base, 89 const base::FilePath& path_base,
93 net::URLRequestContext* request_context, 90 net::URLRequestContext* request_context,
94 blink::WebIDBDataLoss* data_loss, 91 blink::WebIDBDataLoss* data_loss,
95 std::string* data_loss_message, 92 std::string* data_loss_message,
96 bool* disk_full, 93 bool* disk_full,
97 LevelDBFactory* leveldb_factory, 94 LevelDBFactory* leveldb_factory,
98 base::TaskRunner* task_runner, 95 base::SequencedTaskRunner* task_runner,
99 bool clean_journal, 96 bool clean_journal,
100 leveldb::Status* status); 97 leveldb::Status* status);
101 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 98 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
102 const GURL& origin_url, 99 const GURL& origin_url,
103 base::TaskRunner* task_runner, 100 base::SequencedTaskRunner* task_runner,
104 leveldb::Status* status); 101 leveldb::Status* status);
105 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 102 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
106 const GURL& origin_url, 103 const GURL& origin_url,
107 LevelDBFactory* leveldb_factory, 104 LevelDBFactory* leveldb_factory,
108 base::TaskRunner* task_runner, 105 base::SequencedTaskRunner* task_runner,
109 leveldb::Status* status); 106 leveldb::Status* status);
110 107
111 void GrantChildProcessPermissions(int child_process_id); 108 void GrantChildProcessPermissions(int child_process_id);
112 109
113 // Compact is public for testing. 110 // Compact is public for testing.
114 virtual void Compact(); 111 virtual void Compact();
115 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); 112 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*);
116 virtual leveldb::Status GetIDBDatabaseMetaData( 113 virtual leveldb::Status GetIDBDatabaseMetaData(
117 const base::string16& name, 114 const base::string16& name,
118 IndexedDBDatabaseMetadata* metadata, 115 IndexedDBDatabaseMetadata* metadata,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::string primary_key_; 165 std::string primary_key_;
169 int64 version_; 166 int64 version_;
170 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); 167 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier);
171 }; 168 };
172 169
173 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { 170 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> {
174 public: 171 public:
175 virtual void Run(bool succeeded) = 0; 172 virtual void Run(bool succeeded) = 0;
176 173
177 protected: 174 protected:
175 friend class base::RefCounted<BlobWriteCallback>;
178 virtual ~BlobWriteCallback() {} 176 virtual ~BlobWriteCallback() {}
179 friend class base::RefCounted<BlobWriteCallback>;
180 }; 177 };
181 178
182 virtual leveldb::Status GetRecord( 179 virtual leveldb::Status GetRecord(
183 IndexedDBBackingStore::Transaction* transaction, 180 IndexedDBBackingStore::Transaction* transaction,
184 int64 database_id, 181 int64 database_id,
185 int64 object_store_id, 182 int64 object_store_id,
186 const IndexedDBKey& key, 183 const IndexedDBKey& key,
187 IndexedDBValue* record) WARN_UNUSED_RESULT; 184 IndexedDBValue* record) WARN_UNUSED_RESULT;
188 virtual leveldb::Status PutRecord( 185 virtual leveldb::Status PutRecord(
189 IndexedDBBackingStore::Transaction* transaction, 186 IndexedDBBackingStore::Transaction* transaction,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 449
453 private: 450 private:
454 bool is_file_; 451 bool is_file_;
455 GURL url_; 452 GURL url_;
456 base::FilePath file_path_; 453 base::FilePath file_path_;
457 int64_t key_; 454 int64_t key_;
458 int64_t size_; 455 int64_t size_;
459 base::Time last_modified_; 456 base::Time last_modified_;
460 }; 457 };
461 458
462 class ChainedBlobWriter : public base::RefCounted<ChainedBlobWriter> { 459 class ChainedBlobWriter
460 : public base::RefCountedThreadSafe<ChainedBlobWriter> {
463 public: 461 public:
464 virtual void set_delegate( 462 virtual void set_delegate(
465 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; 463 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0;
466 464
467 // TODO(ericu): Add a reason in the event of failure. 465 // TODO(ericu): Add a reason in the event of failure.
468 virtual void ReportWriteCompletion(bool succeeded, 466 virtual void ReportWriteCompletion(bool succeeded,
469 int64 bytes_written) = 0; 467 int64 bytes_written) = 0;
470 468
471 virtual void Abort() = 0; 469 virtual void Abort() = 0;
472 470
473 protected: 471 protected:
472 friend class base::RefCountedThreadSafe<ChainedBlobWriter>;
474 virtual ~ChainedBlobWriter() {} 473 virtual ~ChainedBlobWriter() {}
475 friend class base::RefCounted<ChainedBlobWriter>;
476 }; 474 };
477 475
478 class ChainedBlobWriterImpl; 476 class ChainedBlobWriterImpl;
479 477
480 typedef std::vector<WriteDescriptor> WriteDescriptorVec; 478 typedef std::vector<WriteDescriptor> WriteDescriptorVec;
481 479
482 private: 480 private:
483 class BlobWriteCallbackWrapper; 481 class BlobWriteCallbackWrapper;
484 482
485 leveldb::Status HandleBlobPreTransaction( 483 leveldb::Status HandleBlobPreTransaction(
(...skipping 10 matching lines...) Expand all
496 IndexedDBBackingStore* backing_store_; 494 IndexedDBBackingStore* backing_store_;
497 scoped_refptr<LevelDBTransaction> transaction_; 495 scoped_refptr<LevelDBTransaction> transaction_;
498 BlobChangeMap blob_change_map_; 496 BlobChangeMap blob_change_map_;
499 BlobChangeMap incognito_blob_map_; 497 BlobChangeMap incognito_blob_map_;
500 int64 database_id_; 498 int64 database_id_;
501 BlobJournalType blobs_to_remove_; 499 BlobJournalType blobs_to_remove_;
502 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; 500 scoped_refptr<ChainedBlobWriter> chained_blob_writer_;
503 }; 501 };
504 502
505 protected: 503 protected:
504 friend class base::RefCounted<IndexedDBBackingStore>;
506 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 505 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
507 const GURL& origin_url, 506 const GURL& origin_url,
508 const base::FilePath& blob_path, 507 const base::FilePath& blob_path,
509 net::URLRequestContext* request_context, 508 net::URLRequestContext* request_context,
510 scoped_ptr<LevelDBDatabase> db, 509 scoped_ptr<LevelDBDatabase> db,
511 scoped_ptr<LevelDBComparator> comparator, 510 scoped_ptr<LevelDBComparator> comparator,
512 base::TaskRunner* task_runner); 511 base::SequencedTaskRunner* task_runner);
513 virtual ~IndexedDBBackingStore(); 512 virtual ~IndexedDBBackingStore();
514 friend class base::RefCounted<IndexedDBBackingStore>;
515 513
516 bool is_incognito() const { return !indexed_db_factory_; } 514 bool is_incognito() const { return !indexed_db_factory_; }
517 515
518 leveldb::Status SetUpMetadata(); 516 leveldb::Status SetUpMetadata();
519 517
520 virtual bool WriteBlobFile( 518 virtual bool WriteBlobFile(
521 int64 database_id, 519 int64 database_id,
522 const Transaction::WriteDescriptor& descriptor, 520 const Transaction::WriteDescriptor& descriptor,
523 Transaction::ChainedBlobWriter* chained_blob_writer); 521 Transaction::ChainedBlobWriter* chained_blob_writer);
524 virtual bool RemoveBlobFile(int64 database_id, int64 key); 522 virtual bool RemoveBlobFile(int64 database_id, int64 key);
525 virtual void StartJournalCleaningTimer(); 523 virtual void StartJournalCleaningTimer();
526 void CleanPrimaryJournalIgnoreReturn(); 524 void CleanPrimaryJournalIgnoreReturn();
527 525
528 private: 526 private:
529 static scoped_refptr<IndexedDBBackingStore> Create( 527 static scoped_refptr<IndexedDBBackingStore> Create(
530 IndexedDBFactory* indexed_db_factory, 528 IndexedDBFactory* indexed_db_factory,
531 const GURL& origin_url, 529 const GURL& origin_url,
532 const base::FilePath& blob_path, 530 const base::FilePath& blob_path,
533 net::URLRequestContext* request_context, 531 net::URLRequestContext* request_context,
534 scoped_ptr<LevelDBDatabase> db, 532 scoped_ptr<LevelDBDatabase> db,
535 scoped_ptr<LevelDBComparator> comparator, 533 scoped_ptr<LevelDBComparator> comparator,
536 base::TaskRunner* task_runner, 534 base::SequencedTaskRunner* task_runner,
537 leveldb::Status* status); 535 leveldb::Status* status);
538 536
539 static bool ReadCorruptionInfo(const base::FilePath& path_base, 537 static bool ReadCorruptionInfo(const base::FilePath& path_base,
540 const GURL& origin_url, 538 const GURL& origin_url,
541 std::string* message); 539 std::string* message);
542 540
543 leveldb::Status FindKeyInIndex( 541 leveldb::Status FindKeyInIndex(
544 IndexedDBBackingStore::Transaction* transaction, 542 IndexedDBBackingStore::Transaction* transaction,
545 int64 database_id, 543 int64 database_id,
546 int64 object_store_id, 544 int64 object_store_id,
(...skipping 14 matching lines...) Expand all
561 559
562 // The origin identifier is a key prefix unique to the origin used in the 560 // 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 561 // 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. 562 // 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 563 // "http_localhost_81@1" Since only one origin is stored per backing store
566 // this is redundant but necessary for backwards compatibility; the suffix 564 // this is redundant but necessary for backwards compatibility; the suffix
567 // provides for future flexibility. 565 // provides for future flexibility.
568 const std::string origin_identifier_; 566 const std::string origin_identifier_;
569 567
570 net::URLRequestContext* request_context_; 568 net::URLRequestContext* request_context_;
571 base::TaskRunner* task_runner_; 569 base::SequencedTaskRunner* task_runner_;
michaeln 2014/07/24 00:20:24 huh... i'm surprised this is not a scoped_refptr<T
cmumford 2014/07/24 18:18:26 Not in indexed_db_context_impl.h either.
572 std::set<int> child_process_ids_granted_; 570 std::set<int> child_process_ids_granted_;
573 BlobChangeMap incognito_blob_map_; 571 BlobChangeMap incognito_blob_map_;
574 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_; 572 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_;
575 573
576 scoped_ptr<LevelDBDatabase> db_; 574 scoped_ptr<LevelDBDatabase> db_;
577 scoped_ptr<LevelDBComparator> comparator_; 575 scoped_ptr<LevelDBComparator> comparator_;
578 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ 576 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_
579 // will hold a reference to this backing store. 577 // will hold a reference to this backing store.
580 IndexedDBActiveBlobRegistry active_blob_registry_; 578 IndexedDBActiveBlobRegistry active_blob_registry_;
581 base::OneShotTimer<IndexedDBBackingStore> close_timer_; 579 base::OneShotTimer<IndexedDBBackingStore> close_timer_;
582 580
583 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); 581 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore);
584 }; 582 };
585 583
586 } // namespace content 584 } // namespace content
587 585
588 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ 586 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698