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

Unified Diff: content/browser/indexed_db/indexed_db_transaction.cc

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: post dmuprh review Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_transaction.cc
diff --git a/content/browser/indexed_db/indexed_db_transaction.cc b/content/browser/indexed_db/indexed_db_transaction.cc
index 768cf1dc2f8a96929a372b0659c6a882821619f5..76a10f743095016294041b0814b085a3a5c52d17 100644
--- a/content/browser/indexed_db/indexed_db_transaction.cc
+++ b/content/browser/indexed_db/indexed_db_transaction.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -14,6 +15,7 @@
#include "content/browser/indexed_db/indexed_db_cursor.h"
#include "content/browser/indexed_db/indexed_db_database.h"
#include "content/browser/indexed_db/indexed_db_database_callbacks.h"
+#include "content/browser/indexed_db/indexed_db_observer.h"
#include "content/browser/indexed_db/indexed_db_tracing.h"
#include "content/browser/indexed_db/indexed_db_transaction_coordinator.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
@@ -66,6 +68,7 @@ IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() {
IndexedDBTransaction::IndexedDBTransaction(
int64_t id,
+ base::WeakPtr<IndexedDBConnection> connection,
scoped_refptr<IndexedDBDatabaseCallbacks> callbacks,
const std::set<int64_t>& object_store_ids,
blink::WebIDBTransactionMode mode,
@@ -77,6 +80,7 @@ IndexedDBTransaction::IndexedDBTransaction(
used_(false),
state_(CREATED),
commit_pending_(false),
+ connection_(std::move(connection)),
callbacks_(callbacks),
database_(database),
transaction_(backing_store_transaction),
@@ -191,6 +195,7 @@ void IndexedDBTransaction::Abort(const IndexedDBDatabaseError& error) {
database_->TransactionFinished(this, false);
database_ = NULL;
+ connection_ = nullptr;
}
bool IndexedDBTransaction::IsTaskQueueEmpty() const {
@@ -339,6 +344,9 @@ leveldb::Status IndexedDBTransaction::CommitPhaseTwo() {
database_->transaction_coordinator().DidFinishTransaction(this);
if (committed) {
+ // TODO (palakj) : Send Observations to observers
+ if (!pending_observers_.empty())
dmurph 2016/06/23 21:53:04 Do a check that the connection is around as well.
palakj1 2016/06/24 00:03:00 Done.
+ connection_->ActivatePendingObservers(&pending_observers_);
abort_task_stack_.clear();
{
IDB_TRACE1(
@@ -445,4 +453,23 @@ void IndexedDBTransaction::CloseOpenCursors() {
open_cursors_.clear();
}
+void IndexedDBTransaction::AddPendingObserver(int32_t observer_id) {
+ pending_observers_.push_back(
+ base::WrapUnique(new IndexedDBObserver(observer_id)));
+}
+
+void IndexedDBTransaction::RemovePendingObservers(
+ const std::vector<int32_t>& pending_observer_ids) {
+ // TODO(palakj): Change from vector to set or create a tmp vector instead of
+ // erase.
+ for (uint32_t i = 0; i < pending_observer_ids.size(); i++) {
+ for (uint32_t j = 0; j < pending_observers_.size(); j++) {
+ if (pending_observers_[j]->id() == pending_observer_ids[i]) {
+ pending_observers_.erase(pending_observers_.begin() + j);
dmurph 2016/06/23 21:53:04 Same issue here. You have to either use iterator i
palakj1 2016/06/24 00:03:00 Same reason here.
+ break;
+ }
+ }
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698