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

Side by Side Diff: Source/WebCore/Modules/indexeddb/IDBBackingStore.cpp

Issue 12549003: Merge 144323 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 bool ok = getInt(db, maxObjectStoreIdKey, maxObjectStoreId, found); 316 bool ok = getInt(db, maxObjectStoreIdKey, maxObjectStoreId, found);
317 if (!ok) 317 if (!ok)
318 return false; 318 return false;
319 if (!found) 319 if (!found)
320 maxObjectStoreId = 0; 320 maxObjectStoreId = 0;
321 321
322 ASSERT(maxObjectStoreId >= 0); 322 ASSERT(maxObjectStoreId >= 0);
323 return true; 323 return true;
324 } 324 }
325 325
326 class DefaultLevelDBFactory : public LevelDBFactory {
327 public:
328 virtual PassOwnPtr<LevelDBDatabase> openLevelDB(const String& fileName, cons t LevelDBComparator* comparator)
329 {
330 return LevelDBDatabase::open(fileName, comparator);
331 }
332 virtual bool destroyLevelDB(const String& fileName)
333 {
334 return LevelDBDatabase::destroy(fileName);
335 }
336 };
337
326 IDBBackingStore::IDBBackingStore(const String& identifier, IDBFactoryBackendImpl * factory, PassOwnPtr<LevelDBDatabase> db) 338 IDBBackingStore::IDBBackingStore(const String& identifier, IDBFactoryBackendImpl * factory, PassOwnPtr<LevelDBDatabase> db)
327 : m_identifier(identifier) 339 : m_identifier(identifier)
328 , m_factory(factory) 340 , m_factory(factory)
329 , m_db(db) 341 , m_db(db)
330 { 342 {
331 m_factory->addIDBBackingStore(identifier, this); 343 m_factory->addIDBBackingStore(identifier, this);
332 } 344 }
333 345
334 IDBBackingStore::IDBBackingStore() 346 IDBBackingStore::IDBBackingStore()
335 { 347 {
(...skipping 17 matching lines...) Expand all
353 IDBLevelDBBackingStoreOpenFailedUnknownSchema, 365 IDBLevelDBBackingStoreOpenFailedUnknownSchema,
354 IDBLevelDBBackingStoreOpenCleanupDestroyFailed, 366 IDBLevelDBBackingStoreOpenCleanupDestroyFailed,
355 IDBLevelDBBackingStoreOpenCleanupReopenFailed, 367 IDBLevelDBBackingStoreOpenCleanupReopenFailed,
356 IDBLevelDBBackingStoreOpenCleanupReopenSuccess, 368 IDBLevelDBBackingStoreOpenCleanupReopenSuccess,
357 IDBLevelDBBackingStoreOpenFailedIOErrCheckingSchema, 369 IDBLevelDBBackingStoreOpenFailedIOErrCheckingSchema,
358 IDBLevelDBBackingStoreOpenMax, 370 IDBLevelDBBackingStoreOpenMax,
359 }; 371 };
360 372
361 PassRefPtr<IDBBackingStore> IDBBackingStore::open(SecurityOrigin* securityOrigin , const String& pathBaseArg, const String& fileIdentifier, IDBFactoryBackendImpl * factory) 373 PassRefPtr<IDBBackingStore> IDBBackingStore::open(SecurityOrigin* securityOrigin , const String& pathBaseArg, const String& fileIdentifier, IDBFactoryBackendImpl * factory)
362 { 374 {
375 DefaultLevelDBFactory levelDBFactory;
376 return IDBBackingStore::open(securityOrigin, pathBaseArg, fileIdentifier, fa ctory, &levelDBFactory);
377 }
378
379 PassRefPtr<IDBBackingStore> IDBBackingStore::open(SecurityOrigin* securityOrigin , const String& pathBaseArg, const String& fileIdentifier, IDBFactoryBackendImpl * factory, LevelDBFactory* levelDBFactory)
380 {
363 IDB_TRACE("IDBBackingStore::open"); 381 IDB_TRACE("IDBBackingStore::open");
364 String pathBase = pathBaseArg; 382 String pathBase = pathBaseArg;
365 383
366 OwnPtr<LevelDBComparator> comparator = adoptPtr(new Comparator()); 384 OwnPtr<LevelDBComparator> comparator = adoptPtr(new Comparator());
367 OwnPtr<LevelDBDatabase> db; 385 OwnPtr<LevelDBDatabase> db;
368 386
369 if (pathBase.isEmpty()) { 387 if (pathBase.isEmpty()) {
370 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingStore.O penStatus", IDBLevelDBBackingStoreOpenMemory, IDBLevelDBBackingStoreOpenMax); 388 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingStore.O penStatus", IDBLevelDBBackingStoreOpenMemory, IDBLevelDBBackingStoreOpenMax);
371 db = LevelDBDatabase::openInMemory(comparator.get()); 389 db = LevelDBDatabase::openInMemory(comparator.get());
372 } else { 390 } else {
373 if (!makeAllDirectories(pathBase)) { 391 if (!makeAllDirectories(pathBase)) {
374 LOG_ERROR("Unable to create IndexedDB database path %s", pathBase.ut f8().data()); 392 LOG_ERROR("Unable to create IndexedDB database path %s", pathBase.ut f8().data());
375 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenFailedDirectory, IDBLevelDBBackingStor eOpenMax); 393 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenFailedDirectory, IDBLevelDBBackingStor eOpenMax);
376 return PassRefPtr<IDBBackingStore>(); 394 return PassRefPtr<IDBBackingStore>();
377 } 395 }
378 396
379 String path = pathByAppendingComponent(pathBase, securityOrigin->databas eIdentifier() + ".indexeddb.leveldb"); 397 String path = pathByAppendingComponent(pathBase, securityOrigin->databas eIdentifier() + ".indexeddb.leveldb");
380 398
381 db = LevelDBDatabase::open(path, comparator.get()); 399 db = levelDBFactory->openLevelDB(path, comparator.get());
382 if (db) { 400 if (db) {
383 bool known = false; 401 bool known = false;
384 bool ok = isSchemaKnown(db.get(), known); 402 bool ok = isSchemaKnown(db.get(), known);
385 if (!ok) { 403 if (!ok) {
404 LOG_ERROR("IndexedDB had IO error checking schema, treating it a s failure to open");
386 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenFailedIOErrCheckingSchema, IDBLeve lDBBackingStoreOpenMax); 405 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenFailedIOErrCheckingSchema, IDBLeve lDBBackingStoreOpenMax);
387 return PassRefPtr<IDBBackingStore>(); 406 db.clear();
388 } 407 } else if (!known) {
389 if (!known) {
390 LOG_ERROR("IndexedDB backing store had unknown schema, treating it as failure to open"); 408 LOG_ERROR("IndexedDB backing store had unknown schema, treating it as failure to open");
391 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenFailedUnknownSchema, IDBLevelDBBac kingStoreOpenMax); 409 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenFailedUnknownSchema, IDBLevelDBBac kingStoreOpenMax);
392 db.clear(); 410 db.clear();
393 } 411 }
394 } 412 }
395 413
396 if (db) 414 if (db)
397 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenSuccess, IDBLevelDBBackingStoreOpenMax ); 415 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenSuccess, IDBLevelDBBackingStoreOpenMax );
398 else { 416 else {
399 LOG_ERROR("IndexedDB backing store open failed, attempting cleanup") ; 417 LOG_ERROR("IndexedDB backing store open failed, attempting cleanup") ;
400 bool success = LevelDBDatabase::destroy(path); 418 bool success = levelDBFactory->destroyLevelDB(path);
401 if (!success) { 419 if (!success) {
402 LOG_ERROR("IndexedDB backing store cleanup failed"); 420 LOG_ERROR("IndexedDB backing store cleanup failed");
403 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenCleanupDestroyFailed, IDBLevelDBBa ckingStoreOpenMax); 421 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenCleanupDestroyFailed, IDBLevelDBBa ckingStoreOpenMax);
404 return PassRefPtr<IDBBackingStore>(); 422 return PassRefPtr<IDBBackingStore>();
405 } 423 }
406 424
407 LOG_ERROR("IndexedDB backing store cleanup succeeded, reopening"); 425 LOG_ERROR("IndexedDB backing store cleanup succeeded, reopening");
408 db = LevelDBDatabase::open(path, comparator.get()); 426 db = levelDBFactory->openLevelDB(path, comparator.get());
409 if (!db) { 427 if (!db) {
410 LOG_ERROR("IndexedDB backing store reopen after recovery failed" ); 428 LOG_ERROR("IndexedDB backing store reopen after recovery failed" );
411 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenCleanupReopenFailed, IDBLevelDBBac kingStoreOpenMax); 429 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.Backin gStore.OpenStatus", IDBLevelDBBackingStoreOpenCleanupReopenFailed, IDBLevelDBBac kingStoreOpenMax);
412 return PassRefPtr<IDBBackingStore>(); 430 return PassRefPtr<IDBBackingStore>();
413 } 431 }
414 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenCleanupReopenSuccess, IDBLevelDBBackin gStoreOpenMax); 432 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingSto re.OpenStatus", IDBLevelDBBackingStoreOpenCleanupReopenSuccess, IDBLevelDBBackin gStoreOpenMax);
415 } 433 }
416 } 434 }
417 435
418 if (!db) 436 if (!db)
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 { 1876 {
1859 IDB_TRACE("IDBBackingStore::Transaction::rollback"); 1877 IDB_TRACE("IDBBackingStore::Transaction::rollback");
1860 ASSERT(m_transaction); 1878 ASSERT(m_transaction);
1861 m_transaction->rollback(); 1879 m_transaction->rollback();
1862 m_transaction.clear(); 1880 m_transaction.clear();
1863 } 1881 }
1864 1882
1865 } // namespace WebCore 1883 } // namespace WebCore
1866 1884
1867 #endif // ENABLE(INDEXED_DATABASE) 1885 #endif // ENABLE(INDEXED_DATABASE)
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/indexeddb/IDBBackingStore.h ('k') | Source/WebCore/platform/leveldb/LevelDBDatabase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698