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_transaction.h" | 5 #include "content/browser/indexed_db/indexed_db_transaction.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 // re-entrantly as that may renter the coordinator. | 220 // re-entrantly as that may renter the coordinator. |
221 base::ThreadTaskRunnerHandle::Get()->PostTask( | 221 base::ThreadTaskRunnerHandle::Get()->PostTask( |
222 FROM_HERE, base::Bind(&CommitUnused, ptr_factory_.GetWeakPtr())); | 222 FROM_HERE, base::Bind(&CommitUnused, ptr_factory_.GetWeakPtr())); |
223 } | 223 } |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 RunTasksIfStarted(); | 227 RunTasksIfStarted(); |
228 } | 228 } |
229 | 229 |
230 void IndexedDBTransaction::GrabSnapshotThenStart() { | |
231 DCHECK(!backing_store_transaction_begun_); | |
232 transaction_->Begin(); | |
233 backing_store_transaction_begun_ = true; | |
234 Start(); | |
235 } | |
236 | |
230 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { | 237 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { |
231 public: | 238 public: |
232 explicit BlobWriteCallbackImpl( | 239 explicit BlobWriteCallbackImpl( |
233 base::WeakPtr<IndexedDBTransaction> transaction) | 240 base::WeakPtr<IndexedDBTransaction> transaction) |
234 : transaction_(std::move(transaction)) {} | 241 : transaction_(std::move(transaction)) {} |
235 | 242 |
236 leveldb::Status Run(IndexedDBBackingStore::BlobWriteResult result) override { | 243 leveldb::Status Run(IndexedDBBackingStore::BlobWriteResult result) override { |
237 if (!transaction_) | 244 if (!transaction_) |
238 return leveldb::Status::OK(); | 245 return leveldb::Status::OK(); |
239 return transaction_->BlobWriteComplete(result); | 246 return transaction_->BlobWriteComplete(result); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 if (!connection_changes_map_.empty()) { | 364 if (!connection_changes_map_.empty()) { |
358 database_->SendObservations(std::move(connection_changes_map_)); | 365 database_->SendObservations(std::move(connection_changes_map_)); |
359 connection_changes_map_.clear(); | 366 connection_changes_map_.clear(); |
360 } | 367 } |
361 { | 368 { |
362 IDB_TRACE1( | 369 IDB_TRACE1( |
363 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", | 370 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", |
364 "txn.id", id()); | 371 "txn.id", id()); |
365 callbacks_->OnComplete(*this); | 372 callbacks_->OnComplete(*this); |
366 } | 373 } |
367 if (!pending_observers_.empty() && connection_) { | 374 if (!pending_observers_.empty() && connection_) |
368 connection_->ActivatePendingObservers(std::move(pending_observers_)); | 375 connection_->ActivatePendingObservers(std::move(pending_observers_)); |
369 pending_observers_.clear(); | |
370 } | |
371 | 376 |
372 database_->TransactionFinished(this, true); | 377 database_->TransactionFinished(this, true); |
373 // RemoveTransaction will delete |this|. | 378 // RemoveTransaction will delete |this|. |
374 connection_->RemoveTransaction(id_); | 379 connection_->RemoveTransaction(id_); |
375 return s; | 380 return s; |
376 } else { | 381 } else { |
377 while (!abort_task_stack_.empty()) | 382 while (!abort_task_stack_.empty()) |
378 abort_task_stack_.pop().Run(); | 383 abort_task_stack_.pop().Run(); |
379 | 384 |
380 IndexedDBDatabaseError error; | 385 IndexedDBDatabaseError error; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 void IndexedDBTransaction::CloseOpenCursors() { | 480 void IndexedDBTransaction::CloseOpenCursors() { |
476 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); | 481 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); |
477 for (auto* cursor : open_cursors_) | 482 for (auto* cursor : open_cursors_) |
478 cursor->Close(); | 483 cursor->Close(); |
479 open_cursors_.clear(); | 484 open_cursors_.clear(); |
480 } | 485 } |
481 | 486 |
482 void IndexedDBTransaction::AddPendingObserver( | 487 void IndexedDBTransaction::AddPendingObserver( |
483 int32_t observer_id, | 488 int32_t observer_id, |
484 const IndexedDBObserver::Options& options) { | 489 const IndexedDBObserver::Options& options) { |
490 CHECK_NE(mode(), blink::WebIDBTransactionModeVersionChange); | |
jsbell
2017/01/13 00:14:12
It seems like DCHECK_NE would be fine here?
dmurph
2017/01/13 01:50:43
Sure.
| |
485 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>( | 491 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>( |
486 observer_id, object_store_ids_, options)); | 492 observer_id, object_store_ids_, options)); |
487 } | 493 } |
488 | 494 |
489 void IndexedDBTransaction::RemovePendingObservers( | 495 void IndexedDBTransaction::RemovePendingObservers( |
490 const std::vector<int32_t>& pending_observer_ids) { | 496 const std::vector<int32_t>& pending_observer_ids) { |
491 const auto& it = std::remove_if( | 497 const auto& it = std::remove_if( |
492 pending_observers_.begin(), pending_observers_.end(), | 498 pending_observers_.begin(), pending_observers_.end(), |
493 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { | 499 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { |
494 return base::ContainsValue(pending_observer_ids, o->id()); | 500 return base::ContainsValue(pending_observer_ids, o->id()); |
495 }); | 501 }); |
496 if (it != pending_observers_.end()) | 502 if (it != pending_observers_.end()) |
497 pending_observers_.erase(it, pending_observers_.end()); | 503 pending_observers_.erase(it, pending_observers_.end()); |
498 } | 504 } |
499 | 505 |
500 void IndexedDBTransaction::AddObservation( | 506 void IndexedDBTransaction::AddObservation( |
501 int32_t connection_id, | 507 int32_t connection_id, |
502 ::indexed_db::mojom::ObservationPtr observation) { | 508 ::indexed_db::mojom::ObservationPtr observation) { |
503 auto it = connection_changes_map_.find(connection_id); | 509 auto it = connection_changes_map_.find(connection_id); |
504 if (it == connection_changes_map_.end()) { | 510 if (it == connection_changes_map_.end()) { |
505 it = connection_changes_map_ | 511 it = connection_changes_map_ |
506 .insert(std::make_pair( | 512 .insert(std::make_pair( |
507 connection_id, ::indexed_db::mojom::ObserverChanges::New())) | 513 connection_id, ::indexed_db::mojom::ObserverChanges::New())) |
508 .first; | 514 .first; |
509 } | 515 } |
510 it->second->observations.push_back(std::move(observation)); | 516 it->second->observations.push_back(std::move(observation)); |
511 } | 517 } |
512 | 518 |
513 void IndexedDBTransaction::RecordObserverForLastObservation( | 519 ::indexed_db::mojom::ObserverChangesPtr* |
514 int32_t connection_id, | 520 IndexedDBTransaction::GetPendingChangesForConnection(int32_t connection_id) { |
515 int32_t observer_id) { | |
516 auto it = connection_changes_map_.find(connection_id); | 521 auto it = connection_changes_map_.find(connection_id); |
517 DCHECK(it != connection_changes_map_.end()); | 522 if (it != connection_changes_map_.end()) |
518 it->second->observation_index_map[observer_id].push_back( | 523 return &it->second; |
519 it->second->observations.size() - 1); | 524 return nullptr; |
520 } | 525 } |
521 | 526 |
522 } // namespace content | 527 } // namespace content |
OLD | NEW |