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

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

Issue 1166553004: IndexedDB: Replace 0 with nullptr where appropriate (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: MOAR Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/indexeddb/IDBTransaction.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false) ; 200 idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false) ;
201 } 201 }
202 202
203 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN ames::readonly) 203 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN ames::readonly)
204 { 204 {
205 TrackExceptionState exceptionState; 205 TrackExceptionState exceptionState;
206 StringOrStringSequenceOrDOMStringList scope; 206 StringOrStringSequenceOrDOMStringList scope;
207 scope.setString(objectStoreName); 207 scope.setString(objectStoreName);
208 IDBTransaction* idbTransaction = idbDatabase->transaction(scriptState, scope , mode, exceptionState); 208 IDBTransaction* idbTransaction = idbDatabase->transaction(scriptState, scope , mode, exceptionState);
209 if (exceptionState.hadException()) 209 if (exceptionState.hadException())
210 return 0; 210 return nullptr;
211 return idbTransaction; 211 return idbTransaction;
212 } 212 }
213 213
214 static IDBObjectStore* objectStoreForTransaction(IDBTransaction* idbTransaction, const String& objectStoreName) 214 static IDBObjectStore* objectStoreForTransaction(IDBTransaction* idbTransaction, const String& objectStoreName)
215 { 215 {
216 TrackExceptionState exceptionState; 216 TrackExceptionState exceptionState;
217 IDBObjectStore* idbObjectStore = idbTransaction->objectStore(objectStoreName , exceptionState); 217 IDBObjectStore* idbObjectStore = idbTransaction->objectStore(objectStoreName , exceptionState);
218 if (exceptionState.hadException()) 218 if (exceptionState.hadException())
219 return 0; 219 return nullptr;
220 return idbObjectStore; 220 return idbObjectStore;
221 } 221 }
222 222
223 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin g& indexName) 223 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin g& indexName)
224 { 224 {
225 TrackExceptionState exceptionState; 225 TrackExceptionState exceptionState;
226 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState); 226 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState);
227 if (exceptionState.hadException()) 227 if (exceptionState.hadException())
228 return 0; 228 return nullptr;
229 return idbIndex; 229 return idbIndex;
230 } 230 }
231 231
232 static PassRefPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) 232 static PassRefPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath)
233 { 233 {
234 RefPtr<KeyPath> keyPath; 234 RefPtr<KeyPath> keyPath;
235 switch (idbKeyPath.type()) { 235 switch (idbKeyPath.type()) {
236 case IDBKeyPath::NullType: 236 case IDBKeyPath::NullType:
237 keyPath = KeyPath::create().setType(KeyPath::Type::Null); 237 keyPath = KeyPath::create().setType(KeyPath::Type::Null);
238 break; 238 break;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 , m_requestCallback(requestCallback) { } 313 , m_requestCallback(requestCallback) { }
314 RefPtrWillBePersistent<RequestDatabaseCallback> m_requestCallback; 314 RefPtrWillBePersistent<RequestDatabaseCallback> m_requestCallback;
315 }; 315 };
316 316
317 static IDBKey* idbKeyFromInspectorObject(JSONObject* key) 317 static IDBKey* idbKeyFromInspectorObject(JSONObject* key)
318 { 318 {
319 IDBKey* idbKey; 319 IDBKey* idbKey;
320 320
321 String type; 321 String type;
322 if (!key->getString("type", &type)) 322 if (!key->getString("type", &type))
323 return 0; 323 return nullptr;
324 324
325 DEFINE_STATIC_LOCAL(String, s_number, ("number")); 325 DEFINE_STATIC_LOCAL(String, s_number, ("number"));
326 DEFINE_STATIC_LOCAL(String, s_string, ("string")); 326 DEFINE_STATIC_LOCAL(String, s_string, ("string"));
327 DEFINE_STATIC_LOCAL(String, s_date, ("date")); 327 DEFINE_STATIC_LOCAL(String, s_date, ("date"));
328 DEFINE_STATIC_LOCAL(String, s_array, ("array")); 328 DEFINE_STATIC_LOCAL(String, s_array, ("array"));
329 329
330 if (type == s_number) { 330 if (type == s_number) {
331 double number; 331 double number;
332 if (!key->getNumber("number", &number)) 332 if (!key->getNumber("number", &number))
333 return 0; 333 return nullptr;
334 idbKey = IDBKey::createNumber(number); 334 idbKey = IDBKey::createNumber(number);
335 } else if (type == s_string) { 335 } else if (type == s_string) {
336 String string; 336 String string;
337 if (!key->getString("string", &string)) 337 if (!key->getString("string", &string))
338 return 0; 338 return nullptr;
339 idbKey = IDBKey::createString(string); 339 idbKey = IDBKey::createString(string);
340 } else if (type == s_date) { 340 } else if (type == s_date) {
341 double date; 341 double date;
342 if (!key->getNumber("date", &date)) 342 if (!key->getNumber("date", &date))
343 return 0; 343 return nullptr;
344 idbKey = IDBKey::createDate(date); 344 idbKey = IDBKey::createDate(date);
345 } else if (type == s_array) { 345 } else if (type == s_array) {
346 IDBKey::KeyArray keyArray; 346 IDBKey::KeyArray keyArray;
347 RefPtr<JSONArray> array = key->getArray("array"); 347 RefPtr<JSONArray> array = key->getArray("array");
348 for (size_t i = 0; i < array->length(); ++i) { 348 for (size_t i = 0; i < array->length(); ++i) {
349 RefPtr<JSONValue> value = array->get(i); 349 RefPtr<JSONValue> value = array->get(i);
350 RefPtr<JSONObject> object; 350 RefPtr<JSONObject> object;
351 if (!value->asObject(&object)) 351 if (!value->asObject(&object))
352 return 0; 352 return nullptr;
353 keyArray.append(idbKeyFromInspectorObject(object.get())); 353 keyArray.append(idbKeyFromInspectorObject(object.get()));
354 } 354 }
355 idbKey = IDBKey::createArray(keyArray); 355 idbKey = IDBKey::createArray(keyArray);
356 } else { 356 } else {
357 return 0; 357 return nullptr;
358 } 358 }
359 359
360 return idbKey; 360 return idbKey;
361 } 361 }
362 362
363 static IDBKeyRange* idbKeyRangeFromKeyRange(JSONObject* keyRange) 363 static IDBKeyRange* idbKeyRangeFromKeyRange(JSONObject* keyRange)
364 { 364 {
365 RefPtr<JSONObject> lower = keyRange->getObject("lower"); 365 RefPtr<JSONObject> lower = keyRange->getObject("lower");
366 IDBKey* idbLower = lower ? idbKeyFromInspectorObject(lower.get()) : 0; 366 IDBKey* idbLower = lower ? idbKeyFromInspectorObject(lower.get()) : nullptr;
367 if (lower && !idbLower) 367 if (lower && !idbLower)
368 return 0; 368 return nullptr;
369 369
370 RefPtr<JSONObject> upper = keyRange->getObject("upper"); 370 RefPtr<JSONObject> upper = keyRange->getObject("upper");
371 IDBKey* idbUpper = upper ? idbKeyFromInspectorObject(upper.get()) : 0; 371 IDBKey* idbUpper = upper ? idbKeyFromInspectorObject(upper.get()) : nullptr;
372 if (upper && !idbUpper) 372 if (upper && !idbUpper)
373 return 0; 373 return nullptr;
374 374
375 bool lowerOpen; 375 bool lowerOpen;
376 if (!keyRange->getBoolean("lowerOpen", &lowerOpen)) 376 if (!keyRange->getBoolean("lowerOpen", &lowerOpen))
377 return 0; 377 return nullptr;
378 IDBKeyRange::LowerBoundType lowerBoundType = lowerOpen ? IDBKeyRange::LowerB oundOpen : IDBKeyRange::LowerBoundClosed; 378 IDBKeyRange::LowerBoundType lowerBoundType = lowerOpen ? IDBKeyRange::LowerB oundOpen : IDBKeyRange::LowerBoundClosed;
379 379
380 bool upperOpen; 380 bool upperOpen;
381 if (!keyRange->getBoolean("upperOpen", &upperOpen)) 381 if (!keyRange->getBoolean("upperOpen", &upperOpen))
382 return 0; 382 return nullptr;
383 IDBKeyRange::UpperBoundType upperBoundType = upperOpen ? IDBKeyRange::UpperB oundOpen : IDBKeyRange::UpperBoundClosed; 383 IDBKeyRange::UpperBoundType upperBoundType = upperOpen ? IDBKeyRange::UpperB oundOpen : IDBKeyRange::UpperBoundClosed;
384 384
385 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e); 385 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp e);
386 } 386 }
387 387
388 class DataLoader; 388 class DataLoader;
389 389
390 class OpenCursorCallback final : public EventListener { 390 class OpenCursorCallback final : public EventListener {
391 public: 391 public:
392 static PassRefPtr<OpenCursorCallback> create(ScriptState* scriptState, PassR efPtrWillBeRawPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize) 392 static PassRefPtr<OpenCursorCallback> create(ScriptState* scriptState, PassR efPtrWillBeRawPtr<RequestDataCallback> requestCallback, int skipCount, unsigned pageSize)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return; 430 return;
431 } 431 }
432 432
433 if (m_result->length() == m_pageSize) { 433 if (m_result->length() == m_pageSize) {
434 end(true); 434 end(true);
435 return; 435 return;
436 } 436 }
437 437
438 // Continue cursor before making injected script calls, otherwise transa ction might be finished. 438 // Continue cursor before making injected script calls, otherwise transa ction might be finished.
439 TrackExceptionState exceptionState; 439 TrackExceptionState exceptionState;
440 idbCursor->continueFunction(0, 0, exceptionState); 440 idbCursor->continueFunction(nullptr, nullptr, exceptionState);
441 if (exceptionState.hadException()) { 441 if (exceptionState.hadException()) {
442 m_requestCallback->sendFailure("Could not continue cursor."); 442 m_requestCallback->sendFailure("Could not continue cursor.");
443 return; 443 return;
444 } 444 }
445 445
446 Document* document = toDocument(m_scriptState->executionContext()); 446 Document* document = toDocument(m_scriptState->executionContext());
447 if (!document) 447 if (!document)
448 return; 448 return;
449 // FIXME: There are no tests for this error showing when a recursive 449 // FIXME: There are no tests for this error showing when a recursive
450 // object is inspected. 450 // object is inspected.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 554
555 LocalFrame* findFrameWithSecurityOrigin(Page* page, const String& securityOrigin ) 555 LocalFrame* findFrameWithSecurityOrigin(Page* page, const String& securityOrigin )
556 { 556 {
557 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse Next()) { 557 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse Next()) {
558 if (!frame->isLocalFrame()) 558 if (!frame->isLocalFrame())
559 continue; 559 continue;
560 RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()- >securityOrigin(); 560 RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()- >securityOrigin();
561 if (documentOrigin->toRawString() == securityOrigin) 561 if (documentOrigin->toRawString() == securityOrigin)
562 return toLocalFrame(frame); 562 return toLocalFrame(frame);
563 } 563 }
564 return 0; 564 return nullptr;
565 } 565 }
566 566
567 } // namespace 567 } // namespace
568 568
569 // static 569 // static
570 PassOwnPtrWillBeRawPtr<InspectorIndexedDBAgent> InspectorIndexedDBAgent::create( Page* page) 570 PassOwnPtrWillBeRawPtr<InspectorIndexedDBAgent> InspectorIndexedDBAgent::create( Page* page)
571 { 571 {
572 return adoptPtrWillBeNoop(new InspectorIndexedDBAgent(page)); 572 return adoptPtrWillBeNoop(new InspectorIndexedDBAgent(page));
573 } 573 }
574 574
(...skipping 20 matching lines...) Expand all
595 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true); 595 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true);
596 } 596 }
597 597
598 void InspectorIndexedDBAgent::disable(ErrorString*) 598 void InspectorIndexedDBAgent::disable(ErrorString*)
599 { 599 {
600 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false); 600 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false);
601 } 601 }
602 602
603 static Document* assertDocument(ErrorString* errorString, LocalFrame* frame) 603 static Document* assertDocument(ErrorString* errorString, LocalFrame* frame)
604 { 604 {
605 Document* document = frame ? frame->document() : 0; 605 Document* document = frame ? frame->document() : nullptr;
606 606
607 if (!document) 607 if (!document)
608 *errorString = "No document for given frame found"; 608 *errorString = "No document for given frame found";
609 609
610 return document; 610 return document;
611 } 611 }
612 612
613 static IDBFactory* assertIDBFactory(ErrorString* errorString, Document* document ) 613 static IDBFactory* assertIDBFactory(ErrorString* errorString, Document* document )
614 { 614 {
615 LocalDOMWindow* domWindow = document->domWindow(); 615 LocalDOMWindow* domWindow = document->domWindow();
616 if (!domWindow) { 616 if (!domWindow) {
617 *errorString = "No IndexedDB factory for given frame found"; 617 *errorString = "No IndexedDB factory for given frame found";
618 return 0; 618 return nullptr;
619 } 619 }
620 IDBFactory* idbFactory = DOMWindowIndexedDatabase::indexedDB(*domWindow); 620 IDBFactory* idbFactory = DOMWindowIndexedDatabase::indexedDB(*domWindow);
621 621
622 if (!idbFactory) 622 if (!idbFactory)
623 *errorString = "No IndexedDB factory for given frame found"; 623 *errorString = "No IndexedDB factory for given frame found";
624 624
625 return idbFactory; 625 return idbFactory;
626 } 626 }
627 627
628 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestDatabaseNamesCallback> requestCallback) 628 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestDatabaseNamesCallback> requestCallback)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String & securityOrigin, const String& databaseName, const String& objectStoreName, con st String& indexName, int skipCount, int pageSize, const RefPtr<JSONObject>* key Range, const PassRefPtrWillBeRawPtr<RequestDataCallback> requestCallback) 665 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String & securityOrigin, const String& databaseName, const String& objectStoreName, con st String& indexName, int skipCount, int pageSize, const RefPtr<JSONObject>* key Range, const PassRefPtrWillBeRawPtr<RequestDataCallback> requestCallback)
666 { 666 {
667 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); 667 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
668 Document* document = assertDocument(errorString, frame); 668 Document* document = assertDocument(errorString, frame);
669 if (!document) 669 if (!document)
670 return; 670 return;
671 IDBFactory* idbFactory = assertIDBFactory(errorString, document); 671 IDBFactory* idbFactory = assertIDBFactory(errorString, document);
672 if (!idbFactory) 672 if (!idbFactory)
673 return; 673 return;
674 674
675 IDBKeyRange* idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRange->get( )) : 0; 675 IDBKeyRange* idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRange->get( )) : nullptr;
676 if (keyRange && !idbKeyRange) { 676 if (keyRange && !idbKeyRange) {
677 *errorString = "Can not parse key range."; 677 *errorString = "Can not parse key range.";
678 return; 678 return;
679 } 679 }
680 680
681 ScriptState* scriptState = ScriptState::forMainWorld(frame); 681 ScriptState* scriptState = ScriptState::forMainWorld(frame);
682 ScriptState::Scope scope(scriptState); 682 ScriptState::Scope scope(scriptState);
683 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); 683 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize);
684 dataLoader->start(idbFactory, document->securityOrigin(), databaseName); 684 dataLoader->start(idbFactory, document->securityOrigin(), databaseName);
685 } 685 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName ); 783 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName );
784 } 784 }
785 785
786 DEFINE_TRACE(InspectorIndexedDBAgent) 786 DEFINE_TRACE(InspectorIndexedDBAgent)
787 { 787 {
788 visitor->trace(m_page); 788 visitor->trace(m_page);
789 InspectorBaseAgent::trace(visitor); 789 InspectorBaseAgent::trace(visitor);
790 } 790 }
791 791
792 } // namespace blink 792 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBTransaction.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698