summaryrefslogtreecommitdiffstats
path: root/webkit/database
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 19:15:26 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 19:15:26 +0000
commit7c5f2ec9461aa36833e208944abce93a8a810394 (patch)
tree8c9a481e18b2a050e075429bb29a046cd1109428 /webkit/database
parent208aad79d76c5c9a5e05322be674b2d81738cb68 (diff)
downloadchromium_src-7c5f2ec9461aa36833e208944abce93a8a810394.zip
chromium_src-7c5f2ec9461aa36833e208944abce93a8a810394.tar.gz
chromium_src-7c5f2ec9461aa36833e208944abce93a8a810394.tar.bz2
More WebSQLDatabase and QuotaManager integration.
1) Fix bugs with how usage and deltas in usage were being computed. The tracker was reporting confusing numbers because in some cases it was stat'ing files and in other cases it was using a value cached in memory. Now the tracker always uses a cached value for open database files, and updates the cached value when changes are noticed. During that update, delta notifications are sent. 2) Remove the old and unsed support for quota from the DatabaseTracker. Changes to the class interface rippled to various unit tests. BUG=61676 TEST=updated existing unit tests Review URL: http://codereview.chromium.org/7056025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r--webkit/database/database_connections.cc27
-rw-r--r--webkit/database/database_connections.h12
-rw-r--r--webkit/database/database_connections_unittest.cc11
-rw-r--r--webkit/database/database_tracker.cc198
-rw-r--r--webkit/database/database_tracker.h34
-rw-r--r--webkit/database/database_tracker_unittest.cc133
6 files changed, 148 insertions, 267 deletions
diff --git a/webkit/database/database_connections.cc b/webkit/database/database_connections.cc
index 35483de..d90498f 100644
--- a/webkit/database/database_connections.cc
+++ b/webkit/database/database_connections.cc
@@ -38,14 +38,15 @@ bool DatabaseConnections::IsOriginUsed(
return (connections_.find(origin_identifier) != connections_.end());
}
-void DatabaseConnections::AddConnection(const string16& origin_identifier,
+bool DatabaseConnections::AddConnection(const string16& origin_identifier,
const string16& database_name) {
- connections_[origin_identifier][database_name].first++;
+ int& count = connections_[origin_identifier][database_name].first;
+ return ++count == 1;
}
-void DatabaseConnections::RemoveConnection(const string16& origin_identifier,
+bool DatabaseConnections::RemoveConnection(const string16& origin_identifier,
const string16& database_name) {
- RemoveConnectionsHelper(origin_identifier, database_name, 1);
+ return RemoveConnectionsHelper(origin_identifier, database_name, 1);
}
void DatabaseConnections::RemoveAllConnections() {
@@ -62,9 +63,8 @@ void DatabaseConnections::RemoveConnections(
const DBConnections& db_connections = origin_it->second;
for (DBConnections::const_iterator db_it = db_connections.begin();
db_it != db_connections.end(); db_it++) {
- RemoveConnectionsHelper(origin_it->first, db_it->first,
- db_it->second.first);
- if (!IsDatabaseOpened(origin_it->first, db_it->first))
+ if (RemoveConnectionsHelper(origin_it->first, db_it->first,
+ db_it->second.first))
closed_dbs->push_back(std::make_pair(origin_it->first, db_it->first));
}
}
@@ -99,7 +99,7 @@ void DatabaseConnections::ListConnections(
}
}
-void DatabaseConnections::RemoveConnectionsHelper(
+bool DatabaseConnections::RemoveConnectionsHelper(
const string16& origin_identifier,
const string16& database_name,
int num_connections) {
@@ -110,11 +110,12 @@ void DatabaseConnections::RemoveConnectionsHelper(
int& count = db_connections[database_name].first;
DCHECK(count >= num_connections);
count -= num_connections;
- if (!count) {
- db_connections.erase(database_name);
- if (db_connections.empty())
- connections_.erase(origin_iterator);
- }
+ if (count)
+ return false;
+ db_connections.erase(database_name);
+ if (db_connections.empty())
+ connections_.erase(origin_iterator);
+ return true;
}
DatabaseConnectionsWrapper::DatabaseConnectionsWrapper()
diff --git a/webkit/database/database_connections.h b/webkit/database/database_connections.h
index e358e43..8f956ac 100644
--- a/webkit/database/database_connections.h
+++ b/webkit/database/database_connections.h
@@ -27,10 +27,15 @@ class DatabaseConnections {
bool IsDatabaseOpened(const string16& origin_identifier,
const string16& database_name) const;
bool IsOriginUsed(const string16& origin_identifier) const;
- void AddConnection(const string16& origin_identifier,
+
+ // Returns true if this is the first connection.
+ bool AddConnection(const string16& origin_identifier,
const string16& database_name);
- void RemoveConnection(const string16& origin_identifier,
+
+ // Returns true if the last connection was removed.
+ bool RemoveConnection(const string16& origin_identifier,
const string16& database_name);
+
void RemoveAllConnections();
void RemoveConnections(
const DatabaseConnections& connections,
@@ -53,7 +58,8 @@ class DatabaseConnections {
typedef std::map<string16, DBConnections> OriginConnections;
mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize
- void RemoveConnectionsHelper(const string16& origin_identifier,
+ // Returns true if the last connection was removed.
+ bool RemoveConnectionsHelper(const string16& origin_identifier,
const string16& database_name,
int num_connections);
};
diff --git a/webkit/database/database_connections_unittest.cc b/webkit/database/database_connections_unittest.cc
index b6081cc..a91654a 100644
--- a/webkit/database/database_connections_unittest.cc
+++ b/webkit/database/database_connections_unittest.cc
@@ -81,11 +81,18 @@ TEST(DatabaseConnectionsTest, DatabaseConnectionsTest) {
EXPECT_FALSE(connections.IsDatabaseOpened(kOriginId, kName2));
EXPECT_TRUE(connections.IsDatabaseOpened(kOriginId, kName));
EXPECT_EQ(kSize, connections.GetOpenDatabaseSize(kOriginId, kName));
-
+ another.RemoveAllConnections();
connections.RemoveAllConnections();
EXPECT_TRUE(connections.IsEmpty());
- another.RemoveAllConnections();
+ // Ensure the return value properly indicates the initial
+ // addition and final removal.
+ EXPECT_TRUE(connections.AddConnection(kOriginId, kName));
+ EXPECT_FALSE(connections.AddConnection(kOriginId, kName));
+ EXPECT_FALSE(connections.AddConnection(kOriginId, kName));
+ EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName));
+ EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName));
+ EXPECT_TRUE(connections.RemoveConnection(kOriginId, kName));
}
TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) {
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index 6c764f7..7497c38 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -21,7 +21,6 @@
#include "webkit/database/database_quota_client.h"
#include "webkit/database/database_util.h"
#include "webkit/database/databases_table.h"
-#include "webkit/database/quota_table.h"
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
@@ -51,13 +50,11 @@ static const int kCompatibleVersion = 1;
static const char* kExtensionOriginIdentifierPrefix = "chrome-extension_";
OriginInfo::OriginInfo()
- : total_size_(0),
- quota_(0) {}
+ : total_size_(0) {}
OriginInfo::OriginInfo(const OriginInfo& origin_info)
: origin_(origin_info.origin_),
total_size_(origin_info.total_size_),
- quota_(origin_info.quota_),
database_info_(origin_info.database_info_) {}
OriginInfo::~OriginInfo() {}
@@ -84,8 +81,8 @@ string16 OriginInfo::GetDatabaseDescription(
return string16();
}
-OriginInfo::OriginInfo(const string16& origin, int64 total_size, int64 quota)
- : origin_(origin), total_size_(total_size), quota_(quota) {}
+OriginInfo::OriginInfo(const string16& origin, int64 total_size)
+ : origin_(origin), total_size_(total_size) {}
DatabaseTracker::DatabaseTracker(
const FilePath& profile_path,
@@ -103,7 +100,6 @@ DatabaseTracker::DatabaseTracker(
db_(new sql::Connection()),
databases_table_(NULL),
meta_table_(NULL),
- default_quota_(5 * 1024 * 1024),
special_storage_policy_(special_storage_policy),
quota_manager_proxy_(quota_manager_proxy),
incognito_origin_directories_generator_(0) {
@@ -118,66 +114,37 @@ DatabaseTracker::~DatabaseTracker() {
DCHECK(deletion_callbacks_.empty());
}
-void DatabaseTracker::SetDefaultQuota(int64 quota) {
- default_quota_ = quota;
- ClearAllCachedOriginInfo();
-}
-
void DatabaseTracker::DatabaseOpened(const string16& origin_identifier,
const string16& database_name,
const string16& database_description,
int64 estimated_size,
- int64* database_size,
- int64* space_available) {
+ int64* database_size) {
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 = SeedOpenDatabaseSize(origin_identifier, database_name);
+ return;
}
+ *database_size = UpdateOpenDatabaseSizeAndNotify(origin_identifier,
+ 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);
- }
- }
+ UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name);
}
void DatabaseTracker::DatabaseClosed(const string16& origin_identifier,
@@ -186,8 +153,17 @@ void DatabaseTracker::DatabaseClosed(const string16& origin_identifier,
DCHECK(!is_initialized_);
return;
}
- database_connections_.RemoveConnection(origin_identifier, database_name);
- if (!database_connections_.IsDatabaseOpened(origin_identifier, database_name))
+
+ // We call NotifiyStorageAccessed when a db is opened and also when
+ // closed because we don't call it for read while open.
+ if (quota_manager_proxy_)
+ quota_manager_proxy_->NotifyStorageAccessed(
+ quota::QuotaClient::kDatabase,
+ DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
+ quota::kStorageTypeTemporary);
+
+ UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name);
+ if (database_connections_.RemoveConnection(origin_identifier, database_name))
DeleteDatabaseIfNeeded(origin_identifier, database_name);
}
@@ -197,31 +173,17 @@ void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) {
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)
+ UpdateOpenDatabaseSizeAndNotify(it->first, it->second);
std::vector<std::pair<string16, string16> > closed_dbs;
database_connections_.RemoveConnections(connections, &closed_dbs);
@@ -283,7 +245,6 @@ void DatabaseTracker::CloseTrackerDatabaseAndClearCaches() {
if (!is_incognito_) {
meta_table_.reset(NULL);
databases_table_.reset(NULL);
- quota_table_.reset(NULL);
db_->Close();
is_initialized_ = false;
}
@@ -365,18 +326,6 @@ bool DatabaseTracker::GetAllOriginsInfo(std::vector<OriginInfo>* origins_info) {
return true;
}
-void DatabaseTracker::SetOriginQuota(const string16& origin_identifier,
- int64 new_quota) {
- if (!LazyInit())
- return;
-
- if (quota_table_->SetOriginQuota(origin_identifier, new_quota) &&
- (origins_info_map_.find(origin_identifier) != origins_info_map_.end())) {
- origins_info_map_[origin_identifier].SetQuota(new_quota);
- }
-}
-
-
bool DatabaseTracker::DeleteClosedDatabase(const string16& origin_identifier,
const string16& database_name) {
if (!LazyInit())
@@ -471,7 +420,6 @@ bool DatabaseTracker::LazyInit() {
if (!is_initialized_ && !shutting_down_) {
DCHECK(!db_->is_open());
DCHECK(!databases_table_.get());
- DCHECK(!quota_table_.get());
DCHECK(!meta_table_.get());
// If the tracker database exists, but it's corrupt or doesn't
@@ -490,7 +438,6 @@ bool DatabaseTracker::LazyInit() {
db_->set_error_delegate(GetErrorHandlerForTrackerDb());
databases_table_.reset(new DatabasesTable(db_.get()));
- quota_table_.reset(new QuotaTable(db_.get()));
meta_table_.reset(new sql::MetaTable());
is_initialized_ =
@@ -501,7 +448,6 @@ bool DatabaseTracker::LazyInit() {
UpgradeToCurrentVersion();
if (!is_initialized_) {
databases_table_.reset(NULL);
- quota_table_.reset(NULL);
meta_table_.reset(NULL);
db_->Close();
}
@@ -514,8 +460,7 @@ bool DatabaseTracker::UpgradeToCurrentVersion() {
if (!transaction.Begin() ||
!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion) ||
(meta_table_->GetCompatibleVersionNumber() > kCurrentVersion) ||
- !databases_table_->Init() ||
- !quota_table_->Init())
+ !databases_table_->Init())
return false;
if (meta_table_->GetVersionNumber() < kCurrentVersion)
@@ -566,25 +511,17 @@ DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo(
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);
}
-
- if (special_storage_policy_.get() &&
- special_storage_policy_->IsStorageUnlimited(
- DatabaseUtil::GetOriginFromIdentifier(origin_identifier))) {
- // TODO(michaeln): handle the case where it changes status sometime after
- // the cached origin_info has been established
- origin_info.SetQuota(kint64max);
- } else {
- int64 origin_quota = quota_table_->GetOriginQuota(origin_identifier);
- if (origin_quota > 0)
- origin_info.SetQuota(origin_quota);
- else
- origin_info.SetQuota(default_quota_);
- }
}
return &origins_info_map_[origin_identifier];
@@ -599,23 +536,34 @@ int64 DatabaseTracker::GetDBFileSize(const string16& origin_identifier,
return db_file_size;
}
-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);
-}
-
-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);
+int64 DatabaseTracker::SeedOpenDatabaseSize(
+ const string16& origin_id, const string16& name) {
+ DCHECK(database_connections_.IsDatabaseOpened(origin_id, name));
+ int64 size = GetDBFileSize(origin_id, name);
+ database_connections_.SetOpenDatabaseSize(origin_id, name, size);
+ if (origins_info_map_.find(origin_id) != origins_info_map_.end())
+ origins_info_map_[origin_id].SetDatabaseSize(name, size);
+ return size;
+}
+
+int64 DatabaseTracker::UpdateOpenDatabaseSizeAndNotify(
+ 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);
+ FOR_EACH_OBSERVER(Observer, observers_, OnDatabaseSizeChanged(
+ origin_id, name, new_size));
+ }
return new_size;
}
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 9894ea8..bbc308a 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -40,7 +40,6 @@ extern const FilePath::CharType kDatabaseDirectoryName[];
extern const FilePath::CharType kTrackerDatabaseFileName[];
class DatabasesTable;
-class QuotaTable;
// This class is used to store information about all databases in an origin.
class OriginInfo {
@@ -51,7 +50,6 @@ class OriginInfo {
const string16& GetOrigin() const { return origin_; }
int64 TotalSize() const { return total_size_; }
- int64 Quota() const { return quota_; }
void GetAllDatabaseNames(std::vector<string16>* databases) const;
int64 GetDatabaseSize(const string16& database_name) const;
string16 GetDatabaseDescription(const string16& database_name) const;
@@ -59,15 +57,14 @@ class OriginInfo {
protected:
typedef std::map<string16, std::pair<int64, string16> > DatabaseInfoMap;
- OriginInfo(const string16& origin, int64 total_size, int64 quota);
+ OriginInfo(const string16& origin, int64 total_size);
string16 origin_;
int64 total_size_;
- int64 quota_;
DatabaseInfoMap database_info_;
};
-// This class manages the main database, and keeps track of per origin quotas.
+// This class manages the main database and keeps track of open databases.
//
// The data in this class is not thread-safe, so all methods of this class
// should be called on the same thread. The only exceptions are the ctor(),
@@ -84,8 +81,7 @@ class DatabaseTracker
public:
virtual void OnDatabaseSizeChanged(const string16& origin_identifier,
const string16& database_name,
- int64 database_size,
- int64 space_available) = 0;
+ int64 database_size) = 0;
virtual void OnDatabaseScheduledForDeletion(
const string16& origin_identifier,
const string16& database_name) = 0;
@@ -101,8 +97,7 @@ class DatabaseTracker
const string16& database_name,
const string16& database_details,
int64 estimated_size,
- int64* database_size,
- int64* space_available);
+ int64* database_size);
void DatabaseModified(const string16& origin_identifier,
const string16& database_name);
void DatabaseClosed(const string16& origin_identifier,
@@ -123,12 +118,6 @@ class DatabaseTracker
virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids);
virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info);
- // TODO(michaeln): remove quota related stuff when quota manager
- // integration is complete
- void SetOriginQuota(const string16& origin_identifier, int64 new_quota);
- int64 GetDefaultQuota() { return default_quota_; }
- void SetDefaultQuota(int64 quota); // for testing
-
// Safe to call on any thread.
quota::QuotaManagerProxy* quota_manager_proxy() const {
return quota_manager_proxy_.get();
@@ -185,9 +174,8 @@ class DatabaseTracker
class CachedOriginInfo : public OriginInfo {
public:
- CachedOriginInfo() : OriginInfo(string16(), 0, 0) {}
+ CachedOriginInfo() : OriginInfo(string16(), 0) {}
void SetOrigin(const string16& origin) { origin_ = origin; }
- void SetQuota(int64 new_quota) { quota_ = new_quota; }
void SetDatabaseSize(const string16& database_name, int64 new_size) {
int64 old_size = 0;
if (database_info_.find(database_name) != database_info_.end())
@@ -223,11 +211,11 @@ class DatabaseTracker
int64 GetDBFileSize(const string16& origin_identifier,
const string16& database_name);
+ int64 SeedOpenDatabaseSize(const string16& origin_identifier,
+ const string16& database_name);
+ int64 UpdateOpenDatabaseSizeAndNotify(const string16& origin_identifier,
+ const string16& database_name);
- int64 GetOriginSpaceAvailable(const string16& origin_identifier);
-
- int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier,
- const string16& database_name);
void ScheduleDatabaseForDeletion(const string16& origin_identifier,
const string16& database_name);
// Schedule a set of open databases for deletion. If non-null, callback is
@@ -245,7 +233,6 @@ class DatabaseTracker
const FilePath db_dir_;
scoped_ptr<sql::Connection> db_;
scoped_ptr<DatabasesTable> databases_table_;
- scoped_ptr<QuotaTable> quota_table_;
scoped_ptr<sql::MetaTable> meta_table_;
ObserverList<Observer, true> observers_;
std::map<string16, CachedOriginInfo> origins_info_map_;
@@ -255,9 +242,6 @@ class DatabaseTracker
DatabaseSet dbs_to_be_deleted_;
PendingCompletionMap deletion_callbacks_;
- // Default quota for all origins; changed only by tests
- int64 default_quota_;
-
// Apps and Extensions can have special rights.
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc
index 61add64..f10a8ce 100644
--- a/webkit/database/database_tracker_unittest.cc
+++ b/webkit/database/database_tracker_unittest.cc
@@ -42,13 +42,11 @@ class TestObserver : public webkit_database::DatabaseTracker::Observer {
virtual ~TestObserver() {}
virtual void OnDatabaseSizeChanged(const string16& origin_identifier,
const string16& database_name,
- int64 database_size,
- int64 space_available) {
+ int64 database_size) {
new_notification_received_ = true;
origin_identifier_ = origin_identifier;
database_name_ = database_name;
database_size_ = database_size;
- space_available_ = space_available;
}
virtual void OnDatabaseScheduledForDeletion(const string16& origin_identifier,
const string16& database_name) {
@@ -64,21 +62,18 @@ class TestObserver : public webkit_database::DatabaseTracker::Observer {
string16 GetNotificationOriginIdentifier() { return origin_identifier_; }
string16 GetNotificationDatabaseName() { return database_name_; }
int64 GetNotificationDatabaseSize() { return database_size_; }
- int64 GetNotificationSpaceAvailable() { return space_available_; }
private:
bool new_notification_received_;
string16 origin_identifier_;
string16 database_name_;
int64 database_size_;
- int64 space_available_;
};
void CheckNotificationReceived(TestObserver* observer,
const string16& expected_origin_identifier,
const string16& expected_database_name,
- int64 expected_database_size,
- int64 expected_space_available) {
+ int64 expected_database_size) {
EXPECT_TRUE(observer->DidReceiveNewNotification());
EXPECT_EQ(expected_origin_identifier,
observer->GetNotificationOriginIdentifier());
@@ -86,8 +81,6 @@ void CheckNotificationReceived(TestObserver* observer,
observer->GetNotificationDatabaseName());
EXPECT_EQ(expected_database_size,
observer->GetNotificationDatabaseSize());
- EXPECT_EQ(expected_space_available,
- observer->GetNotificationSpaceAvailable());
}
class TestQuotaManagerProxy : public quota::QuotaManagerProxy {
@@ -197,7 +190,6 @@ class DatabaseTracker_TestHelper_Test {
// Create and open three databases.
int64 database_size = 0;
- int64 space_available = 0;
const string16 kOrigin1 =
DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
const string16 kOrigin2 =
@@ -208,11 +200,11 @@ class DatabaseTracker_TestHelper_Test {
const string16 kDescription = ASCIIToUTF16("database_description");
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
FilePath::FromWStringHack(UTF16ToWide(
@@ -248,7 +240,7 @@ class DatabaseTracker_TestHelper_Test {
// Recreate db1.
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
FilePath::FromWStringHack(UTF16ToWide(
tracker->GetOriginDirectory(kOrigin1))))));
@@ -307,7 +299,6 @@ class DatabaseTracker_TestHelper_Test {
// Open three new databases.
int64 database_size = 0;
- int64 space_available = 0;
const string16 kOrigin1 =
DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
const string16 kOrigin2 =
@@ -317,43 +308,24 @@ class DatabaseTracker_TestHelper_Test {
const string16 kDB3 = ASCIIToUTF16("db3");
const string16 kDescription = ASCIIToUTF16("database_description");
- // Get the quota for kOrigin1 and kOrigin2
+ // Get the info for kOrigin1 and kOrigin2
DatabaseTracker::CachedOriginInfo* origin1_info =
tracker->GetCachedOriginInfo(kOrigin1);
DatabaseTracker::CachedOriginInfo* origin2_info =
tracker->GetCachedOriginInfo(kOrigin1);
EXPECT_TRUE(origin1_info);
EXPECT_TRUE(origin2_info);
- int64 origin1_quota = origin1_info->Quota();
- int64 origin2_quota = origin2_info->Quota();
- EXPECT_EQ(origin1_quota, tracker->GetOriginSpaceAvailable(kOrigin1));
- EXPECT_EQ(origin2_quota, tracker->GetOriginSpaceAvailable(kOrigin2));
-
- // Set a new quota for kOrigin1
- origin1_quota *= 2;
- tracker->SetOriginQuota(kOrigin1, origin1_quota);
- origin1_info = tracker->GetCachedOriginInfo(kOrigin1);
- EXPECT_TRUE(origin1_info);
- EXPECT_EQ(origin1_quota, origin1_info->Quota());
+
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_EQ(0, database_size);
- EXPECT_EQ(origin1_quota, space_available);
tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_EQ(0, database_size);
- EXPECT_EQ(origin2_quota, space_available);
tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_EQ(0, database_size);
- EXPECT_EQ(origin1_quota, space_available);
-
- // Tell the tracker that a database has changed.
- // Even though nothing has changed, the observers should be notified.
- tracker->DatabaseModified(kOrigin1, kDB1);
- CheckNotificationReceived(&observer1, kOrigin1, kDB1, 0, origin1_quota);
- CheckNotificationReceived(&observer2, kOrigin1, kDB1, 0, origin1_quota);
// Write some data to each file and check that the listeners are
// called with the appropriate values.
@@ -370,18 +342,14 @@ class DatabaseTracker_TestHelper_Test {
EXPECT_EQ(4, file_util::WriteFile(
tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4));
tracker->DatabaseModified(kOrigin1, kDB1);
- CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1, origin1_quota - 1);
- CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1, origin1_quota - 1);
+ CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1);
+ CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1);
tracker->DatabaseModified(kOrigin2, kDB2);
- CheckNotificationReceived(&observer1, kOrigin2, kDB2, 2, origin2_quota - 2);
- CheckNotificationReceived(&observer2, kOrigin2, kDB2, 2, origin2_quota - 2);
+ CheckNotificationReceived(&observer1, kOrigin2, kDB2, 2);
+ CheckNotificationReceived(&observer2, kOrigin2, kDB2, 2);
tracker->DatabaseModified(kOrigin1, kDB3);
- CheckNotificationReceived(&observer1, kOrigin1, kDB3, 4, origin1_quota - 5);
- CheckNotificationReceived(&observer2, kOrigin1, kDB3, 4, origin1_quota - 5);
-
- // Make sure the available space for kOrigin1 and kOrigin2 changed too.
- EXPECT_EQ(origin1_quota - 5, tracker->GetOriginSpaceAvailable(kOrigin1));
- EXPECT_EQ(origin2_quota - 2, tracker->GetOriginSpaceAvailable(kOrigin2));
+ CheckNotificationReceived(&observer1, kOrigin1, kDB3, 4);
+ CheckNotificationReceived(&observer2, kOrigin1, kDB3, 4);
// Close all databases
tracker->DatabaseClosed(kOrigin1, kDB1);
@@ -390,50 +358,19 @@ class DatabaseTracker_TestHelper_Test {
// Open an existing database and check the reported size
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_EQ(1, database_size);
- EXPECT_EQ(origin1_quota - 5, space_available);
-
- // Make sure that the observers are notified even if
- // the size of the database hasn't changed.
- EXPECT_EQ(1, file_util::WriteFile(
- tracker->GetFullDBFilePath(kOrigin1, kDB1), "b", 1));
- tracker->DatabaseModified(kOrigin1, kDB1);
- CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1, origin1_quota - 5);
- CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1, origin1_quota - 5);
tracker->DatabaseClosed(kOrigin1, kDB1);
// Remove an observer; this should clear all caches.
tracker->RemoveObserver(&observer2);
- // Change kDB1's and kDB3's size and call tracker->DatabaseModified()
- // for kDB1 only. If the caches were indeed cleared, then calling
- // tracker->DatabaseModified() should re-populate the cache for
- // kOrigin1 == kOrigin1, and thus, should pick up kDB3's size change too.
- EXPECT_EQ(5, file_util::WriteFile(
- tracker->GetFullDBFilePath(kOrigin1, kDB1), "ccccc", 5));
- EXPECT_EQ(6, file_util::WriteFile(
- tracker->GetFullDBFilePath(kOrigin1, kDB3), "dddddd", 6));
- tracker->DatabaseModified(kOrigin1, kDB1);
- CheckNotificationReceived(&observer1, kOrigin1, kDB1, 5,
- origin1_quota - 11);
- EXPECT_FALSE(observer2.DidReceiveNewNotification());
- EXPECT_EQ(origin1_quota - 11, tracker->GetOriginSpaceAvailable(kOrigin1));
-
// Close the tracker database and clear all caches.
// Then make sure that DatabaseOpened() still returns the correct result.
tracker->CloseTrackerDatabaseAndClearCaches();
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
- EXPECT_EQ(5, database_size);
- EXPECT_EQ(origin1_quota - 11, space_available);
-
- // Close the tracker database and clear all caches. Then make sure that
- // DatabaseModified() still calls the observers with correct values.
- tracker->CloseTrackerDatabaseAndClearCaches();
- tracker->DatabaseModified(kOrigin1, kDB3);
- CheckNotificationReceived(&observer1, kOrigin1, kDB3, 6,
- origin1_quota - 11);
+ &database_size);
+ EXPECT_EQ(1, database_size);
tracker->DatabaseClosed(kOrigin1, kDB1);
// Remove all observers.
@@ -441,19 +378,18 @@ class DatabaseTracker_TestHelper_Test {
// Trying to delete a database in use should fail
tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_FALSE(tracker->DeleteClosedDatabase(kOrigin1, kDB3));
origin1_info = tracker->GetCachedOriginInfo(kOrigin1);
EXPECT_TRUE(origin1_info);
- EXPECT_EQ(6, origin1_info->GetDatabaseSize(kDB3));
+ EXPECT_EQ(4, origin1_info->GetDatabaseSize(kDB3));
tracker->DatabaseClosed(kOrigin1, kDB3);
// Delete a database and make sure the space used by that origin is updated
EXPECT_TRUE(tracker->DeleteClosedDatabase(kOrigin1, kDB3));
origin1_info = tracker->GetCachedOriginInfo(kOrigin1);
EXPECT_TRUE(origin1_info);
- EXPECT_EQ(origin1_quota - 5, tracker->GetOriginSpaceAvailable(kOrigin1));
- EXPECT_EQ(5, origin1_info->GetDatabaseSize(kDB1));
+ EXPECT_EQ(1, origin1_info->GetDatabaseSize(kDB1));
EXPECT_EQ(0, origin1_info->GetDatabaseSize(kDB3));
// Get all data for all origins
@@ -461,22 +397,20 @@ class DatabaseTracker_TestHelper_Test {
EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
EXPECT_EQ(size_t(2), origins_info.size());
EXPECT_EQ(kOrigin1, origins_info[0].GetOrigin());
- EXPECT_EQ(5, origins_info[0].TotalSize());
- EXPECT_EQ(origin1_quota, origins_info[0].Quota());
- EXPECT_EQ(5, origins_info[0].GetDatabaseSize(kDB1));
+ EXPECT_EQ(1, origins_info[0].TotalSize());
+ EXPECT_EQ(1, origins_info[0].GetDatabaseSize(kDB1));
EXPECT_EQ(0, origins_info[0].GetDatabaseSize(kDB3));
EXPECT_EQ(kOrigin2, origins_info[1].GetOrigin());
EXPECT_EQ(2, origins_info[1].TotalSize());
- EXPECT_EQ(origin2_quota, origins_info[1].Quota());
// Trying to delete an origin with databases in use should fail
tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_FALSE(tracker->DeleteOrigin(kOrigin1));
origin1_info = tracker->GetCachedOriginInfo(kOrigin1);
EXPECT_TRUE(origin1_info);
- EXPECT_EQ(5, origin1_info->GetDatabaseSize(kDB1));
+ EXPECT_EQ(1, origin1_info->GetDatabaseSize(kDB1));
tracker->DatabaseClosed(kOrigin1, kDB1);
// Delete an origin that doesn't have any database in use
@@ -488,9 +422,7 @@ class DatabaseTracker_TestHelper_Test {
origin1_info = tracker->GetCachedOriginInfo(kOrigin1);
EXPECT_TRUE(origin1_info);
- EXPECT_EQ(origin1_quota, origin1_info->Quota());
EXPECT_EQ(0, origin1_info->TotalSize());
- EXPECT_EQ(origin1_quota, tracker->GetOriginSpaceAvailable(kOrigin1));
}
static void DatabaseTrackerQuotaIntegration() {
@@ -514,9 +446,8 @@ class DatabaseTracker_TestHelper_Test {
// then delete it. Observe the tracker notifies accordingly.
int64 database_size = 0;
- int64 space_available = 0;
tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
test_quota_proxy->reset();
@@ -533,15 +464,17 @@ class DatabaseTracker_TestHelper_Test {
test_quota_proxy->reset();
tracker->DatabaseClosed(kOriginId, kName);
+ EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
EXPECT_EQ(net::OK, tracker->DeleteDatabase(kOriginId, kName, NULL));
EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
+ test_quota_proxy->reset();
// Create a database and modify it, try to delete it while open,
// then close it (at which time deletion will actually occur).
// Observe the tracker notifies accordingly.
tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
test_quota_proxy->reset();
@@ -557,7 +490,9 @@ class DatabaseTracker_TestHelper_Test {
EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
tracker->DatabaseClosed(kOriginId, kName);
+ EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
+ test_quota_proxy->reset();
// Create a database and up the file size without telling
// the tracker about the modification, than simulate a
@@ -565,7 +500,7 @@ class DatabaseTracker_TestHelper_Test {
// Observe the tracker notifies accordingly.
tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
- &database_size, &space_available);
+ &database_size);
EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
test_quota_proxy->reset();
db_file = tracker->GetFullDBFilePath(kOriginId, kName);