Chromium Code Reviews| 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..4e70db9d12aa7314c18dade84fa8787cac5f5b63 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,37 @@ 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) |
| + observersToRetain.add(it.key, it.value); |
| + else |
| + observerIdsToRemove.push_back(it.key); |
|
palakj1
2016/07/13 17:47:18
typo : the if and else condition must be swapped.
|
| } |
| + 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); |
| + DCHECK_NE(it, m_observerIds.end()); |
| + m_callback->handleEvent(*IDBObserverChanges::create(it->value, observations, observationIndex), *this); |
| } |
| DEFINE_TRACE(IDBObserver) |
| { |
| visitor->trace(m_callback); |
| + visitor->trace(m_observerIds); |
| } |
| } // namespace blink |