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 8cf50425866d245bc449142ed477c6e7d57e548b..60681227effcfd62e6b920b83e511aa93c63e1af 100644 |
--- a/content/browser/indexed_db/indexed_db_factory.cc |
+++ b/content/browser/indexed_db/indexed_db_factory.cc |
@@ -25,14 +25,32 @@ IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context) |
IndexedDBFactory::~IndexedDBFactory() {} |
-void IndexedDBFactory::ReleaseDatabase( |
- const IndexedDBDatabase::Identifier& identifier, |
- bool forcedClose) { |
+void IndexedDBFactory::RemoveDatabaseFromMaps( |
+ const IndexedDBDatabase::Identifier& identifier) { |
IndexedDBDatabaseMap::iterator it = database_map_.find(identifier); |
DCHECK(it != database_map_.end()); |
- DCHECK(!it->second->backing_store()); |
+ IndexedDBDatabase* database = it->second; |
database_map_.erase(it); |
+ std::pair<OriginDbMapIterator, OriginDbMapIterator> range = |
+ GetOpenDatabasesForOrigin(database->identifier().first); |
+ DCHECK(range.first != range.second); |
+ for (OriginDbMapIterator it2 = range.first; it2 != range.second; ++it2) { |
+ if (it2->second == database) { |
+ origin_dbs_.erase(it2); |
+ break; |
+ } |
+ } |
+} |
+ |
+void IndexedDBFactory::ReleaseDatabase( |
+ const IndexedDBDatabase::Identifier& identifier, |
+ bool forcedClose) { |
+ |
+ DCHECK(!database_map_.find(identifier)->second->backing_store()); |
+ |
+ RemoveDatabaseFromMaps(identifier); |
+ |
// No grace period on a forced-close, as the initiator is |
// assuming the backing store will be released once all |
// connections are closed. |
@@ -92,6 +110,16 @@ bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url) |
} |
void IndexedDBFactory::ForceClose(const GURL& origin_url) { |
+ std::pair<OriginDbMapIterator, OriginDbMapIterator> range = |
+ GetOpenDatabasesForOrigin(origin_url); |
+ |
+ // Iterate this way because ForceClose will call back into this instance |
jsbell
2014/01/03 00:34:25
Would the standard "advance iterator before erasin
cmumford
2014/01/03 21:34:01
I wasn't confident enough with the multimap iterat
|
+ // to remove the database from this map - thus invaliding an iterator. |
+ while (range.first != range.second) { |
+ range.first->second->ForceClose(); // Force close the database |
+ range = GetOpenDatabasesForOrigin(origin_url); |
+ } |
+ |
if (backing_store_map_.find(origin_url) != backing_store_map_.end()) |
ReleaseBackingStore(origin_url, true /* immediate */); |
} |
@@ -183,8 +211,9 @@ void IndexedDBFactory::DeleteDatabase( |
} |
database_map_[unique_identifier] = database; |
+ origin_dbs_.insert(std::make_pair(origin_url, database)); |
database->DeleteDatabase(callbacks); |
- database_map_.erase(unique_identifier); |
+ RemoveDatabaseFromMaps(unique_identifier); |
database = NULL; |
backing_store = NULL; |
ReleaseBackingStore(origin_url, false /* immediate */); |
@@ -324,20 +353,27 @@ void IndexedDBFactory::Open( |
database->OpenConnection( |
callbacks, database_callbacks, transaction_id, version); |
- if (!was_open && database->ConnectionCount() > 0) |
+ if (!was_open && database->ConnectionCount() > 0) { |
database_map_[unique_identifier] = database; |
+ origin_dbs_.insert(std::make_pair(origin_url, database)); |
+ } |
} |
-std::vector<IndexedDBDatabase*> IndexedDBFactory::GetOpenDatabasesForOrigin( |
- const GURL& origin_url) const { |
- std::vector<IndexedDBDatabase*> result; |
- for (IndexedDBDatabaseMap::const_iterator it = database_map_.begin(); |
- it != database_map_.end(); |
- ++it) { |
- if (it->first.first == origin_url) |
- result.push_back(it->second); |
- } |
- return result; |
+std::pair<IndexedDBFactory::OriginDbMapIterator, |
+ IndexedDBFactory::OriginDbMapIterator> |
+IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const { |
+ return origin_dbs_.equal_range(origin_url); |
+} |
+ |
+size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const { |
+ size_t count(0); |
+ |
+ std::pair<OriginDbMapIterator, OriginDbMapIterator> range = |
jsbell
2014/01/03 00:34:25
Can't this be:
return origin_dbs_.count(origin_ur
cmumford
2014/01/03 21:34:01
That would return the number of open DB's for an o
jsbell
2014/01/03 21:37:26
Oops, you're right, sorry.
|
+ GetOpenDatabasesForOrigin(origin_url); |
+ for (OriginDbMapIterator it = range.first; it != range.second; ++it) |
+ count += it->second->ConnectionCount(); |
+ |
+ return count; |
} |
} // namespace content |