diff options
Diffstat (limited to 'storage')
-rw-r--r-- | storage/browser/quota/quota_database.cc | 27 | ||||
-rw-r--r-- | storage/browser/quota/quota_database.h | 45 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.cc | 21 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.h | 2 |
4 files changed, 75 insertions, 20 deletions
diff --git a/storage/browser/quota/quota_database.cc b/storage/browser/quota/quota_database.cc index 5fcacd5..36632c6 100644 --- a/storage/browser/quota/quota_database.cc +++ b/storage/browser/quota/quota_database.cc @@ -275,7 +275,7 @@ bool QuotaDatabase::GetOriginLastEvictionTime(const GURL& origin, statement.BindInt(1, static_cast<int>(type)); if (!statement.Step()) - return statement.Succeeded(); + return false; *last_modified_time = base::Time::FromInternalValue(statement.ColumnInt64(0)); return true; @@ -346,6 +346,31 @@ bool QuotaDatabase::RegisterInitialOriginInfo( return true; } +bool QuotaDatabase::GetOriginInfo(const GURL& origin, + StorageType type, + QuotaDatabase::OriginInfoTableEntry* entry) { + if (!LazyOpen(false)) + return false; + + const char* kSql = + "SELECT * FROM OriginInfoTable" + " WHERE origin = ? AND type = ?"; + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); + statement.BindString(0, origin.spec()); + statement.BindInt(1, static_cast<int>(type)); + + if (!statement.Step()) + return false; + + *entry = OriginInfoTableEntry( + GURL(statement.ColumnString(0)), + static_cast<StorageType>(statement.ColumnInt(1)), statement.ColumnInt(2), + base::Time::FromInternalValue(statement.ColumnInt64(3)), + base::Time::FromInternalValue(statement.ColumnInt64(4))); + + return true; +} + bool QuotaDatabase::DeleteHostQuota( const std::string& host, StorageType type) { if (!LazyOpen(false)) diff --git a/storage/browser/quota/quota_database.h b/storage/browser/quota/quota_database.h index e95fba8..dae5581 100644 --- a/storage/browser/quota/quota_database.h +++ b/storage/browser/quota/quota_database.h @@ -36,6 +36,20 @@ class SpecialStoragePolicy; // All the methods of this class must run on the DB thread. class STORAGE_EXPORT_PRIVATE QuotaDatabase { public: + struct STORAGE_EXPORT_PRIVATE OriginInfoTableEntry { + OriginInfoTableEntry(); + OriginInfoTableEntry(const GURL& origin, + StorageType type, + int used_count, + const base::Time& last_access_time, + const base::Time& last_modified_time); + GURL origin; + StorageType type; + int used_count; + base::Time last_access_time; + base::Time last_modified_time; + }; + // Constants for {Get,Set}QuotaConfigValue keys. static const char kDesiredAvailableSpaceKey[]; static const char kTemporaryQuotaOverrideKey[]; @@ -46,7 +60,10 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { void CloseConnection(); + // Returns whether the record could be found. bool GetHostQuota(const std::string& host, StorageType type, int64* quota); + + // Returns whether the operation succeeded. bool SetHostQuota(const std::string& host, StorageType type, int64 quota); bool DeleteHostQuota(const std::string& host, StorageType type); @@ -58,9 +75,14 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { StorageType type, base::Time last_modified_time); + // Gets the time |origin| was last evicted. Returns whether the record could + // be found. bool GetOriginLastEvictionTime(const GURL& origin, StorageType type, base::Time* last_eviction_time); + + // Sets the time the origin was last evicted. Returns whether the operation + // succeeded. bool SetOriginLastEvictionTime(const GURL& origin, StorageType type, base::Time last_eviction_time); @@ -72,6 +94,12 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { bool RegisterInitialOriginInfo( const std::set<GURL>& origins, StorageType type); + // Gets the OriginInfoTableEntry for |origin|. Returns whether the record + // could be found. + bool GetOriginInfo(const GURL& origin, + StorageType type, + OriginInfoTableEntry* entry); + bool DeleteOriginInfo(const GURL& origin, StorageType type); bool GetQuotaConfigValue(const char* key, int64* value); @@ -87,7 +115,7 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { GURL* origin); // Populates |origins| with the ones that have been modified since - // the |modified_since|. + // the |modified_since|. Returns whether the operation succeeded. bool GetOriginsModifiedSince(StorageType type, std::set<GURL>* origins, base::Time modified_since); @@ -111,21 +139,6 @@ class STORAGE_EXPORT_PRIVATE QuotaDatabase { }; friend STORAGE_EXPORT_PRIVATE bool operator <( const QuotaTableEntry& lhs, const QuotaTableEntry& rhs); - - struct STORAGE_EXPORT_PRIVATE OriginInfoTableEntry { - OriginInfoTableEntry(); - OriginInfoTableEntry( - const GURL& origin, - StorageType type, - int used_count, - const base::Time& last_access_time, - const base::Time& last_modified_time); - GURL origin; - StorageType type; - int used_count; - base::Time last_access_time; - base::Time last_modified_time; - }; friend STORAGE_EXPORT_PRIVATE bool operator <( const OriginInfoTableEntry& lhs, const OriginInfoTableEntry& rhs); diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc index 0052f2d..c0f7560 100644 --- a/storage/browser/quota/quota_manager.cc +++ b/storage/browser/quota/quota_manager.cc @@ -76,6 +76,10 @@ const int QuotaManager::kEvictionIntervalInMilliSeconds = const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] = "Quota.TimeBetweenRepeatedOriginEvictions"; +const char QuotaManager::kEvictedOriginAccessedCountHistogram[] = + "Quota.EvictedOriginAccessCount"; +const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] = + "Quota.EvictedOriginTimeSinceAccess"; // Heuristics: assuming average cloud server allows a few Gigs storage // on the server side and the storage needs to be shared for user data @@ -159,6 +163,19 @@ bool DeleteOriginInfoOnDBThread(const GURL& origin, bool is_eviction, QuotaDatabase* database) { DCHECK(database); + + base::Time now = base::Time::Now(); + + if (is_eviction) { + QuotaDatabase::OriginInfoTableEntry entry; + database->GetOriginInfo(origin, type, &entry); + UMA_HISTOGRAM_COUNTS(QuotaManager::kEvictedOriginAccessedCountHistogram, + entry.used_count); + UMA_HISTOGRAM_LONG_TIMES( + QuotaManager::kEvictedOriginTimeSinceAccessHistogram, + now - entry.last_access_time); + } + if (!database->DeleteOriginInfo(origin, type)) return false; @@ -168,10 +185,8 @@ bool DeleteOriginInfoOnDBThread(const GURL& origin, return database->DeleteOriginLastEvictionTime(origin, type); base::Time last_eviction_time; - if (!database->GetOriginLastEvictionTime(origin, type, &last_eviction_time)) - return false; + database->GetOriginLastEvictionTime(origin, type, &last_eviction_time); - base::Time now = base::Time::Now(); if (last_eviction_time != base::Time()) { UMA_HISTOGRAM_LONG_TIMES( QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h index bacf80b..2f9f16f 100644 --- a/storage/browser/quota/quota_manager.h +++ b/storage/browser/quota/quota_manager.h @@ -277,6 +277,8 @@ class STORAGE_EXPORT QuotaManager static const int kEvictionIntervalInMilliSeconds; static const char kTimeBetweenRepeatedOriginEvictionsHistogram[]; + static const char kEvictedOriginAccessedCountHistogram[]; + static const char kEvictedOriginTimeSinceAccessHistogram[]; // These are kept non-const so that test code can change the value. // TODO(kinuko): Make this a real const value and add a proper way to set |