| 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()) { |
| 197 // TODO(cmumford): Handle this error |
| 198 DLOG(ERROR) << "Internal error getting database names"; |
| 199 } |
| 200 callbacks->OnSuccess(names); |
| 195 backing_store = NULL; | 201 backing_store = NULL; |
| 196 ReleaseBackingStore(origin_url, false /* immediate */); | 202 ReleaseBackingStore(origin_url, false /* immediate */); |
| 197 } | 203 } |
| 198 | 204 |
| 199 void IndexedDBFactory::DeleteDatabase( | 205 void IndexedDBFactory::DeleteDatabase( |
| 200 const base::string16& name, | 206 const base::string16& name, |
| 201 scoped_refptr<IndexedDBCallbacks> callbacks, | 207 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 202 const GURL& origin_url, | 208 const GURL& origin_url, |
| 203 const base::FilePath& data_directory) { | 209 const base::FilePath& data_directory) { |
| 204 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 210 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 223 &disk_full); | 229 &disk_full); |
| 224 if (!backing_store) { | 230 if (!backing_store) { |
| 225 callbacks->OnError( | 231 callbacks->OnError( |
| 226 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 232 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 227 ASCIIToUTF16( | 233 ASCIIToUTF16( |
| 228 "Internal error opening backing store " | 234 "Internal error opening backing store " |
| 229 "for indexedDB.deleteDatabase."))); | 235 "for indexedDB.deleteDatabase."))); |
| 230 return; | 236 return; |
| 231 } | 237 } |
| 232 | 238 |
| 233 scoped_refptr<IndexedDBDatabase> database = | 239 leveldb::Status s; |
| 234 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 240 scoped_refptr<IndexedDBDatabase> database = IndexedDBDatabase::Create( |
| 241 name, backing_store, this, unique_identifier, &s); |
| 235 if (!database) { | 242 if (!database) { |
| 236 callbacks->OnError(IndexedDBDatabaseError( | 243 IndexedDBDatabaseError error( |
| 237 blink::WebIDBDatabaseExceptionUnknownError, | 244 blink::WebIDBDatabaseExceptionUnknownError, |
| 238 ASCIIToUTF16( | 245 ASCIIToUTF16( |
| 239 "Internal error creating database backend for " | 246 "Internal error creating database backend for " |
| 240 "indexedDB.deleteDatabase."))); | 247 "indexedDB.deleteDatabase.")); |
| 248 callbacks->OnError(error); |
| 249 if (s.IsCorruption()) |
| 250 HandleBackingStoreCorruption(origin_url, error); |
| 241 return; | 251 return; |
| 242 } | 252 } |
| 243 | 253 |
| 244 database_map_[unique_identifier] = database; | 254 database_map_[unique_identifier] = database; |
| 245 origin_dbs_.insert(std::make_pair(origin_url, database)); | 255 origin_dbs_.insert(std::make_pair(origin_url, database)); |
| 246 database->DeleteDatabase(callbacks); | 256 database->DeleteDatabase(callbacks); |
| 247 RemoveDatabaseFromMaps(unique_identifier); | 257 RemoveDatabaseFromMaps(unique_identifier); |
| 248 database = NULL; | 258 database = NULL; |
| 249 backing_store = NULL; | 259 backing_store = NULL; |
| 250 ReleaseBackingStore(origin_url, false /* immediate */); | 260 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 | 282 // 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. | 283 // backing store which this function will be deleting. |
| 274 GURL saved_origin_url(origin_url); | 284 GURL saved_origin_url(origin_url); |
| 275 DCHECK(context_); | 285 DCHECK(context_); |
| 276 base::FilePath path_base = context_->data_path(); | 286 base::FilePath path_base = context_->data_path(); |
| 277 IndexedDBBackingStore::RecordCorruptionInfo( | 287 IndexedDBBackingStore::RecordCorruptionInfo( |
| 278 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); | 288 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); |
| 279 HandleBackingStoreFailure(saved_origin_url); | 289 HandleBackingStoreFailure(saved_origin_url); |
| 280 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, | 290 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, |
| 281 // so our corruption info file will remain. | 291 // so our corruption info file will remain. |
| 282 if (!IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url) | 292 leveldb::Status s = |
| 283 .ok()) | 293 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); |
| 284 DLOG(ERROR) << "Unable to delete backing store"; | 294 if (!s.ok()) |
| 295 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); |
| 285 } | 296 } |
| 286 | 297 |
| 287 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 298 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, |
| 288 const base::string16& name) const { | 299 const base::string16& name) const { |
| 289 | 300 |
| 290 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 301 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
| 291 } | 302 } |
| 292 | 303 |
| 293 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 304 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { |
| 294 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 305 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."))); | 387 "backing store for indexedDB.open."))); |
| 377 return; | 388 return; |
| 378 } | 389 } |
| 379 connection.callbacks->OnError(IndexedDBDatabaseError( | 390 connection.callbacks->OnError(IndexedDBDatabaseError( |
| 380 blink::WebIDBDatabaseExceptionUnknownError, | 391 blink::WebIDBDatabaseExceptionUnknownError, |
| 381 ASCIIToUTF16( | 392 ASCIIToUTF16( |
| 382 "Internal error opening backing store for indexedDB.open."))); | 393 "Internal error opening backing store for indexedDB.open."))); |
| 383 return; | 394 return; |
| 384 } | 395 } |
| 385 | 396 |
| 386 database = | 397 leveldb::Status s; |
| 387 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 398 database = IndexedDBDatabase::Create( |
| 399 name, backing_store, this, unique_identifier, &s); |
| 388 if (!database) { | 400 if (!database) { |
| 389 connection.callbacks->OnError(IndexedDBDatabaseError( | 401 DLOG(ERROR) << "Unable to create the database"; |
| 390 blink::WebIDBDatabaseExceptionUnknownError, | 402 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 391 ASCIIToUTF16( | 403 ASCIIToUTF16( |
| 392 "Internal error creating database backend for indexedDB.open."))); | 404 "Internal error creating " |
| 405 "database backend for " |
| 406 "indexedDB.open.")); |
| 407 connection.callbacks->OnError(error); |
| 408 if (s.IsCorruption()) { |
| 409 backing_store = NULL; // Closes the LevelDB so that it can be deleted |
| 410 HandleBackingStoreCorruption(origin_url, error); |
| 411 } |
| 393 return; | 412 return; |
| 394 } | 413 } |
| 395 } else { | 414 } else { |
| 396 database = it->second; | 415 database = it->second; |
| 397 } | 416 } |
| 398 | 417 |
| 399 if (data_loss != blink::WebIDBDataLossNone) | 418 if (data_loss != blink::WebIDBDataLossNone) |
| 400 connection.callbacks->OnDataLoss(data_loss, data_loss_message); | 419 connection.callbacks->OnDataLoss(data_loss, data_loss_message); |
| 401 | 420 |
| 402 database->OpenConnection(connection); | 421 database->OpenConnection(connection); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 418 | 437 |
| 419 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 438 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
| 420 GetOpenDatabasesForOrigin(origin_url); | 439 GetOpenDatabasesForOrigin(origin_url); |
| 421 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 440 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
| 422 count += it->second->ConnectionCount(); | 441 count += it->second->ConnectionCount(); |
| 423 | 442 |
| 424 return count; | 443 return count; |
| 425 } | 444 } |
| 426 | 445 |
| 427 } // namespace content | 446 } // namespace content |
| OLD | NEW |