| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/browser/quota/quota_manager.h" | 5 #include "storage/browser/quota/quota_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // TODO(kinuko): This should be like 10% of the actual disk space. | 69 // TODO(kinuko): This should be like 10% of the actual disk space. |
| 70 // For now we simply use a constant as getting the disk size needs | 70 // For now we simply use a constant as getting the disk size needs |
| 71 // platform-dependent code. (http://crbug.com/178976) | 71 // platform-dependent code. (http://crbug.com/178976) |
| 72 int64 QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes; | 72 int64 QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes; |
| 73 | 73 |
| 74 const int QuotaManager::kEvictionIntervalInMilliSeconds = | 74 const int QuotaManager::kEvictionIntervalInMilliSeconds = |
| 75 30 * kMinutesInMilliSeconds; | 75 30 * kMinutesInMilliSeconds; |
| 76 | 76 |
| 77 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] = | 77 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] = |
| 78 "Quota.TimeBetweenRepeatedOriginEvictions"; | 78 "Quota.TimeBetweenRepeatedOriginEvictions"; |
| 79 const char QuotaManager::kEvictedOriginAccessedCountHistogram[] = |
| 80 "Quota.EvictedOriginAccessCount"; |
| 81 const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] = |
| 82 "Quota.EvictedOriginTimeSinceAccess"; |
| 79 | 83 |
| 80 // Heuristics: assuming average cloud server allows a few Gigs storage | 84 // Heuristics: assuming average cloud server allows a few Gigs storage |
| 81 // on the server side and the storage needs to be shared for user data | 85 // on the server side and the storage needs to be shared for user data |
| 82 // and by multiple apps. | 86 // and by multiple apps. |
| 83 int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes; | 87 int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes; |
| 84 | 88 |
| 85 namespace { | 89 namespace { |
| 86 | 90 |
| 87 void CountOriginType(const std::set<GURL>& origins, | 91 void CountOriginType(const std::set<GURL>& origins, |
| 88 SpecialStoragePolicy* policy, | 92 SpecialStoragePolicy* policy, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 DCHECK(database); | 156 DCHECK(database); |
| 153 database->GetLRUOrigin(type, exceptions, policy, url); | 157 database->GetLRUOrigin(type, exceptions, policy, url); |
| 154 return true; | 158 return true; |
| 155 } | 159 } |
| 156 | 160 |
| 157 bool DeleteOriginInfoOnDBThread(const GURL& origin, | 161 bool DeleteOriginInfoOnDBThread(const GURL& origin, |
| 158 StorageType type, | 162 StorageType type, |
| 159 bool is_eviction, | 163 bool is_eviction, |
| 160 QuotaDatabase* database) { | 164 QuotaDatabase* database) { |
| 161 DCHECK(database); | 165 DCHECK(database); |
| 166 |
| 167 base::Time now = base::Time::Now(); |
| 168 |
| 169 if (is_eviction) { |
| 170 QuotaDatabase::OriginInfoTableEntry entry; |
| 171 database->GetOriginInfo(origin, type, &entry); |
| 172 UMA_HISTOGRAM_COUNTS(QuotaManager::kEvictedOriginAccessedCountHistogram, |
| 173 entry.used_count); |
| 174 UMA_HISTOGRAM_LONG_TIMES( |
| 175 QuotaManager::kEvictedOriginTimeSinceAccessHistogram, |
| 176 now - entry.last_access_time); |
| 177 } |
| 178 |
| 162 if (!database->DeleteOriginInfo(origin, type)) | 179 if (!database->DeleteOriginInfo(origin, type)) |
| 163 return false; | 180 return false; |
| 164 | 181 |
| 165 // If the deletion is not due to an eviction, delete the entry in the eviction | 182 // If the deletion is not due to an eviction, delete the entry in the eviction |
| 166 // table as well due to privacy concerns. | 183 // table as well due to privacy concerns. |
| 167 if (!is_eviction) | 184 if (!is_eviction) |
| 168 return database->DeleteOriginLastEvictionTime(origin, type); | 185 return database->DeleteOriginLastEvictionTime(origin, type); |
| 169 | 186 |
| 170 base::Time last_eviction_time; | 187 base::Time last_eviction_time; |
| 171 if (!database->GetOriginLastEvictionTime(origin, type, &last_eviction_time)) | 188 database->GetOriginLastEvictionTime(origin, type, &last_eviction_time); |
| 172 return false; | |
| 173 | 189 |
| 174 base::Time now = base::Time::Now(); | |
| 175 if (last_eviction_time != base::Time()) { | 190 if (last_eviction_time != base::Time()) { |
| 176 UMA_HISTOGRAM_LONG_TIMES( | 191 UMA_HISTOGRAM_LONG_TIMES( |
| 177 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, | 192 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, |
| 178 now - last_eviction_time); | 193 now - last_eviction_time); |
| 179 } | 194 } |
| 180 | 195 |
| 181 return database->SetOriginLastEvictionTime(origin, type, now); | 196 return database->SetOriginLastEvictionTime(origin, type, now); |
| 182 } | 197 } |
| 183 | 198 |
| 184 bool InitializeTemporaryOriginsInfoOnDBThread(const std::set<GURL>* origins, | 199 bool InitializeTemporaryOriginsInfoOnDBThread(const std::set<GURL>* origins, |
| (...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 // |database_|, therefore we can be sure that database_ is alive when this | 1747 // |database_|, therefore we can be sure that database_ is alive when this |
| 1733 // task runs. | 1748 // task runs. |
| 1734 base::PostTaskAndReplyWithResult( | 1749 base::PostTaskAndReplyWithResult( |
| 1735 db_thread_.get(), | 1750 db_thread_.get(), |
| 1736 from_here, | 1751 from_here, |
| 1737 base::Bind(task, base::Unretained(database_.get())), | 1752 base::Bind(task, base::Unretained(database_.get())), |
| 1738 reply); | 1753 reply); |
| 1739 } | 1754 } |
| 1740 | 1755 |
| 1741 } // namespace storage | 1756 } // namespace storage |
| OLD | NEW |