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

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

Issue 2397363002: Replace hand-written IDBObserverCallback with auto-generated code (Closed)
Patch Set: Created 4 years, 2 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 "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/modules/v8/IDBObserverCallback.h"
8 #include "bindings/modules/v8/ToV8ForModules.h" 9 #include "bindings/modules/v8/ToV8ForModules.h"
9 #include "bindings/modules/v8/V8BindingForModules.h" 10 #include "bindings/modules/v8/V8BindingForModules.h"
10 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
11 #include "modules/IndexedDBNames.h" 12 #include "modules/IndexedDBNames.h"
12 #include "modules/indexeddb/IDBDatabase.h" 13 #include "modules/indexeddb/IDBDatabase.h"
13 #include "modules/indexeddb/IDBObserverCallback.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(IDBObserverCallback& callback, 21 IDBObserver* IDBObserver::create(ScriptState* scriptState,
22 IDBObserverCallback* callback,
22 const IDBObserverInit& options) { 23 const IDBObserverInit& options) {
23 return new IDBObserver(callback, options); 24 return new IDBObserver(scriptState, callback, options);
24 } 25 }
25 26
26 IDBObserver::IDBObserver(IDBObserverCallback& callback, 27 IDBObserver::IDBObserver(ScriptState* scriptState,
28 IDBObserverCallback* callback,
27 const IDBObserverInit& options) 29 const IDBObserverInit& options)
28 : m_callback(&callback), 30 : m_scriptState(scriptState),
31 m_callback(callback),
29 m_transaction(options.transaction()), 32 m_transaction(options.transaction()),
30 m_values(options.values()), 33 m_values(options.values()),
31 m_noRecords(options.noRecords()) { 34 m_noRecords(options.noRecords()) {
32 // TODO(palakj): Throw an exception if unknown operation type. 35 // TODO(palakj): Throw an exception if unknown operation type.
33 DCHECK_EQ(m_operationTypes.size(), 36 DCHECK_EQ(m_operationTypes.size(),
34 static_cast<size_t>(WebIDBOperationTypeCount)); 37 static_cast<size_t>(WebIDBOperationTypeCount));
35 m_operationTypes.reset(); 38 m_operationTypes.reset();
36 m_operationTypes[WebIDBAdd] = 39 m_operationTypes[WebIDBAdd] =
37 options.operationTypes().contains(IndexedDBNames::add); 40 options.operationTypes().contains(IndexedDBNames::add);
38 m_operationTypes[WebIDBPut] = 41 m_operationTypes[WebIDBPut] =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 95
93 void IDBObserver::removeObserver(int32_t id) { 96 void IDBObserver::removeObserver(int32_t id) {
94 m_observerIds.remove(id); 97 m_observerIds.remove(id);
95 } 98 }
96 99
97 void IDBObserver::onChange(int32_t id, 100 void IDBObserver::onChange(int32_t id,
98 const WebVector<WebIDBObservation>& observations, 101 const WebVector<WebIDBObservation>& observations,
99 const WebVector<int32_t>& observationIndex) { 102 const WebVector<int32_t>& observationIndex) {
100 auto it = m_observerIds.find(id); 103 auto it = m_observerIds.find(id);
101 DCHECK(it != m_observerIds.end()); 104 DCHECK(it != m_observerIds.end());
102 m_callback->handleChanges( 105 // TODO(bashi): Make sure that using TrackExceptionState is OK.
103 *IDBObserverChanges::create(it->value, observations, observationIndex), 106 // crbug.com/653769
haraken 2016/10/07 07:23:35 BTW, is there any scenario where we want to handle
bashi 2016/10/07 07:37:31 (Forgot to reply this...) Yeah, if we don't have
104 *this); 107 TrackExceptionState exceptionState;
108 m_callback->call(
109 m_scriptState.get(), this, exceptionState,
110 IDBObserverChanges::create(it->value, observations, observationIndex));
105 } 111 }
106 112
107 DEFINE_TRACE(IDBObserver) { 113 DEFINE_TRACE(IDBObserver) {
108 visitor->trace(m_callback); 114 visitor->trace(m_callback);
109 visitor->trace(m_observerIds); 115 visitor->trace(m_observerIds);
110 } 116 }
111 117
112 } // namespace blink 118 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698