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

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

Issue 2349413002: Minor IndexedDB refactorings. (Closed)
Patch Set: Created 4 years, 3 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) 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (m_closePending) { 300 if (m_closePending) {
301 exceptionState.throwDOMException(InvalidStateError, "The database connec tion is closing."); 301 exceptionState.throwDOMException(InvalidStateError, "The database connec tion is closing.");
302 return nullptr; 302 return nullptr;
303 } 303 }
304 304
305 if (!m_backend) { 305 if (!m_backend) {
306 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 306 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
307 return nullptr; 307 return nullptr;
308 } 308 }
309 309
310
311 if (scope.isEmpty()) { 310 if (scope.isEmpty()) {
312 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par ameter was empty."); 311 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par ameter was empty.");
313 return nullptr; 312 return nullptr;
314 } 313 }
315 314
316 Vector<int64_t> objectStoreIds; 315 Vector<int64_t> objectStoreIds;
317 for (const String& name : scope) { 316 for (const String& name : scope) {
318 int64_t objectStoreId = findObjectStoreId(name); 317 int64_t objectStoreId = findObjectStoreId(name);
319 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { 318 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) {
320 exceptionState.throwDOMException(NotFoundError, "One of the specifie d object stores was not found."); 319 exceptionState.throwDOMException(NotFoundError, "One of the specifie d object stores was not found.");
321 return nullptr; 320 return nullptr;
322 } 321 }
323 objectStoreIds.append(objectStoreId); 322 objectStoreIds.append(objectStoreId);
324 } 323 }
325 324
326 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString); 325 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString);
327 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe adWrite) { 326 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe adWrite) {
328 exceptionState.throwTypeError("The mode provided ('" + modeString + "') is not one of 'readonly' or 'readwrite'."); 327 exceptionState.throwTypeError("The mode provided ('" + modeString + "') is not one of 'readonly' or 'readwrite'.");
329 return nullptr; 328 return nullptr;
330 } 329 }
331 330
332 int64_t transactionId = nextTransactionId(); 331 int64_t transactionId = nextTransactionId();
333 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre ate(m_databaseCallbacks).release(), objectStoreIds, mode); 332 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre ate(m_databaseCallbacks).release(), objectStoreIds, mode);
334 333
335 return IDBTransaction::create(scriptState, transactionId, scope, mode, this) ; 334 return IDBTransaction::createNonVersionChange(scriptState, transactionId, sc ope, mode, this);
336 } 335 }
337 336
338 void IDBDatabase::forceClose() 337 void IDBDatabase::forceClose()
339 { 338 {
340 for (const auto& it : m_transactions) 339 for (const auto& it : m_transactions)
341 it.value->abort(IGNORE_EXCEPTION); 340 it.value->abort(IGNORE_EXCEPTION);
342 this->close(); 341 this->close();
343 enqueueEvent(Event::create(EventTypeNames::close)); 342 enqueueEvent(Event::create(EventTypeNames::close));
344 } 343 }
345 344
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 { 427 {
429 for (const auto& it : m_metadata.objectStores) { 428 for (const auto& it : m_metadata.objectStores) {
430 if (it.value.name == name) { 429 if (it.value.name == name) {
431 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId); 430 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId);
432 return it.key; 431 return it.key;
433 } 432 }
434 } 433 }
435 return IDBObjectStoreMetadata::InvalidId; 434 return IDBObjectStoreMetadata::InvalidId;
436 } 435 }
437 436
438 void IDBDatabase::objectStoreRenamed(int64_t storeId, const String& newName) 437 void IDBDatabase::objectStoreRenamed(int64_t objectStoreId, const String& newNam e)
439 { 438 {
440 DCHECK(m_metadata.objectStores.contains(storeId)); 439 DCHECK(m_versionChangeTransaction) << "Object store renamed on database with out a versionchange transaction";
441 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f ind(storeId); 440 DCHECK(m_versionChangeTransaction->isActive()) << "Object store renamed when versionchange transaction is not active";
441 DCHECK(m_backend) << "Object store renamed after database connection closed" ;
442 DCHECK(m_metadata.objectStores.contains(objectStoreId));
443 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f ind(objectStoreId);
442 it->value.name = newName; 444 it->value.name = newName;
443 } 445 }
444 446
445 bool IDBDatabase::hasPendingActivity() const 447 bool IDBDatabase::hasPendingActivity() const
446 { 448 {
447 // The script wrapper must not be collected before the object is closed or 449 // The script wrapper must not be collected before the object is closed or
448 // we can't fire a "versionchange" event to let script manually close the co nnection. 450 // we can't fire a "versionchange" event to let script manually close the co nnection.
449 return !m_closePending && hasEventListeners() && !m_contextStopped; 451 return !m_closePending && hasEventListeners() && !m_contextStopped;
450 } 452 }
451 453
(...skipping 20 matching lines...) Expand all
472 return ActiveDOMObject::getExecutionContext(); 474 return ActiveDOMObject::getExecutionContext();
473 } 475 }
474 476
475 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) 477 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method)
476 { 478 {
477 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); 479 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax));
478 apiCallsHistogram.count(method); 480 apiCallsHistogram.count(method);
479 } 481 }
480 482
481 } // namespace blink 483 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698