Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_factory.cc |
| diff --git a/content/browser/indexed_db/indexed_db_factory.cc b/content/browser/indexed_db/indexed_db_factory.cc |
| index 2cfef62c90643e6c8f75bf98910b10bc9a0d21f3..797d4a0ed355337ec0d81f638878bba8113663c5 100644 |
| --- a/content/browser/indexed_db/indexed_db_factory.cc |
| +++ b/content/browser/indexed_db/indexed_db_factory.cc |
| @@ -41,7 +41,7 @@ void IndexedDBFactory::ReleaseDatabase( |
| void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url, |
| bool immediate) { |
| // Only close if this is the last reference. |
| - if (!HasLastBackingStoreReference(origin_url)) |
| + if (!HasLastBackingStoreReference(origin_url, immediate)) |
| return; |
| // If this factory does hold the last reference to the backing store, it can |
| @@ -64,7 +64,7 @@ void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url, |
| void IndexedDBFactory::MaybeCloseBackingStore(const GURL& origin_url) { |
| // Another reference may have opened since the maybe-close was posted, so it |
| // is necessary to check again. |
| - if (HasLastBackingStoreReference(origin_url)) |
| + if (HasLastBackingStoreReference(origin_url, false)) |
| CloseBackingStore(origin_url); |
| } |
| @@ -77,8 +77,8 @@ void IndexedDBFactory::CloseBackingStore(const GURL& origin_url) { |
| backing_store_map_.erase(it); |
| } |
| -bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url) |
| - const { |
| +bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url, |
| + bool forcedClose) const { |
| IndexedDBBackingStore* ptr; |
| { |
| // Scope so that the implicit scoped_refptr<> is freed. |
| @@ -87,6 +87,11 @@ bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url) |
| DCHECK(it != backing_store_map_.end()); |
| ptr = it->second.get(); |
| } |
| + if (ptr->HasOneRef()) |
| + return true; |
| + if (!forcedClose) |
| + return false; |
| + ptr->active_blob_registry()->ForceShutdown(); |
|
jsbell
2013/12/03 00:10:03
Hrm, unfortunate placement (in a Has.... method).
jsbell
2013/12/03 00:11:24
ISTM this is a good reason to move away from relyi
ericu
2013/12/03 02:03:55
It's idempotent, but currently assumes that once i
ericu
2013/12/03 02:03:55
I'm fine with that too; this code I've put in feel
|
| return ptr->HasOneRef(); |
| } |
| @@ -106,7 +111,8 @@ void IndexedDBFactory::ContextDestroyed() { |
| void IndexedDBFactory::GetDatabaseNames( |
| scoped_refptr<IndexedDBCallbacks> callbacks, |
| const GURL& origin_url, |
| - const base::FilePath& data_directory) { |
| + const base::FilePath& data_directory, |
| + base::TaskRunner* task_runner) { |
| IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); |
| // TODO(dgrogan): Plumb data_loss back to script eventually? |
| blink::WebIDBDataLoss data_loss; |
| @@ -115,9 +121,11 @@ void IndexedDBFactory::GetDatabaseNames( |
| scoped_refptr<IndexedDBBackingStore> backing_store = |
| OpenBackingStore(origin_url, |
| data_directory, |
| + NULL, |
| &data_loss, |
| &data_loss_message, |
| - &disk_full); |
| + &disk_full, |
| + task_runner); |
| if (!backing_store) { |
| callbacks->OnError( |
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| @@ -131,9 +139,11 @@ void IndexedDBFactory::GetDatabaseNames( |
| void IndexedDBFactory::DeleteDatabase( |
| const string16& name, |
| + net::URLRequestContext* request_context, |
| scoped_refptr<IndexedDBCallbacks> callbacks, |
| const GURL& origin_url, |
| - const base::FilePath& data_directory) { |
| + const base::FilePath& data_directory, |
| + base::TaskRunner* task_runner) { |
| IDB_TRACE("IndexedDBFactory::DeleteDatabase"); |
| IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
| @@ -151,9 +161,11 @@ void IndexedDBFactory::DeleteDatabase( |
| scoped_refptr<IndexedDBBackingStore> backing_store = |
| OpenBackingStore(origin_url, |
| data_directory, |
| + request_context, |
| &data_loss, |
| &data_loss_message, |
| - &disk_full); |
| + &disk_full, |
| + task_runner); |
| if (!backing_store) { |
| callbacks->OnError( |
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| @@ -194,9 +206,11 @@ bool IndexedDBFactory::IsBackingStoreOpenForTesting(const GURL& origin_url) |
| scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
| const GURL& origin_url, |
| const base::FilePath& data_directory, |
| + net::URLRequestContext* request_context, |
| blink::WebIDBDataLoss* data_loss, |
| std::string* data_loss_message, |
| - bool* disk_full) { |
| + bool* disk_full, |
| + base::TaskRunner* task_runner) { |
| const bool open_in_memory = data_directory.empty(); |
| IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); |
| @@ -206,17 +220,26 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
| } |
| scoped_refptr<IndexedDBBackingStore> backing_store; |
| + bool first_time = false; |
| if (open_in_memory) { |
| + // TODO(ericu): Support blobs in in-memory backends. |
| backing_store = IndexedDBBackingStore::OpenInMemory(origin_url); |
| } else { |
| - backing_store = IndexedDBBackingStore::Open(origin_url, |
| + first_time = !backends_opened_since_boot_.count(origin_url); |
| + backing_store = IndexedDBBackingStore::Open(this, |
| + origin_url, |
| data_directory, |
| + request_context, |
| data_loss, |
| data_loss_message, |
| - disk_full); |
| + disk_full, |
| + task_runner, |
| + first_time); |
| } |
| if (backing_store.get()) { |
| + if (first_time) |
| + backends_opened_since_boot_.insert(origin_url); |
| backing_store_map_[origin_url] = backing_store; |
| // If an in-memory database, bind lifetime to this factory instance. |
| if (open_in_memory) |
| @@ -224,7 +247,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
| // All backing stores associated with this factory should be of the same |
| // type. |
| - DCHECK(session_only_backing_stores_.empty() || open_in_memory); |
| + DCHECK(session_only_backing_stores_.empty() != open_in_memory); |
| return backing_store; |
| } |
| @@ -235,11 +258,14 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
| void IndexedDBFactory::Open( |
| const string16& name, |
| int64 version, |
| + net::URLRequestContext* request_context, |
| int64 transaction_id, |
| scoped_refptr<IndexedDBCallbacks> callbacks, |
| scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| const GURL& origin_url, |
| - const base::FilePath& data_directory) { |
| + const base::FilePath& data_directory, |
| + int child_process_id, |
| + base::TaskRunner* task_runner) { |
| IDB_TRACE("IndexedDBFactory::Open"); |
| scoped_refptr<IndexedDBDatabase> database; |
| IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| @@ -252,9 +278,11 @@ void IndexedDBFactory::Open( |
| scoped_refptr<IndexedDBBackingStore> backing_store = |
| OpenBackingStore(origin_url, |
| data_directory, |
| + request_context, |
| &data_loss, |
| &data_loss_message, |
| - &disk_full); |
| + &disk_full, |
| + task_runner); |
| if (!backing_store) { |
| if (disk_full) { |
| callbacks->OnError( |
| @@ -288,6 +316,7 @@ void IndexedDBFactory::Open( |
| database->OpenConnection(callbacks, |
| database_callbacks, |
| + child_process_id, |
| transaction_id, |
| version, |
| data_loss, |