Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 4048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4059 std::unique_ptr<IndexCursorImpl> cursor( | 4059 std::unique_ptr<IndexCursorImpl> cursor( |
| 4060 new IndexCursorImpl(this, transaction, database_id, cursor_options)); | 4060 new IndexCursorImpl(this, transaction, database_id, cursor_options)); |
| 4061 if (!cursor->FirstSeek(s)) | 4061 if (!cursor->FirstSeek(s)) |
| 4062 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); | 4062 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); |
| 4063 | 4063 |
| 4064 return std::move(cursor); | 4064 return std::move(cursor); |
| 4065 } | 4065 } |
| 4066 | 4066 |
| 4067 IndexedDBBackingStore::Transaction::Transaction( | 4067 IndexedDBBackingStore::Transaction::Transaction( |
| 4068 IndexedDBBackingStore* backing_store) | 4068 IndexedDBBackingStore* backing_store) |
| 4069 : backing_store_(backing_store), database_id_(-1), committing_(false) { | 4069 : backing_store_(backing_store), |
| 4070 } | 4070 database_id_(-1), |
| 4071 committing_(false), | |
| 4072 ptr_factory_(this) {} | |
| 4071 | 4073 |
| 4072 IndexedDBBackingStore::Transaction::~Transaction() { | 4074 IndexedDBBackingStore::Transaction::~Transaction() { |
| 4073 DCHECK(!committing_); | 4075 DCHECK(!committing_); |
| 4074 } | 4076 } |
| 4075 | 4077 |
| 4076 void IndexedDBBackingStore::Transaction::Begin() { | 4078 void IndexedDBBackingStore::Transaction::Begin() { |
| 4077 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin"); | 4079 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin"); |
| 4078 DCHECK(!transaction_.get()); | 4080 DCHECK(!transaction_.get()); |
| 4079 transaction_ = IndexedDBClassFactory::Get()->CreateLevelDBTransaction( | 4081 transaction_ = IndexedDBClassFactory::Get()->CreateLevelDBTransaction( |
| 4080 backing_store_->db_.get()); | 4082 backing_store_->db_.get()); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4334 UpdatePrimaryBlobJournal(update_journal_transaction.get(), | 4336 UpdatePrimaryBlobJournal(update_journal_transaction.get(), |
| 4335 saved_primary_journal); | 4337 saved_primary_journal); |
| 4336 s = update_journal_transaction->Commit(); | 4338 s = update_journal_transaction->Commit(); |
| 4337 return s; | 4339 return s; |
| 4338 } | 4340 } |
| 4339 | 4341 |
| 4340 | 4342 |
| 4341 class IndexedDBBackingStore::Transaction::BlobWriteCallbackWrapper | 4343 class IndexedDBBackingStore::Transaction::BlobWriteCallbackWrapper |
| 4342 : public IndexedDBBackingStore::BlobWriteCallback { | 4344 : public IndexedDBBackingStore::BlobWriteCallback { |
| 4343 public: | 4345 public: |
| 4344 BlobWriteCallbackWrapper(IndexedDBBackingStore::Transaction* transaction, | 4346 BlobWriteCallbackWrapper( |
| 4345 scoped_refptr<BlobWriteCallback> callback) | 4347 base::WeakPtr<IndexedDBBackingStore::Transaction> transaction, |
| 4346 : transaction_(transaction), callback_(callback) {} | 4348 scoped_refptr<BlobWriteCallback> callback) |
| 4349 : transaction_(std::move(transaction)), | |
| 4350 transaction_ptr_(transaction_.get()), | |
| 4351 callback_(callback) {} | |
| 4347 void Run(bool succeeded) override { | 4352 void Run(bool succeeded) override { |
| 4348 IDB_ASYNC_TRACE_END("IndexedDBBackingStore::Transaction::WriteNewBlobs", | 4353 IDB_ASYNC_TRACE_END("IndexedDBBackingStore::Transaction::WriteNewBlobs", |
| 4349 transaction_); | 4354 transaction_ptr_); |
| 4350 callback_->Run(succeeded); | 4355 callback_->Run(succeeded); |
| 4351 if (succeeded) // Else it's already been deleted during rollback. | 4356 if (transaction_ && succeeded) |
| 4352 transaction_->chained_blob_writer_ = NULL; | 4357 transaction_->chained_blob_writer_ = nullptr; |
| 4353 } | 4358 } |
| 4354 | 4359 |
| 4355 private: | 4360 private: |
| 4356 ~BlobWriteCallbackWrapper() override {} | 4361 ~BlobWriteCallbackWrapper() override {} |
| 4357 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; | 4362 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; |
| 4358 | 4363 |
| 4359 IndexedDBBackingStore::Transaction* transaction_; | 4364 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
| |
| 4365 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.
| |
| 4360 scoped_refptr<BlobWriteCallback> callback_; | 4366 scoped_refptr<BlobWriteCallback> callback_; |
| 4361 | 4367 |
| 4362 DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper); | 4368 DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper); |
| 4363 }; | 4369 }; |
| 4364 | 4370 |
| 4365 void IndexedDBBackingStore::Transaction::WriteNewBlobs( | 4371 void IndexedDBBackingStore::Transaction::WriteNewBlobs( |
| 4366 BlobEntryKeyValuePairVec* new_blob_entries, | 4372 BlobEntryKeyValuePairVec* new_blob_entries, |
| 4367 WriteDescriptorVec* new_files_to_write, | 4373 WriteDescriptorVec* new_files_to_write, |
| 4368 scoped_refptr<BlobWriteCallback> callback) { | 4374 scoped_refptr<BlobWriteCallback> callback) { |
| 4369 IDB_ASYNC_TRACE_BEGIN("IndexedDBBackingStore::Transaction::WriteNewBlobs", | 4375 IDB_ASYNC_TRACE_BEGIN("IndexedDBBackingStore::Transaction::WriteNewBlobs", |
| 4370 this); | 4376 this); |
| 4371 DCHECK(!new_files_to_write->empty()); | 4377 DCHECK(!new_files_to_write->empty()); |
| 4372 DCHECK_GT(database_id_, 0); | 4378 DCHECK_GT(database_id_, 0); |
| 4373 for (auto& blob_entry_iter : *new_blob_entries) { | 4379 for (auto& blob_entry_iter : *new_blob_entries) { |
| 4374 // Add the new blob-table entry for each blob to the main transaction, or | 4380 // Add the new blob-table entry for each blob to the main transaction, or |
| 4375 // remove any entry that may exist if there's no new one. | 4381 // remove any entry that may exist if there's no new one. |
| 4376 if (blob_entry_iter.second.empty()) | 4382 if (blob_entry_iter.second.empty()) |
| 4377 transaction_->Remove(blob_entry_iter.first.Encode()); | 4383 transaction_->Remove(blob_entry_iter.first.Encode()); |
| 4378 else | 4384 else |
| 4379 transaction_->Put(blob_entry_iter.first.Encode(), | 4385 transaction_->Put(blob_entry_iter.first.Encode(), |
| 4380 &blob_entry_iter.second); | 4386 &blob_entry_iter.second); |
| 4381 } | 4387 } |
| 4382 // Creating the writer will start it going asynchronously. | 4388 // Creating the writer will start it going asynchronously. The transaction |
| 4383 chained_blob_writer_ = | 4389 // can be destructed before the callback is triggered. |
| 4384 new ChainedBlobWriterImpl(database_id_, | 4390 chained_blob_writer_ = new ChainedBlobWriterImpl( |
| 4385 backing_store_, | 4391 database_id_, backing_store_, new_files_to_write, |
| 4386 new_files_to_write, | 4392 new BlobWriteCallbackWrapper(ptr_factory_.GetWeakPtr(), callback)); |
| 4387 new BlobWriteCallbackWrapper(this, callback)); | |
| 4388 } | 4393 } |
| 4389 | 4394 |
| 4390 void IndexedDBBackingStore::Transaction::Rollback() { | 4395 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.
| |
| 4391 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); | 4396 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); |
| 4392 if (committing_) { | 4397 if (committing_) { |
| 4393 committing_ = false; | 4398 committing_ = false; |
| 4394 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL); | 4399 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL); |
| 4395 --backing_store_->committing_transaction_count_; | 4400 --backing_store_->committing_transaction_count_; |
| 4396 } | 4401 } |
| 4397 | 4402 |
| 4398 if (chained_blob_writer_.get()) { | 4403 if (chained_blob_writer_.get()) { |
| 4399 chained_blob_writer_->Abort(); | 4404 chained_blob_writer_->Abort(); |
| 4400 chained_blob_writer_ = NULL; | 4405 chained_blob_writer_ = NULL; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4529 | 4534 |
| 4530 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4535 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4531 const WriteDescriptor& other) = default; | 4536 const WriteDescriptor& other) = default; |
| 4532 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4537 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4533 default; | 4538 default; |
| 4534 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4539 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4535 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4540 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4536 operator=(const WriteDescriptor& other) = default; | 4541 operator=(const WriteDescriptor& other) = default; |
| 4537 | 4542 |
| 4538 } // namespace content | 4543 } // namespace content |
| OLD | NEW |