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

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

Issue 1752213003: DevTools: migrate protocol dispatcher off RefPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 9 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 /* 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 namespace IndexedDBAgentState { 82 namespace IndexedDBAgentState {
83 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; 83 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled";
84 }; 84 };
85 85
86 namespace { 86 namespace {
87 87
88 class GetDatabaseNamesCallback final : public EventListener { 88 class GetDatabaseNamesCallback final : public EventListener {
89 WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback); 89 WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback);
90 public: 90 public:
91 static PassRefPtrWillBeRawPtr<GetDatabaseNamesCallback> create(PassRefPtr<Re questDatabaseNamesCallback> requestCallback, const String& securityOrigin) 91 static PassRefPtrWillBeRawPtr<GetDatabaseNamesCallback> create(PassOwnPtr<Re questDatabaseNamesCallback> requestCallback, const String& securityOrigin)
92 { 92 {
93 return adoptRefWillBeNoop(new GetDatabaseNamesCallback(requestCallback, securityOrigin)); 93 return adoptRefWillBeNoop(new GetDatabaseNamesCallback(requestCallback, securityOrigin));
94 } 94 }
95 95
96 ~GetDatabaseNamesCallback() override { } 96 ~GetDatabaseNamesCallback() override { }
97 97
98 bool operator==(const EventListener& other) const override 98 bool operator==(const EventListener& other) const override
99 { 99 {
100 return this == &other; 100 return this == &other;
101 } 101 }
102 102
103 void handleEvent(ExecutionContext*, Event* event) override 103 void handleEvent(ExecutionContext*, Event* event) override
104 { 104 {
105 if (!m_requestCallback->isActive())
106 return;
107 if (event->type() != EventTypeNames::success) { 105 if (event->type() != EventTypeNames::success) {
108 m_requestCallback->sendFailure("Unexpected event type."); 106 m_requestCallback->sendFailure("Unexpected event type.");
109 return; 107 return;
110 } 108 }
111 109
112 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); 110 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target());
113 IDBAny* requestResult = idbRequest->resultAsAny(); 111 IDBAny* requestResult = idbRequest->resultAsAny();
114 if (requestResult->getType() != IDBAny::DOMStringListType) { 112 if (requestResult->getType() != IDBAny::DOMStringListType) {
115 m_requestCallback->sendFailure("Unexpected result type."); 113 m_requestCallback->sendFailure("Unexpected result type.");
116 return; 114 return;
117 } 115 }
118 116
119 RefPtrWillBeRawPtr<DOMStringList> databaseNamesList = requestResult->dom StringList(); 117 RefPtrWillBeRawPtr<DOMStringList> databaseNamesList = requestResult->dom StringList();
120 OwnPtr<protocol::Array<String>> databaseNames = protocol::Array<String>: :create(); 118 OwnPtr<protocol::Array<String>> databaseNames = protocol::Array<String>: :create();
121 for (size_t i = 0; i < databaseNamesList->length(); ++i) 119 for (size_t i = 0; i < databaseNamesList->length(); ++i)
122 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)) ; 120 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)) ;
123 m_requestCallback->sendSuccess(databaseNames.release()); 121 m_requestCallback->sendSuccess(databaseNames.release());
124 } 122 }
125 123
126 DEFINE_INLINE_VIRTUAL_TRACE() 124 DEFINE_INLINE_VIRTUAL_TRACE()
127 { 125 {
128 EventListener::trace(visitor); 126 EventListener::trace(visitor);
129 } 127 }
130 128
131 private: 129 private:
132 GetDatabaseNamesCallback(PassRefPtr<RequestDatabaseNamesCallback> requestCal lback, const String& securityOrigin) 130 GetDatabaseNamesCallback(PassOwnPtr<RequestDatabaseNamesCallback> requestCal lback, const String& securityOrigin)
133 : EventListener(EventListener::CPPEventListenerType) 131 : EventListener(EventListener::CPPEventListenerType)
134 , m_requestCallback(requestCallback) 132 , m_requestCallback(requestCallback)
135 , m_securityOrigin(securityOrigin) { } 133 , m_securityOrigin(securityOrigin) { }
136 RefPtr<RequestDatabaseNamesCallback> m_requestCallback; 134 OwnPtr<RequestDatabaseNamesCallback> m_requestCallback;
137 String m_securityOrigin; 135 String m_securityOrigin;
138 }; 136 };
139 137
140 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> { 138 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> {
141 public: 139 public:
142 ExecutableWithDatabase(ScriptState* scriptState) 140 ExecutableWithDatabase(ScriptState* scriptState)
143 : m_scriptState(scriptState) { } 141 : m_scriptState(scriptState) { }
144 virtual ~ExecutableWithDatabase() { } 142 virtual ~ExecutableWithDatabase() { }
145 void start(IDBFactory*, SecurityOrigin*, const String& databaseName); 143 void start(IDBFactory*, SecurityOrigin*, const String& databaseName);
146 virtual void execute(IDBDatabase*) = 0; 144 virtual void execute(IDBDatabase*) = 0;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 291 }
294 default: 292 default:
295 ASSERT_NOT_REACHED(); 293 ASSERT_NOT_REACHED();
296 } 294 }
297 295
298 return keyPath.release(); 296 return keyPath.release();
299 } 297 }
300 298
301 class DatabaseLoader final : public ExecutableWithDatabase { 299 class DatabaseLoader final : public ExecutableWithDatabase {
302 public: 300 public:
303 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, PassRefPt r<RequestDatabaseCallback> requestCallback) 301 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, PassOwnPt r<RequestDatabaseCallback> requestCallback)
304 { 302 {
305 return adoptRef(new DatabaseLoader(scriptState, requestCallback)); 303 return adoptRef(new DatabaseLoader(scriptState, requestCallback));
306 } 304 }
307 305
308 ~DatabaseLoader() override { } 306 ~DatabaseLoader() override { }
309 307
310 void execute(IDBDatabase* idbDatabase) override 308 void execute(IDBDatabase* idbDatabase) override
311 { 309 {
312 if (!requestCallback()->isActive())
313 return;
314
315 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata(); 310 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata();
316 311
317 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStore>> objectStores = protocol::Array<protocol::IndexedDB::ObjectStore>::create(); 312 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStore>> objectStores = protocol::Array<protocol::IndexedDB::ObjectStore>::create();
318 313
319 for (const auto& storeMapEntry : databaseMetadata.objectStores) { 314 for (const auto& storeMapEntry : databaseMetadata.objectStores) {
320 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va lue; 315 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va lue;
321 316
322 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStoreIndex>> index es = protocol::Array<protocol::IndexedDB::ObjectStoreIndex>::create(); 317 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStoreIndex>> index es = protocol::Array<protocol::IndexedDB::ObjectStoreIndex>::create();
323 318
324 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) { 319 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) {
(...skipping 17 matching lines...) Expand all
342 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea te() 337 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea te()
343 .setName(databaseMetadata.name) 338 .setName(databaseMetadata.name)
344 .setVersion(databaseMetadata.version) 339 .setVersion(databaseMetadata.version)
345 .setObjectStores(objectStores.release()).build(); 340 .setObjectStores(objectStores.release()).build();
346 341
347 m_requestCallback->sendSuccess(result.release()); 342 m_requestCallback->sendSuccess(result.release());
348 } 343 }
349 344
350 RequestCallback* requestCallback() override { return m_requestCallback.get() ; } 345 RequestCallback* requestCallback() override { return m_requestCallback.get() ; }
351 private: 346 private:
352 DatabaseLoader(ScriptState* scriptState, PassRefPtr<RequestDatabaseCallback> requestCallback) 347 DatabaseLoader(ScriptState* scriptState, PassOwnPtr<RequestDatabaseCallback> requestCallback)
353 : ExecutableWithDatabase(scriptState) 348 : ExecutableWithDatabase(scriptState)
354 , m_requestCallback(requestCallback) { } 349 , m_requestCallback(requestCallback) { }
355 RefPtr<RequestDatabaseCallback> m_requestCallback; 350 OwnPtr<RequestDatabaseCallback> m_requestCallback;
356 }; 351 };
357 352
358 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key) 353 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key)
359 { 354 {
360 IDBKey* idbKey; 355 IDBKey* idbKey;
361 356
362 if (!key) 357 if (!key)
363 return nullptr; 358 return nullptr;
364 String type = key->getType(); 359 String type = key->getType();
365 360
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 400
406 IDBKeyRange::LowerBoundType lowerBoundType = keyRange->getLowerOpen() ? IDBK eyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed; 401 IDBKeyRange::LowerBoundType lowerBoundType = keyRange->getLowerOpen() ? IDBK eyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed;
407 IDBKeyRange::UpperBoundType upperBoundType = keyRange->getUpperOpen() ? IDBK eyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed; 402 IDBKeyRange::UpperBoundType upperBoundType = keyRange->getUpperOpen() ? IDBK eyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed;
408 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e); 403 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e);
409 } 404 }
410 405
411 class DataLoader; 406 class DataLoader;
412 407
413 class OpenCursorCallback final : public EventListener { 408 class OpenCursorCallback final : public EventListener {
414 public: 409 public:
415 static PassRefPtrWillBeRawPtr<OpenCursorCallback> create(ScriptState* script State, PassRefPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize) 410 static PassRefPtrWillBeRawPtr<OpenCursorCallback> create(ScriptState* script State, PassOwnPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize)
416 { 411 {
417 return adoptRefWillBeNoop(new OpenCursorCallback(scriptState, requestCal lback, skipCount, pageSize)); 412 return adoptRefWillBeNoop(new OpenCursorCallback(scriptState, requestCal lback, skipCount, pageSize));
418 } 413 }
419 414
420 ~OpenCursorCallback() override { } 415 ~OpenCursorCallback() override { }
421 416
422 bool operator==(const EventListener& other) const override 417 bool operator==(const EventListener& other) const override
423 { 418 {
424 return this == &other; 419 return this == &other;
425 } 420 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr ing() : errorMessage; 477 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr ing() : errorMessage;
483 OwnPtr<DataEntry> dataEntry = DataEntry::create() 478 OwnPtr<DataEntry> dataEntry = DataEntry::create()
484 .setKey(key) 479 .setKey(key)
485 .setPrimaryKey(primaryKey) 480 .setPrimaryKey(primaryKey)
486 .setValue(value).build(); 481 .setValue(value).build();
487 m_result->addItem(dataEntry.release()); 482 m_result->addItem(dataEntry.release());
488 } 483 }
489 484
490 void end(bool hasMore) 485 void end(bool hasMore)
491 { 486 {
492 if (!m_requestCallback->isActive())
493 return;
494 m_requestCallback->sendSuccess(m_result.release(), hasMore); 487 m_requestCallback->sendSuccess(m_result.release(), hasMore);
495 } 488 }
496 489
497 DEFINE_INLINE_VIRTUAL_TRACE() 490 DEFINE_INLINE_VIRTUAL_TRACE()
498 { 491 {
499 EventListener::trace(visitor); 492 EventListener::trace(visitor);
500 } 493 }
501 494
502 private: 495 private:
503 OpenCursorCallback(ScriptState* scriptState, PassRefPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize) 496 OpenCursorCallback(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize)
504 : EventListener(EventListener::CPPEventListenerType) 497 : EventListener(EventListener::CPPEventListenerType)
505 , m_scriptState(scriptState) 498 , m_scriptState(scriptState)
506 , m_requestCallback(requestCallback) 499 , m_requestCallback(requestCallback)
507 , m_skipCount(skipCount) 500 , m_skipCount(skipCount)
508 , m_pageSize(pageSize) 501 , m_pageSize(pageSize)
509 { 502 {
510 m_result = Array<DataEntry>::create(); 503 m_result = Array<DataEntry>::create();
511 } 504 }
512 505
513 RefPtr<ScriptState> m_scriptState; 506 RefPtr<ScriptState> m_scriptState;
514 RefPtr<RequestDataCallback> m_requestCallback; 507 OwnPtr<RequestDataCallback> m_requestCallback;
515 int m_skipCount; 508 int m_skipCount;
516 unsigned m_pageSize; 509 unsigned m_pageSize;
517 OwnPtr<Array<DataEntry>> m_result; 510 OwnPtr<Array<DataEntry>> m_result;
518 }; 511 };
519 512
520 class DataLoader final : public ExecutableWithDatabase { 513 class DataLoader final : public ExecutableWithDatabase {
521 public: 514 public:
522 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassRefPtr<Re questDataCallback> requestCallback, const String& objectStoreName, const String& indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) 515 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassOwnPtr<Re questDataCallback> requestCallback, const String& objectStoreName, const String& indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize)
523 { 516 {
524 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore Name, indexName, idbKeyRange, skipCount, pageSize)); 517 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore Name, indexName, idbKeyRange, skipCount, pageSize));
525 } 518 }
526 519
527 ~DataLoader() override { } 520 ~DataLoader() override { }
528 521
529 void execute(IDBDatabase* idbDatabase) override 522 void execute(IDBDatabase* idbDatabase) override
530 { 523 {
531 if (!requestCallback()->isActive())
532 return;
533 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i dbDatabase, m_objectStoreName); 524 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i dbDatabase, m_objectStoreName);
534 if (!idbTransaction) { 525 if (!idbTransaction) {
535 m_requestCallback->sendFailure("Could not get transaction"); 526 m_requestCallback->sendFailure("Could not get transaction");
536 return; 527 return;
537 } 528 }
538 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio n, m_objectStoreName); 529 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio n, m_objectStoreName);
539 if (!idbObjectStore) { 530 if (!idbObjectStore) {
540 m_requestCallback->sendFailure("Could not get object store"); 531 m_requestCallback->sendFailure("Could not get object store");
541 return; 532 return;
542 } 533 }
543 534
544 RefPtrWillBeRawPtr<OpenCursorCallback> openCursorCallback = OpenCursorCa llback::create(scriptState(), m_requestCallback, m_skipCount, m_pageSize);
545
546 IDBRequest* idbRequest; 535 IDBRequest* idbRequest;
547 if (!m_indexName.isEmpty()) { 536 if (!m_indexName.isEmpty()) {
548 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName ); 537 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName );
549 if (!idbIndex) { 538 if (!idbIndex) {
550 m_requestCallback->sendFailure("Could not get index"); 539 m_requestCallback->sendFailure("Could not get index");
551 return; 540 return;
552 } 541 }
553 542
554 idbRequest = idbIndex->openCursor(scriptState(), m_idbKeyRange.get() , WebIDBCursorDirectionNext); 543 idbRequest = idbIndex->openCursor(scriptState(), m_idbKeyRange.get() , WebIDBCursorDirectionNext);
555 } else { 544 } else {
556 idbRequest = idbObjectStore->openCursor(scriptState(), m_idbKeyRange .get(), WebIDBCursorDirectionNext); 545 idbRequest = idbObjectStore->openCursor(scriptState(), m_idbKeyRange .get(), WebIDBCursorDirectionNext);
557 } 546 }
547 RefPtrWillBeRawPtr<OpenCursorCallback> openCursorCallback = OpenCursorCa llback::create(scriptState(), m_requestCallback.release(), m_skipCount, m_pageSi ze);
558 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback , false); 548 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback , false);
559 } 549 }
560 550
561 RequestCallback* requestCallback() override { return m_requestCallback.get() ; } 551 RequestCallback* requestCallback() override { return m_requestCallback.get() ; }
562 DataLoader(ScriptState* scriptState, PassRefPtr<RequestDataCallback> request Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i dbKeyRange, int skipCount, unsigned pageSize) 552 DataLoader(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> request Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i dbKeyRange, int skipCount, unsigned pageSize)
563 : ExecutableWithDatabase(scriptState) 553 : ExecutableWithDatabase(scriptState)
564 , m_requestCallback(requestCallback) 554 , m_requestCallback(requestCallback)
565 , m_objectStoreName(objectStoreName) 555 , m_objectStoreName(objectStoreName)
566 , m_indexName(indexName) 556 , m_indexName(indexName)
567 , m_idbKeyRange(idbKeyRange) 557 , m_idbKeyRange(idbKeyRange)
568 , m_skipCount(skipCount) 558 , m_skipCount(skipCount)
569 , m_pageSize(pageSize) 559 , m_pageSize(pageSize)
570 { 560 {
571 } 561 }
572 562
573 RefPtr<RequestDataCallback> m_requestCallback; 563 OwnPtr<RequestDataCallback> m_requestCallback;
574 String m_objectStoreName; 564 String m_objectStoreName;
575 String m_indexName; 565 String m_indexName;
576 Persistent<IDBKeyRange> m_idbKeyRange; 566 Persistent<IDBKeyRange> m_idbKeyRange;
577 int m_skipCount; 567 int m_skipCount;
578 unsigned m_pageSize; 568 unsigned m_pageSize;
579 }; 569 };
580 570
581 } // namespace 571 } // namespace
582 572
583 // static 573 // static
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 return nullptr; 622 return nullptr;
633 } 623 }
634 IDBFactory* idbFactory = DOMWindowIndexedDatabase::indexedDB(*domWindow); 624 IDBFactory* idbFactory = DOMWindowIndexedDatabase::indexedDB(*domWindow);
635 625
636 if (!idbFactory) 626 if (!idbFactory)
637 *errorString = "No IndexedDB factory for given frame found"; 627 *errorString = "No IndexedDB factory for given frame found";
638 628
639 return idbFactory; 629 return idbFactory;
640 } 630 }
641 631
642 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtr<RequestDatabaseNamesCallback> requestCallb ack) 632 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, PassOwnPtr<RequestDatabaseNamesCallback> requestCallb ack)
643 { 633 {
644 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 634 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
645 Document* document = assertDocument(errorString, frame); 635 Document* document = assertDocument(errorString, frame);
646 if (!document) 636 if (!document)
647 return; 637 return;
648 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 638 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
649 if (!idbFactory) 639 if (!idbFactory)
650 return; 640 return;
651 641
652 ScriptState* scriptState = ScriptState::forMainWorld(frame); 642 ScriptState* scriptState = ScriptState::forMainWorld(frame);
653 if (!scriptState) 643 if (!scriptState)
654 return; 644 return;
655 ScriptState::Scope scope(scriptState); 645 ScriptState::Scope scope(scriptState);
656 TrackExceptionState exceptionState; 646 TrackExceptionState exceptionState;
657 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception State); 647 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception State);
658 if (exceptionState.hadException()) { 648 if (exceptionState.hadException()) {
659 requestCallback->sendFailure("Could not obtain database names."); 649 requestCallback->sendFailure("Could not obtain database names.");
660 return; 650 return;
661 } 651 }
662 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba ck::create(requestCallback, document->securityOrigin()->toRawString()), false); 652 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba ck::create(requestCallback, document->securityOrigin()->toRawString()), false);
663 } 653 }
664 654
665 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St ring& securityOrigin, const String& databaseName, PassRefPtr<RequestDatabaseCall back> requestCallback) 655 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St ring& securityOrigin, const String& databaseName, PassOwnPtr<RequestDatabaseCall back> requestCallback)
666 { 656 {
667 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 657 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
668 Document* document = assertDocument(errorString, frame); 658 Document* document = assertDocument(errorString, frame);
669 if (!document) 659 if (!document)
670 return; 660 return;
671 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 661 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
672 if (!idbFactory) 662 if (!idbFactory)
673 return; 663 return;
674 664
675 ScriptState* scriptState = ScriptState::forMainWorld(frame); 665 ScriptState* scriptState = ScriptState::forMainWorld(frame);
676 if (!scriptState) 666 if (!scriptState)
677 return; 667 return;
678 ScriptState::Scope scope(scriptState); 668 ScriptState::Scope scope(scriptState);
679 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState, requestCallback); 669 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState, requestCallback);
680 databaseLoader->start(idbFactory, document->securityOrigin(), databaseName); 670 databaseLoader->start(idbFactory, document->securityOrigin(), databaseName);
681 } 671 }
682 672
683 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, 673 void InspectorIndexedDBAgent::requestData(ErrorString* errorString,
684 const String& securityOrigin, 674 const String& securityOrigin,
685 const String& databaseName, 675 const String& databaseName,
686 const String& objectStoreName, 676 const String& objectStoreName,
687 const String& indexName, 677 const String& indexName,
688 int skipCount, 678 int skipCount,
689 int pageSize, 679 int pageSize,
690 const Maybe<protocol::IndexedDB::KeyRange>& keyRange, 680 const Maybe<protocol::IndexedDB::KeyRange>& keyRange,
691 const PassRefPtr<RequestDataCallback> requestCallback) 681 const PassOwnPtr<RequestDataCallback> requestCallback)
692 { 682 {
693 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 683 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
694 Document* document = assertDocument(errorString, frame); 684 Document* document = assertDocument(errorString, frame);
695 if (!document) 685 if (!document)
696 return; 686 return;
697 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 687 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
698 if (!idbFactory) 688 if (!idbFactory)
699 return; 689 return;
700 690
701 IDBKeyRange* idbKeyRange = keyRange.isJust() ? idbKeyRangeFromKeyRange(keyRa nge.fromJust()) : nullptr; 691 IDBKeyRange* idbKeyRange = keyRange.isJust() ? idbKeyRangeFromKeyRange(keyRa nge.fromJust()) : nullptr;
702 if (keyRange.isJust() && !idbKeyRange) { 692 if (keyRange.isJust() && !idbKeyRange) {
703 *errorString = "Can not parse key range."; 693 *errorString = "Can not parse key range.";
704 return; 694 return;
705 } 695 }
706 696
707 ScriptState* scriptState = ScriptState::forMainWorld(frame); 697 ScriptState* scriptState = ScriptState::forMainWorld(frame);
708 if (!scriptState) 698 if (!scriptState)
709 return; 699 return;
710 ScriptState::Scope scope(scriptState); 700 ScriptState::Scope scope(scriptState);
711 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); 701 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize);
712 dataLoader->start(idbFactory, document->securityOrigin(), databaseName); 702 dataLoader->start(idbFactory, document->securityOrigin(), databaseName);
713 } 703 }
714 704
715 class ClearObjectStoreListener final : public EventListener { 705 class ClearObjectStoreListener final : public EventListener {
716 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); 706 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener);
717 public: 707 public:
718 static PassRefPtrWillBeRawPtr<ClearObjectStoreListener> create(PassRefPtr<Cl earObjectStoreCallback> requestCallback) 708 static PassRefPtrWillBeRawPtr<ClearObjectStoreListener> create(PassOwnPtr<Cl earObjectStoreCallback> requestCallback)
719 { 709 {
720 return adoptRefWillBeNoop(new ClearObjectStoreListener(requestCallback)) ; 710 return adoptRefWillBeNoop(new ClearObjectStoreListener(requestCallback)) ;
721 } 711 }
722 712
723 ~ClearObjectStoreListener() override { } 713 ~ClearObjectStoreListener() override { }
724 714
725 bool operator==(const EventListener& other) const override 715 bool operator==(const EventListener& other) const override
726 { 716 {
727 return this == &other; 717 return this == &other;
728 } 718 }
729 719
730 void handleEvent(ExecutionContext*, Event* event) override 720 void handleEvent(ExecutionContext*, Event* event) override
731 { 721 {
732 if (!m_requestCallback->isActive())
733 return;
734 if (event->type() != EventTypeNames::complete) { 722 if (event->type() != EventTypeNames::complete) {
735 m_requestCallback->sendFailure("Unexpected event type."); 723 m_requestCallback->sendFailure("Unexpected event type.");
736 return; 724 return;
737 } 725 }
738 726
739 m_requestCallback->sendSuccess(); 727 m_requestCallback->sendSuccess();
740 } 728 }
741 729
742 DEFINE_INLINE_VIRTUAL_TRACE() 730 DEFINE_INLINE_VIRTUAL_TRACE()
743 { 731 {
744 EventListener::trace(visitor); 732 EventListener::trace(visitor);
745 } 733 }
746 734
747 private: 735 private:
748 ClearObjectStoreListener(PassRefPtr<ClearObjectStoreCallback> requestCallbac k) 736 ClearObjectStoreListener(PassOwnPtr<ClearObjectStoreCallback> requestCallbac k)
749 : EventListener(EventListener::CPPEventListenerType) 737 : EventListener(EventListener::CPPEventListenerType)
750 , m_requestCallback(requestCallback) 738 , m_requestCallback(requestCallback)
751 { 739 {
752 } 740 }
753 741
754 RefPtr<ClearObjectStoreCallback> m_requestCallback; 742 OwnPtr<ClearObjectStoreCallback> m_requestCallback;
755 }; 743 };
756 744
757 745
758 class ClearObjectStore final : public ExecutableWithDatabase { 746 class ClearObjectStore final : public ExecutableWithDatabase {
759 public: 747 public:
760 static PassRefPtr<ClearObjectStore> create(ScriptState* scriptState, const S tring& objectStoreName, PassRefPtr<ClearObjectStoreCallback> requestCallback) 748 static PassRefPtr<ClearObjectStore> create(ScriptState* scriptState, const S tring& objectStoreName, PassOwnPtr<ClearObjectStoreCallback> requestCallback)
761 { 749 {
762 return adoptRef(new ClearObjectStore(scriptState, objectStoreName, reque stCallback)); 750 return adoptRef(new ClearObjectStore(scriptState, objectStoreName, reque stCallback));
763 } 751 }
764 752
765 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, Pa ssRefPtr<ClearObjectStoreCallback> requestCallback) 753 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, Pa ssOwnPtr<ClearObjectStoreCallback> requestCallback)
766 : ExecutableWithDatabase(scriptState) 754 : ExecutableWithDatabase(scriptState)
767 , m_objectStoreName(objectStoreName) 755 , m_objectStoreName(objectStoreName)
768 , m_requestCallback(requestCallback) 756 , m_requestCallback(requestCallback)
769 { 757 {
770 } 758 }
771 759
772 void execute(IDBDatabase* idbDatabase) override 760 void execute(IDBDatabase* idbDatabase) override
773 { 761 {
774 if (!requestCallback()->isActive())
775 return;
776 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i dbDatabase, m_objectStoreName, IndexedDBNames::readwrite); 762 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i dbDatabase, m_objectStoreName, IndexedDBNames::readwrite);
777 if (!idbTransaction) { 763 if (!idbTransaction) {
778 m_requestCallback->sendFailure("Could not get transaction"); 764 m_requestCallback->sendFailure("Could not get transaction");
779 return; 765 return;
780 } 766 }
781 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio n, m_objectStoreName); 767 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio n, m_objectStoreName);
782 if (!idbObjectStore) { 768 if (!idbObjectStore) {
783 m_requestCallback->sendFailure("Could not get object store"); 769 m_requestCallback->sendFailure("Could not get object store");
784 return; 770 return;
785 } 771 }
786 772
787 TrackExceptionState exceptionState; 773 TrackExceptionState exceptionState;
788 idbObjectStore->clear(scriptState(), exceptionState); 774 idbObjectStore->clear(scriptState(), exceptionState);
789 ASSERT(!exceptionState.hadException()); 775 ASSERT(!exceptionState.hadException());
790 if (exceptionState.hadException()) { 776 if (exceptionState.hadException()) {
791 ExceptionCode ec = exceptionState.code(); 777 ExceptionCode ec = exceptionState.code();
792 m_requestCallback->sendFailure(String::format("Could not clear objec t store '%s': %d", m_objectStoreName.utf8().data(), ec)); 778 m_requestCallback->sendFailure(String::format("Could not clear objec t store '%s': %d", m_objectStoreName.utf8().data(), ec));
793 return; 779 return;
794 } 780 }
795 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt oreListener::create(m_requestCallback), false); 781 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt oreListener::create(m_requestCallback.release()), false);
796 } 782 }
797 783
798 RequestCallback* requestCallback() override { return m_requestCallback.get() ; } 784 RequestCallback* requestCallback() override { return m_requestCallback.get() ; }
799 private: 785 private:
800 const String m_objectStoreName; 786 const String m_objectStoreName;
801 RefPtr<ClearObjectStoreCallback> m_requestCallback; 787 OwnPtr<ClearObjectStoreCallback> m_requestCallback;
802 }; 788 };
803 789
804 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S tring& securityOrigin, const String& databaseName, const String& objectStoreName , PassRefPtr<ClearObjectStoreCallback> requestCallback) 790 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S tring& securityOrigin, const String& databaseName, const String& objectStoreName , PassOwnPtr<ClearObjectStoreCallback> requestCallback)
805 { 791 {
806 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 792 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
807 Document* document = assertDocument(errorString, frame); 793 Document* document = assertDocument(errorString, frame);
808 if (!document) 794 if (!document)
809 return; 795 return;
810 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 796 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
811 if (!idbFactory) 797 if (!idbFactory)
812 return; 798 return;
813 799
814 ScriptState* scriptState = ScriptState::forMainWorld(frame); 800 ScriptState* scriptState = ScriptState::forMainWorld(frame);
815 if (!scriptState) 801 if (!scriptState)
816 return; 802 return;
817 ScriptState::Scope scope(scriptState); 803 ScriptState::Scope scope(scriptState);
818 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, requestCallback); 804 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, requestCallback);
819 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName ); 805 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName );
820 } 806 }
821 807
822 DEFINE_TRACE(InspectorIndexedDBAgent) 808 DEFINE_TRACE(InspectorIndexedDBAgent)
823 { 809 {
824 visitor->trace(m_inspectedFrames); 810 visitor->trace(m_inspectedFrames);
825 InspectorBaseAgent::trace(visitor); 811 InspectorBaseAgent::trace(visitor);
826 } 812 }
827 813
828 } // namespace blink 814 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698