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

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

Issue 2349413002: Minor IndexedDB refactorings. (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/indexeddb/IDBDatabase.h » ('j') | 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return new IDBCursor(std::move(backend), direction, request, source, transac tion); 54 return new IDBCursor(std::move(backend), direction, request, source, transac tion);
55 } 55 }
56 56
57 IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend, WebIDBCursorDirectio n direction, IDBRequest* request, IDBAny* source, IDBTransaction* transaction) 57 IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend, WebIDBCursorDirectio n direction, IDBRequest* request, IDBAny* source, IDBTransaction* transaction)
58 : m_backend(std::move(backend)) 58 : m_backend(std::move(backend))
59 , m_request(request) 59 , m_request(request)
60 , m_direction(direction) 60 , m_direction(direction)
61 , m_source(source) 61 , m_source(source)
62 , m_transaction(transaction) 62 , m_transaction(transaction)
63 { 63 {
64 ASSERT(m_backend); 64 DCHECK(m_backend);
65 ASSERT(m_request); 65 DCHECK(m_request);
66 ASSERT(m_source->getType() == IDBAny::IDBObjectStoreType || m_source->getTyp e() == IDBAny::IDBIndexType); 66 DCHECK(m_source->getType() == IDBAny::IDBObjectStoreType || m_source->getTyp e() == IDBAny::IDBIndexType);
67 ASSERT(m_transaction); 67 DCHECK(m_transaction);
68 } 68 }
69 69
70 IDBCursor::~IDBCursor() 70 IDBCursor::~IDBCursor()
71 { 71 {
72 } 72 }
73 73
74 DEFINE_TRACE(IDBCursor) 74 DEFINE_TRACE(IDBCursor)
75 { 75 {
76 visitor->trace(m_request); 76 visitor->trace(m_request);
77 visitor->trace(m_source); 77 visitor->trace(m_source);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (isKeyCursor()) { 292 if (isKeyCursor()) {
293 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu rsorErrorMessage); 293 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu rsorErrorMessage);
294 return nullptr; 294 return nullptr;
295 } 295 }
296 if (!m_transaction->backendDB()) { 296 if (!m_transaction->backendDB()) {
297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
298 return nullptr; 298 return nullptr;
299 } 299 }
300 300
301 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState); 301 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState);
302 ASSERT(!exceptionState.hadException()); 302 DCHECK(!exceptionState.hadException());
303 303
304 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 304 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
305 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, WebIDBCallbacksImpl::create(request).release()); 305 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, WebIDBCallbacksImpl::create(request).release());
306 return request; 306 return request;
307 } 307 }
308 308
309 void IDBCursor::postSuccessHandlerCallback() 309 void IDBCursor::postSuccessHandlerCallback()
310 { 310 {
311 if (m_backend) 311 if (m_backend)
312 m_backend->postSuccessHandlerCallback(); 312 m_backend->postSuccessHandlerCallback();
(...skipping 13 matching lines...) Expand all
326 } 326 }
327 327
328 ScriptValue IDBCursor::primaryKey(ScriptState* scriptState) 328 ScriptValue IDBCursor::primaryKey(ScriptState* scriptState)
329 { 329 {
330 m_primaryKeyDirty = false; 330 m_primaryKeyDirty = false;
331 return ScriptValue::from(scriptState, m_primaryKey); 331 return ScriptValue::from(scriptState, m_primaryKey);
332 } 332 }
333 333
334 ScriptValue IDBCursor::value(ScriptState* scriptState) 334 ScriptValue IDBCursor::value(ScriptState* scriptState)
335 { 335 {
336 ASSERT(isCursorWithValue()); 336 DCHECK(isCursorWithValue());
337 337
338 IDBObjectStore* objectStore = effectiveObjectStore(); 338 IDBObjectStore* objectStore = effectiveObjectStore();
339 const IDBObjectStoreMetadata& metadata = objectStore->metadata();
340 IDBAny* value; 339 IDBAny* value;
341 if (!m_value) { 340 if (!m_value) {
342 value = IDBAny::createUndefined(); 341 value = IDBAny::createUndefined();
343 } else if (metadata.autoIncrement && !metadata.keyPath.isNull()) { 342 } else if (objectStore->autoIncrement() && !objectStore->idbKeyPath().isNull ()) {
344 RefPtr<IDBValue> idbValue = IDBValue::create(m_value.get(), m_primaryKey , metadata.keyPath); 343 RefPtr<IDBValue> idbValue = IDBValue::create(m_value.get(), m_primaryKey , objectStore->idbKeyPath());
345 #if ENABLE(ASSERT) 344 #if DCHECK_IS_ON()
346 assertPrimaryKeyValidOrInjectable(scriptState, idbValue.get()); 345 assertPrimaryKeyValidOrInjectable(scriptState, idbValue.get());
347 #endif 346 #endif // DCHECK_IS_ON()
348 value = IDBAny::create(idbValue.release()); 347 value = IDBAny::create(idbValue.release());
349 } else { 348 } else {
350 value = IDBAny::create(m_value); 349 value = IDBAny::create(m_value);
351 } 350 }
352 351
353 m_valueDirty = false; 352 m_valueDirty = false;
354 ScriptValue scriptValue = ScriptValue::from(scriptState, value); 353 ScriptValue scriptValue = ScriptValue::from(scriptState, value);
355 return scriptValue; 354 return scriptValue;
356 } 355 }
357 356
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 { 393 {
395 if (directionString == IndexedDBNames::next) 394 if (directionString == IndexedDBNames::next)
396 return WebIDBCursorDirectionNext; 395 return WebIDBCursorDirectionNext;
397 if (directionString == IndexedDBNames::nextunique) 396 if (directionString == IndexedDBNames::nextunique)
398 return WebIDBCursorDirectionNextNoDuplicate; 397 return WebIDBCursorDirectionNextNoDuplicate;
399 if (directionString == IndexedDBNames::prev) 398 if (directionString == IndexedDBNames::prev)
400 return WebIDBCursorDirectionPrev; 399 return WebIDBCursorDirectionPrev;
401 if (directionString == IndexedDBNames::prevunique) 400 if (directionString == IndexedDBNames::prevunique)
402 return WebIDBCursorDirectionPrevNoDuplicate; 401 return WebIDBCursorDirectionPrevNoDuplicate;
403 402
404 ASSERT_NOT_REACHED(); 403 NOTREACHED();
405 return WebIDBCursorDirectionNext; 404 return WebIDBCursorDirectionNext;
406 } 405 }
407 406
408 const String& IDBCursor::direction() const 407 const String& IDBCursor::direction() const
409 { 408 {
410 switch (m_direction) { 409 switch (m_direction) {
411 case WebIDBCursorDirectionNext: 410 case WebIDBCursorDirectionNext:
412 return IndexedDBNames::next; 411 return IndexedDBNames::next;
413 412
414 case WebIDBCursorDirectionNextNoDuplicate: 413 case WebIDBCursorDirectionNextNoDuplicate:
415 return IndexedDBNames::nextunique; 414 return IndexedDBNames::nextunique;
416 415
417 case WebIDBCursorDirectionPrev: 416 case WebIDBCursorDirectionPrev:
418 return IndexedDBNames::prev; 417 return IndexedDBNames::prev;
419 418
420 case WebIDBCursorDirectionPrevNoDuplicate: 419 case WebIDBCursorDirectionPrevNoDuplicate:
421 return IndexedDBNames::prevunique; 420 return IndexedDBNames::prevunique;
422 421
423 default: 422 default:
424 ASSERT_NOT_REACHED(); 423 NOTREACHED();
425 return IndexedDBNames::next; 424 return IndexedDBNames::next;
426 } 425 }
427 } 426 }
428 427
429 } // namespace blink 428 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/indexeddb/IDBDatabase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698