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

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

Issue 2463673004: [inspector_protocol] Support fall through. (Closed)
Patch Set: example domain converted Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 using blink::protocol::Array; 64 using blink::protocol::Array;
65 using blink::protocol::IndexedDB::DatabaseWithObjectStores; 65 using blink::protocol::IndexedDB::DatabaseWithObjectStores;
66 using blink::protocol::IndexedDB::DataEntry; 66 using blink::protocol::IndexedDB::DataEntry;
67 using blink::protocol::IndexedDB::Key; 67 using blink::protocol::IndexedDB::Key;
68 using blink::protocol::IndexedDB::KeyPath; 68 using blink::protocol::IndexedDB::KeyPath;
69 using blink::protocol::IndexedDB::KeyRange; 69 using blink::protocol::IndexedDB::KeyRange;
70 using blink::protocol::IndexedDB::ObjectStore; 70 using blink::protocol::IndexedDB::ObjectStore;
71 using blink::protocol::IndexedDB::ObjectStoreIndex; 71 using blink::protocol::IndexedDB::ObjectStoreIndex;
72 72
73 typedef blink::protocol::BackendCallback RequestCallback;
74 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseNamesCallback 73 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseNamesCallback
75 RequestDatabaseNamesCallback; 74 RequestDatabaseNamesCallback;
76 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseCallback 75 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseCallback
77 RequestDatabaseCallback; 76 RequestDatabaseCallback;
78 typedef blink::protocol::IndexedDB::Backend::RequestDataCallback 77 typedef blink::protocol::IndexedDB::Backend::RequestDataCallback
79 RequestDataCallback; 78 RequestDataCallback;
80 typedef blink::protocol::IndexedDB::Backend::ClearObjectStoreCallback 79 typedef blink::protocol::IndexedDB::Backend::ClearObjectStoreCallback
81 ClearObjectStoreCallback; 80 ClearObjectStoreCallback;
82 81
83 namespace blink { 82 namespace blink {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 GetDatabaseNamesCallback( 133 GetDatabaseNamesCallback(
135 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback, 134 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback,
136 const String& securityOrigin) 135 const String& securityOrigin)
137 : EventListener(EventListener::CPPEventListenerType), 136 : EventListener(EventListener::CPPEventListenerType),
138 m_requestCallback(std::move(requestCallback)), 137 m_requestCallback(std::move(requestCallback)),
139 m_securityOrigin(securityOrigin) {} 138 m_securityOrigin(securityOrigin) {}
140 std::unique_ptr<RequestDatabaseNamesCallback> m_requestCallback; 139 std::unique_ptr<RequestDatabaseNamesCallback> m_requestCallback;
141 String m_securityOrigin; 140 String m_securityOrigin;
142 }; 141 };
143 142
144 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> { 143 template <typename RequestCallback>
144 class OpenDatabaseCallback;
145 template <typename RequestCallback>
146 class UpgradeDatabaseCallback;
147
148 template <typename RequestCallback>
149 class ExecutableWithDatabase
150 : public RefCounted<ExecutableWithDatabase<RequestCallback>> {
145 public: 151 public:
146 ExecutableWithDatabase(ScriptState* scriptState) 152 ExecutableWithDatabase(ScriptState* scriptState)
147 : m_scriptState(scriptState) {} 153 : m_scriptState(scriptState) {}
148 virtual ~ExecutableWithDatabase() {} 154 virtual ~ExecutableWithDatabase() {}
149 void start(IDBFactory*, SecurityOrigin*, const String& databaseName); 155 void start(IDBFactory* idbFactory,
156 SecurityOrigin*,
157 const String& databaseName) {
158 OpenDatabaseCallback<RequestCallback>* openCallback =
159 OpenDatabaseCallback<RequestCallback>::create(this);
160 UpgradeDatabaseCallback<RequestCallback>* upgradeCallback =
161 UpgradeDatabaseCallback<RequestCallback>::create(this);
162 TrackExceptionState exceptionState;
163 IDBOpenDBRequest* idbOpenDBRequest =
164 idbFactory->open(getScriptState(), databaseName, exceptionState);
165 if (exceptionState.hadException()) {
166 getRequestCallback()->sendFailure("Could not open database.");
167 return;
168 }
169 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded,
170 upgradeCallback, false);
171 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback,
172 false);
173 }
150 virtual void execute(IDBDatabase*) = 0; 174 virtual void execute(IDBDatabase*) = 0;
151 virtual RequestCallback* getRequestCallback() = 0; 175 virtual RequestCallback* getRequestCallback() = 0;
152 ExecutionContext* context() const { 176 ExecutionContext* context() const {
153 return m_scriptState->getExecutionContext(); 177 return m_scriptState->getExecutionContext();
154 } 178 }
155 ScriptState* getScriptState() const { return m_scriptState.get(); } 179 ScriptState* getScriptState() const { return m_scriptState.get(); }
156 180
157 private: 181 private:
158 RefPtr<ScriptState> m_scriptState; 182 RefPtr<ScriptState> m_scriptState;
159 }; 183 };
160 184
185 template <typename RequestCallback>
161 class OpenDatabaseCallback final : public EventListener { 186 class OpenDatabaseCallback final : public EventListener {
162 public: 187 public:
163 static OpenDatabaseCallback* create( 188 static OpenDatabaseCallback* create(
164 ExecutableWithDatabase* executableWithDatabase) { 189 ExecutableWithDatabase<RequestCallback>* executableWithDatabase) {
165 return new OpenDatabaseCallback(executableWithDatabase); 190 return new OpenDatabaseCallback(executableWithDatabase);
166 } 191 }
167 192
168 ~OpenDatabaseCallback() override {} 193 ~OpenDatabaseCallback() override {}
169 194
170 bool operator==(const EventListener& other) const override { 195 bool operator==(const EventListener& other) const override {
171 return this == &other; 196 return this == &other;
172 } 197 }
173 198
174 void handleEvent(ExecutionContext* context, Event* event) override { 199 void handleEvent(ExecutionContext* context, Event* event) override {
(...skipping 14 matching lines...) Expand all
189 214
190 IDBDatabase* idbDatabase = requestResult->idbDatabase(); 215 IDBDatabase* idbDatabase = requestResult->idbDatabase();
191 m_executableWithDatabase->execute(idbDatabase); 216 m_executableWithDatabase->execute(idbDatabase);
192 V8PerIsolateData::from( 217 V8PerIsolateData::from(
193 m_executableWithDatabase->getScriptState()->isolate()) 218 m_executableWithDatabase->getScriptState()->isolate())
194 ->runEndOfScopeTasks(); 219 ->runEndOfScopeTasks();
195 idbDatabase->close(); 220 idbDatabase->close();
196 } 221 }
197 222
198 private: 223 private:
199 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) 224 OpenDatabaseCallback(
225 ExecutableWithDatabase<RequestCallback>* executableWithDatabase)
200 : EventListener(EventListener::CPPEventListenerType), 226 : EventListener(EventListener::CPPEventListenerType),
201 m_executableWithDatabase(executableWithDatabase) {} 227 m_executableWithDatabase(executableWithDatabase) {}
202 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; 228 RefPtr<ExecutableWithDatabase<RequestCallback>> m_executableWithDatabase;
203 }; 229 };
204 230
231 template <typename RequestCallback>
205 class UpgradeDatabaseCallback final : public EventListener { 232 class UpgradeDatabaseCallback final : public EventListener {
206 public: 233 public:
207 static UpgradeDatabaseCallback* create( 234 static UpgradeDatabaseCallback* create(
208 ExecutableWithDatabase* executableWithDatabase) { 235 ExecutableWithDatabase<RequestCallback>* executableWithDatabase) {
209 return new UpgradeDatabaseCallback(executableWithDatabase); 236 return new UpgradeDatabaseCallback(executableWithDatabase);
210 } 237 }
211 238
212 ~UpgradeDatabaseCallback() override {} 239 ~UpgradeDatabaseCallback() override {}
213 240
214 bool operator==(const EventListener& other) const override { 241 bool operator==(const EventListener& other) const override {
215 return this == &other; 242 return this == &other;
216 } 243 }
217 244
218 void handleEvent(ExecutionContext* context, Event* event) override { 245 void handleEvent(ExecutionContext* context, Event* event) override {
219 if (event->type() != EventTypeNames::upgradeneeded) { 246 if (event->type() != EventTypeNames::upgradeneeded) {
220 m_executableWithDatabase->getRequestCallback()->sendFailure( 247 m_executableWithDatabase->getRequestCallback()->sendFailure(
221 "Unexpected event type."); 248 "Unexpected event type.");
222 return; 249 return;
223 } 250 }
224 251
225 // If an "upgradeneeded" event comes through then the database that 252 // If an "upgradeneeded" event comes through then the database that
226 // had previously been enumerated was deleted. We don't want to 253 // had previously been enumerated was deleted. We don't want to
227 // implicitly re-create it here, so abort the transaction. 254 // implicitly re-create it here, so abort the transaction.
228 IDBOpenDBRequest* idbOpenDBRequest = 255 IDBOpenDBRequest* idbOpenDBRequest =
229 static_cast<IDBOpenDBRequest*>(event->target()); 256 static_cast<IDBOpenDBRequest*>(event->target());
230 NonThrowableExceptionState exceptionState; 257 NonThrowableExceptionState exceptionState;
231 idbOpenDBRequest->transaction()->abort(exceptionState); 258 idbOpenDBRequest->transaction()->abort(exceptionState);
232 m_executableWithDatabase->getRequestCallback()->sendFailure( 259 m_executableWithDatabase->getRequestCallback()->sendFailure(
233 "Aborted upgrade."); 260 "Aborted upgrade.");
234 } 261 }
235 262
236 private: 263 private:
237 UpgradeDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) 264 UpgradeDatabaseCallback(
265 ExecutableWithDatabase<RequestCallback>* executableWithDatabase)
238 : EventListener(EventListener::CPPEventListenerType), 266 : EventListener(EventListener::CPPEventListenerType),
239 m_executableWithDatabase(executableWithDatabase) {} 267 m_executableWithDatabase(executableWithDatabase) {}
240 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; 268 RefPtr<ExecutableWithDatabase<RequestCallback>> m_executableWithDatabase;
241 }; 269 };
242 270
243 void ExecutableWithDatabase::start(IDBFactory* idbFactory,
244 SecurityOrigin*,
245 const String& databaseName) {
246 OpenDatabaseCallback* openCallback = OpenDatabaseCallback::create(this);
247 UpgradeDatabaseCallback* upgradeCallback =
248 UpgradeDatabaseCallback::create(this);
249 TrackExceptionState exceptionState;
250 IDBOpenDBRequest* idbOpenDBRequest =
251 idbFactory->open(getScriptState(), databaseName, exceptionState);
252 if (exceptionState.hadException()) {
253 getRequestCallback()->sendFailure("Could not open database.");
254 return;
255 }
256 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded,
257 upgradeCallback, false);
258 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback,
259 false);
260 }
261
262 static IDBTransaction* transactionForDatabase( 271 static IDBTransaction* transactionForDatabase(
263 ScriptState* scriptState, 272 ScriptState* scriptState,
264 IDBDatabase* idbDatabase, 273 IDBDatabase* idbDatabase,
265 const String& objectStoreName, 274 const String& objectStoreName,
266 const String& mode = IndexedDBNames::readonly) { 275 const String& mode = IndexedDBNames::readonly) {
267 TrackExceptionState exceptionState; 276 TrackExceptionState exceptionState;
268 StringOrStringSequenceOrDOMStringList scope; 277 StringOrStringSequenceOrDOMStringList scope;
269 scope.setString(objectStoreName); 278 scope.setString(objectStoreName);
270 IDBTransaction* idbTransaction = 279 IDBTransaction* idbTransaction =
271 idbDatabase->transaction(scriptState, scope, mode, exceptionState); 280 idbDatabase->transaction(scriptState, scope, mode, exceptionState);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 keyPath->setArray(std::move(array)); 326 keyPath->setArray(std::move(array));
318 break; 327 break;
319 } 328 }
320 default: 329 default:
321 ASSERT_NOT_REACHED(); 330 ASSERT_NOT_REACHED();
322 } 331 }
323 332
324 return keyPath; 333 return keyPath;
325 } 334 }
326 335
327 class DatabaseLoader final : public ExecutableWithDatabase { 336 class DatabaseLoader final
337 : public ExecutableWithDatabase<RequestDatabaseCallback> {
328 public: 338 public:
329 static PassRefPtr<DatabaseLoader> create( 339 static PassRefPtr<DatabaseLoader> create(
330 ScriptState* scriptState, 340 ScriptState* scriptState,
331 std::unique_ptr<RequestDatabaseCallback> requestCallback) { 341 std::unique_ptr<RequestDatabaseCallback> requestCallback) {
332 return adoptRef( 342 return adoptRef(
333 new DatabaseLoader(scriptState, std::move(requestCallback))); 343 new DatabaseLoader(scriptState, std::move(requestCallback)));
334 } 344 }
335 345
336 ~DatabaseLoader() override {} 346 ~DatabaseLoader() override {}
337 347
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 std::unique_ptr<DatabaseWithObjectStores> result = 384 std::unique_ptr<DatabaseWithObjectStores> result =
375 DatabaseWithObjectStores::create() 385 DatabaseWithObjectStores::create()
376 .setName(idbDatabase->name()) 386 .setName(idbDatabase->name())
377 .setVersion(idbDatabase->version()) 387 .setVersion(idbDatabase->version())
378 .setObjectStores(std::move(objectStores)) 388 .setObjectStores(std::move(objectStores))
379 .build(); 389 .build();
380 390
381 m_requestCallback->sendSuccess(std::move(result)); 391 m_requestCallback->sendSuccess(std::move(result));
382 } 392 }
383 393
384 RequestCallback* getRequestCallback() override { 394 RequestDatabaseCallback* getRequestCallback() override {
385 return m_requestCallback.get(); 395 return m_requestCallback.get();
386 } 396 }
387 397
388 private: 398 private:
389 DatabaseLoader(ScriptState* scriptState, 399 DatabaseLoader(ScriptState* scriptState,
390 std::unique_ptr<RequestDatabaseCallback> requestCallback) 400 std::unique_ptr<RequestDatabaseCallback> requestCallback)
391 : ExecutableWithDatabase(scriptState), 401 : ExecutableWithDatabase(scriptState),
392 m_requestCallback(std::move(requestCallback)) {} 402 m_requestCallback(std::move(requestCallback)) {}
393 std::unique_ptr<RequestDatabaseCallback> m_requestCallback; 403 std::unique_ptr<RequestDatabaseCallback> m_requestCallback;
394 }; 404 };
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 566 }
557 567
558 v8_inspector::V8InspectorSession* m_v8Session; 568 v8_inspector::V8InspectorSession* m_v8Session;
559 RefPtr<ScriptState> m_scriptState; 569 RefPtr<ScriptState> m_scriptState;
560 std::unique_ptr<RequestDataCallback> m_requestCallback; 570 std::unique_ptr<RequestDataCallback> m_requestCallback;
561 int m_skipCount; 571 int m_skipCount;
562 unsigned m_pageSize; 572 unsigned m_pageSize;
563 std::unique_ptr<Array<DataEntry>> m_result; 573 std::unique_ptr<Array<DataEntry>> m_result;
564 }; 574 };
565 575
566 class DataLoader final : public ExecutableWithDatabase { 576 class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> {
567 public: 577 public:
568 static PassRefPtr<DataLoader> create( 578 static PassRefPtr<DataLoader> create(
569 v8_inspector::V8InspectorSession* v8Session, 579 v8_inspector::V8InspectorSession* v8Session,
570 ScriptState* scriptState, 580 ScriptState* scriptState,
571 std::unique_ptr<RequestDataCallback> requestCallback, 581 std::unique_ptr<RequestDataCallback> requestCallback,
572 const String& objectStoreName, 582 const String& objectStoreName,
573 const String& indexName, 583 const String& indexName,
574 IDBKeyRange* idbKeyRange, 584 IDBKeyRange* idbKeyRange,
575 int skipCount, 585 int skipCount,
576 unsigned pageSize) { 586 unsigned pageSize) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 idbRequest = idbObjectStore->openCursor( 619 idbRequest = idbObjectStore->openCursor(
610 getScriptState(), m_idbKeyRange.get(), WebIDBCursorDirectionNext); 620 getScriptState(), m_idbKeyRange.get(), WebIDBCursorDirectionNext);
611 } 621 }
612 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create( 622 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create(
613 m_v8Session, getScriptState(), std::move(m_requestCallback), 623 m_v8Session, getScriptState(), std::move(m_requestCallback),
614 m_skipCount, m_pageSize); 624 m_skipCount, m_pageSize);
615 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback, 625 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback,
616 false); 626 false);
617 } 627 }
618 628
619 RequestCallback* getRequestCallback() override { 629 RequestDataCallback* getRequestCallback() override {
620 return m_requestCallback.get(); 630 return m_requestCallback.get();
621 } 631 }
622 DataLoader(v8_inspector::V8InspectorSession* v8Session, 632 DataLoader(v8_inspector::V8InspectorSession* v8Session,
623 ScriptState* scriptState, 633 ScriptState* scriptState,
624 std::unique_ptr<RequestDataCallback> requestCallback, 634 std::unique_ptr<RequestDataCallback> requestCallback,
625 const String& objectStoreName, 635 const String& objectStoreName,
626 const String& indexName, 636 const String& indexName,
627 IDBKeyRange* idbKeyRange, 637 IDBKeyRange* idbKeyRange,
628 int skipCount, 638 int skipCount,
629 unsigned pageSize) 639 unsigned pageSize)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 846
837 private: 847 private:
838 ClearObjectStoreListener( 848 ClearObjectStoreListener(
839 std::unique_ptr<ClearObjectStoreCallback> requestCallback) 849 std::unique_ptr<ClearObjectStoreCallback> requestCallback)
840 : EventListener(EventListener::CPPEventListenerType), 850 : EventListener(EventListener::CPPEventListenerType),
841 m_requestCallback(std::move(requestCallback)) {} 851 m_requestCallback(std::move(requestCallback)) {}
842 852
843 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback; 853 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback;
844 }; 854 };
845 855
846 class ClearObjectStore final : public ExecutableWithDatabase { 856 class ClearObjectStore final
857 : public ExecutableWithDatabase<ClearObjectStoreCallback> {
847 public: 858 public:
848 static PassRefPtr<ClearObjectStore> create( 859 static PassRefPtr<ClearObjectStore> create(
849 ScriptState* scriptState, 860 ScriptState* scriptState,
850 const String& objectStoreName, 861 const String& objectStoreName,
851 std::unique_ptr<ClearObjectStoreCallback> requestCallback) { 862 std::unique_ptr<ClearObjectStoreCallback> requestCallback) {
852 return adoptRef(new ClearObjectStore(scriptState, objectStoreName, 863 return adoptRef(new ClearObjectStore(scriptState, objectStoreName,
853 std::move(requestCallback))); 864 std::move(requestCallback)));
854 } 865 }
855 866
856 ClearObjectStore(ScriptState* scriptState, 867 ClearObjectStore(ScriptState* scriptState,
(...skipping 26 matching lines...) Expand all
883 m_requestCallback->sendFailure( 894 m_requestCallback->sendFailure(
884 String::format("Could not clear object store '%s': %d", 895 String::format("Could not clear object store '%s': %d",
885 m_objectStoreName.utf8().data(), ec)); 896 m_objectStoreName.utf8().data(), ec));
886 return; 897 return;
887 } 898 }
888 idbTransaction->addEventListener( 899 idbTransaction->addEventListener(
889 EventTypeNames::complete, 900 EventTypeNames::complete,
890 ClearObjectStoreListener::create(std::move(m_requestCallback)), false); 901 ClearObjectStoreListener::create(std::move(m_requestCallback)), false);
891 } 902 }
892 903
893 RequestCallback* getRequestCallback() override { 904 ClearObjectStoreCallback* getRequestCallback() override {
894 return m_requestCallback.get(); 905 return m_requestCallback.get();
895 } 906 }
896 907
897 private: 908 private:
898 const String m_objectStoreName; 909 const String m_objectStoreName;
899 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback; 910 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback;
900 }; 911 };
901 912
902 void InspectorIndexedDBAgent::clearObjectStore( 913 void InspectorIndexedDBAgent::clearObjectStore(
903 const String& securityOrigin, 914 const String& securityOrigin,
(...skipping 23 matching lines...) Expand all
927 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), 938 clearObjectStore->start(idbFactory, document->getSecurityOrigin(),
928 databaseName); 939 databaseName);
929 } 940 }
930 941
931 DEFINE_TRACE(InspectorIndexedDBAgent) { 942 DEFINE_TRACE(InspectorIndexedDBAgent) {
932 visitor->trace(m_inspectedFrames); 943 visitor->trace(m_inspectedFrames);
933 InspectorBaseAgent::trace(visitor); 944 InspectorBaseAgent::trace(visitor);
934 } 945 }
935 946
936 } // namespace blink 947 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698