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

Side by Side Diff: content/browser/indexed_db/indexed_db_transaction.cc

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: added comments and bug link Created 3 years, 11 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 #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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // re-entrantly as that may renter the coordinator. 219 // re-entrantly as that may renter the coordinator.
220 base::ThreadTaskRunnerHandle::Get()->PostTask( 220 base::ThreadTaskRunnerHandle::Get()->PostTask(
221 FROM_HERE, base::Bind(&CommitUnused, ptr_factory_.GetWeakPtr())); 221 FROM_HERE, base::Bind(&CommitUnused, ptr_factory_.GetWeakPtr()));
222 } 222 }
223 return; 223 return;
224 } 224 }
225 225
226 RunTasksIfStarted(); 226 RunTasksIfStarted();
227 } 227 }
228 228
229 void IndexedDBTransaction::GrabSnapshotThenStart() {
230 DCHECK(!backing_store_transaction_begun_);
231 transaction_->Begin();
232 backing_store_transaction_begun_ = true;
233 Start();
234 }
235
229 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { 236 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback {
230 public: 237 public:
231 explicit BlobWriteCallbackImpl( 238 explicit BlobWriteCallbackImpl(
232 base::WeakPtr<IndexedDBTransaction> transaction) 239 base::WeakPtr<IndexedDBTransaction> transaction)
233 : transaction_(std::move(transaction)) {} 240 : transaction_(std::move(transaction)) {}
234 241
235 leveldb::Status Run(IndexedDBBackingStore::BlobWriteResult result) override { 242 leveldb::Status Run(IndexedDBBackingStore::BlobWriteResult result) override {
236 if (!transaction_) 243 if (!transaction_)
237 return leveldb::Status::OK(); 244 return leveldb::Status::OK();
238 return transaction_->BlobWriteComplete(result); 245 return transaction_->BlobWriteComplete(result);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (!connection_changes_map_.empty()) { 363 if (!connection_changes_map_.empty()) {
357 database_->SendObservations(std::move(connection_changes_map_)); 364 database_->SendObservations(std::move(connection_changes_map_));
358 connection_changes_map_.clear(); 365 connection_changes_map_.clear();
359 } 366 }
360 { 367 {
361 IDB_TRACE1( 368 IDB_TRACE1(
362 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", 369 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks",
363 "txn.id", id()); 370 "txn.id", id());
364 callbacks_->OnComplete(*this); 371 callbacks_->OnComplete(*this);
365 } 372 }
366 if (!pending_observers_.empty() && connection_) { 373 if (!pending_observers_.empty() && connection_)
367 connection_->ActivatePendingObservers(std::move(pending_observers_)); 374 connection_->ActivatePendingObservers(std::move(pending_observers_));
368 pending_observers_.clear();
369 }
370 375
371 database_->TransactionFinished(this, true); 376 database_->TransactionFinished(this, true);
372 // RemoveTransaction will delete |this|. 377 // RemoveTransaction will delete |this|.
373 connection_->RemoveTransaction(id_); 378 connection_->RemoveTransaction(id_);
374 return s; 379 return s;
375 } else { 380 } else {
376 while (!abort_task_stack_.empty()) 381 while (!abort_task_stack_.empty())
377 abort_task_stack_.pop().Run(); 382 abort_task_stack_.pop().Run();
378 383
379 IndexedDBDatabaseError error; 384 IndexedDBDatabaseError error;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 void IndexedDBTransaction::CloseOpenCursors() { 479 void IndexedDBTransaction::CloseOpenCursors() {
475 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); 480 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id());
476 for (auto* cursor : open_cursors_) 481 for (auto* cursor : open_cursors_)
477 cursor->Close(); 482 cursor->Close();
478 open_cursors_.clear(); 483 open_cursors_.clear();
479 } 484 }
480 485
481 void IndexedDBTransaction::AddPendingObserver( 486 void IndexedDBTransaction::AddPendingObserver(
482 int32_t observer_id, 487 int32_t observer_id,
483 const IndexedDBObserver::Options& options) { 488 const IndexedDBObserver::Options& options) {
489 DCHECK_NE(mode(), blink::WebIDBTransactionModeVersionChange);
484 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>( 490 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>(
485 observer_id, object_store_ids_, options)); 491 observer_id, object_store_ids_, options));
486 } 492 }
487 493
488 void IndexedDBTransaction::RemovePendingObservers( 494 void IndexedDBTransaction::RemovePendingObservers(
489 const std::vector<int32_t>& pending_observer_ids) { 495 const std::vector<int32_t>& pending_observer_ids) {
490 const auto& it = std::remove_if( 496 const auto& it = std::remove_if(
491 pending_observers_.begin(), pending_observers_.end(), 497 pending_observers_.begin(), pending_observers_.end(),
492 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { 498 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) {
493 return base::ContainsValue(pending_observer_ids, o->id()); 499 return base::ContainsValue(pending_observer_ids, o->id());
494 }); 500 });
495 if (it != pending_observers_.end()) 501 if (it != pending_observers_.end())
496 pending_observers_.erase(it, pending_observers_.end()); 502 pending_observers_.erase(it, pending_observers_.end());
497 } 503 }
498 504
499 void IndexedDBTransaction::AddObservation( 505 void IndexedDBTransaction::AddObservation(
500 int32_t connection_id, 506 int32_t connection_id,
501 ::indexed_db::mojom::ObservationPtr observation) { 507 ::indexed_db::mojom::ObservationPtr observation) {
502 auto it = connection_changes_map_.find(connection_id); 508 auto it = connection_changes_map_.find(connection_id);
503 if (it == connection_changes_map_.end()) { 509 if (it == connection_changes_map_.end()) {
504 it = connection_changes_map_ 510 it = connection_changes_map_
505 .insert(std::make_pair( 511 .insert(std::make_pair(
506 connection_id, ::indexed_db::mojom::ObserverChanges::New())) 512 connection_id, ::indexed_db::mojom::ObserverChanges::New()))
507 .first; 513 .first;
508 } 514 }
509 it->second->observations.push_back(std::move(observation)); 515 it->second->observations.push_back(std::move(observation));
510 } 516 }
511 517
512 void IndexedDBTransaction::RecordObserverForLastObservation( 518 ::indexed_db::mojom::ObserverChangesPtr*
513 int32_t connection_id, 519 IndexedDBTransaction::GetPendingChangesForConnection(int32_t connection_id) {
514 int32_t observer_id) {
515 auto it = connection_changes_map_.find(connection_id); 520 auto it = connection_changes_map_.find(connection_id);
516 DCHECK(it != connection_changes_map_.end()); 521 if (it != connection_changes_map_.end())
517 it->second->observation_index_map[observer_id].push_back( 522 return &it->second;
518 it->second->observations.size() - 1); 523 return nullptr;
519 } 524 }
520 525
521 } // namespace content 526 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction.h ('k') | content/browser/indexed_db/indexed_db_transaction_coordinator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698