| 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 18 matching lines...) Expand all Loading... |
| 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 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 1845 //static |
| 1858 bool QuotaManager::GetVolumeInfo(const base::FilePath& path, | 1846 bool QuotaManager::GetVolumeInfo(const base::FilePath& path, |
| 1859 uint64_t* available_space, | 1847 uint64_t* available_space, |
| 1860 uint64_t* total_size) { | 1848 uint64_t* total_size) { |
| 1861 // Inspired by similar code in the base::SysInfo class. | 1849 // Inspired by similar code in the base::SysInfo class. |
| 1862 base::ThreadRestrictions::AssertIOAllowed(); | 1850 base::ThreadRestrictions::AssertIOAllowed(); |
| 1863 #if defined(OS_WIN) | 1851 |
| 1864 ULARGE_INTEGER available, total, free; | 1852 int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path); |
| 1865 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) | 1853 if (available < 0) |
| 1866 return false; | 1854 return false; |
| 1867 *available_space = static_cast<uint64_t>(available.QuadPart); | 1855 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(path); |
| 1868 *total_size = static_cast<uint64_t>(total.QuadPart); | 1856 if (total < 0) |
| 1869 #elif defined(OS_POSIX) | |
| 1870 struct statvfs stats; | |
| 1871 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | |
| 1872 return false; | 1857 return false; |
| 1873 *available_space = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize; | 1858 |
| 1874 *total_size = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize; | 1859 *available_space = static_cast<uint64_t>(available); |
| 1875 #else | 1860 *total_size = static_cast<uint64_t>(total); |
| 1876 #error Not implemented | |
| 1877 #endif | |
| 1878 return true; | 1861 return true; |
| 1879 } | 1862 } |
| 1880 | 1863 |
| 1881 } // namespace storage | 1864 } // namespace storage |
| OLD | NEW |