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

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: Replying to comments, disallowed observing from versionchange txn 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 if (!connection_changes_map_.empty()) { 357 if (!connection_changes_map_.empty()) {
358 database_->SendObservations(std::move(connection_changes_map_)); 358 database_->SendObservations(std::move(connection_changes_map_));
359 connection_changes_map_.clear(); 359 connection_changes_map_.clear();
360 } 360 }
361 { 361 {
362 IDB_TRACE1( 362 IDB_TRACE1(
363 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", 363 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks",
364 "txn.id", id()); 364 "txn.id", id());
365 callbacks_->OnComplete(*this); 365 callbacks_->OnComplete(*this);
366 } 366 }
367 if (!pending_observers_.empty() && connection_) { 367 if (!pending_observers_.empty() && connection_)
368 connection_->ActivatePendingObservers(std::move(pending_observers_)); 368 connection_->ActivatePendingObservers(std::move(pending_observers_));
369 pending_observers_.clear();
370 }
371 369
372 database_->TransactionFinished(this, true); 370 database_->TransactionFinished(this, true);
373 // RemoveTransaction will delete |this|. 371 // RemoveTransaction will delete |this|.
374 connection_->RemoveTransaction(id_); 372 connection_->RemoveTransaction(id_);
375 return s; 373 return s;
376 } else { 374 } else {
377 while (!abort_task_stack_.empty()) 375 while (!abort_task_stack_.empty())
378 abort_task_stack_.pop().Run(); 376 abort_task_stack_.pop().Run();
379 377
380 IndexedDBDatabaseError error; 378 IndexedDBDatabaseError error;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 void IndexedDBTransaction::CloseOpenCursors() { 473 void IndexedDBTransaction::CloseOpenCursors() {
476 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); 474 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id());
477 for (auto* cursor : open_cursors_) 475 for (auto* cursor : open_cursors_)
478 cursor->Close(); 476 cursor->Close();
479 open_cursors_.clear(); 477 open_cursors_.clear();
480 } 478 }
481 479
482 void IndexedDBTransaction::AddPendingObserver( 480 void IndexedDBTransaction::AddPendingObserver(
483 int32_t observer_id, 481 int32_t observer_id,
484 const IndexedDBObserver::Options& options) { 482 const IndexedDBObserver::Options& options) {
483 CHECK_NE(mode(), blink::WebIDBTransactionModeVersionChange);
485 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>( 484 pending_observers_.push_back(base::MakeUnique<IndexedDBObserver>(
486 observer_id, object_store_ids_, options)); 485 observer_id, object_store_ids_, options));
487 } 486 }
488 487
489 void IndexedDBTransaction::RemovePendingObservers( 488 void IndexedDBTransaction::RemovePendingObservers(
490 const std::vector<int32_t>& pending_observer_ids) { 489 const std::vector<int32_t>& pending_observer_ids) {
491 const auto& it = std::remove_if( 490 const auto& it = std::remove_if(
492 pending_observers_.begin(), pending_observers_.end(), 491 pending_observers_.begin(), pending_observers_.end(),
493 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { 492 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) {
494 return base::ContainsValue(pending_observer_ids, o->id()); 493 return base::ContainsValue(pending_observer_ids, o->id());
495 }); 494 });
496 if (it != pending_observers_.end()) 495 if (it != pending_observers_.end())
497 pending_observers_.erase(it, pending_observers_.end()); 496 pending_observers_.erase(it, pending_observers_.end());
498 } 497 }
499 498
500 void IndexedDBTransaction::AddObservation( 499 void IndexedDBTransaction::AddObservation(
501 int32_t connection_id, 500 int32_t connection_id,
502 ::indexed_db::mojom::ObservationPtr observation) { 501 ::indexed_db::mojom::ObservationPtr observation) {
503 auto it = connection_changes_map_.find(connection_id); 502 auto it = connection_changes_map_.find(connection_id);
504 if (it == connection_changes_map_.end()) { 503 if (it == connection_changes_map_.end()) {
505 it = connection_changes_map_ 504 it = connection_changes_map_
506 .insert(std::make_pair( 505 .insert(std::make_pair(
507 connection_id, ::indexed_db::mojom::ObserverChanges::New())) 506 connection_id, ::indexed_db::mojom::ObserverChanges::New()))
508 .first; 507 .first;
509 } 508 }
510 it->second->observations.push_back(std::move(observation)); 509 it->second->observations.push_back(std::move(observation));
511 } 510 }
512 511
513 void IndexedDBTransaction::RecordObserverForLastObservation( 512 ::indexed_db::mojom::ObserverChangesPtr*
514 int32_t connection_id, 513 IndexedDBTransaction::GetPendingChangesForConnection(int32_t connection_id) {
515 int32_t observer_id) {
516 auto it = connection_changes_map_.find(connection_id); 514 auto it = connection_changes_map_.find(connection_id);
517 DCHECK(it != connection_changes_map_.end()); 515 if (it != connection_changes_map_.end())
518 it->second->observation_index_map[observer_id].push_back( 516 return &it->second;
519 it->second->observations.size() - 1); 517 return nullptr;
520 } 518 }
521 519
522 } // namespace content 520 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698