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

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

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 6 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 GetDatabaseNamesCallback* create(PassOwnPtr<RequestDatabaseNamesCallb ack> requestCallback, const String& securityOrigin) 91 static GetDatabaseNamesCallback* create(std::unique_ptr<RequestDatabaseNames Callback> requestCallback, const String& securityOrigin)
92 { 92 {
93 return new GetDatabaseNamesCallback(std::move(requestCallback), security Origin); 93 return new GetDatabaseNamesCallback(std::move(requestCallback), security Origin);
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 (event->type() != EventTypeNames::success) { 105 if (event->type() != EventTypeNames::success) {
106 m_requestCallback->sendFailure("Unexpected event type."); 106 m_requestCallback->sendFailure("Unexpected event type.");
107 return; 107 return;
108 } 108 }
109 109
110 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); 110 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target());
111 IDBAny* requestResult = idbRequest->resultAsAny(); 111 IDBAny* requestResult = idbRequest->resultAsAny();
112 if (requestResult->getType() != IDBAny::DOMStringListType) { 112 if (requestResult->getType() != IDBAny::DOMStringListType) {
113 m_requestCallback->sendFailure("Unexpected result type."); 113 m_requestCallback->sendFailure("Unexpected result type.");
114 return; 114 return;
115 } 115 }
116 116
117 DOMStringList* databaseNamesList = requestResult->domStringList(); 117 DOMStringList* databaseNamesList = requestResult->domStringList();
118 OwnPtr<protocol::Array<String>> databaseNames = protocol::Array<String>: :create(); 118 std::unique_ptr<protocol::Array<String>> databaseNames = protocol::Array <String>::create();
119 for (size_t i = 0; i < databaseNamesList->length(); ++i) 119 for (size_t i = 0; i < databaseNamesList->length(); ++i)
120 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)) ; 120 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)) ;
121 m_requestCallback->sendSuccess(std::move(databaseNames)); 121 m_requestCallback->sendSuccess(std::move(databaseNames));
122 } 122 }
123 123
124 DEFINE_INLINE_VIRTUAL_TRACE() 124 DEFINE_INLINE_VIRTUAL_TRACE()
125 { 125 {
126 EventListener::trace(visitor); 126 EventListener::trace(visitor);
127 } 127 }
128 128
129 private: 129 private:
130 GetDatabaseNamesCallback(PassOwnPtr<RequestDatabaseNamesCallback> requestCal lback, const String& securityOrigin) 130 GetDatabaseNamesCallback(std::unique_ptr<RequestDatabaseNamesCallback> reque stCallback, const String& securityOrigin)
131 : EventListener(EventListener::CPPEventListenerType) 131 : EventListener(EventListener::CPPEventListenerType)
132 , m_requestCallback(std::move(requestCallback)) 132 , m_requestCallback(std::move(requestCallback))
133 , m_securityOrigin(securityOrigin) { } 133 , m_securityOrigin(securityOrigin) { }
134 OwnPtr<RequestDatabaseNamesCallback> m_requestCallback; 134 std::unique_ptr<RequestDatabaseNamesCallback> m_requestCallback;
135 String m_securityOrigin; 135 String m_securityOrigin;
136 }; 136 };
137 137
138 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> { 138 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> {
139 public: 139 public:
140 ExecutableWithDatabase(ScriptState* scriptState) 140 ExecutableWithDatabase(ScriptState* scriptState)
141 : m_scriptState(scriptState) { } 141 : m_scriptState(scriptState) { }
142 virtual ~ExecutableWithDatabase() { } 142 virtual ~ExecutableWithDatabase() { }
143 void start(IDBFactory*, SecurityOrigin*, const String& databaseName); 143 void start(IDBFactory*, SecurityOrigin*, const String& databaseName);
144 virtual void execute(IDBDatabase*) = 0; 144 virtual void execute(IDBDatabase*) = 0;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin g& indexName) 264 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin g& indexName)
265 { 265 {
266 TrackExceptionState exceptionState; 266 TrackExceptionState exceptionState;
267 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState); 267 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState);
268 if (exceptionState.hadException()) 268 if (exceptionState.hadException())
269 return nullptr; 269 return nullptr;
270 return idbIndex; 270 return idbIndex;
271 } 271 }
272 272
273 static PassOwnPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) 273 static std::unique_ptr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPa th)
274 { 274 {
275 OwnPtr<KeyPath> keyPath; 275 std::unique_ptr<KeyPath> keyPath;
276 switch (idbKeyPath.getType()) { 276 switch (idbKeyPath.getType()) {
277 case IDBKeyPath::NullType: 277 case IDBKeyPath::NullType:
278 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Null).build(); 278 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Null).build();
279 break; 279 break;
280 case IDBKeyPath::StringType: 280 case IDBKeyPath::StringType:
281 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::String).setString (idbKeyPath.string()).build(); 281 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::String).setString (idbKeyPath.string()).build();
282 break; 282 break;
283 case IDBKeyPath::ArrayType: { 283 case IDBKeyPath::ArrayType: {
284 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Array).build(); 284 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Array).build();
285 OwnPtr<protocol::Array<String>> array = protocol::Array<String>::create( ); 285 std::unique_ptr<protocol::Array<String>> array = protocol::Array<String> ::create();
286 const Vector<String>& stringArray = idbKeyPath.array(); 286 const Vector<String>& stringArray = idbKeyPath.array();
287 for (size_t i = 0; i < stringArray.size(); ++i) 287 for (size_t i = 0; i < stringArray.size(); ++i)
288 array->addItem(stringArray[i]); 288 array->addItem(stringArray[i]);
289 keyPath->setArray(std::move(array)); 289 keyPath->setArray(std::move(array));
290 break; 290 break;
291 } 291 }
292 default: 292 default:
293 ASSERT_NOT_REACHED(); 293 ASSERT_NOT_REACHED();
294 } 294 }
295 295
296 return keyPath; 296 return keyPath;
297 } 297 }
298 298
299 class DatabaseLoader final : public ExecutableWithDatabase { 299 class DatabaseLoader final : public ExecutableWithDatabase {
300 public: 300 public:
301 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, PassOwnPt r<RequestDatabaseCallback> requestCallback) 301 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, std::uniq ue_ptr<RequestDatabaseCallback> requestCallback)
302 { 302 {
303 return adoptRef(new DatabaseLoader(scriptState, std::move(requestCallbac k))); 303 return adoptRef(new DatabaseLoader(scriptState, std::move(requestCallbac k)));
304 } 304 }
305 305
306 ~DatabaseLoader() override { } 306 ~DatabaseLoader() override { }
307 307
308 void execute(IDBDatabase* idbDatabase) override 308 void execute(IDBDatabase* idbDatabase) override
309 { 309 {
310 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata(); 310 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata();
311 311
312 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStore>> objectStores = protocol::Array<protocol::IndexedDB::ObjectStore>::create(); 312 std::unique_ptr<protocol::Array<protocol::IndexedDB::ObjectStore>> objec tStores = protocol::Array<protocol::IndexedDB::ObjectStore>::create();
313 313
314 for (const auto& storeMapEntry : databaseMetadata.objectStores) { 314 for (const auto& storeMapEntry : databaseMetadata.objectStores) {
315 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va lue; 315 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va lue;
316 316
317 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStoreIndex>> index es = protocol::Array<protocol::IndexedDB::ObjectStoreIndex>::create(); 317 std::unique_ptr<protocol::Array<protocol::IndexedDB::ObjectStoreInde x>> indexes = protocol::Array<protocol::IndexedDB::ObjectStoreIndex>::create();
318 318
319 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) { 319 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) {
320 const IDBIndexMetadata& indexMetadata = metadataMapEntry.value; 320 const IDBIndexMetadata& indexMetadata = metadataMapEntry.value;
321 321
322 OwnPtr<ObjectStoreIndex> objectStoreIndex = ObjectStoreIndex::cr eate() 322 std::unique_ptr<ObjectStoreIndex> objectStoreIndex = ObjectStore Index::create()
323 .setName(indexMetadata.name) 323 .setName(indexMetadata.name)
324 .setKeyPath(keyPathFromIDBKeyPath(indexMetadata.keyPath)) 324 .setKeyPath(keyPathFromIDBKeyPath(indexMetadata.keyPath))
325 .setUnique(indexMetadata.unique) 325 .setUnique(indexMetadata.unique)
326 .setMultiEntry(indexMetadata.multiEntry).build(); 326 .setMultiEntry(indexMetadata.multiEntry).build();
327 indexes->addItem(std::move(objectStoreIndex)); 327 indexes->addItem(std::move(objectStoreIndex));
328 } 328 }
329 329
330 OwnPtr<ObjectStore> objectStore = ObjectStore::create() 330 std::unique_ptr<ObjectStore> objectStore = ObjectStore::create()
331 .setName(objectStoreMetadata.name) 331 .setName(objectStoreMetadata.name)
332 .setKeyPath(keyPathFromIDBKeyPath(objectStoreMetadata.keyPath)) 332 .setKeyPath(keyPathFromIDBKeyPath(objectStoreMetadata.keyPath))
333 .setAutoIncrement(objectStoreMetadata.autoIncrement) 333 .setAutoIncrement(objectStoreMetadata.autoIncrement)
334 .setIndexes(std::move(indexes)).build(); 334 .setIndexes(std::move(indexes)).build();
335 objectStores->addItem(std::move(objectStore)); 335 objectStores->addItem(std::move(objectStore));
336 } 336 }
337 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea te() 337 std::unique_ptr<DatabaseWithObjectStores> result = DatabaseWithObjectSto res::create()
338 .setName(databaseMetadata.name) 338 .setName(databaseMetadata.name)
339 .setVersion(databaseMetadata.version) 339 .setVersion(databaseMetadata.version)
340 .setObjectStores(std::move(objectStores)).build(); 340 .setObjectStores(std::move(objectStores)).build();
341 341
342 m_requestCallback->sendSuccess(std::move(result)); 342 m_requestCallback->sendSuccess(std::move(result));
343 } 343 }
344 344
345 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); } 345 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); }
346 private: 346 private:
347 DatabaseLoader(ScriptState* scriptState, PassOwnPtr<RequestDatabaseCallback> requestCallback) 347 DatabaseLoader(ScriptState* scriptState, std::unique_ptr<RequestDatabaseCall back> requestCallback)
348 : ExecutableWithDatabase(scriptState) 348 : ExecutableWithDatabase(scriptState)
349 , m_requestCallback(std::move(requestCallback)) { } 349 , m_requestCallback(std::move(requestCallback)) { }
350 OwnPtr<RequestDatabaseCallback> m_requestCallback; 350 std::unique_ptr<RequestDatabaseCallback> m_requestCallback;
351 }; 351 };
352 352
353 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key) 353 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key)
354 { 354 {
355 IDBKey* idbKey; 355 IDBKey* idbKey;
356 356
357 if (!key) 357 if (!key)
358 return nullptr; 358 return nullptr;
359 String type = key->getType(); 359 String type = key->getType();
360 360
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 IDBKeyRange::LowerBoundType lowerBoundType = keyRange->getLowerOpen() ? IDBK eyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed; 401 IDBKeyRange::LowerBoundType lowerBoundType = keyRange->getLowerOpen() ? IDBK eyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed;
402 IDBKeyRange::UpperBoundType upperBoundType = keyRange->getUpperOpen() ? IDBK eyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed; 402 IDBKeyRange::UpperBoundType upperBoundType = keyRange->getUpperOpen() ? IDBK eyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed;
403 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e); 403 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e);
404 } 404 }
405 405
406 class DataLoader; 406 class DataLoader;
407 407
408 class OpenCursorCallback final : public EventListener { 408 class OpenCursorCallback final : public EventListener {
409 public: 409 public:
410 static OpenCursorCallback* create(ScriptState* scriptState, PassOwnPtr<Reque stDataCallback> requestCallback, int skipCount, unsigned pageSize) 410 static OpenCursorCallback* create(ScriptState* scriptState, std::unique_ptr< RequestDataCallback> requestCallback, int skipCount, unsigned pageSize)
411 { 411 {
412 return new OpenCursorCallback(scriptState, std::move(requestCallback), s kipCount, pageSize); 412 return new OpenCursorCallback(scriptState, std::move(requestCallback), s kipCount, pageSize);
413 } 413 }
414 414
415 ~OpenCursorCallback() override { } 415 ~OpenCursorCallback() override { }
416 416
417 bool operator==(const EventListener& other) const override 417 bool operator==(const EventListener& other) const override
418 { 418 {
419 return this == &other; 419 return this == &other;
420 } 420 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 463
464 Document* document = toDocument(m_scriptState->getExecutionContext()); 464 Document* document = toDocument(m_scriptState->getExecutionContext());
465 if (!document) 465 if (!document)
466 return; 466 return;
467 // FIXME: There are no tests for this error showing when a recursive 467 // FIXME: There are no tests for this error showing when a recursive
468 // object is inspected. 468 // object is inspected.
469 const String16 errorMessage("\"Inspection error. Maximum depth reached?\ ""); 469 const String16 errorMessage("\"Inspection error. Maximum depth reached?\ "");
470 ScriptState* scriptState = m_scriptState.get(); 470 ScriptState* scriptState = m_scriptState.get();
471 ScriptState::Scope scope(scriptState); 471 ScriptState::Scope scope(scriptState);
472 OwnPtr<protocol::Value> keyJsonValue = toProtocolValue(scriptState->cont ext(), idbCursor->key(scriptState).v8Value()); 472 std::unique_ptr<protocol::Value> keyJsonValue = toProtocolValue(scriptSt ate->context(), idbCursor->key(scriptState).v8Value());
473 OwnPtr<protocol::Value> primaryKeyJsonValue = toProtocolValue(scriptStat e->context(), idbCursor->primaryKey(scriptState).v8Value()); 473 std::unique_ptr<protocol::Value> primaryKeyJsonValue = toProtocolValue(s criptState->context(), idbCursor->primaryKey(scriptState).v8Value());
474 OwnPtr<protocol::Value> valueJsonValue = toProtocolValue(scriptState->co ntext(), idbCursor->value(scriptState).v8Value()); 474 std::unique_ptr<protocol::Value> valueJsonValue = toProtocolValue(script State->context(), idbCursor->value(scriptState).v8Value());
475 String16 key = keyJsonValue ? keyJsonValue->toJSONString() : errorMessag e; 475 String16 key = keyJsonValue ? keyJsonValue->toJSONString() : errorMessag e;
476 String16 value = valueJsonValue ? valueJsonValue->toJSONString() : error Message; 476 String16 value = valueJsonValue ? valueJsonValue->toJSONString() : error Message;
477 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr ing() : errorMessage; 477 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr ing() : errorMessage;
478 OwnPtr<DataEntry> dataEntry = DataEntry::create() 478 std::unique_ptr<DataEntry> dataEntry = DataEntry::create()
479 .setKey(key) 479 .setKey(key)
480 .setPrimaryKey(primaryKey) 480 .setPrimaryKey(primaryKey)
481 .setValue(value).build(); 481 .setValue(value).build();
482 m_result->addItem(std::move(dataEntry)); 482 m_result->addItem(std::move(dataEntry));
483 } 483 }
484 484
485 void end(bool hasMore) 485 void end(bool hasMore)
486 { 486 {
487 m_requestCallback->sendSuccess(std::move(m_result), hasMore); 487 m_requestCallback->sendSuccess(std::move(m_result), hasMore);
488 } 488 }
489 489
490 DEFINE_INLINE_VIRTUAL_TRACE() 490 DEFINE_INLINE_VIRTUAL_TRACE()
491 { 491 {
492 EventListener::trace(visitor); 492 EventListener::trace(visitor);
493 } 493 }
494 494
495 private: 495 private:
496 OpenCursorCallback(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize) 496 OpenCursorCallback(ScriptState* scriptState, std::unique_ptr<RequestDataCall back> requestCallback, int skipCount, unsigned pageSize)
497 : EventListener(EventListener::CPPEventListenerType) 497 : EventListener(EventListener::CPPEventListenerType)
498 , m_scriptState(scriptState) 498 , m_scriptState(scriptState)
499 , m_requestCallback(std::move(requestCallback)) 499 , m_requestCallback(std::move(requestCallback))
500 , m_skipCount(skipCount) 500 , m_skipCount(skipCount)
501 , m_pageSize(pageSize) 501 , m_pageSize(pageSize)
502 { 502 {
503 m_result = Array<DataEntry>::create(); 503 m_result = Array<DataEntry>::create();
504 } 504 }
505 505
506 RefPtr<ScriptState> m_scriptState; 506 RefPtr<ScriptState> m_scriptState;
507 OwnPtr<RequestDataCallback> m_requestCallback; 507 std::unique_ptr<RequestDataCallback> m_requestCallback;
508 int m_skipCount; 508 int m_skipCount;
509 unsigned m_pageSize; 509 unsigned m_pageSize;
510 OwnPtr<Array<DataEntry>> m_result; 510 std::unique_ptr<Array<DataEntry>> m_result;
511 }; 511 };
512 512
513 class DataLoader final : public ExecutableWithDatabase { 513 class DataLoader final : public ExecutableWithDatabase {
514 public: 514 public:
515 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassOwnPtr<Re questDataCallback> requestCallback, const String& objectStoreName, const String& indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) 515 static PassRefPtr<DataLoader> create(ScriptState* scriptState, std::unique_p tr<RequestDataCallback> requestCallback, const String& objectStoreName, const St ring& indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize)
516 { 516 {
517 return adoptRef(new DataLoader(scriptState, std::move(requestCallback), objectStoreName, indexName, idbKeyRange, skipCount, pageSize)); 517 return adoptRef(new DataLoader(scriptState, std::move(requestCallback), objectStoreName, indexName, idbKeyRange, skipCount, pageSize));
518 } 518 }
519 519
520 ~DataLoader() override { } 520 ~DataLoader() override { }
521 521
522 void execute(IDBDatabase* idbDatabase) override 522 void execute(IDBDatabase* idbDatabase) override
523 { 523 {
524 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState() , idbDatabase, m_objectStoreName); 524 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState() , idbDatabase, m_objectStoreName);
525 if (!idbTransaction) { 525 if (!idbTransaction) {
(...skipping 16 matching lines...) Expand all
542 542
543 idbRequest = idbIndex->openCursor(getScriptState(), m_idbKeyRange.ge t(), WebIDBCursorDirectionNext); 543 idbRequest = idbIndex->openCursor(getScriptState(), m_idbKeyRange.ge t(), WebIDBCursorDirectionNext);
544 } else { 544 } else {
545 idbRequest = idbObjectStore->openCursor(getScriptState(), m_idbKeyRa nge.get(), WebIDBCursorDirectionNext); 545 idbRequest = idbObjectStore->openCursor(getScriptState(), m_idbKeyRa nge.get(), WebIDBCursorDirectionNext);
546 } 546 }
547 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create(getS criptState(), std::move(m_requestCallback), m_skipCount, m_pageSize); 547 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create(getS criptState(), std::move(m_requestCallback), m_skipCount, m_pageSize);
548 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback , false); 548 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback , false);
549 } 549 }
550 550
551 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); } 551 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); }
552 DataLoader(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> request Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i dbKeyRange, int skipCount, unsigned pageSize) 552 DataLoader(ScriptState* scriptState, std::unique_ptr<RequestDataCallback> re questCallback, const String& objectStoreName, const String& indexName, IDBKeyRan ge* idbKeyRange, int skipCount, unsigned pageSize)
553 : ExecutableWithDatabase(scriptState) 553 : ExecutableWithDatabase(scriptState)
554 , m_requestCallback(std::move(requestCallback)) 554 , m_requestCallback(std::move(requestCallback))
555 , m_objectStoreName(objectStoreName) 555 , m_objectStoreName(objectStoreName)
556 , m_indexName(indexName) 556 , m_indexName(indexName)
557 , m_idbKeyRange(idbKeyRange) 557 , m_idbKeyRange(idbKeyRange)
558 , m_skipCount(skipCount) 558 , m_skipCount(skipCount)
559 , m_pageSize(pageSize) 559 , m_pageSize(pageSize)
560 { 560 {
561 } 561 }
562 562
563 OwnPtr<RequestDataCallback> m_requestCallback; 563 std::unique_ptr<RequestDataCallback> m_requestCallback;
564 String m_objectStoreName; 564 String m_objectStoreName;
565 String m_indexName; 565 String m_indexName;
566 Persistent<IDBKeyRange> m_idbKeyRange; 566 Persistent<IDBKeyRange> m_idbKeyRange;
567 int m_skipCount; 567 int m_skipCount;
568 unsigned m_pageSize; 568 unsigned m_pageSize;
569 }; 569 };
570 570
571 } // namespace 571 } // namespace
572 572
573 // static 573 // static
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 return nullptr; 622 return nullptr;
623 } 623 }
624 IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow); 624 IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow);
625 625
626 if (!idbFactory) 626 if (!idbFactory)
627 *errorString = "No IndexedDB factory for given frame found"; 627 *errorString = "No IndexedDB factory for given frame found";
628 628
629 return idbFactory; 629 return idbFactory;
630 } 630 }
631 631
632 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, PassOwnPtr<RequestDatabaseNamesCallback> requestCallb ack) 632 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, std::unique_ptr<RequestDatabaseNamesCallback> request Callback)
633 { 633 {
634 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 634 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
635 Document* document = assertDocument(errorString, frame); 635 Document* document = assertDocument(errorString, frame);
636 if (!document) 636 if (!document)
637 return; 637 return;
638 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 638 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
639 if (!idbFactory) 639 if (!idbFactory)
640 return; 640 return;
641 641
642 ScriptState* scriptState = ScriptState::forMainWorld(frame); 642 ScriptState* scriptState = ScriptState::forMainWorld(frame);
643 if (!scriptState) 643 if (!scriptState)
644 return; 644 return;
645 ScriptState::Scope scope(scriptState); 645 ScriptState::Scope scope(scriptState);
646 TrackExceptionState exceptionState; 646 TrackExceptionState exceptionState;
647 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception State); 647 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception State);
648 if (exceptionState.hadException()) { 648 if (exceptionState.hadException()) {
649 requestCallback->sendFailure("Could not obtain database names."); 649 requestCallback->sendFailure("Could not obtain database names.");
650 return; 650 return;
651 } 651 }
652 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba ck::create(std::move(requestCallback), document->getSecurityOrigin()->toRawStrin g()), false); 652 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba ck::create(std::move(requestCallback), document->getSecurityOrigin()->toRawStrin g()), false);
653 } 653 }
654 654
655 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St ring& securityOrigin, const String& databaseName, PassOwnPtr<RequestDatabaseCall back> requestCallback) 655 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St ring& securityOrigin, const String& databaseName, std::unique_ptr<RequestDatabas eCallback> requestCallback)
656 { 656 {
657 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 657 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
658 Document* document = assertDocument(errorString, frame); 658 Document* document = assertDocument(errorString, frame);
659 if (!document) 659 if (!document)
660 return; 660 return;
661 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 661 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
662 if (!idbFactory) 662 if (!idbFactory)
663 return; 663 return;
664 664
665 ScriptState* scriptState = ScriptState::forMainWorld(frame); 665 ScriptState* scriptState = ScriptState::forMainWorld(frame);
666 if (!scriptState) 666 if (!scriptState)
667 return; 667 return;
668 ScriptState::Scope scope(scriptState); 668 ScriptState::Scope scope(scriptState);
669 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState, std::move(requestCallback)); 669 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState, std::move(requestCallback));
670 databaseLoader->start(idbFactory, document->getSecurityOrigin(), databaseNam e); 670 databaseLoader->start(idbFactory, document->getSecurityOrigin(), databaseNam e);
671 } 671 }
672 672
673 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, 673 void InspectorIndexedDBAgent::requestData(ErrorString* errorString,
674 const String& securityOrigin, 674 const String& securityOrigin,
675 const String& databaseName, 675 const String& databaseName,
676 const String& objectStoreName, 676 const String& objectStoreName,
677 const String& indexName, 677 const String& indexName,
678 int skipCount, 678 int skipCount,
679 int pageSize, 679 int pageSize,
680 const Maybe<protocol::IndexedDB::KeyRange>& keyRange, 680 const Maybe<protocol::IndexedDB::KeyRange>& keyRange,
681 PassOwnPtr<RequestDataCallback> requestCallback) 681 std::unique_ptr<RequestDataCallback> requestCallback)
682 { 682 {
683 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 683 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
684 Document* document = assertDocument(errorString, frame); 684 Document* document = assertDocument(errorString, frame);
685 if (!document) 685 if (!document)
686 return; 686 return;
687 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 687 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
688 if (!idbFactory) 688 if (!idbFactory)
689 return; 689 return;
690 690
691 IDBKeyRange* idbKeyRange = keyRange.isJust() ? idbKeyRangeFromKeyRange(keyRa nge.fromJust()) : nullptr; 691 IDBKeyRange* idbKeyRange = keyRange.isJust() ? idbKeyRangeFromKeyRange(keyRa nge.fromJust()) : nullptr;
692 if (keyRange.isJust() && !idbKeyRange) { 692 if (keyRange.isJust() && !idbKeyRange) {
693 *errorString = "Can not parse key range."; 693 *errorString = "Can not parse key range.";
694 return; 694 return;
695 } 695 }
696 696
697 ScriptState* scriptState = ScriptState::forMainWorld(frame); 697 ScriptState* scriptState = ScriptState::forMainWorld(frame);
698 if (!scriptState) 698 if (!scriptState)
699 return; 699 return;
700 ScriptState::Scope scope(scriptState); 700 ScriptState::Scope scope(scriptState);
701 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, std::move(re questCallback), objectStoreName, indexName, idbKeyRange, skipCount, pageSize); 701 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, std::move(re questCallback), objectStoreName, indexName, idbKeyRange, skipCount, pageSize);
702 dataLoader->start(idbFactory, document->getSecurityOrigin(), databaseName); 702 dataLoader->start(idbFactory, document->getSecurityOrigin(), databaseName);
703 } 703 }
704 704
705 class ClearObjectStoreListener final : public EventListener { 705 class ClearObjectStoreListener final : public EventListener {
706 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); 706 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener);
707 public: 707 public:
708 static ClearObjectStoreListener* create(PassOwnPtr<ClearObjectStoreCallback> requestCallback) 708 static ClearObjectStoreListener* create(std::unique_ptr<ClearObjectStoreCall back> requestCallback)
709 { 709 {
710 return new ClearObjectStoreListener(std::move(requestCallback)); 710 return new ClearObjectStoreListener(std::move(requestCallback));
711 } 711 }
712 712
713 ~ClearObjectStoreListener() override { } 713 ~ClearObjectStoreListener() override { }
714 714
715 bool operator==(const EventListener& other) const override 715 bool operator==(const EventListener& other) const override
716 { 716 {
717 return this == &other; 717 return this == &other;
718 } 718 }
719 719
720 void handleEvent(ExecutionContext*, Event* event) override 720 void handleEvent(ExecutionContext*, Event* event) override
721 { 721 {
722 if (event->type() != EventTypeNames::complete) { 722 if (event->type() != EventTypeNames::complete) {
723 m_requestCallback->sendFailure("Unexpected event type."); 723 m_requestCallback->sendFailure("Unexpected event type.");
724 return; 724 return;
725 } 725 }
726 726
727 m_requestCallback->sendSuccess(); 727 m_requestCallback->sendSuccess();
728 } 728 }
729 729
730 DEFINE_INLINE_VIRTUAL_TRACE() 730 DEFINE_INLINE_VIRTUAL_TRACE()
731 { 731 {
732 EventListener::trace(visitor); 732 EventListener::trace(visitor);
733 } 733 }
734 734
735 private: 735 private:
736 ClearObjectStoreListener(PassOwnPtr<ClearObjectStoreCallback> requestCallbac k) 736 ClearObjectStoreListener(std::unique_ptr<ClearObjectStoreCallback> requestCa llback)
737 : EventListener(EventListener::CPPEventListenerType) 737 : EventListener(EventListener::CPPEventListenerType)
738 , m_requestCallback(std::move(requestCallback)) 738 , m_requestCallback(std::move(requestCallback))
739 { 739 {
740 } 740 }
741 741
742 OwnPtr<ClearObjectStoreCallback> m_requestCallback; 742 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback;
743 }; 743 };
744 744
745 745
746 class ClearObjectStore final : public ExecutableWithDatabase { 746 class ClearObjectStore final : public ExecutableWithDatabase {
747 public: 747 public:
748 static PassRefPtr<ClearObjectStore> create(ScriptState* scriptState, const S tring& objectStoreName, PassOwnPtr<ClearObjectStoreCallback> requestCallback) 748 static PassRefPtr<ClearObjectStore> create(ScriptState* scriptState, const S tring& objectStoreName, std::unique_ptr<ClearObjectStoreCallback> requestCallbac k)
749 { 749 {
750 return adoptRef(new ClearObjectStore(scriptState, objectStoreName, std:: move(requestCallback))); 750 return adoptRef(new ClearObjectStore(scriptState, objectStoreName, std:: move(requestCallback)));
751 } 751 }
752 752
753 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, Pa ssOwnPtr<ClearObjectStoreCallback> requestCallback) 753 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, st d::unique_ptr<ClearObjectStoreCallback> requestCallback)
754 : ExecutableWithDatabase(scriptState) 754 : ExecutableWithDatabase(scriptState)
755 , m_objectStoreName(objectStoreName) 755 , m_objectStoreName(objectStoreName)
756 , m_requestCallback(std::move(requestCallback)) 756 , m_requestCallback(std::move(requestCallback))
757 { 757 {
758 } 758 }
759 759
760 void execute(IDBDatabase* idbDatabase) override 760 void execute(IDBDatabase* idbDatabase) override
761 { 761 {
762 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState() , idbDatabase, m_objectStoreName, IndexedDBNames::readwrite); 762 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState() , idbDatabase, m_objectStoreName, IndexedDBNames::readwrite);
763 if (!idbTransaction) { 763 if (!idbTransaction) {
(...skipping 13 matching lines...) Expand all
777 ExceptionCode ec = exceptionState.code(); 777 ExceptionCode ec = exceptionState.code();
778 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));
779 return; 779 return;
780 } 780 }
781 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt oreListener::create(std::move(m_requestCallback)), false); 781 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt oreListener::create(std::move(m_requestCallback)), false);
782 } 782 }
783 783
784 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); } 784 RequestCallback* getRequestCallback() override { return m_requestCallback.ge t(); }
785 private: 785 private:
786 const String m_objectStoreName; 786 const String m_objectStoreName;
787 OwnPtr<ClearObjectStoreCallback> m_requestCallback; 787 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback;
788 }; 788 };
789 789
790 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S tring& securityOrigin, const String& databaseName, const String& objectStoreName , PassOwnPtr<ClearObjectStoreCallback> requestCallback) 790 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S tring& securityOrigin, const String& databaseName, const String& objectStoreName , std::unique_ptr<ClearObjectStoreCallback> requestCallback)
791 { 791 {
792 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n); 792 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi n);
793 Document* document = assertDocument(errorString, frame); 793 Document* document = assertDocument(errorString, frame);
794 if (!document) 794 if (!document)
795 return; 795 return;
796 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 796 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
797 if (!idbFactory) 797 if (!idbFactory)
798 return; 798 return;
799 799
800 ScriptState* scriptState = ScriptState::forMainWorld(frame); 800 ScriptState* scriptState = ScriptState::forMainWorld(frame);
801 if (!scriptState) 801 if (!scriptState)
802 return; 802 return;
803 ScriptState::Scope scope(scriptState); 803 ScriptState::Scope scope(scriptState);
804 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, std::move(requestCallback)); 804 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, std::move(requestCallback));
805 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), databaseN ame); 805 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), databaseN ame);
806 } 806 }
807 807
808 DEFINE_TRACE(InspectorIndexedDBAgent) 808 DEFINE_TRACE(InspectorIndexedDBAgent)
809 { 809 {
810 visitor->trace(m_inspectedFrames); 810 visitor->trace(m_inspectedFrames);
811 InspectorBaseAgent::trace(visitor); 811 InspectorBaseAgent::trace(visitor);
812 } 812 }
813 813
814 } // namespace blink 814 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698