diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:15:55 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:15:55 +0000 |
commit | 3ccfe535658c8852c1cc1df01372ecc602f376cd (patch) | |
tree | 47582af5ba2a4f0658126d564d618c18a93173cf /webkit/database/database_tracker.h | |
parent | 6d8e2a64b6961331816689850192a8ee864f9a97 (diff) | |
download | chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.zip chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.gz chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.bz2 |
Adding methods that will be used by the quota management UI.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/507014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_tracker.h')
-rw-r--r-- | webkit/database/database_tracker.h | 84 |
1 files changed, 63 insertions, 21 deletions
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h index 2bcfc6f..8d65109 100644 --- a/webkit/database/database_tracker.h +++ b/webkit/database/database_tracker.h @@ -12,7 +12,9 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/string16.h" +#include "base/string_util.h" #include "testing/gtest/include/gtest/gtest_prod.h" +#include "webkit/database/database_connections.h" namespace sql { class Connection; @@ -22,6 +24,42 @@ class MetaTable; namespace webkit_database { class DatabasesTable; +class QuotaTable; + +// This class is used to store information about all databases in an origin. +class OriginInfo { + public: + OriginInfo(const OriginInfo& origin_info) + : origin_(origin_info.origin_), + total_size_(origin_info.total_size_), + quota_(origin_info.quota_), + database_sizes_(origin_info.database_sizes_) {} + string16 GetOrigin() const { return origin_; } + int64 TotalSize() const { return total_size_; } + int64 Quota() const { return quota_; } + void GetAllDatabaseNames(std::vector<string16>* databases) const { + for (std::map<string16, int64>::const_iterator it = database_sizes_.begin(); + it != database_sizes_.end(); it++) { + databases->push_back(it->first); + } + } + int64 GetDatabaseSize(const string16& database_name) const { + std::map<string16, int64>::const_iterator it = + database_sizes_.find(database_name); + if (it != database_sizes_.end()) + return it->second; + return 0; + } + + protected: + OriginInfo(const string16& origin, int64 total_size, int64 quota) + : origin_(origin), total_size_(total_size), quota_(quota) { } + + string16 origin_; + int64 total_size_; + int64 quota_; + std::map<string16, int64> database_sizes_; +}; // This class manages the main database, and keeps track of per origin quotas. // @@ -58,6 +96,7 @@ class DatabaseTracker const string16& database_name); void DatabaseClosed(const string16& origin_identifier, const string16& database_name); + void CloseDatabases(const DatabaseConnections& connections); void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); @@ -68,31 +107,33 @@ class DatabaseTracker FilePath GetFullDBFilePath(const string16& origin_identifier, const string16& database_name) const; + bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info); + void SetOriginQuota(const string16& origin_identifier, int64 new_quota); + bool DeleteDatabase(const string16& origin_identifier, + const string16& database_name); + bool DeleteOrigin(const string16& origin_identifier); + private: + // Need this here to allow RefCountedThreadSafe to call ~DatabaseTracker(). friend class base::RefCountedThreadSafe<DatabaseTracker>; - ~DatabaseTracker(); - - class CachedOriginInfo { + class CachedOriginInfo : public OriginInfo { public: - CachedOriginInfo() : total_size_(0) { } - int64 TotalSize() const { return total_size_; } - int64 GetCachedDatabaseSize(const string16& database_name) { - return cached_database_sizes_[database_name]; - } - void SetCachedDatabaseSize(const string16& database_name, int64 new_size) { - int64 old_size = cached_database_sizes_[database_name]; - cached_database_sizes_[database_name] = new_size; + CachedOriginInfo() : OriginInfo(EmptyString16(), 0, 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 = database_sizes_[database_name]; + database_sizes_[database_name] = new_size; if (new_size != old_size) total_size_ += new_size - old_size; } - - private: - int64 total_size_; - std::map<string16, int64> cached_database_sizes_; }; + ~DatabaseTracker(); + bool LazyInit(); + bool UpgradeToCurrentVersion(); void InsertOrUpdateDatabaseDetails(const string16& origin_identifier, const string16& database_name, const string16& database_details, @@ -100,23 +141,24 @@ class DatabaseTracker void ClearAllCachedOriginInfo(); CachedOriginInfo* GetCachedOriginInfo(const string16& origin_identifier); - int64 GetCachedDatabaseFileSize(const string16& origin_identifier, - const string16& database_name); - int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier, - const string16& database_name); + int64 GetDBFileSize(const string16& origin_identifier, const string16& database_name) const; - int64 GetOriginUsage(const string16& origin_identifer); - int64 GetOriginQuota(const string16& origin_identifier) const; + int64 GetOriginSpaceAvailable(const string16& origin_identifier); + int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier, + const string16& database_name); + bool initialized_; 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> observers_; std::map<string16, CachedOriginInfo> origins_info_map_; + DatabaseConnections database_connections_; FRIEND_TEST(DatabaseTrackerTest, TestIt); }; |