Chromium Code Reviews| Index: storage/browser/quota/quota_manager.cc |
| diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc |
| index 52f728086b7169b02f5b62831cf50f7108b6c619..53e0dd066449a6b5a95120f2270bba0cfd31629f 100644 |
| --- a/storage/browser/quota/quota_manager.cc |
| +++ b/storage/browser/quota/quota_manager.cc |
| @@ -73,6 +73,9 @@ int64 QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes; |
| const int QuotaManager::kEvictionIntervalInMilliSeconds = |
| 30 * kMinutesInMilliSeconds; |
| +const char QuotaManager::kTimeBetweenOriginEvictionsHistogram[] = |
| + "Quota.TimeBetweenOriginEvictions"; |
| + |
| // Heuristics: assuming average cloud server allows a few Gigs storage |
| // on the server side and the storage needs to be shared for user data |
| // and by multiple apps. |
| @@ -152,9 +155,31 @@ bool GetLRUOriginOnDBThread(StorageType type, |
| bool DeleteOriginInfoOnDBThread(const GURL& origin, |
| StorageType type, |
| + bool is_eviction, |
| QuotaDatabase* database) { |
| DCHECK(database); |
| - return database->DeleteOriginInfo(origin, type); |
| + if (!database->DeleteOriginInfo(origin, type)) |
| + return false; |
| + |
| + // If the deletion is not due to an eviction, delete the entry in the eviction |
| + // table as well due to privacy concerns. |
| + if (!is_eviction) |
| + return database->DeleteOriginLastEvictionTime(origin, type); |
| + |
| + base::Time last_eviction_time; |
| + if (!database->GetOriginLastEvictionTime(origin, type, &last_eviction_time)) |
|
michaeln
2015/10/15 21:25:23
In looking at this closely now, I see there are tw
calamity
2015/10/16 00:53:04
Yeah, I agree. I think these are all great things
|
| + return false; |
| + |
| + base::Time now = base::Time::Now(); |
| + if (last_eviction_time != base::Time()) { |
| + UMA_HISTOGRAM_LONG_TIMES(QuotaManager::kTimeBetweenOriginEvictionsHistogram, |
|
michaeln
2015/10/15 21:25:23
To compute a failure rate (where failure is we rep
calamity
2015/10/16 00:53:04
Good point.
I think we have the total eviction co
|
| + now - last_eviction_time); |
| + } |
| + |
| + if (!database->SetOriginLastEvictionTime(origin, type, now)) |
| + return false; |
| + |
| + return true; |
| } |
| bool InitializeTemporaryOriginsInfoOnDBThread(const std::set<GURL>* origins, |
| @@ -534,6 +559,7 @@ class QuotaManager::OriginDataDeleter : public QuotaTask { |
| const GURL& origin, |
| StorageType type, |
| int quota_client_mask, |
| + bool is_eviction, |
| const StatusCallback& callback) |
| : QuotaTask(manager), |
| origin_(origin), |
| @@ -542,6 +568,7 @@ class QuotaManager::OriginDataDeleter : public QuotaTask { |
| error_count_(0), |
| remaining_clients_(-1), |
| skipped_clients_(0), |
| + is_eviction_(is_eviction), |
| callback_(callback), |
| weak_factory_(this) {} |
| @@ -568,7 +595,7 @@ class QuotaManager::OriginDataDeleter : public QuotaTask { |
| if (error_count_ == 0) { |
| // Only remove the entire origin if we didn't skip any client types. |
| if (skipped_clients_ == 0) |
| - manager()->DeleteOriginFromDatabase(origin_, type_); |
| + manager()->DeleteOriginFromDatabase(origin_, type_, is_eviction_); |
| callback_.Run(kQuotaStatusOk); |
| } else { |
| callback_.Run(kQuotaErrorInvalidModification); |
| @@ -602,6 +629,7 @@ class QuotaManager::OriginDataDeleter : public QuotaTask { |
| int error_count_; |
| int remaining_clients_; |
| int skipped_clients_; |
| + bool is_eviction_; |
| StatusCallback callback_; |
| base::WeakPtrFactory<OriginDataDeleter> weak_factory_; |
| @@ -671,11 +699,10 @@ class QuotaManager::HostDataDeleter : public QuotaTask { |
| for (std::set<GURL>::const_iterator p = origins_.begin(); |
| p != origins_.end(); |
| ++p) { |
| - OriginDataDeleter* deleter = |
| - new OriginDataDeleter( |
| - manager(), *p, type_, quota_client_mask_, |
| - base::Bind(&HostDataDeleter::DidDeleteOriginData, |
| - weak_factory_.GetWeakPtr())); |
| + OriginDataDeleter* deleter = new OriginDataDeleter( |
| + manager(), *p, type_, quota_client_mask_, false, |
| + base::Bind(&HostDataDeleter::DidDeleteOriginData, |
| + weak_factory_.GetWeakPtr())); |
| deleter->Start(); |
| } |
| } |
| @@ -925,20 +952,11 @@ void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id, |
| GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled); |
| } |
| -void QuotaManager::DeleteOriginData( |
| - const GURL& origin, StorageType type, int quota_client_mask, |
| - const StatusCallback& callback) { |
| - LazyInitialize(); |
| - |
| - if (origin.is_empty() || clients_.empty()) { |
| - callback.Run(kQuotaStatusOk); |
| - return; |
| - } |
| - |
| - DCHECK(origin == origin.GetOrigin()); |
| - OriginDataDeleter* deleter = |
| - new OriginDataDeleter(this, origin, type, quota_client_mask, callback); |
| - deleter->Start(); |
| +void QuotaManager::DeleteOriginData(const GURL& origin, |
| + StorageType type, |
| + int quota_client_mask, |
| + const StatusCallback& callback) { |
| + DeleteOriginDataInternal(origin, type, quota_client_mask, false, callback); |
| } |
| void QuotaManager::DeleteHostData(const std::string& host, |
| @@ -1354,17 +1372,17 @@ void QuotaManager::StartEviction() { |
| temporary_storage_evictor_->Start(); |
| } |
| -void QuotaManager::DeleteOriginFromDatabase( |
| - const GURL& origin, StorageType type) { |
| +void QuotaManager::DeleteOriginFromDatabase(const GURL& origin, |
| + StorageType type, |
| + bool is_eviction) { |
| LazyInitialize(); |
| if (db_disabled_) |
| return; |
| PostTaskAndReplyWithResultForDBThread( |
| FROM_HERE, |
| - base::Bind(&DeleteOriginInfoOnDBThread, origin, type), |
| - base::Bind(&QuotaManager::DidDatabaseWork, |
| - weak_factory_.GetWeakPtr())); |
| + base::Bind(&DeleteOriginInfoOnDBThread, origin, type, is_eviction), |
| + base::Bind(&QuotaManager::DidDatabaseWork, weak_factory_.GetWeakPtr())); |
| } |
| void QuotaManager::DidOriginDataEvicted(QuotaStatusCode status) { |
| @@ -1381,6 +1399,24 @@ void QuotaManager::DidOriginDataEvicted(QuotaStatusCode status) { |
| eviction_context_.evict_origin_data_callback.Reset(); |
| } |
| +void QuotaManager::DeleteOriginDataInternal(const GURL& origin, |
| + StorageType type, |
| + int quota_client_mask, |
| + bool is_eviction, |
| + const StatusCallback& callback) { |
| + LazyInitialize(); |
| + |
| + if (origin.is_empty() || clients_.empty()) { |
| + callback.Run(kQuotaStatusOk); |
| + return; |
| + } |
| + |
| + DCHECK(origin == origin.GetOrigin()); |
| + OriginDataDeleter* deleter = new OriginDataDeleter( |
| + this, origin, type, quota_client_mask, is_eviction, callback); |
| + deleter->Start(); |
| +} |
| + |
| void QuotaManager::ReportHistogram() { |
| GetGlobalUsage(kStorageTypeTemporary, |
| base::Bind( |
| @@ -1455,9 +1491,9 @@ void QuotaManager::EvictOriginData(const GURL& origin, |
| eviction_context_.evicted_type = type; |
| eviction_context_.evict_origin_data_callback = callback; |
| - DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, |
| - base::Bind(&QuotaManager::DidOriginDataEvicted, |
| - weak_factory_.GetWeakPtr())); |
| + DeleteOriginDataInternal(origin, type, QuotaClient::kAllClientsMask, true, |
| + base::Bind(&QuotaManager::DidOriginDataEvicted, |
| + weak_factory_.GetWeakPtr())); |
| } |
| void QuotaManager::GetUsageAndQuotaForEviction( |