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 <bitset> | 7 #include <bitset> |
8 | 8 |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/modules/v8/IDBObserverCallback.h" | 10 #include "bindings/modules/v8/IDBObserverCallback.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 types[WebIDBClear] = true; | 67 types[WebIDBClear] = true; |
68 } else { | 68 } else { |
69 exceptionState.throwTypeError( | 69 exceptionState.throwTypeError( |
70 "Unknown operation type in observe options: " + operationType); | 70 "Unknown operation type in observe options: " + operationType); |
71 return; | 71 return; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 int32_t observerId = | 75 int32_t observerId = |
76 database->addObserver(this, transaction->id(), options.transaction(), | 76 database->addObserver(this, transaction->id(), options.transaction(), |
77 options.values(), options.noRecords(), types); | 77 options.noRecords(), options.values(), types); |
78 m_observerIds.add(observerId, database); | 78 m_observerIds.add(observerId, database); |
79 } | 79 } |
80 | 80 |
81 void IDBObserver::unobserve(IDBDatabase* database, | 81 void IDBObserver::unobserve(IDBDatabase* database, |
82 ExceptionState& exceptionState) { | 82 ExceptionState& exceptionState) { |
83 if (!database->backend()) { | 83 if (!database->backend()) { |
84 exceptionState.throwDOMException(InvalidStateError, | 84 exceptionState.throwDOMException(InvalidStateError, |
85 IDBDatabase::databaseClosedErrorMessage); | 85 IDBDatabase::databaseClosedErrorMessage); |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 Vector<int32_t> observerIdsToRemove; | 89 Vector<int32_t> observerIdsToRemove; |
90 for (const auto& it : m_observerIds) { | 90 for (const auto& it : m_observerIds) { |
91 if (it.value == database) | 91 if (it.value == database) |
92 observerIdsToRemove.append(it.key); | 92 observerIdsToRemove.append(it.key); |
93 } | 93 } |
94 m_observerIds.removeAll(observerIdsToRemove); | 94 m_observerIds.removeAll(observerIdsToRemove); |
95 | 95 |
96 if (!observerIdsToRemove.isEmpty()) | 96 if (!observerIdsToRemove.isEmpty()) |
97 database->removeObservers(observerIdsToRemove); | 97 database->removeObservers(observerIdsToRemove); |
98 } | 98 } |
99 | 99 |
100 DEFINE_TRACE(IDBObserver) { | 100 DEFINE_TRACE(IDBObserver) { |
101 visitor->trace(m_callback); | 101 visitor->trace(m_callback); |
102 visitor->trace(m_observerIds); | 102 visitor->trace(m_observerIds); |
103 } | 103 } |
104 | 104 |
105 } // namespace blink | 105 } // namespace blink |
OLD | NEW |