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

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final architechture Created 4 years, 5 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: third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
index 219b81832bebfc898a2e679fa329c0a2b21d26c8..db4a1ea7763e34fa39c8f7a7bf1e0167f75c5878 100644
--- a/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
@@ -7,8 +7,12 @@
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/modules/v8/ToV8ForModules.h"
#include "bindings/modules/v8/V8BindingForModules.h"
+#include "core/dom/ExceptionCode.h"
+#include "modules/indexeddb/IDBDatabase.h"
#include "modules/indexeddb/IDBObserverCallback.h"
#include "modules/indexeddb/IDBObserverInit.h"
+#include "modules/indexeddb/IDBTransaction.h"
+#include "modules/indexeddb/WebIDBObserverImpl.h"
namespace blink {
@@ -25,9 +29,53 @@ IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o
{
}
+IDBObserver::~IDBObserver() {}
+
void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, ExceptionState& exceptionState)
{
- // TODO(palakj): Finish implementation.
+ if (transaction->isFinished() || transaction->isFinishing()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
+ return;
+ }
+ if (!transaction->isActive()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
+ return;
+ }
+ if (!database->backend()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databaseClosedErrorMessage);
+ return;
+ }
+
+ std::unique_ptr<WebIDBObserverImpl> observer = WebIDBObserverImpl::create(this);
+ WebIDBObserverImpl* observerPtr = observer.get();
+ int32_t observerId = database->backend()->addObserver(std::move(observer), transaction->id());
+ m_observerIds.insert(observerId);
+ observerPtr->setId(observerId);
+}
+
+void IDBObserver::unobserve(IDBDatabase* database, ExceptionState& exceptionState)
+{
+ if (!database->backend()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databaseClosedErrorMessage);
+ return;
+ }
+ auto it = m_observerIds.begin();
+ std::vector<int32_t> observerIdsToRemove;
+ while (it != m_observerIds.end()) {
+ if (database->backend()->containsObserverId(*it)) {
+ observerIdsToRemove.push_back(*it);
+ it = m_observerIds.erase(it);
+ } else {
+ it++;
+ }
+ }
+ if (!observerIdsToRemove.empty())
+ database->backend()->removeObservers(observerIdsToRemove);
+}
+
+void IDBObserver::removeObserver(int32_t id)
+{
+ m_observerIds.erase(id);
}
DEFINE_TRACE(IDBObserver)
« no previous file with comments | « third_party/WebKit/Source/modules/indexeddb/IDBObserver.h ('k') | third_party/WebKit/Source/modules/indexeddb/IDBObserver.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698