| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/indexeddb/IDBObserver.h" | 5 #include "modules/indexeddb/IDBObserver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/modules/v8/IDBObserverCallback.h" | 8 #include "bindings/modules/v8/IDBObserverCallback.h" |
| 9 #include "bindings/modules/v8/ToV8ForModules.h" | 9 #include "bindings/modules/v8/ToV8ForModules.h" |
| 10 #include "bindings/modules/v8/V8BindingForModules.h" | 10 #include "bindings/modules/v8/V8BindingForModules.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "modules/IndexedDBNames.h" | 12 #include "modules/IndexedDBNames.h" |
| 13 #include "modules/indexeddb/IDBDatabase.h" | 13 #include "modules/indexeddb/IDBDatabase.h" |
| 14 #include "modules/indexeddb/IDBObserverChanges.h" | 14 #include "modules/indexeddb/IDBObserverChanges.h" |
| 15 #include "modules/indexeddb/IDBObserverInit.h" | 15 #include "modules/indexeddb/IDBObserverInit.h" |
| 16 #include "modules/indexeddb/IDBTransaction.h" | 16 #include "modules/indexeddb/IDBTransaction.h" |
| 17 #include "modules/indexeddb/WebIDBObserverImpl.h" | 17 #include "modules/indexeddb/WebIDBObserverImpl.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 IDBObserver* IDBObserver::create(ScriptState* scriptState, | 21 IDBObserver* IDBObserver::create(IDBObserverCallback* callback, |
| 22 IDBObserverCallback* callback, | |
| 23 const IDBObserverInit& options) { | 22 const IDBObserverInit& options) { |
| 24 return new IDBObserver(scriptState, callback, options); | 23 return new IDBObserver(callback, options); |
| 25 } | 24 } |
| 26 | 25 |
| 27 IDBObserver::IDBObserver(ScriptState* scriptState, | 26 IDBObserver::IDBObserver(IDBObserverCallback* callback, |
| 28 IDBObserverCallback* callback, | |
| 29 const IDBObserverInit& options) | 27 const IDBObserverInit& options) |
| 30 : m_scriptState(scriptState), | 28 : m_callback(callback), |
| 31 m_callback(callback), | |
| 32 m_transaction(options.transaction()), | 29 m_transaction(options.transaction()), |
| 33 m_values(options.values()), | 30 m_values(options.values()), |
| 34 m_noRecords(options.noRecords()) { | 31 m_noRecords(options.noRecords()) { |
| 35 // TODO(palakj): Throw an exception if unknown operation type. | 32 // TODO(palakj): Throw an exception if unknown operation type. |
| 36 DCHECK_EQ(m_operationTypes.size(), | 33 DCHECK_EQ(m_operationTypes.size(), |
| 37 static_cast<size_t>(WebIDBOperationTypeCount)); | 34 static_cast<size_t>(WebIDBOperationTypeCount)); |
| 38 m_operationTypes.reset(); | 35 m_operationTypes.reset(); |
| 39 m_operationTypes[WebIDBAdd] = | 36 m_operationTypes[WebIDBAdd] = |
| 40 options.operationTypes().contains(IndexedDBNames::add); | 37 options.operationTypes().contains(IndexedDBNames::add); |
| 41 m_operationTypes[WebIDBPut] = | 38 m_operationTypes[WebIDBPut] = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 92 |
| 96 void IDBObserver::removeObserver(int32_t id) { | 93 void IDBObserver::removeObserver(int32_t id) { |
| 97 m_observerIds.remove(id); | 94 m_observerIds.remove(id); |
| 98 } | 95 } |
| 99 | 96 |
| 100 void IDBObserver::onChange(int32_t id, | 97 void IDBObserver::onChange(int32_t id, |
| 101 const WebVector<WebIDBObservation>& observations, | 98 const WebVector<WebIDBObservation>& observations, |
| 102 const WebVector<int32_t>& observationIndex) { | 99 const WebVector<int32_t>& observationIndex) { |
| 103 auto it = m_observerIds.find(id); | 100 auto it = m_observerIds.find(id); |
| 104 DCHECK(it != m_observerIds.end()); | 101 DCHECK(it != m_observerIds.end()); |
| 105 m_callback->call( | 102 m_callback->call(this, IDBObserverChanges::create(it->value, observations, |
| 106 m_scriptState.get(), this, | 103 observationIndex)); |
| 107 IDBObserverChanges::create(it->value, observations, observationIndex)); | |
| 108 } | 104 } |
| 109 | 105 |
| 110 DEFINE_TRACE(IDBObserver) { | 106 DEFINE_TRACE(IDBObserver) { |
| 111 visitor->trace(m_callback); | 107 visitor->trace(m_callback); |
| 112 visitor->trace(m_observerIds); | 108 visitor->trace(m_observerIds); |
| 113 } | 109 } |
| 114 | 110 |
| 115 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |