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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 51 UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
52 (name), static_cast<int>((sample) / kMBytes), \ | 52 (name), static_cast<int>((sample) / kMBytes), \ |
53 1, 10 * 1024 * 1024 /* 10TB */, 100) | 53 1, 10 * 1024 * 1024 /* 10TB */, 100) |
54 | 54 |
55 namespace storage { | 55 namespace storage { |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 const int64_t kMBytes = 1024 * 1024; | 59 const int64_t kMBytes = 1024 * 1024; |
60 const int kMinutesInMilliSeconds = 60 * 1000; | 60 const int kMinutesInMilliSeconds = 60 * 1000; |
61 | |
62 const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour | 61 const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour |
63 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% | |
64 | 62 |
65 } // namespace | 63 } // namespace |
66 | 64 |
67 // Arbitrary for now, but must be reasonably small so that | 65 // Arbitrary for now, but must be reasonably small so that |
68 // in-memory databases can fit. | 66 // in-memory databases can fit. |
69 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. | 67 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. |
70 const int64_t QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; | 68 const int64_t QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; |
71 | 69 |
72 const int64_t QuotaManager::kNoLimit = INT64_MAX; | 70 const int64_t QuotaManager::kNoLimit = INT64_MAX; |
73 | 71 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 } | 236 } |
239 | 237 |
240 bool UpdateModifiedTimeOnDBThread(const GURL& origin, | 238 bool UpdateModifiedTimeOnDBThread(const GURL& origin, |
241 StorageType type, | 239 StorageType type, |
242 base::Time modified_time, | 240 base::Time modified_time, |
243 QuotaDatabase* database) { | 241 QuotaDatabase* database) { |
244 DCHECK(database); | 242 DCHECK(database); |
245 return database->SetOriginLastModifiedTime(origin, type, modified_time); | 243 return database->SetOriginLastModifiedTime(origin, type, modified_time); |
246 } | 244 } |
247 | 245 |
248 int64_t CalculateTemporaryGlobalQuota(int64_t global_limited_usage, | |
249 int64_t available_space) { | |
250 DCHECK_GE(global_limited_usage, 0); | |
251 int64_t avail_space = available_space; | |
252 if (avail_space < | |
253 std::numeric_limits<int64_t>::max() - global_limited_usage) { | |
254 // We basically calculate the temporary quota by | |
255 // [available_space + space_used_for_temp] * kTempQuotaRatio, | |
256 // but make sure we'll have no overflow. | |
257 avail_space += global_limited_usage; | |
258 } | |
259 int64_t pool_size = avail_space * kTemporaryQuotaRatioToAvail; | |
260 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size); | |
261 return pool_size; | |
262 } | |
263 | |
264 void DispatchTemporaryGlobalQuotaCallback( | |
265 const QuotaCallback& callback, | |
266 QuotaStatusCode status, | |
267 const UsageAndQuota& usage_and_quota) { | |
268 if (status != kQuotaStatusOk) { | |
269 callback.Run(status, 0); | |
270 return; | |
271 } | |
272 | |
273 callback.Run(status, CalculateTemporaryGlobalQuota( | |
274 usage_and_quota.global_limited_usage, | |
275 usage_and_quota.available_disk_space)); | |
276 } | |
277 | |
278 int64_t CalculateQuotaWithDiskSpace(int64_t available_disk_space, | 246 int64_t CalculateQuotaWithDiskSpace(int64_t available_disk_space, |
279 int64_t usage, | 247 int64_t usage, |
280 int64_t quota) { | 248 int64_t quota) { |
281 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) { | 249 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) { |
282 LOG(WARNING) | 250 LOG(WARNING) |
283 << "Running out of disk space for profile." | 251 << "Running out of disk space for profile." |
284 << " QuotaManager starts forbidding further quota consumption."; | 252 << " QuotaManager starts forbidding further quota consumption."; |
285 return usage; | 253 return usage; |
286 } | 254 } |
287 | 255 |
288 if (quota < usage) { | 256 if (quota < usage) { |
289 // No more space; cap the quota to the current usage. | 257 // No more space; cap the quota to the current usage. |
290 return usage; | 258 return usage; |
291 } | 259 } |
292 | 260 |
293 available_disk_space -= QuotaManager::kMinimumPreserveForSystem; | 261 available_disk_space -= QuotaManager::kMinimumPreserveForSystem; |
294 if (available_disk_space < quota - usage) | 262 if (available_disk_space < quota - usage) |
295 return available_disk_space + usage; | 263 return available_disk_space + usage; |
296 | 264 |
297 return quota; | 265 return quota; |
298 } | 266 } |
299 | 267 |
300 int64_t CalculateTemporaryHostQuota(int64_t host_usage, | 268 int64_t CalculateTemporaryHostQuota(int64_t host_usage, |
301 int64_t global_quota, | 269 int64_t global_quota, |
302 int64_t global_limited_usage) { | 270 int64_t available_disk_space) { |
303 DCHECK_GE(global_limited_usage, 0); | 271 const int64_t desired_quota = global_quota / |
304 int64_t host_quota = global_quota / QuotaManager::kPerHostTemporaryPortion; | 272 QuotaManager::kPerHostTemporaryPortion; |
305 if (global_limited_usage > global_quota) | 273 |
306 host_quota = std::min(host_quota, host_usage); | 274 // We define "too low" as not enough room for another hosts |
307 return host_quota; | 275 // nominal desired amount of data. (TODO: what should this be) |
jsbell
2016/04/07 19:33:41
This seems fine to me. (i.e. remove the TODO)
michaeln
2016/04/07 20:54:48
Done.
| |
276 const int64_t too_low_threshold = desired_quota; | |
277 | |
278 // If disk space is too low, cap usage at current levels. | |
279 // If its close to being too low, cap growth to avoid it getting too low. | |
jsbell
2016/04/07 19:33:41
nit: it's
michaeln
2016/04/07 20:54:47
Done.
| |
280 return std::min( | |
281 desired_quota, | |
282 host_usage + | |
283 std::max(INT64_C(0), available_disk_space - too_low_threshold)); | |
308 } | 284 } |
309 | 285 |
310 void DispatchUsageAndQuotaForWebApps( | 286 void DispatchUsageAndQuotaForWebApps( |
311 StorageType type, | 287 StorageType type, |
312 bool is_incognito, | 288 bool is_incognito, |
313 bool is_unlimited, | 289 bool is_unlimited, |
314 bool can_query_disk_size, | 290 bool can_query_disk_size, |
315 const QuotaManager::GetUsageAndQuotaCallback& callback, | 291 const QuotaManager::GetUsageAndQuotaCallback& callback, |
316 QuotaStatusCode status, | 292 QuotaStatusCode status, |
317 const UsageAndQuota& usage_and_quota) { | 293 const UsageAndQuota& usage_and_quota) { |
318 if (status != kQuotaStatusOk) { | 294 if (status != kQuotaStatusOk) { |
319 callback.Run(status, 0, 0); | 295 callback.Run(status, 0, 0); |
320 return; | 296 return; |
321 } | 297 } |
322 | 298 |
323 int64_t usage = usage_and_quota.usage; | 299 int64_t host_usage = usage_and_quota.usage; |
324 int64_t quota = usage_and_quota.quota; | 300 int64_t global_quota = usage_and_quota.quota; |
301 int64_t host_quota = global_quota; | |
325 | 302 |
326 if (type == kStorageTypeTemporary && !is_unlimited) { | 303 if (type == kStorageTypeTemporary && !is_unlimited) { |
327 quota = CalculateTemporaryHostQuota( | 304 host_quota = CalculateTemporaryHostQuota( |
328 usage, quota, usage_and_quota.global_limited_usage); | 305 host_usage, global_quota, usage_and_quota.available_disk_space); |
329 } | 306 } |
330 | 307 |
331 if (is_incognito) { | 308 if (is_incognito) { |
332 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit); | 309 host_quota = std::min(host_quota, |
333 callback.Run(status, usage, quota); | 310 QuotaManager::kIncognitoDefaultQuotaLimit); |
311 callback.Run(status, host_usage, host_quota); | |
334 return; | 312 return; |
335 } | 313 } |
336 | 314 |
337 // For apps with unlimited permission or can_query_disk_size is true (and not | 315 // For apps with unlimited permission or can_query_disk_size is true (and not |
338 // in incognito mode). | 316 // in incognito mode). |
339 // We assume we can expose the actual disk size for them and cap the quota by | 317 // We assume we can expose the actual disk size for them and cap the quota by |
340 // the available disk space. | 318 // the available disk space. |
341 if (is_unlimited || can_query_disk_size) { | 319 if (is_unlimited || can_query_disk_size) { |
342 callback.Run( | 320 callback.Run( |
343 status, usage, | 321 status, host_usage, |
344 CalculateQuotaWithDiskSpace( | 322 CalculateQuotaWithDiskSpace( |
345 usage_and_quota.available_disk_space, | 323 usage_and_quota.available_disk_space, |
346 usage, quota)); | 324 host_usage, host_quota)); |
347 return; | 325 return; |
348 } | 326 } |
349 | 327 |
350 callback.Run(status, usage, quota); | 328 callback.Run(status, host_usage, host_quota); |
351 } | 329 } |
352 | 330 |
353 } // namespace | 331 } // namespace |
354 | 332 |
355 UsageAndQuota::UsageAndQuota() | 333 UsageAndQuota::UsageAndQuota() |
356 : usage(0), | 334 : usage(0), |
357 global_limited_usage(0), | 335 global_limited_usage(0), |
358 quota(0), | 336 quota(0), |
359 available_disk_space(0) { | 337 available_disk_space(0) { |
360 } | 338 } |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 bool unlimited = IsStorageUnlimited(origin, type); | 898 bool unlimited = IsStorageUnlimited(origin, type); |
921 bool can_query_disk_size = CanQueryDiskSize(origin); | 899 bool can_query_disk_size = CanQueryDiskSize(origin); |
922 | 900 |
923 UsageAndQuotaCallbackDispatcher* dispatcher = | 901 UsageAndQuotaCallbackDispatcher* dispatcher = |
924 new UsageAndQuotaCallbackDispatcher(this); | 902 new UsageAndQuotaCallbackDispatcher(this); |
925 | 903 |
926 if (unlimited) { | 904 if (unlimited) { |
927 dispatcher->set_quota(kNoLimit); | 905 dispatcher->set_quota(kNoLimit); |
928 } else { | 906 } else { |
929 if (type == kStorageTypeTemporary) { | 907 if (type == kStorageTypeTemporary) { |
930 GetUsageTracker(type)->GetGlobalLimitedUsage( | |
931 dispatcher->GetGlobalLimitedUsageCallback()); | |
932 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); | 908 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); |
933 } else if (type == kStorageTypePersistent) { | 909 } else if (type == kStorageTypePersistent) { |
934 GetPersistentHostQuota(net::GetHostOrSpecFromURL(origin), | 910 GetPersistentHostQuota(net::GetHostOrSpecFromURL(origin), |
935 dispatcher->GetQuotaCallback()); | 911 dispatcher->GetQuotaCallback()); |
936 } else { | 912 } else { |
937 dispatcher->set_quota(kSyncableStorageDefaultHostQuota); | 913 dispatcher->set_quota(kSyncableStorageDefaultHostQuota); |
938 } | 914 } |
939 } | 915 } |
940 | 916 |
941 DCHECK(GetUsageTracker(type)); | 917 DCHECK(GetUsageTracker(type)); |
942 GetUsageTracker(type)->GetHostUsage(net::GetHostOrSpecFromURL(origin), | 918 GetUsageTracker(type)->GetHostUsage(net::GetHostOrSpecFromURL(origin), |
943 dispatcher->GetHostUsageCallback()); | 919 dispatcher->GetHostUsageCallback()); |
944 | 920 |
945 if (!is_incognito_ && (unlimited || can_query_disk_size)) | 921 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); |
946 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); | |
947 | 922 |
948 dispatcher->WaitForResults(base::Bind( | 923 dispatcher->WaitForResults(base::Bind( |
949 &DispatchUsageAndQuotaForWebApps, | 924 &DispatchUsageAndQuotaForWebApps, |
950 type, is_incognito_, unlimited, can_query_disk_size, | 925 type, is_incognito_, unlimited, can_query_disk_size, |
951 callback)); | 926 callback)); |
952 } | 927 } |
953 | 928 |
954 void QuotaManager::GetUsageAndQuota( | 929 void QuotaManager::GetUsageAndQuota( |
955 const GURL& origin, StorageType type, | 930 const GURL& origin, StorageType type, |
956 const GetUsageAndQuotaCallback& callback) { | 931 const GetUsageAndQuotaCallback& callback) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 new HostDataDeleter(this, host, type, quota_client_mask, callback); | 1004 new HostDataDeleter(this, host, type, quota_client_mask, callback); |
1030 deleter->Start(); | 1005 deleter->Start(); |
1031 } | 1006 } |
1032 | 1007 |
1033 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { | 1008 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { |
1034 if (!available_space_callbacks_.Add(callback)) | 1009 if (!available_space_callbacks_.Add(callback)) |
1035 return; | 1010 return; |
1036 // crbug.com/349708 | 1011 // crbug.com/349708 |
1037 TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace"); | 1012 TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace"); |
1038 | 1013 |
1039 PostTaskAndReplyWithResult( | 1014 base::PostTaskAndReplyWithResult( |
1040 db_thread_.get(), | 1015 db_thread_.get(), |
1041 FROM_HERE, | 1016 FROM_HERE, |
1042 base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace, | 1017 base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace, |
1043 get_volume_info_fn_, profile_path_), | 1018 get_volume_info_fn_, profile_path_), |
1044 base::Bind(&QuotaManager::DidGetAvailableSpace, | 1019 base::Bind(&QuotaManager::DidGetAvailableSpace, |
1045 weak_factory_.GetWeakPtr())); | 1020 weak_factory_.GetWeakPtr())); |
1046 } | 1021 } |
1047 | 1022 |
1048 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { | 1023 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { |
1049 LazyInitialize(); | 1024 LazyInitialize(); |
1050 if (!temporary_quota_initialized_) { | 1025 if (!temporary_quota_initialized_) { |
1051 db_initialization_callbacks_.Add(base::Bind( | 1026 db_initialization_callbacks_.Add(base::Bind( |
1052 &QuotaManager::GetTemporaryGlobalQuota, | 1027 &QuotaManager::GetTemporaryGlobalQuota, |
1053 weak_factory_.GetWeakPtr(), callback)); | 1028 weak_factory_.GetWeakPtr(), callback)); |
1054 return; | 1029 return; |
1055 } | 1030 } |
1056 | 1031 |
1057 if (temporary_quota_override_ > 0) { | 1032 if (temporary_quota_override_ > 0) { |
1058 callback.Run(kQuotaStatusOk, temporary_quota_override_); | 1033 callback.Run(kQuotaStatusOk, temporary_quota_override_); |
1059 return; | 1034 return; |
1060 } | 1035 } |
1061 | 1036 |
1062 UsageAndQuotaCallbackDispatcher* dispatcher = | 1037 base::PostTaskAndReplyWithResult( |
1063 new UsageAndQuotaCallbackDispatcher(this); | 1038 db_thread_.get(), |
1064 GetUsageTracker(kStorageTypeTemporary)-> | 1039 FROM_HERE, |
1065 GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); | 1040 base::Bind(&QuotaManager::CalculateTemporaryPoolSize, |
1066 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); | 1041 get_volume_info_fn_, profile_path_), |
1067 dispatcher->WaitForResults( | 1042 base::Bind(&QuotaManager::DidCalculateTemporaryPoolSize, |
1068 base::Bind(&DispatchTemporaryGlobalQuotaCallback, callback)); | 1043 weak_factory_.GetWeakPtr(), |
1044 callback)); | |
1069 } | 1045 } |
1070 | 1046 |
1071 void QuotaManager::SetTemporaryGlobalOverrideQuota( | 1047 void QuotaManager::SetTemporaryGlobalOverrideQuota( |
1072 int64_t new_quota, | 1048 int64_t new_quota, |
1073 const QuotaCallback& callback) { | 1049 const QuotaCallback& callback) { |
1074 LazyInitialize(); | 1050 LazyInitialize(); |
1075 | 1051 |
1076 if (new_quota < 0) { | 1052 if (new_quota < 0) { |
1077 if (!callback.is_null()) | 1053 if (!callback.is_null()) |
1078 callback.Run(kQuotaErrorInvalidModification, -1); | 1054 callback.Run(kQuotaErrorInvalidModification, -1); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1626 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); | 1602 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); |
1627 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); | 1603 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); |
1628 dispatcher->WaitForResults(callback); | 1604 dispatcher->WaitForResults(callback); |
1629 } | 1605 } |
1630 | 1606 |
1631 void QuotaManager::AsyncGetVolumeInfo( | 1607 void QuotaManager::AsyncGetVolumeInfo( |
1632 const VolumeInfoCallback& callback) { | 1608 const VolumeInfoCallback& callback) { |
1633 DCHECK(io_thread_->BelongsToCurrentThread()); | 1609 DCHECK(io_thread_->BelongsToCurrentThread()); |
1634 uint64_t* available_space = new uint64_t(0); | 1610 uint64_t* available_space = new uint64_t(0); |
1635 uint64_t* total_space = new uint64_t(0); | 1611 uint64_t* total_space = new uint64_t(0); |
1636 PostTaskAndReplyWithResult( | 1612 base::PostTaskAndReplyWithResult( |
1637 db_thread_.get(), | 1613 db_thread_.get(), |
1638 FROM_HERE, | 1614 FROM_HERE, |
1639 base::Bind(get_volume_info_fn_, | 1615 base::Bind(get_volume_info_fn_, |
1640 profile_path_, | 1616 profile_path_, |
1641 base::Unretained(available_space), | 1617 base::Unretained(available_space), |
1642 base::Unretained(total_space)), | 1618 base::Unretained(total_space)), |
1643 base::Bind(&QuotaManager::DidGetVolumeInfo, | 1619 base::Bind(&QuotaManager::DidGetVolumeInfo, |
1644 weak_factory_.GetWeakPtr(), | 1620 weak_factory_.GetWeakPtr(), |
1645 callback, | 1621 callback, |
1646 base::Owned(available_space), | 1622 base::Owned(available_space), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 } | 1741 } |
1766 | 1742 |
1767 void QuotaManager::DidGetAvailableSpace(int64_t space) { | 1743 void QuotaManager::DidGetAvailableSpace(int64_t space) { |
1768 // crbug.com/349708 | 1744 // crbug.com/349708 |
1769 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace", | 1745 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace", |
1770 "n_callbacks", available_space_callbacks_.size()); | 1746 "n_callbacks", available_space_callbacks_.size()); |
1771 | 1747 |
1772 available_space_callbacks_.Run(kQuotaStatusOk, space); | 1748 available_space_callbacks_.Run(kQuotaStatusOk, space); |
1773 } | 1749 } |
1774 | 1750 |
1751 void QuotaManager::DidCalculateTemporaryPoolSize( | |
1752 const QuotaCallback& callback, int64_t pool_size) { | |
1753 QuotaStatusCode status = pool_size ? kQuotaStatusUnknown : kQuotaStatusOk; | |
1754 callback.Run(status, pool_size); | |
1755 } | |
1756 | |
1775 void QuotaManager::DidDatabaseWork(bool success) { | 1757 void QuotaManager::DidDatabaseWork(bool success) { |
1776 db_disabled_ = !success; | 1758 db_disabled_ = !success; |
1777 } | 1759 } |
1778 | 1760 |
1779 void QuotaManager::DeleteOnCorrectThread() const { | 1761 void QuotaManager::DeleteOnCorrectThread() const { |
1780 if (!io_thread_->BelongsToCurrentThread() && | 1762 if (!io_thread_->BelongsToCurrentThread() && |
1781 io_thread_->DeleteSoon(FROM_HERE, this)) { | 1763 io_thread_->DeleteSoon(FROM_HERE, this)) { |
1782 return; | 1764 return; |
1783 } | 1765 } |
1784 delete this; | 1766 delete this; |
1785 } | 1767 } |
1786 | 1768 |
1787 void QuotaManager::PostTaskAndReplyWithResultForDBThread( | 1769 void QuotaManager::PostTaskAndReplyWithResultForDBThread( |
1788 const tracked_objects::Location& from_here, | 1770 const tracked_objects::Location& from_here, |
1789 const base::Callback<bool(QuotaDatabase*)>& task, | 1771 const base::Callback<bool(QuotaDatabase*)>& task, |
1790 const base::Callback<void(bool)>& reply) { | 1772 const base::Callback<void(bool)>& reply) { |
1791 // Deleting manager will post another task to DB thread to delete | 1773 // Deleting manager will post another task to DB thread to delete |
1792 // |database_|, therefore we can be sure that database_ is alive when this | 1774 // |database_|, therefore we can be sure that database_ is alive when this |
1793 // task runs. | 1775 // task runs. |
1794 base::PostTaskAndReplyWithResult( | 1776 base::PostTaskAndReplyWithResult( |
1795 db_thread_.get(), | 1777 db_thread_.get(), |
1796 from_here, | 1778 from_here, |
1797 base::Bind(task, base::Unretained(database_.get())), | 1779 base::Bind(task, base::Unretained(database_.get())), |
1798 reply); | 1780 reply); |
1799 } | 1781 } |
1800 | 1782 |
1801 // static | 1783 // static |
1784 int64_t QuotaManager::CalculateTemporaryPoolSize( | |
1785 GetVolumeInfoFn get_volume_info_fn, | |
1786 const base::FilePath& profile_path) { | |
1787 // A rough estimate of how much storage is consumed by the base OS and | |
1788 // essential application code outside of the browser. | |
1789 #if defined(OS_ANDROID) | |
1790 const uint64_t kOsAccomodation = 250 * kMBytes; | |
1791 #elif defined(OS_CHROMEOS) | |
1792 const uint64_t kOsAccomodation = 1000 * kMBytes; | |
1793 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
1794 const uint64_t kOsAccomodation = 10000 * kMBytes; | |
1795 #else | |
1796 #error "Port: Need to define kOsAccomodation for unkown os." | |
jsbell
2016/04/07 19:33:41
Typo: unknown
michaeln
2016/04/07 20:54:48
Done.
| |
1797 #endif | |
1798 | |
1799 // The fraction of the device's storage the browser is willing to | |
1800 // use for temporary storage, this is applied after having taken | |
1801 // the OSAccomodation into account. | |
jsbell
2016/04/07 19:33:41
nit: kOsAccomodation (or otherwise be consistent i
michaeln
2016/04/07 20:54:47
Done.
| |
1802 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% | |
1803 | |
1804 int64_t pool_size = 0; | |
1805 uint64_t available, total; | |
1806 if (get_volume_info_fn(profile_path, &available, &total)) { | |
1807 if (total > kOsAccomodation) | |
1808 total -= kOsAccomodation; // todo: what if total is super small??? | |
jsbell
2016/04/07 19:33:41
To make the calculation clearer, can we leave `tot
michaeln
2016/04/07 20:54:47
thnx for the suggestions, i had forgotten about ad
michaeln
2016/07/27 19:57:47
Done in chrome_content_browser_client.cc
| |
1809 pool_size = static_cast<int64_t>(total * kTemporaryPoolSizeRatio); | |
1810 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size); | |
1811 } | |
1812 return pool_size; | |
1813 } | |
1814 | |
1815 // static | |
1802 int64_t QuotaManager::CallGetAmountOfFreeDiskSpace( | 1816 int64_t QuotaManager::CallGetAmountOfFreeDiskSpace( |
1803 GetVolumeInfoFn get_volume_info_fn, | 1817 GetVolumeInfoFn get_volume_info_fn, |
1804 const base::FilePath& profile_path) { | 1818 const base::FilePath& profile_path) { |
1805 // crbug.com/349708 | 1819 // crbug.com/349708 |
1806 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace"); | 1820 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace"); |
1807 if (!base::CreateDirectory(profile_path)) { | 1821 if (!base::CreateDirectory(profile_path)) { |
1808 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); | 1822 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); |
1809 return 0; | 1823 return 0; |
1810 } | 1824 } |
1811 uint64_t available, total; | 1825 uint64_t available, total; |
(...skipping 23 matching lines...) Expand all Loading... | |
1835 return false; | 1849 return false; |
1836 *available_space = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize; | 1850 *available_space = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize; |
1837 *total_size = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize; | 1851 *total_size = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize; |
1838 #else | 1852 #else |
1839 #error Not implemented | 1853 #error Not implemented |
1840 #endif | 1854 #endif |
1841 return true; | 1855 return true; |
1842 } | 1856 } |
1843 | 1857 |
1844 } // namespace storage | 1858 } // namespace storage |
OLD | NEW |