| 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_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 backing_stores_with_active_blobs_.erase(it); | 165 backing_stores_with_active_blobs_.erase(it); |
| 166 ReleaseBackingStore(origin, false /* immediate */); | 166 ReleaseBackingStore(origin, false /* immediate */); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 void IndexedDBFactoryImpl::GetDatabaseNames( | 171 void IndexedDBFactoryImpl::GetDatabaseNames( |
| 172 scoped_refptr<IndexedDBCallbacks> callbacks, | 172 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 173 const Origin& origin, | 173 const Origin& origin, |
| 174 const base::FilePath& data_directory, | 174 const base::FilePath& data_directory, |
| 175 net::URLRequestContext* request_context) { | 175 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { |
| 176 IDB_TRACE("IndexedDBFactoryImpl::GetDatabaseNames"); | 176 IDB_TRACE("IndexedDBFactoryImpl::GetDatabaseNames"); |
| 177 // TODO(dgrogan): Plumb data_loss back to script eventually? | 177 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 178 IndexedDBDataLossInfo data_loss_info; | 178 IndexedDBDataLossInfo data_loss_info; |
| 179 bool disk_full; | 179 bool disk_full; |
| 180 leveldb::Status s; | 180 leveldb::Status s; |
| 181 // TODO(cmumford): Handle this error | 181 // TODO(cmumford): Handle this error |
| 182 scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore( | 182 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 183 origin, data_directory, request_context, &data_loss_info, &disk_full, &s); | 183 OpenBackingStore(origin, data_directory, request_context_getter, |
| 184 &data_loss_info, &disk_full, &s); |
| 184 if (!backing_store.get()) { | 185 if (!backing_store.get()) { |
| 185 callbacks->OnError( | 186 callbacks->OnError( |
| 186 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 187 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 187 "Internal error opening backing store for " | 188 "Internal error opening backing store for " |
| 188 "indexedDB.webkitGetDatabaseNames.")); | 189 "indexedDB.webkitGetDatabaseNames.")); |
| 189 return; | 190 return; |
| 190 } | 191 } |
| 191 | 192 |
| 192 std::vector<base::string16> names = backing_store->GetDatabaseNames(&s); | 193 std::vector<base::string16> names = backing_store->GetDatabaseNames(&s); |
| 193 if (!s.ok()) { | 194 if (!s.ok()) { |
| 194 DLOG(ERROR) << "Internal error getting database names"; | 195 DLOG(ERROR) << "Internal error getting database names"; |
| 195 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 196 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 196 "Internal error opening backing store for " | 197 "Internal error opening backing store for " |
| 197 "indexedDB.webkitGetDatabaseNames."); | 198 "indexedDB.webkitGetDatabaseNames."); |
| 198 callbacks->OnError(error); | 199 callbacks->OnError(error); |
| 199 backing_store = NULL; | 200 backing_store = NULL; |
| 200 if (s.IsCorruption()) | 201 if (s.IsCorruption()) |
| 201 HandleBackingStoreCorruption(origin, error); | 202 HandleBackingStoreCorruption(origin, error); |
| 202 return; | 203 return; |
| 203 } | 204 } |
| 204 callbacks->OnSuccess(names); | 205 callbacks->OnSuccess(names); |
| 205 backing_store = NULL; | 206 backing_store = NULL; |
| 206 ReleaseBackingStore(origin, false /* immediate */); | 207 ReleaseBackingStore(origin, false /* immediate */); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void IndexedDBFactoryImpl::DeleteDatabase( | 210 void IndexedDBFactoryImpl::DeleteDatabase( |
| 210 const base::string16& name, | 211 const base::string16& name, |
| 211 net::URLRequestContext* request_context, | 212 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 212 scoped_refptr<IndexedDBCallbacks> callbacks, | 213 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 213 const Origin& origin, | 214 const Origin& origin, |
| 214 const base::FilePath& data_directory) { | 215 const base::FilePath& data_directory) { |
| 215 IDB_TRACE("IndexedDBFactoryImpl::DeleteDatabase"); | 216 IDB_TRACE("IndexedDBFactoryImpl::DeleteDatabase"); |
| 216 IndexedDBDatabase::Identifier unique_identifier(origin, name); | 217 IndexedDBDatabase::Identifier unique_identifier(origin, name); |
| 217 const auto& it = database_map_.find(unique_identifier); | 218 const auto& it = database_map_.find(unique_identifier); |
| 218 if (it != database_map_.end()) { | 219 if (it != database_map_.end()) { |
| 219 // If there are any connections to the database, directly delete the | 220 // If there are any connections to the database, directly delete the |
| 220 // database. | 221 // database. |
| 221 it->second->DeleteDatabase(callbacks); | 222 it->second->DeleteDatabase(callbacks); |
| 222 return; | 223 return; |
| 223 } | 224 } |
| 224 | 225 |
| 225 // TODO(dgrogan): Plumb data_loss back to script eventually? | 226 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 226 IndexedDBDataLossInfo data_loss_info; | 227 IndexedDBDataLossInfo data_loss_info; |
| 227 bool disk_full = false; | 228 bool disk_full = false; |
| 228 leveldb::Status s; | 229 leveldb::Status s; |
| 229 scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore( | 230 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 230 origin, data_directory, request_context, &data_loss_info, &disk_full, &s); | 231 OpenBackingStore(origin, data_directory, request_context_getter, |
| 232 &data_loss_info, &disk_full, &s); |
| 231 if (!backing_store.get()) { | 233 if (!backing_store.get()) { |
| 232 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 234 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 233 ASCIIToUTF16( | 235 ASCIIToUTF16( |
| 234 "Internal error opening backing store " | 236 "Internal error opening backing store " |
| 235 "for indexedDB.deleteDatabase.")); | 237 "for indexedDB.deleteDatabase.")); |
| 236 callbacks->OnError(error); | 238 callbacks->OnError(error); |
| 237 if (s.IsCorruption()) { | 239 if (s.IsCorruption()) { |
| 238 HandleBackingStoreCorruption(origin, error); | 240 HandleBackingStoreCorruption(origin, error); |
| 239 } | 241 } |
| 240 return; | 242 return; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 const auto& it = backing_store_map_.find(origin); | 336 const auto& it = backing_store_map_.find(origin); |
| 335 if (it == backing_store_map_.end()) | 337 if (it == backing_store_map_.end()) |
| 336 return false; | 338 return false; |
| 337 return it->second->close_timer()->IsRunning(); | 339 return it->second->close_timer()->IsRunning(); |
| 338 } | 340 } |
| 339 | 341 |
| 340 scoped_refptr<IndexedDBBackingStore> | 342 scoped_refptr<IndexedDBBackingStore> |
| 341 IndexedDBFactoryImpl::OpenBackingStoreHelper( | 343 IndexedDBFactoryImpl::OpenBackingStoreHelper( |
| 342 const Origin& origin, | 344 const Origin& origin, |
| 343 const base::FilePath& data_directory, | 345 const base::FilePath& data_directory, |
| 344 net::URLRequestContext* request_context, | 346 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 345 IndexedDBDataLossInfo* data_loss_info, | 347 IndexedDBDataLossInfo* data_loss_info, |
| 346 bool* disk_full, | 348 bool* disk_full, |
| 347 bool first_time, | 349 bool first_time, |
| 348 leveldb::Status* status) { | 350 leveldb::Status* status) { |
| 349 return IndexedDBBackingStore::Open( | 351 return IndexedDBBackingStore::Open( |
| 350 this, origin, data_directory, request_context, data_loss_info, disk_full, | 352 this, origin, data_directory, request_context_getter, data_loss_info, |
| 351 context_->TaskRunner(), first_time, status); | 353 disk_full, context_->TaskRunner(), first_time, status); |
| 352 } | 354 } |
| 353 | 355 |
| 354 scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore( | 356 scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore( |
| 355 const Origin& origin, | 357 const Origin& origin, |
| 356 const base::FilePath& data_directory, | 358 const base::FilePath& data_directory, |
| 357 net::URLRequestContext* request_context, | 359 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 358 IndexedDBDataLossInfo* data_loss_info, | 360 IndexedDBDataLossInfo* data_loss_info, |
| 359 bool* disk_full, | 361 bool* disk_full, |
| 360 leveldb::Status* status) { | 362 leveldb::Status* status) { |
| 361 const bool open_in_memory = data_directory.empty(); | 363 const bool open_in_memory = data_directory.empty(); |
| 362 | 364 |
| 363 const auto& it2 = backing_store_map_.find(origin); | 365 const auto& it2 = backing_store_map_.find(origin); |
| 364 if (it2 != backing_store_map_.end()) { | 366 if (it2 != backing_store_map_.end()) { |
| 365 it2->second->close_timer()->Stop(); | 367 it2->second->close_timer()->Stop(); |
| 366 return it2->second; | 368 return it2->second; |
| 367 } | 369 } |
| 368 | 370 |
| 369 scoped_refptr<IndexedDBBackingStore> backing_store; | 371 scoped_refptr<IndexedDBBackingStore> backing_store; |
| 370 bool first_time = false; | 372 bool first_time = false; |
| 371 if (open_in_memory) { | 373 if (open_in_memory) { |
| 372 backing_store = IndexedDBBackingStore::OpenInMemory( | 374 backing_store = IndexedDBBackingStore::OpenInMemory( |
| 373 origin, context_->TaskRunner(), status); | 375 origin, context_->TaskRunner(), status); |
| 374 } else { | 376 } else { |
| 375 first_time = !backends_opened_since_boot_.count(origin); | 377 first_time = !backends_opened_since_boot_.count(origin); |
| 376 | 378 |
| 377 backing_store = | 379 backing_store = |
| 378 OpenBackingStoreHelper(origin, data_directory, request_context, | 380 OpenBackingStoreHelper(origin, data_directory, request_context_getter, |
| 379 data_loss_info, disk_full, first_time, status); | 381 data_loss_info, disk_full, first_time, status); |
| 380 } | 382 } |
| 381 | 383 |
| 382 if (backing_store.get()) { | 384 if (backing_store.get()) { |
| 383 if (first_time) | 385 if (first_time) |
| 384 backends_opened_since_boot_.insert(origin); | 386 backends_opened_since_boot_.insert(origin); |
| 385 backing_store_map_[origin] = backing_store; | 387 backing_store_map_[origin] = backing_store; |
| 386 // If an in-memory database, bind lifetime to this factory instance. | 388 // If an in-memory database, bind lifetime to this factory instance. |
| 387 if (open_in_memory) | 389 if (open_in_memory) |
| 388 session_only_backing_stores_.insert(backing_store); | 390 session_only_backing_stores_.insert(backing_store); |
| 389 | 391 |
| 390 // All backing stores associated with this factory should be of the same | 392 // All backing stores associated with this factory should be of the same |
| 391 // type. | 393 // type. |
| 392 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); | 394 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); |
| 393 | 395 |
| 394 return backing_store; | 396 return backing_store; |
| 395 } | 397 } |
| 396 | 398 |
| 397 return 0; | 399 return 0; |
| 398 } | 400 } |
| 399 | 401 |
| 400 void IndexedDBFactoryImpl::Open( | 402 void IndexedDBFactoryImpl::Open( |
| 401 const base::string16& name, | 403 const base::string16& name, |
| 402 std::unique_ptr<IndexedDBPendingConnection> connection, | 404 std::unique_ptr<IndexedDBPendingConnection> connection, |
| 403 net::URLRequestContext* request_context, | 405 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 404 const Origin& origin, | 406 const Origin& origin, |
| 405 const base::FilePath& data_directory) { | 407 const base::FilePath& data_directory) { |
| 406 IDB_TRACE("IndexedDBFactoryImpl::Open"); | 408 IDB_TRACE("IndexedDBFactoryImpl::Open"); |
| 407 scoped_refptr<IndexedDBDatabase> database; | 409 scoped_refptr<IndexedDBDatabase> database; |
| 408 IndexedDBDatabase::Identifier unique_identifier(origin, name); | 410 IndexedDBDatabase::Identifier unique_identifier(origin, name); |
| 409 const auto& it = database_map_.find(unique_identifier); | 411 const auto& it = database_map_.find(unique_identifier); |
| 410 IndexedDBDataLossInfo data_loss_info; | 412 IndexedDBDataLossInfo data_loss_info; |
| 411 bool disk_full = false; | 413 bool disk_full = false; |
| 412 bool was_open = (it != database_map_.end()); | 414 bool was_open = (it != database_map_.end()); |
| 413 if (!was_open) { | 415 if (!was_open) { |
| 414 leveldb::Status s; | 416 leveldb::Status s; |
| 415 scoped_refptr<IndexedDBBackingStore> backing_store = | 417 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 416 OpenBackingStore(origin, data_directory, request_context, | 418 OpenBackingStore(origin, data_directory, request_context_getter, |
| 417 &data_loss_info, &disk_full, &s); | 419 &data_loss_info, &disk_full, &s); |
| 418 if (!backing_store.get()) { | 420 if (!backing_store.get()) { |
| 419 if (disk_full) { | 421 if (disk_full) { |
| 420 connection->callbacks->OnError(IndexedDBDatabaseError( | 422 connection->callbacks->OnError(IndexedDBDatabaseError( |
| 421 blink::WebIDBDatabaseExceptionQuotaError, | 423 blink::WebIDBDatabaseExceptionQuotaError, |
| 422 ASCIIToUTF16("Encountered full disk while opening " | 424 ASCIIToUTF16("Encountered full disk while opening " |
| 423 "backing store for indexedDB.open."))); | 425 "backing store for indexedDB.open."))); |
| 424 return; | 426 return; |
| 425 } | 427 } |
| 426 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 428 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 size_t count(0); | 476 size_t count(0); |
| 475 | 477 |
| 476 OriginDBs range = GetOpenDatabasesForOrigin(origin); | 478 OriginDBs range = GetOpenDatabasesForOrigin(origin); |
| 477 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 479 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
| 478 count += it->second->ConnectionCount(); | 480 count += it->second->ConnectionCount(); |
| 479 | 481 |
| 480 return count; | 482 return count; |
| 481 } | 483 } |
| 482 | 484 |
| 483 } // namespace content | 485 } // namespace content |
| OLD | NEW |