Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBObserver.cpp

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: added comments and bug link Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 if (transaction->isFinished() || transaction->isFinishing()) { 33 if (transaction->isFinished() || transaction->isFinishing()) {
34 exceptionState.throwDOMException( 34 exceptionState.throwDOMException(
35 TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage); 35 TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
36 return; 36 return;
37 } 37 }
38 if (!transaction->isActive()) { 38 if (!transaction->isActive()) {
39 exceptionState.throwDOMException( 39 exceptionState.throwDOMException(
40 TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage); 40 TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
41 return; 41 return;
42 } 42 }
43 if (transaction->isVersionChange()) {
44 exceptionState.throwDOMException(
45 TransactionInactiveError,
46 IDBDatabase::cannotObserveVersionChangeTransaction);
47 return;
48 }
43 if (!database->backend()) { 49 if (!database->backend()) {
44 exceptionState.throwDOMException(InvalidStateError, 50 exceptionState.throwDOMException(InvalidStateError,
45 IDBDatabase::databaseClosedErrorMessage); 51 IDBDatabase::databaseClosedErrorMessage);
46 return; 52 return;
47 } 53 }
48 if (!options.hasOperationTypes()) { 54 if (!options.hasOperationTypes()) {
49 exceptionState.throwTypeError( 55 exceptionState.throwTypeError(
50 "operationTypes not specified in observe options."); 56 "operationTypes not specified in observe options.");
51 return; 57 return;
52 } 58 }
(...skipping 14 matching lines...) Expand all
67 types[WebIDBClear] = true; 73 types[WebIDBClear] = true;
68 } else { 74 } else {
69 exceptionState.throwTypeError( 75 exceptionState.throwTypeError(
70 "Unknown operation type in observe options: " + operationType); 76 "Unknown operation type in observe options: " + operationType);
71 return; 77 return;
72 } 78 }
73 } 79 }
74 80
75 int32_t observerId = 81 int32_t observerId =
76 database->addObserver(this, transaction->id(), options.transaction(), 82 database->addObserver(this, transaction->id(), options.transaction(),
77 options.values(), options.noRecords(), types); 83 options.noRecords(), options.values(), types);
78 m_observerIds.add(observerId, database); 84 m_observerIds.add(observerId, database);
79 } 85 }
80 86
81 void IDBObserver::unobserve(IDBDatabase* database, 87 void IDBObserver::unobserve(IDBDatabase* database,
82 ExceptionState& exceptionState) { 88 ExceptionState& exceptionState) {
83 if (!database->backend()) { 89 if (!database->backend()) {
84 exceptionState.throwDOMException(InvalidStateError, 90 exceptionState.throwDOMException(InvalidStateError,
85 IDBDatabase::databaseClosedErrorMessage); 91 IDBDatabase::databaseClosedErrorMessage);
86 return; 92 return;
87 } 93 }
88 94
89 Vector<int32_t> observerIdsToRemove; 95 Vector<int32_t> observerIdsToRemove;
90 for (const auto& it : m_observerIds) { 96 for (const auto& it : m_observerIds) {
91 if (it.value == database) 97 if (it.value == database)
92 observerIdsToRemove.push_back(it.key); 98 observerIdsToRemove.push_back(it.key);
93 } 99 }
94 m_observerIds.removeAll(observerIdsToRemove); 100 m_observerIds.removeAll(observerIdsToRemove);
95 101
96 if (!observerIdsToRemove.isEmpty()) 102 if (!observerIdsToRemove.isEmpty())
97 database->removeObservers(observerIdsToRemove); 103 database->removeObservers(observerIdsToRemove);
98 } 104 }
99 105
100 DEFINE_TRACE(IDBObserver) { 106 DEFINE_TRACE(IDBObserver) {
101 visitor->trace(m_callback); 107 visitor->trace(m_callback);
102 visitor->trace(m_observerIds); 108 visitor->trace(m_observerIds);
103 } 109 }
104 110
105 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698