| 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 db4a1ea7763e34fa39c8f7a7bf1e0167f75c5878..9798bc8777a10aa5e1d5a1c4887a617f86538b97 100644
|
| --- a/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
|
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp
|
| @@ -10,6 +10,7 @@
|
| #include "core/dom/ExceptionCode.h"
|
| #include "modules/indexeddb/IDBDatabase.h"
|
| #include "modules/indexeddb/IDBObserverCallback.h"
|
| +#include "modules/indexeddb/IDBObserverChanges.h"
|
| #include "modules/indexeddb/IDBObserverInit.h"
|
| #include "modules/indexeddb/IDBTransaction.h"
|
| #include "modules/indexeddb/WebIDBObserverImpl.h"
|
| @@ -49,7 +50,7 @@ void IDBObserver::observe(IDBDatabase* database, IDBTransaction* transaction, Ex
|
| 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);
|
| + m_observerIds.add(observerId, database);
|
| observerPtr->setId(observerId);
|
| }
|
|
|
| @@ -59,28 +60,38 @@ void IDBObserver::unobserve(IDBDatabase* database, ExceptionState& exceptionStat
|
| exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databaseClosedErrorMessage);
|
| return;
|
| }
|
| - auto it = m_observerIds.begin();
|
| +
|
| + HeapHashMap<int32_t, WeakMember<IDBDatabase>> observersToRetain;
|
| 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++;
|
| - }
|
| + for (const auto& it : m_observerIds) {
|
| + if (it.value == database)
|
| + observerIdsToRemove.push_back(it.key);
|
| + else
|
| + observersToRetain.add(it.key, it.value);
|
| }
|
| + m_observerIds.swap(observersToRetain);
|
| +
|
| if (!observerIdsToRemove.empty())
|
| database->backend()->removeObservers(observerIdsToRemove);
|
| }
|
|
|
| void IDBObserver::removeObserver(int32_t id)
|
| {
|
| - m_observerIds.erase(id);
|
| + m_observerIds.remove(id);
|
| +}
|
| +
|
| +void IDBObserver::onChange(int32_t id, const std::vector<WebIDBObservation>& observations, const std::vector<int32_t>& observationIndex)
|
| +{
|
| + auto it = m_observerIds.find(id);
|
| + if (it == m_observerIds.end())
|
| + return;
|
| + m_callback->handleEvent(*IDBObserverChanges::create(it->value, observations, observationIndex), *this);
|
| }
|
|
|
| DEFINE_TRACE(IDBObserver)
|
| {
|
| visitor->trace(m_callback);
|
| + visitor->trace(m_observerIds);
|
| }
|
|
|
| } // namespace blink
|
|
|