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

Unified Diff: webkit/database/database_tracker.cc

Issue 7056025: More WebSQLDatabase and QuotaManager integration. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
Index: webkit/database/database_tracker.cc
===================================================================
--- webkit/database/database_tracker.cc (revision 86348)
+++ webkit/database/database_tracker.cc (working copy)
@@ -129,55 +129,38 @@
int64 estimated_size,
int64* database_size,
int64* space_available) {
+ // TODO(michaeln): remove space_available from the interface
+ *space_available = 0;
+
if (!LazyInit()) {
*database_size = 0;
*space_available = 0;
return;
}
- InsertOrUpdateDatabaseDetails(origin_identifier, database_name,
- database_description, estimated_size);
- database_connections_.AddConnection(origin_identifier, database_name);
-
- CachedOriginInfo* info = GetCachedOriginInfo(origin_identifier);
- *database_size = (info ? info->GetDatabaseSize(database_name) : 0);
- *space_available = GetOriginSpaceAvailable(origin_identifier);
-
- if (quota_manager_proxy_) {
- // So we can compute deltas as modifications are made.
- database_connections_.SetOpenDatabaseSize(
- origin_identifier, database_name, *database_size);
+ if (quota_manager_proxy_)
quota_manager_proxy_->NotifyStorageAccessed(
quota::QuotaClient::kDatabase,
DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
quota::kStorageTypeTemporary);
+
+ InsertOrUpdateDatabaseDetails(origin_identifier, database_name,
+ database_description, estimated_size);
+ if (database_connections_.AddConnection(origin_identifier, database_name)) {
+ *database_size = GetDBFileSize(origin_identifier, database_name);
michaeln 2011/05/24 04:18:18 I also need to update the size in the CachedOrigin
+ database_connections_.SetOpenDatabaseSize(origin_identifier, database_name,
+ *database_size);
+ return;
}
+ *database_size = UpdateCachedDatabaseFileSize(origin_identifier,
michaeln 2011/05/24 04:18:18 I plan to rename this to UpdateOpenDatabaseSizeAnd
+ database_name);
}
void DatabaseTracker::DatabaseModified(const string16& origin_identifier,
const string16& database_name) {
if (!LazyInit())
return;
-
- int64 new_size =
- UpdateCachedDatabaseFileSize(origin_identifier, database_name);
- int64 space_available = GetOriginSpaceAvailable(origin_identifier);
- FOR_EACH_OBSERVER(Observer, observers_, OnDatabaseSizeChanged(
- origin_identifier, database_name, new_size, space_available));
-
- if (quota_manager_proxy_) {
- int64 old_size = database_connections_.GetOpenDatabaseSize(
- origin_identifier, database_name);
- if (old_size != new_size) {
- database_connections_.SetOpenDatabaseSize(
- origin_identifier, database_name, new_size);
- quota_manager_proxy_->NotifyStorageModified(
- quota::QuotaClient::kDatabase,
- DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
- quota::kStorageTypeTemporary,
- new_size - old_size);
- }
- }
+ UpdateCachedDatabaseFileSize(origin_identifier, database_name);
}
void DatabaseTracker::DatabaseClosed(const string16& origin_identifier,
@@ -186,8 +169,15 @@
DCHECK(!is_initialized_);
return;
}
- database_connections_.RemoveConnection(origin_identifier, database_name);
- if (!database_connections_.IsDatabaseOpened(origin_identifier, database_name))
+
+ if (quota_manager_proxy_)
+ quota_manager_proxy_->NotifyStorageAccessed(
+ quota::QuotaClient::kDatabase,
+ DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
+ quota::kStorageTypeTemporary);
+
+ UpdateCachedDatabaseFileSize(origin_identifier, database_name);
+ if (database_connections_.RemoveConnection(origin_identifier, database_name))
DeleteDatabaseIfNeeded(origin_identifier, database_name);
}
@@ -197,31 +187,17 @@
return;
}
- if (quota_manager_proxy_) {
- // When being closed by this route, there's a chance that
- // the tracker missed some DatabseModified calls. This method is used
- // when a renderer crashes to cleanup it's open resources.
- // We need to examine what we have in connections for the
- // size of each open databases and notify any differences between the
- // actual file sizes now.
- std::vector<std::pair<string16, string16> > open_dbs;
- connections.ListConnections(&open_dbs);
- for (std::vector<std::pair<string16, string16> >::iterator it =
- open_dbs.begin(); it != open_dbs.end(); ++it) {
- int64 old_size = database_connections_.GetOpenDatabaseSize(
- it->first, it->second);
- int64 new_size = GetDBFileSize(it->first, it->second);
- if (new_size != old_size) {
- database_connections_.SetOpenDatabaseSize(
- it->first, it->second, new_size);
- quota_manager_proxy_->NotifyStorageModified(
- quota::QuotaClient::kDatabase,
- DatabaseUtil::GetOriginFromIdentifier(it->first),
- quota::kStorageTypeTemporary,
- new_size - old_size);
- }
- }
- }
+ // When being closed by this route, there's a chance that
+ // the tracker missed some DatabseModified calls. This method is used
+ // when a renderer crashes to cleanup it's open resources.
+ // We need to examine what we have in connections for the
+ // size of each open databases and notify any differences between the
+ // actual file sizes now.
+ std::vector<std::pair<string16, string16> > open_dbs;
+ connections.ListConnections(&open_dbs);
+ for (std::vector<std::pair<string16, string16> >::iterator it =
+ open_dbs.begin(); it != open_dbs.end(); ++it)
+ UpdateCachedDatabaseFileSize(it->first, it->second);
std::vector<std::pair<string16, string16> > closed_dbs;
database_connections_.RemoveConnections(connections, &closed_dbs);
@@ -566,8 +542,14 @@
origin_info.SetOrigin(origin_identifier);
for (std::vector<DatabaseDetails>::const_iterator it = details.begin();
it != details.end(); it++) {
- int64 db_file_size =
- GetDBFileSize(origin_identifier, it->database_name);
+ int64 db_file_size;
+ if (database_connections_.IsDatabaseOpened(
+ origin_identifier, it->database_name)) {
+ db_file_size = database_connections_.GetOpenDatabaseSize(
+ origin_identifier, it->database_name);
+ } else {
+ db_file_size = GetDBFileSize(origin_identifier, it->database_name);
+ }
origin_info.SetDatabaseSize(it->database_name, db_file_size);
origin_info.SetDatabaseDescription(it->database_name, it->description);
}
@@ -601,21 +583,30 @@
int64 DatabaseTracker::GetOriginSpaceAvailable(
const string16& origin_identifier) {
- // TODO(michaeln): Come up with a value according to the the QuotaMgr.
- CachedOriginInfo* origin_info = GetCachedOriginInfo(origin_identifier);
- if (!origin_info)
- return 0;
- int64 space_available = origin_info->Quota() - origin_info->TotalSize();
- return (space_available < 0 ? 0 : space_available);
+ // TODO(michaeln): remove method from the interface
+ return 0;
}
+// TODO(michaeln): rename to UpdateOpenDatabaseFileSize
int64 DatabaseTracker::UpdateCachedDatabaseFileSize(
- const string16& origin_identifier,
- const string16& database_name) {
- int64 new_size = GetDBFileSize(origin_identifier, database_name);
- CachedOriginInfo* origin_info = GetCachedOriginInfo(origin_identifier);
- if (origin_info)
- origin_info->SetDatabaseSize(database_name, new_size);
+ const string16& origin_id, const string16& name) {
+ DCHECK(database_connections_.IsDatabaseOpened(origin_id, name));
+ int64 new_size = GetDBFileSize(origin_id, name);
+ int64 old_size = database_connections_.GetOpenDatabaseSize(origin_id, name);
+ if (old_size != new_size) {
+ database_connections_.SetOpenDatabaseSize(origin_id, name, new_size);
+ if (origins_info_map_.find(origin_id) != origins_info_map_.end())
+ origins_info_map_[origin_id].SetDatabaseSize(name, new_size);
+ if (quota_manager_proxy_)
+ quota_manager_proxy_->NotifyStorageModified(
+ quota::QuotaClient::kDatabase,
+ DatabaseUtil::GetOriginFromIdentifier(origin_id),
+ quota::kStorageTypeTemporary,
+ new_size - old_size);
+ const int64 kNotUsed = 0;
+ FOR_EACH_OBSERVER(Observer, observers_, OnDatabaseSizeChanged(
+ origin_id, name, new_size, kNotUsed));
+ }
return new_size;
}

Powered by Google App Engine
This is Rietveld 408576698