Chromium Code Reviews| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 int64_t quota = usage_and_quota.quota; | 324 int64_t quota = usage_and_quota.quota; |
| 325 | 325 |
| 326 if (type == kStorageTypeTemporary && !is_unlimited) { | 326 if (type == kStorageTypeTemporary && !is_unlimited) { |
| 327 quota = CalculateTemporaryHostQuota( | 327 quota = CalculateTemporaryHostQuota( |
| 328 usage, quota, usage_and_quota.global_limited_usage); | 328 usage, quota, usage_and_quota.global_limited_usage); |
| 329 } | 329 } |
| 330 | 330 |
| 331 if (is_incognito) { | 331 if (is_incognito) { |
| 332 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit); | 332 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit); |
| 333 callback.Run(status, usage, quota); | 333 callback.Run(status, usage, quota); |
| 334 UMA_HISTOGRAM_MBYTES("Quota.QuotaForOriginIncognito", quota); | |
|
Ilya Sherman
2016/05/19 04:06:01
It's worth double-checking with the privacy team,
michaeln
2016/05/19 19:09:15
hmmm... i see many metrics that are specific to 'i
Ilya Sherman
2016/05/19 22:31:16
I'd recommend removing this for now, and checking
michaeln
2016/05/19 22:56:30
Done.
| |
| 334 return; | 335 return; |
| 335 } | 336 } |
| 336 | 337 |
| 337 // For apps with unlimited permission or can_query_disk_size is true (and not | 338 // For apps with unlimited permission or can_query_disk_size is true (and not |
| 338 // in incognito mode). | 339 // in incognito mode). |
| 339 // We assume we can expose the actual disk size for them and cap the quota by | 340 // We assume we can expose the actual disk size for them and cap the quota by |
| 340 // the available disk space. | 341 // the available disk space. |
| 341 if (is_unlimited || can_query_disk_size) { | 342 if (is_unlimited || can_query_disk_size) { |
| 342 callback.Run( | 343 quota = CalculateQuotaWithDiskSpace( |
| 343 status, usage, | 344 usage_and_quota.available_disk_space, |
| 344 CalculateQuotaWithDiskSpace( | 345 usage, quota); |
| 345 usage_and_quota.available_disk_space, | |
| 346 usage, quota)); | |
| 347 return; | |
| 348 } | 346 } |
| 349 | 347 |
| 350 callback.Run(status, usage, quota); | 348 callback.Run(status, usage, quota); |
| 349 | |
| 350 if (type == kStorageTypeTemporary && !is_unlimited) | |
| 351 UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", quota); | |
| 351 } | 352 } |
| 352 | 353 |
| 353 } // namespace | 354 } // namespace |
| 354 | 355 |
| 355 UsageAndQuota::UsageAndQuota() | 356 UsageAndQuota::UsageAndQuota() |
| 356 : usage(0), | 357 : usage(0), |
| 357 global_limited_usage(0), | 358 global_limited_usage(0), |
| 358 quota(0), | 359 quota(0), |
| 359 available_disk_space(0) { | 360 available_disk_space(0) { |
| 360 } | 361 } |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 return; | 1471 return; |
| 1471 } | 1472 } |
| 1472 | 1473 |
| 1473 DCHECK(origin == origin.GetOrigin()); | 1474 DCHECK(origin == origin.GetOrigin()); |
| 1474 OriginDataDeleter* deleter = new OriginDataDeleter( | 1475 OriginDataDeleter* deleter = new OriginDataDeleter( |
| 1475 this, origin, type, quota_client_mask, is_eviction, callback); | 1476 this, origin, type, quota_client_mask, is_eviction, callback); |
| 1476 deleter->Start(); | 1477 deleter->Start(); |
| 1477 } | 1478 } |
| 1478 | 1479 |
| 1479 void QuotaManager::ReportHistogram() { | 1480 void QuotaManager::ReportHistogram() { |
| 1481 DCHECK(!is_incognito_); | |
| 1480 GetGlobalUsage(kStorageTypeTemporary, | 1482 GetGlobalUsage(kStorageTypeTemporary, |
| 1481 base::Bind( | 1483 base::Bind( |
| 1482 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram, | 1484 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram, |
| 1483 weak_factory_.GetWeakPtr())); | 1485 weak_factory_.GetWeakPtr())); |
| 1484 GetGlobalUsage(kStorageTypePersistent, | |
| 1485 base::Bind( | |
| 1486 &QuotaManager::DidGetPersistentGlobalUsageForHistogram, | |
| 1487 weak_factory_.GetWeakPtr())); | |
| 1488 } | 1486 } |
| 1489 | 1487 |
| 1490 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram( | 1488 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram( |
| 1491 int64_t usage, | 1489 int64_t usage, |
| 1492 int64_t unlimited_usage) { | 1490 int64_t unlimited_usage) { |
| 1493 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); | 1491 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); |
| 1494 | 1492 |
| 1495 std::set<GURL> origins; | 1493 std::set<GURL> origins; |
| 1496 GetCachedOrigins(kStorageTypeTemporary, &origins); | 1494 GetCachedOrigins(kStorageTypeTemporary, &origins); |
| 1497 | 1495 |
| 1498 size_t num_origins = origins.size(); | 1496 size_t num_origins = origins.size(); |
| 1499 size_t protected_origins = 0; | 1497 size_t protected_origins = 0; |
| 1500 size_t unlimited_origins = 0; | 1498 size_t unlimited_origins = 0; |
| 1501 CountOriginType(origins, | 1499 CountOriginType(origins, |
| 1502 special_storage_policy_.get(), | 1500 special_storage_policy_.get(), |
| 1503 &protected_origins, | 1501 &protected_origins, |
| 1504 &unlimited_origins); | 1502 &unlimited_origins); |
| 1505 | |
| 1506 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins", | 1503 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins", |
| 1507 num_origins); | 1504 num_origins); |
| 1508 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins", | 1505 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins", |
| 1509 protected_origins); | 1506 protected_origins); |
| 1510 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins", | 1507 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins", |
| 1511 unlimited_origins); | 1508 unlimited_origins); |
| 1509 | |
| 1510 GetGlobalUsage(kStorageTypePersistent, | |
| 1511 base::Bind( | |
| 1512 &QuotaManager::DidGetPersistentGlobalUsageForHistogram, | |
| 1513 weak_factory_.GetWeakPtr())); | |
| 1512 } | 1514 } |
| 1513 | 1515 |
| 1514 void QuotaManager::DidGetPersistentGlobalUsageForHistogram( | 1516 void QuotaManager::DidGetPersistentGlobalUsageForHistogram( |
| 1515 int64_t usage, | 1517 int64_t usage, |
| 1516 int64_t unlimited_usage) { | 1518 int64_t unlimited_usage) { |
| 1517 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage); | 1519 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage); |
| 1518 | 1520 |
| 1519 std::set<GURL> origins; | 1521 std::set<GURL> origins; |
| 1520 GetCachedOrigins(kStorageTypePersistent, &origins); | 1522 GetCachedOrigins(kStorageTypePersistent, &origins); |
| 1521 | 1523 |
| 1522 size_t num_origins = origins.size(); | 1524 size_t num_origins = origins.size(); |
| 1523 size_t protected_origins = 0; | 1525 size_t protected_origins = 0; |
| 1524 size_t unlimited_origins = 0; | 1526 size_t unlimited_origins = 0; |
| 1525 CountOriginType(origins, | 1527 CountOriginType(origins, |
| 1526 special_storage_policy_.get(), | 1528 special_storage_policy_.get(), |
| 1527 &protected_origins, | 1529 &protected_origins, |
| 1528 &unlimited_origins); | 1530 &unlimited_origins); |
| 1529 | |
| 1530 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", | 1531 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", |
| 1531 num_origins); | 1532 num_origins); |
| 1532 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", | 1533 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", |
| 1533 protected_origins); | 1534 protected_origins); |
| 1534 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", | 1535 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", |
| 1535 unlimited_origins); | 1536 unlimited_origins); |
| 1537 | |
| 1538 // We DumpOriginInfoTable last to ensure the trackers caches are loaded. | |
| 1539 DumpOriginInfoTable( | |
| 1540 base::Bind(&QuotaManager::DidDumpOriginInfoTableForHistogram, | |
| 1541 weak_factory_.GetWeakPtr())); | |
| 1542 } | |
| 1543 | |
| 1544 void QuotaManager::DidDumpOriginInfoTableForHistogram( | |
| 1545 const OriginInfoTableEntries& entries) { | |
| 1546 using UsageMap = std::map<GURL, int64_t>; | |
| 1547 UsageMap usage_map; | |
| 1548 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map); | |
| 1549 | |
| 1550 int64_t usage_day_old = 0; | |
| 1551 int64_t usage_week_old = 0; | |
| 1552 int64_t usage_month_old = 0; | |
| 1553 int64_t usage_three_month_old = 0; | |
| 1554 int64_t usage_six_month_old = 0; | |
| 1555 int64_t usage_year_old = 0; | |
| 1556 int64_t usage_over_year_old = 0; | |
| 1557 base::Time now = base::Time::Now(); | |
| 1558 | |
| 1559 for (const auto& info : entries) { | |
| 1560 if (info.type != kStorageTypeTemporary) | |
| 1561 continue; | |
| 1562 | |
| 1563 // Ignore stale database entries. If there is no map entry, the origin's | |
| 1564 // data has been deleted. | |
| 1565 UsageMap::const_iterator found = usage_map.find(info.origin); | |
| 1566 if (found == usage_map.end() || found->second == 0) | |
| 1567 continue; | |
| 1568 | |
| 1569 base::TimeDelta age = now - std::max(info.last_access_time, | |
| 1570 info.last_modified_time); | |
| 1571 UMA_HISTOGRAM_COUNTS_1000("Quota.OriginAgeInDays", age.InDays()); | |
| 1572 | |
| 1573 if (age < base::TimeDelta::FromDays(1)) | |
| 1574 usage_day_old += found->second; | |
| 1575 else if (age < base::TimeDelta::FromDays(7)) | |
| 1576 usage_week_old += found->second; | |
| 1577 else if (age < base::TimeDelta::FromDays(30)) | |
| 1578 usage_month_old += found->second; | |
| 1579 else if (age < base::TimeDelta::FromDays(90)) | |
| 1580 usage_three_month_old += found->second; | |
| 1581 else if (age < base::TimeDelta::FromDays(180)) | |
| 1582 usage_six_month_old += found->second; | |
| 1583 else if (age < base::TimeDelta::FromDays(365)) | |
| 1584 usage_year_old += found->second; | |
| 1585 else | |
| 1586 usage_over_year_old += found->second; | |
| 1587 } | |
| 1588 | |
| 1589 UMA_HISTOGRAM_MBYTES("Quota.AmountDayOldData", usage_day_old); | |
| 1590 UMA_HISTOGRAM_MBYTES("Quota.AmountWeekOldData", usage_week_old); | |
| 1591 UMA_HISTOGRAM_MBYTES("Quota.AmountMonthOldData", usage_month_old); | |
| 1592 UMA_HISTOGRAM_MBYTES("Quota.AmountThreeMonthOldData", usage_three_month_old); | |
| 1593 UMA_HISTOGRAM_MBYTES("Quota.AmountSixMonthOldData", usage_six_month_old); | |
| 1594 UMA_HISTOGRAM_MBYTES("Quota.AmountYearOldData", usage_year_old); | |
| 1595 UMA_HISTOGRAM_MBYTES("Quota.AmountOverYearOldData", usage_over_year_old); | |
|
Ilya Sherman
2016/05/19 04:06:01
This is a fairly significant number of similar his
michaeln
2016/05/19 19:09:15
Two reasons for the granularity.
- to get a sense
michaeln
2016/05/19 19:51:24
Oh... I'll redo these to use a single histogram wi
Ilya Sherman
2016/05/19 22:31:16
Yep, that's a reasonable approach, as long as you'
michaeln
2016/05/19 22:56:30
Done
| |
| 1536 } | 1596 } |
| 1537 | 1597 |
| 1538 std::set<GURL> QuotaManager::GetEvictionOriginExceptions( | 1598 std::set<GURL> QuotaManager::GetEvictionOriginExceptions( |
| 1539 const std::set<GURL>& extra_exceptions) { | 1599 const std::set<GURL>& extra_exceptions) { |
| 1540 std::set<GURL> exceptions = extra_exceptions; | 1600 std::set<GURL> exceptions = extra_exceptions; |
| 1541 for (const auto& p : origins_in_use_) { | 1601 for (const auto& p : origins_in_use_) { |
| 1542 if (p.second > 0) | 1602 if (p.second > 0) |
| 1543 exceptions.insert(p.first); | 1603 exceptions.insert(p.first); |
| 1544 } | 1604 } |
| 1545 | 1605 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1709 } | 1769 } |
| 1710 | 1770 |
| 1711 void QuotaManager::DidInitialize(int64_t* temporary_quota_override, | 1771 void QuotaManager::DidInitialize(int64_t* temporary_quota_override, |
| 1712 int64_t* desired_available_space, | 1772 int64_t* desired_available_space, |
| 1713 bool success) { | 1773 bool success) { |
| 1714 temporary_quota_override_ = *temporary_quota_override; | 1774 temporary_quota_override_ = *temporary_quota_override; |
| 1715 desired_available_space_ = *desired_available_space; | 1775 desired_available_space_ = *desired_available_space; |
| 1716 temporary_quota_initialized_ = true; | 1776 temporary_quota_initialized_ = true; |
| 1717 DidDatabaseWork(success); | 1777 DidDatabaseWork(success); |
| 1718 | 1778 |
| 1719 histogram_timer_.Start(FROM_HERE, | 1779 if (!is_incognito_) { |
| 1720 base::TimeDelta::FromMilliseconds( | 1780 histogram_timer_.Start(FROM_HERE, |
| 1721 kReportHistogramInterval), | 1781 base::TimeDelta::FromMilliseconds( |
| 1722 this, &QuotaManager::ReportHistogram); | 1782 kReportHistogramInterval), |
| 1783 this, &QuotaManager::ReportHistogram); | |
| 1784 } | |
| 1723 | 1785 |
| 1724 db_initialization_callbacks_.Run(); | 1786 db_initialization_callbacks_.Run(); |
| 1725 GetTemporaryGlobalQuota( | 1787 GetTemporaryGlobalQuota( |
| 1726 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, | 1788 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, |
| 1727 weak_factory_.GetWeakPtr(), base::TimeTicks::Now())); | 1789 weak_factory_.GetWeakPtr(), base::TimeTicks::Now())); |
| 1728 } | 1790 } |
| 1729 | 1791 |
| 1730 void QuotaManager::DidGetLRUOrigin(const GURL* origin, | 1792 void QuotaManager::DidGetLRUOrigin(const GURL* origin, |
| 1731 bool success) { | 1793 bool success) { |
| 1732 DidDatabaseWork(success); | 1794 DidDatabaseWork(success); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1835 return false; | 1897 return false; |
| 1836 *available_space = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize; | 1898 *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; | 1899 *total_size = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize; |
| 1838 #else | 1900 #else |
| 1839 #error Not implemented | 1901 #error Not implemented |
| 1840 #endif | 1902 #endif |
| 1841 return true; | 1903 return true; |
| 1842 } | 1904 } |
| 1843 | 1905 |
| 1844 } // namespace storage | 1906 } // namespace storage |
| OLD | NEW |