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..45894f7b9c73823dbde871ceb1c646637ae9aa2d 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" |
| @@ -27,6 +28,12 @@ IDBObserver::IDBObserver(IDBObserverCallback& callback, const IDBObserverInit& o |
| , m_values(options.values()) |
| , m_noRecords(options.noRecords()) |
| { |
| + // TODO(palakj): Throw an exception if unknown operation type. |
| + m_operationTypes.reset(); |
| + m_operationTypes[0] = options.operationTypes().contains("add"); |
|
jsbell
2016/07/18 23:38:57
[0] should be [WebIDBAdd]
jsbell
2016/07/18 23:38:57
#include "modules/IndexedDBNames.h" and then this
palakj1
2016/07/19 03:53:11
Done
|
| + m_operationTypes[1] = options.operationTypes().contains("put"); |
| + m_operationTypes[2] = options.operationTypes().contains("delete"); |
|
jsbell
2016/07/18 23:38:57
This ends up being IndexedDBNames::kDelete I guess
palakj1
2016/07/19 03:53:11
done
|
| + m_operationTypes[3] = options.operationTypes().contains("clear"); |
| } |
| IDBObserver::~IDBObserver() {} |
| @@ -49,7 +56,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 +66,37 @@ void IDBObserver::unobserve(IDBDatabase* database, ExceptionState& exceptionStat |
| 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++; |
| - } |
| + |
| + HeapHashMap<int32_t, WeakMember<IDBDatabase>> observersToRetain; |
| + Vector<int32_t> observerIdsToRemove; |
| + for (const auto& it : m_observerIds) { |
| + if (it.value == database) |
| + observerIdsToRemove.append(it.key); |
| + else |
| + observersToRetain.add(it.key, it.value); |
| } |
| - if (!observerIdsToRemove.empty()) |
| + m_observerIds.swap(observersToRetain); |
| + |
| + if (!observerIdsToRemove.isEmpty()) |
| 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 WebVector<WebIDBObservation>& observations, const WebVector<int32_t>& observationIndex) |
| +{ |
| + auto it = m_observerIds.find(id); |
| + DCHECK(it != m_observerIds.end()); |
| + m_callback->handleChanges(*IDBObserverChanges::create(it->value, observations, observationIndex), *this); |
| } |
| DEFINE_TRACE(IDBObserver) |
| { |
| visitor->trace(m_callback); |
| + visitor->trace(m_observerIds); |
| } |
| } // namespace blink |