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

Unified Diff: content/browser/indexed_db/indexed_db_backing_store.cc

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: updated unittests Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_backing_store.cc
diff --git a/content/browser/indexed_db/indexed_db_backing_store.cc b/content/browser/indexed_db/indexed_db_backing_store.cc
index e09458913785c85a1b5e963db68819147f48c3a4..71ad0448b3634420bf76c9ee89c14bc18b7ca2ec 100644
--- a/content/browser/indexed_db/indexed_db_backing_store.cc
+++ b/content/browser/indexed_db/indexed_db_backing_store.cc
@@ -4066,8 +4066,10 @@ IndexedDBBackingStore::OpenIndexCursor(
IndexedDBBackingStore::Transaction::Transaction(
IndexedDBBackingStore* backing_store)
- : backing_store_(backing_store), database_id_(-1), committing_(false) {
-}
+ : backing_store_(backing_store),
+ database_id_(-1),
+ committing_(false),
+ ptr_factory_(this) {}
IndexedDBBackingStore::Transaction::~Transaction() {
DCHECK(!committing_);
@@ -4341,22 +4343,26 @@ leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseTwo() {
class IndexedDBBackingStore::Transaction::BlobWriteCallbackWrapper
: public IndexedDBBackingStore::BlobWriteCallback {
public:
- BlobWriteCallbackWrapper(IndexedDBBackingStore::Transaction* transaction,
- scoped_refptr<BlobWriteCallback> callback)
- : transaction_(transaction), callback_(callback) {}
+ BlobWriteCallbackWrapper(
+ base::WeakPtr<IndexedDBBackingStore::Transaction> transaction,
+ scoped_refptr<BlobWriteCallback> callback)
+ : transaction_(std::move(transaction)),
+ transaction_ptr_(transaction_.get()),
+ callback_(callback) {}
void Run(bool succeeded) override {
IDB_ASYNC_TRACE_END("IndexedDBBackingStore::Transaction::WriteNewBlobs",
- transaction_);
+ transaction_ptr_);
callback_->Run(succeeded);
- if (succeeded) // Else it's already been deleted during rollback.
- transaction_->chained_blob_writer_ = NULL;
+ if (transaction_ && succeeded)
+ transaction_->chained_blob_writer_ = nullptr;
}
private:
~BlobWriteCallbackWrapper() override {}
friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>;
- IndexedDBBackingStore::Transaction* transaction_;
+ base::WeakPtr<IndexedDBBackingStore::Transaction> transaction_;
cmumford 2016/11/04 23:33:12 What about the other places in this file where tra
dmurph 2016/11/07 20:05:22 I'm not quite sure what you mean here. In this spe
+ IndexedDBBackingStore::Transaction* transaction_ptr_;
jsbell 2016/11/04 17:48:19 Nit: comment that this is only for ASYNC_TRACE mac
dmurph 2016/11/04 22:52:24 Done.
cmumford 2016/11/04 23:33:12 Also, maybe make it: const IndexedDBBackingStor
dmurph 2016/11/07 20:05:22 Done.
scoped_refptr<BlobWriteCallback> callback_;
DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper);
@@ -4379,12 +4385,11 @@ void IndexedDBBackingStore::Transaction::WriteNewBlobs(
transaction_->Put(blob_entry_iter.first.Encode(),
&blob_entry_iter.second);
}
- // Creating the writer will start it going asynchronously.
- chained_blob_writer_ =
- new ChainedBlobWriterImpl(database_id_,
- backing_store_,
- new_files_to_write,
- new BlobWriteCallbackWrapper(this, callback));
+ // Creating the writer will start it going asynchronously. The transaction
+ // can be destructed before the callback is triggered.
+ chained_blob_writer_ = new ChainedBlobWriterImpl(
+ database_id_, backing_store_, new_files_to_write,
+ new BlobWriteCallbackWrapper(ptr_factory_.GetWeakPtr(), callback));
}
void IndexedDBBackingStore::Transaction::Rollback() {
cmumford 2016/11/04 23:33:12 Not your change, but on line 4407 you can simplify
dmurph 2016/11/07 20:05:22 Done.

Powered by Google App Engine
This is Rietveld 408576698