Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: storage/browser/quota/quota_manager.cc

Issue 2052663003: Move implementation of QuotaManager.getVolumeInfo to base::SysInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
31 #include "net/base/url_util.h" 31 #include "net/base/url_util.h"
32 #include "storage/browser/quota/client_usage_tracker.h" 32 #include "storage/browser/quota/client_usage_tracker.h"
33 #include "storage/browser/quota/quota_manager_proxy.h" 33 #include "storage/browser/quota/quota_manager_proxy.h"
34 #include "storage/browser/quota/quota_temporary_storage_evictor.h" 34 #include "storage/browser/quota/quota_temporary_storage_evictor.h"
35 #include "storage/browser/quota/storage_monitor.h" 35 #include "storage/browser/quota/storage_monitor.h"
36 #include "storage/browser/quota/usage_tracker.h" 36 #include "storage/browser/quota/usage_tracker.h"
37 #include "storage/common/quota/quota_types.h" 37 #include "storage/common/quota/quota_types.h"
38 38
39 // Platform specific includes for GetVolumeInfo().
40 #if defined(OS_WIN)
41 #include <windows.h>
42 #elif defined(OS_POSIX)
43 #if defined(OS_ANDROID)
44 #include <sys/vfs.h>
45 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
46 #else
47 #include <sys/statvfs.h>
48 #endif
49 #endif
50
51 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 39 #define UMA_HISTOGRAM_MBYTES(name, sample) \
52 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 40 UMA_HISTOGRAM_CUSTOM_COUNTS( \
53 (name), static_cast<int>((sample) / kMBytes), \ 41 (name), static_cast<int>((sample) / kMBytes), \
54 1, 10 * 1024 * 1024 /* 10TB */, 100) 42 1, 10 * 1024 * 1024 /* 10TB */, 100)
55 43
56 namespace storage { 44 namespace storage {
57 45
58 namespace { 46 namespace {
59 47
60 const int64_t kMBytes = 1024 * 1024; 48 const int64_t kMBytes = 1024 * 1024;
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 profile_path_(profile_path), 871 profile_path_(profile_path),
884 proxy_(new QuotaManagerProxy(this, io_thread)), 872 proxy_(new QuotaManagerProxy(this, io_thread)),
885 db_disabled_(false), 873 db_disabled_(false),
886 eviction_disabled_(false), 874 eviction_disabled_(false),
887 io_thread_(io_thread), 875 io_thread_(io_thread),
888 db_thread_(db_thread), 876 db_thread_(db_thread),
889 is_getting_eviction_origin_(false), 877 is_getting_eviction_origin_(false),
890 temporary_quota_initialized_(false), 878 temporary_quota_initialized_(false),
891 temporary_quota_override_(-1), 879 temporary_quota_override_(-1),
892 special_storage_policy_(special_storage_policy), 880 special_storage_policy_(special_storage_policy),
893 get_volume_info_fn_(&QuotaManager::GetVolumeInfo), 881 get_volume_info_fn_(&base::SysInfo::GetDiskSpaceInfo),
894 storage_monitor_(new StorageMonitor(this)), 882 storage_monitor_(new StorageMonitor(this)),
895 weak_factory_(this) {} 883 weak_factory_(this) {}
896 884
897 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 885 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
898 LazyInitialize(); 886 LazyInitialize();
899 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 887 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
900 get_usage_info->Start(); 888 get_usage_info->Start();
901 } 889 }
902 890
903 void QuotaManager::GetUsageAndQuotaForWebApps( 891 void QuotaManager::GetUsageAndQuotaForWebApps(
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 GetUsageTracker(kStorageTypeTemporary) 1647 GetUsageTracker(kStorageTypeTemporary)
1660 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); 1648 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
1661 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); 1649 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
1662 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); 1650 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
1663 dispatcher->WaitForResults(callback); 1651 dispatcher->WaitForResults(callback);
1664 } 1652 }
1665 1653
1666 void QuotaManager::AsyncGetVolumeInfo( 1654 void QuotaManager::AsyncGetVolumeInfo(
1667 const VolumeInfoCallback& callback) { 1655 const VolumeInfoCallback& callback) {
1668 DCHECK(io_thread_->BelongsToCurrentThread()); 1656 DCHECK(io_thread_->BelongsToCurrentThread());
1669 uint64_t* available_space = new uint64_t(0); 1657 int64_t* available_space = new int64_t(0);
1670 uint64_t* total_space = new uint64_t(0); 1658 int64_t* total_space = new int64_t(0);
1671 PostTaskAndReplyWithResult( 1659 PostTaskAndReplyWithResult(
1672 db_thread_.get(), 1660 db_thread_.get(),
1673 FROM_HERE, 1661 FROM_HERE,
1674 base::Bind(get_volume_info_fn_, 1662 base::Bind(get_volume_info_fn_,
1675 profile_path_, 1663 profile_path_,
1676 base::Unretained(available_space), 1664 base::Unretained(available_space),
1677 base::Unretained(total_space)), 1665 base::Unretained(total_space)),
1678 base::Bind(&QuotaManager::DidGetVolumeInfo, 1666 base::Bind(&QuotaManager::DidGetVolumeInfo,
1679 weak_factory_.GetWeakPtr(), 1667 weak_factory_.GetWeakPtr(),
1680 callback, 1668 callback,
1681 base::Owned(available_space), 1669 base::Owned(available_space),
1682 base::Owned(total_space))); 1670 base::Owned(total_space)));
1683 } 1671 }
1684 1672
1685 void QuotaManager::DidGetVolumeInfo( 1673 void QuotaManager::DidGetVolumeInfo(
1686 const VolumeInfoCallback& callback, 1674 const VolumeInfoCallback& callback,
1687 uint64_t* available_space, uint64_t* total_space, bool success) { 1675 int64_t* available_space, int64_t* total_space, bool success) {
1688 DCHECK(io_thread_->BelongsToCurrentThread()); 1676 DCHECK(io_thread_->BelongsToCurrentThread());
1689 callback.Run(success, *available_space, *total_space); 1677 callback.Run(success, *available_space, *total_space);
1690 } 1678 }
1691 1679
1692 void QuotaManager::GetLRUOrigin(StorageType type, 1680 void QuotaManager::GetLRUOrigin(StorageType type,
1693 const GetOriginCallback& callback) { 1681 const GetOriginCallback& callback) {
1694 LazyInitialize(); 1682 LazyInitialize();
1695 // This must not be called while there's an in-flight task. 1683 // This must not be called while there's an in-flight task.
1696 DCHECK(lru_origin_callback_.is_null()); 1684 DCHECK(lru_origin_callback_.is_null());
1697 lru_origin_callback_ = callback; 1685 lru_origin_callback_ = callback;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 // static 1826 // static
1839 int64_t QuotaManager::CallGetAmountOfFreeDiskSpace( 1827 int64_t QuotaManager::CallGetAmountOfFreeDiskSpace(
1840 GetVolumeInfoFn get_volume_info_fn, 1828 GetVolumeInfoFn get_volume_info_fn,
1841 const base::FilePath& profile_path) { 1829 const base::FilePath& profile_path) {
1842 // crbug.com/349708 1830 // crbug.com/349708
1843 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace"); 1831 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace");
1844 if (!base::CreateDirectory(profile_path)) { 1832 if (!base::CreateDirectory(profile_path)) {
1845 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); 1833 LOG(WARNING) << "Create directory failed for path" << profile_path.value();
1846 return 0; 1834 return 0;
1847 } 1835 }
1848 uint64_t available, total; 1836 int64_t available, total;
Lei Zhang 2016/06/10 05:46:37 style: One variable declaration per line please.
fukino 2016/06/10 12:10:09 In the new patch, this line doesn't need to be cha
1849 if (!get_volume_info_fn(profile_path, &available, &total)) { 1837 if (!get_volume_info_fn(profile_path, &available, &total)) {
1850 return 0; 1838 return 0;
1851 } 1839 }
1852 UMA_HISTOGRAM_MBYTES("Quota.AvailableDiskSpace", available); 1840 UMA_HISTOGRAM_MBYTES("Quota.AvailableDiskSpace", available);
1853 UMA_HISTOGRAM_MBYTES("Quota.TotalDiskSpace", total); 1841 UMA_HISTOGRAM_MBYTES("Quota.TotalDiskSpace", total);
1854 return static_cast<int64_t>(available); 1842 return static_cast<int64_t>(available);
1855 } 1843 }
1856 1844
1857 //static
1858 bool QuotaManager::GetVolumeInfo(const base::FilePath& path,
1859 uint64_t* available_space,
1860 uint64_t* total_size) {
1861 // Inspired by similar code in the base::SysInfo class.
1862 base::ThreadRestrictions::AssertIOAllowed();
1863 #if defined(OS_WIN)
1864 ULARGE_INTEGER available, total, free;
1865 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free))
1866 return false;
1867 *available_space = static_cast<uint64_t>(available.QuadPart);
1868 *total_size = static_cast<uint64_t>(total.QuadPart);
1869 #elif defined(OS_POSIX)
1870 struct statvfs stats;
1871 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
1872 return false;
1873 *available_space = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize;
1874 *total_size = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize;
1875 #else
1876 #error Not implemented
1877 #endif
1878 return true;
1879 }
1880
1881 } // namespace storage 1845 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698