Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1236)

Unified Diff: content/browser/indexed_db/indexed_db_factory.cc

Issue 93873017: IndexedDBFactory now ForceCloses databases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed memory leak Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.h ('k') | content/browser/indexed_db/indexed_db_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..55403314ecb4e6a91f177c2cde407a2c3a5731db 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<OriginDBMap::iterator, OriginDBMap::iterator> range =
+ origin_dbs_.equal_range(database->identifier().first);
+ DCHECK(range.first != range.second);
+ for (OriginDBMap::iterator 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,15 @@ bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url)
}
void IndexedDBFactory::ForceClose(const GURL& origin_url) {
+ std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
+ GetOpenDatabasesForOrigin(origin_url);
+
+ while (range.first != range.second) {
+ IndexedDBDatabase* db = range.first->second;
+ ++range.first;
+ db->ForceClose();
+ }
+
if (backing_store_map_.find(origin_url) != backing_store_map_.end())
ReleaseBackingStore(origin_url, true /* immediate */);
}
@@ -183,8 +210,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 +352,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 =
+ GetOpenDatabasesForOrigin(origin_url);
+ for (OriginDBMapIterator it = range.first; it != range.second; ++it)
+ count += it->second->ConnectionCount();
+
+ return count;
}
} // namespace content
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.h ('k') | content/browser/indexed_db/indexed_db_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698