Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_factory.h" | 5 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 &data_loss_message, | 184 &data_loss_message, |
| 185 &disk_full); | 185 &disk_full); |
| 186 if (!backing_store) { | 186 if (!backing_store) { |
| 187 callbacks->OnError( | 187 callbacks->OnError( |
| 188 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 188 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 189 "Internal error opening backing store for " | 189 "Internal error opening backing store for " |
| 190 "indexedDB.webkitGetDatabaseNames.")); | 190 "indexedDB.webkitGetDatabaseNames.")); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 194 leveldb::Status s; |
| 195 std::vector<base::string16> names = backing_store->GetDatabaseNames(s); | |
| 196 if (s.ok()) { | |
|
jsbell
2014/04/14 20:44:20
I'd reduce this to just an !s.ok() case for now, s
cmumford
2014/04/14 23:39:23
Done.
| |
| 197 callbacks->OnSuccess(names); | |
| 198 } else { | |
| 199 // TODO(cmumford): Handle this error | |
| 200 DLOG(ERROR) << "Internal error getting database names"; | |
| 201 callbacks->OnSuccess(names); | |
| 202 } | |
| 195 backing_store = NULL; | 203 backing_store = NULL; |
| 196 ReleaseBackingStore(origin_url, false /* immediate */); | 204 ReleaseBackingStore(origin_url, false /* immediate */); |
| 197 } | 205 } |
| 198 | 206 |
| 199 void IndexedDBFactory::DeleteDatabase( | 207 void IndexedDBFactory::DeleteDatabase( |
| 200 const base::string16& name, | 208 const base::string16& name, |
| 201 scoped_refptr<IndexedDBCallbacks> callbacks, | 209 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 202 const GURL& origin_url, | 210 const GURL& origin_url, |
| 203 const base::FilePath& data_directory) { | 211 const base::FilePath& data_directory) { |
| 204 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 212 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 223 &disk_full); | 231 &disk_full); |
| 224 if (!backing_store) { | 232 if (!backing_store) { |
| 225 callbacks->OnError( | 233 callbacks->OnError( |
| 226 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 234 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 227 ASCIIToUTF16( | 235 ASCIIToUTF16( |
| 228 "Internal error opening backing store " | 236 "Internal error opening backing store " |
| 229 "for indexedDB.deleteDatabase."))); | 237 "for indexedDB.deleteDatabase."))); |
| 230 return; | 238 return; |
| 231 } | 239 } |
| 232 | 240 |
| 233 scoped_refptr<IndexedDBDatabase> database = | 241 leveldb::Status s; |
| 234 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 242 scoped_refptr<IndexedDBDatabase> database = IndexedDBDatabase::Create( |
| 243 name, backing_store, this, unique_identifier, s); | |
| 235 if (!database) { | 244 if (!database) { |
| 236 callbacks->OnError(IndexedDBDatabaseError( | 245 IndexedDBDatabaseError error( |
| 237 blink::WebIDBDatabaseExceptionUnknownError, | 246 blink::WebIDBDatabaseExceptionUnknownError, |
| 238 ASCIIToUTF16( | 247 ASCIIToUTF16( |
| 239 "Internal error creating database backend for " | 248 "Internal error creating database backend for " |
| 240 "indexedDB.deleteDatabase."))); | 249 "indexedDB.deleteDatabase.")); |
| 250 callbacks->OnError(error); | |
| 251 if (s.IsCorruption()) { | |
| 252 backing_store = NULL; // Closes the LevelDB so that it can be deleted | |
|
jsbell
2014/04/14 20:44:20
Does it actually close, or just unblock closing?
cmumford
2014/04/14 23:39:23
If I'm reading that correctly that results in the
| |
| 253 HandleBackingStoreCorruption(origin_url, error); | |
| 254 } | |
| 241 return; | 255 return; |
| 242 } | 256 } |
| 243 | 257 |
| 244 database_map_[unique_identifier] = database; | 258 database_map_[unique_identifier] = database; |
| 245 origin_dbs_.insert(std::make_pair(origin_url, database)); | 259 origin_dbs_.insert(std::make_pair(origin_url, database)); |
| 246 database->DeleteDatabase(callbacks); | 260 database->DeleteDatabase(callbacks); |
| 247 RemoveDatabaseFromMaps(unique_identifier); | 261 RemoveDatabaseFromMaps(unique_identifier); |
| 248 database = NULL; | 262 database = NULL; |
| 249 backing_store = NULL; | 263 backing_store = NULL; |
| 250 ReleaseBackingStore(origin_url, false /* immediate */); | 264 ReleaseBackingStore(origin_url, false /* immediate */); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 272 // Make a copy of origin_url as this is likely a reference to a member of a | 286 // Make a copy of origin_url as this is likely a reference to a member of a |
| 273 // backing store which this function will be deleting. | 287 // backing store which this function will be deleting. |
| 274 GURL saved_origin_url(origin_url); | 288 GURL saved_origin_url(origin_url); |
| 275 DCHECK(context_); | 289 DCHECK(context_); |
| 276 base::FilePath path_base = context_->data_path(); | 290 base::FilePath path_base = context_->data_path(); |
| 277 IndexedDBBackingStore::RecordCorruptionInfo( | 291 IndexedDBBackingStore::RecordCorruptionInfo( |
| 278 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); | 292 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); |
| 279 HandleBackingStoreFailure(saved_origin_url); | 293 HandleBackingStoreFailure(saved_origin_url); |
| 280 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, | 294 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, |
| 281 // so our corruption info file will remain. | 295 // so our corruption info file will remain. |
| 282 if (!IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url) | 296 leveldb::Status s = |
| 283 .ok()) | 297 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); |
| 284 DLOG(ERROR) << "Unable to delete backing store"; | 298 if (!s.ok()) |
| 299 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); | |
| 285 } | 300 } |
| 286 | 301 |
| 287 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 302 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, |
| 288 const base::string16& name) const { | 303 const base::string16& name) const { |
| 289 | 304 |
| 290 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 305 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
| 291 } | 306 } |
| 292 | 307 |
| 293 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 308 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { |
| 294 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 309 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 "backing store for indexedDB.open."))); | 391 "backing store for indexedDB.open."))); |
| 377 return; | 392 return; |
| 378 } | 393 } |
| 379 connection.callbacks->OnError(IndexedDBDatabaseError( | 394 connection.callbacks->OnError(IndexedDBDatabaseError( |
| 380 blink::WebIDBDatabaseExceptionUnknownError, | 395 blink::WebIDBDatabaseExceptionUnknownError, |
| 381 ASCIIToUTF16( | 396 ASCIIToUTF16( |
| 382 "Internal error opening backing store for indexedDB.open."))); | 397 "Internal error opening backing store for indexedDB.open."))); |
| 383 return; | 398 return; |
| 384 } | 399 } |
| 385 | 400 |
| 386 database = | 401 leveldb::Status s; |
| 387 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 402 database = IndexedDBDatabase::Create( |
| 403 name, backing_store, this, unique_identifier, s); | |
| 388 if (!database) { | 404 if (!database) { |
| 389 connection.callbacks->OnError(IndexedDBDatabaseError( | 405 DLOG(ERROR) << "Unable to create the database"; |
| 390 blink::WebIDBDatabaseExceptionUnknownError, | 406 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 391 ASCIIToUTF16( | 407 ASCIIToUTF16( |
| 392 "Internal error creating database backend for indexedDB.open."))); | 408 "Internal error creating " |
| 409 "database backend for " | |
| 410 "indexedDB.open.")); | |
| 411 connection.callbacks->OnError(error); | |
| 412 if (s.IsCorruption()) { | |
| 413 backing_store = NULL; // Closes the LevelDB so that it can be deleted | |
| 414 HandleBackingStoreCorruption(origin_url, error); | |
| 415 } | |
| 393 return; | 416 return; |
| 394 } | 417 } |
| 395 } else { | 418 } else { |
| 396 database = it->second; | 419 database = it->second; |
| 397 } | 420 } |
| 398 | 421 |
| 399 if (data_loss != blink::WebIDBDataLossNone) | 422 if (data_loss != blink::WebIDBDataLossNone) |
| 400 connection.callbacks->OnDataLoss(data_loss, data_loss_message); | 423 connection.callbacks->OnDataLoss(data_loss, data_loss_message); |
| 401 | 424 |
| 402 database->OpenConnection(connection); | 425 database->OpenConnection(connection); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 418 | 441 |
| 419 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 442 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
| 420 GetOpenDatabasesForOrigin(origin_url); | 443 GetOpenDatabasesForOrigin(origin_url); |
| 421 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 444 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
| 422 count += it->second->ConnectionCount(); | 445 count += it->second->ConnectionCount(); |
| 423 | 446 |
| 424 return count; | 447 return count; |
| 425 } | 448 } |
| 426 | 449 |
| 427 } // namespace content | 450 } // namespace content |
| OLD | NEW |