| 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 void* tracing_end_ptr, |
| 4349 scoped_refptr<BlobWriteCallback> callback) |
| 4350 : transaction_(std::move(transaction)), |
| 4351 tracing_end_ptr_(tracing_end_ptr), |
| 4352 callback_(callback) {} |
| 4347 void Run(bool succeeded) override { | 4353 void Run(bool succeeded) override { |
| 4348 IDB_ASYNC_TRACE_END("IndexedDBBackingStore::Transaction::WriteNewBlobs", | 4354 IDB_ASYNC_TRACE_END("IndexedDBBackingStore::Transaction::WriteNewBlobs", |
| 4349 transaction_); | 4355 tracing_end_ptr_); |
| 4350 callback_->Run(succeeded); | 4356 callback_->Run(succeeded); |
| 4351 if (succeeded) // Else it's already been deleted during rollback. | 4357 if (transaction_ && succeeded) |
| 4352 transaction_->chained_blob_writer_ = NULL; | 4358 transaction_->chained_blob_writer_ = nullptr; |
| 4353 } | 4359 } |
| 4354 | 4360 |
| 4355 private: | 4361 private: |
| 4356 ~BlobWriteCallbackWrapper() override {} | 4362 ~BlobWriteCallbackWrapper() override {} |
| 4357 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; | 4363 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; |
| 4358 | 4364 |
| 4359 IndexedDBBackingStore::Transaction* transaction_; | 4365 base::WeakPtr<IndexedDBBackingStore::Transaction> transaction_; |
| 4366 const void* const tracing_end_ptr_; |
| 4360 scoped_refptr<BlobWriteCallback> callback_; | 4367 scoped_refptr<BlobWriteCallback> callback_; |
| 4361 | 4368 |
| 4362 DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper); | 4369 DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper); |
| 4363 }; | 4370 }; |
| 4364 | 4371 |
| 4365 void IndexedDBBackingStore::Transaction::WriteNewBlobs( | 4372 void IndexedDBBackingStore::Transaction::WriteNewBlobs( |
| 4366 BlobEntryKeyValuePairVec* new_blob_entries, | 4373 BlobEntryKeyValuePairVec* new_blob_entries, |
| 4367 WriteDescriptorVec* new_files_to_write, | 4374 WriteDescriptorVec* new_files_to_write, |
| 4368 scoped_refptr<BlobWriteCallback> callback) { | 4375 scoped_refptr<BlobWriteCallback> callback) { |
| 4369 IDB_ASYNC_TRACE_BEGIN("IndexedDBBackingStore::Transaction::WriteNewBlobs", | 4376 IDB_ASYNC_TRACE_BEGIN("IndexedDBBackingStore::Transaction::WriteNewBlobs", |
| 4370 this); | 4377 this); |
| 4371 DCHECK(!new_files_to_write->empty()); | 4378 DCHECK(!new_files_to_write->empty()); |
| 4372 DCHECK_GT(database_id_, 0); | 4379 DCHECK_GT(database_id_, 0); |
| 4373 for (auto& blob_entry_iter : *new_blob_entries) { | 4380 for (auto& blob_entry_iter : *new_blob_entries) { |
| 4374 // Add the new blob-table entry for each blob to the main transaction, or | 4381 // 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. | 4382 // remove any entry that may exist if there's no new one. |
| 4376 if (blob_entry_iter.second.empty()) | 4383 if (blob_entry_iter.second.empty()) |
| 4377 transaction_->Remove(blob_entry_iter.first.Encode()); | 4384 transaction_->Remove(blob_entry_iter.first.Encode()); |
| 4378 else | 4385 else |
| 4379 transaction_->Put(blob_entry_iter.first.Encode(), | 4386 transaction_->Put(blob_entry_iter.first.Encode(), |
| 4380 &blob_entry_iter.second); | 4387 &blob_entry_iter.second); |
| 4381 } | 4388 } |
| 4382 // Creating the writer will start it going asynchronously. | 4389 // Creating the writer will start it going asynchronously. The transaction |
| 4383 chained_blob_writer_ = | 4390 // can be destructed before the callback is triggered. |
| 4384 new ChainedBlobWriterImpl(database_id_, | 4391 chained_blob_writer_ = new ChainedBlobWriterImpl( |
| 4385 backing_store_, | 4392 database_id_, backing_store_, new_files_to_write, |
| 4386 new_files_to_write, | 4393 new BlobWriteCallbackWrapper(ptr_factory_.GetWeakPtr(), this, callback)); |
| 4387 new BlobWriteCallbackWrapper(this, callback)); | |
| 4388 } | 4394 } |
| 4389 | 4395 |
| 4390 void IndexedDBBackingStore::Transaction::Rollback() { | 4396 void IndexedDBBackingStore::Transaction::Rollback() { |
| 4391 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); | 4397 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); |
| 4392 if (committing_) { | 4398 if (committing_) { |
| 4393 committing_ = false; | 4399 committing_ = false; |
| 4394 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL); | 4400 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL); |
| 4395 --backing_store_->committing_transaction_count_; | 4401 --backing_store_->committing_transaction_count_; |
| 4396 } | 4402 } |
| 4397 | 4403 |
| 4398 if (chained_blob_writer_.get()) { | 4404 if (chained_blob_writer_.get()) { |
| 4399 chained_blob_writer_->Abort(); | 4405 chained_blob_writer_->Abort(); |
| 4400 chained_blob_writer_ = NULL; | 4406 chained_blob_writer_ = NULL; |
| 4401 } | 4407 } |
| 4402 if (transaction_.get() == NULL) | 4408 if (!transaction_) |
| 4403 return; | 4409 return; |
| 4404 transaction_->Rollback(); | 4410 transaction_->Rollback(); |
| 4405 transaction_ = NULL; | 4411 transaction_ = NULL; |
| 4406 } | 4412 } |
| 4407 | 4413 |
| 4408 IndexedDBBackingStore::BlobChangeRecord::BlobChangeRecord( | 4414 IndexedDBBackingStore::BlobChangeRecord::BlobChangeRecord( |
| 4409 const std::string& key, | 4415 const std::string& key, |
| 4410 int64_t object_store_id) | 4416 int64_t object_store_id) |
| 4411 : key_(key), object_store_id_(object_store_id) {} | 4417 : key_(key), object_store_id_(object_store_id) {} |
| 4412 | 4418 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4529 | 4535 |
| 4530 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4536 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4531 const WriteDescriptor& other) = default; | 4537 const WriteDescriptor& other) = default; |
| 4532 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4538 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4533 default; | 4539 default; |
| 4534 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4540 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4535 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4541 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4536 operator=(const WriteDescriptor& other) = default; | 4542 operator=(const WriteDescriptor& other) = default; |
| 4537 | 4543 |
| 4538 } // namespace content | 4544 } // namespace content |
| OLD | NEW |