OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/quota/quota_manager.h" | 5 #include "webkit/quota/quota_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; | 71 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; |
72 | 72 |
73 const int QuotaManager::kEvictionIntervalInMilliSeconds = | 73 const int QuotaManager::kEvictionIntervalInMilliSeconds = |
74 30 * kMinutesInMilliSeconds; | 74 30 * kMinutesInMilliSeconds; |
75 | 75 |
76 // Callback translators. | 76 // Callback translators. |
77 void CallGetUsageAndQuotaCallback( | 77 void CallGetUsageAndQuotaCallback( |
78 const QuotaManager::GetUsageAndQuotaCallback& callback, | 78 const QuotaManager::GetUsageAndQuotaCallback& callback, |
79 bool unlimited, | 79 bool unlimited, |
| 80 bool is_installed_app, |
80 QuotaStatusCode status, | 81 QuotaStatusCode status, |
81 const QuotaAndUsage& quota_and_usage) { | 82 const QuotaAndUsage& quota_and_usage) { |
82 int64 usage = | 83 int64 usage; |
83 unlimited ? quota_and_usage.unlimited_usage : quota_and_usage.usage; | 84 int64 quota; |
84 int64 quota = unlimited ? QuotaManager::kNoLimit : quota_and_usage.quota; | 85 |
| 86 if (unlimited) { |
| 87 usage = quota_and_usage.unlimited_usage; |
| 88 quota = is_installed_app ? quota_and_usage.available_disk_space : |
| 89 QuotaManager::kNoLimit; |
| 90 } else { |
| 91 usage = quota_and_usage.usage; |
| 92 quota = quota_and_usage.quota; |
| 93 } |
| 94 |
85 callback.Run(status, usage, quota); | 95 callback.Run(status, usage, quota); |
86 } | 96 } |
87 | 97 |
88 void CallQuotaCallback( | 98 void CallQuotaCallback( |
89 const QuotaCallback& callback, | 99 const QuotaCallback& callback, |
90 StorageType type, | 100 StorageType type, |
91 QuotaStatusCode status, | 101 QuotaStatusCode status, |
92 const QuotaAndUsage& quota_and_usage) { | 102 const QuotaAndUsage& quota_and_usage) { |
93 callback.Run(status, type, quota_and_usage.quota); | 103 callback.Run(status, type, quota_and_usage.quota); |
94 } | 104 } |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 UsageAndQuotaDispatcherTaskForPersistent( | 409 UsageAndQuotaDispatcherTaskForPersistent( |
400 QuotaManager* manager, const HostAndType& host_and_type) | 410 QuotaManager* manager, const HostAndType& host_and_type) |
401 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} | 411 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} |
402 | 412 |
403 protected: | 413 protected: |
404 virtual void RunBody() OVERRIDE { | 414 virtual void RunBody() OVERRIDE { |
405 manager()->persistent_usage_tracker_->GetHostUsage( | 415 manager()->persistent_usage_tracker_->GetHostUsage( |
406 host(), NewWaitableHostUsageCallback()); | 416 host(), NewWaitableHostUsageCallback()); |
407 manager()->GetPersistentHostQuota( | 417 manager()->GetPersistentHostQuota( |
408 host(), NewWaitableHostQuotaCallback()); | 418 host(), NewWaitableHostQuotaCallback()); |
| 419 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); |
409 } | 420 } |
410 | 421 |
411 virtual void DispatchCallbacks() OVERRIDE { | 422 virtual void DispatchCallbacks() OVERRIDE { |
412 CallCallbacksAndClear(quota_status(), | 423 CallCallbacksAndClear(quota_status(), |
413 host_usage(), host_usage(), host_quota(), | 424 host_usage(), host_usage(), host_quota(), |
414 available_space()); | 425 available_space()); |
415 } | 426 } |
416 }; | 427 }; |
417 | 428 |
418 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal | 429 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 }; | 961 }; |
951 | 962 |
952 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask { | 963 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask { |
953 public: | 964 public: |
954 AvailableSpaceQueryTask( | 965 AvailableSpaceQueryTask( |
955 QuotaManager* manager, | 966 QuotaManager* manager, |
956 const AvailableSpaceCallback& callback) | 967 const AvailableSpaceCallback& callback) |
957 : QuotaThreadTask(manager, manager->db_thread_), | 968 : QuotaThreadTask(manager, manager->db_thread_), |
958 profile_path_(manager->profile_path_), | 969 profile_path_(manager->profile_path_), |
959 space_(-1), | 970 space_(-1), |
| 971 get_disk_space_fn_(manager->get_disk_space_fn_), |
960 callback_(callback) { | 972 callback_(callback) { |
| 973 DCHECK(get_disk_space_fn_); |
961 } | 974 } |
962 | 975 |
963 protected: | 976 protected: |
964 virtual ~AvailableSpaceQueryTask() {} | 977 virtual ~AvailableSpaceQueryTask() {} |
965 | 978 |
966 // QuotaThreadTask: | 979 // QuotaThreadTask: |
967 virtual void RunOnTargetThread() OVERRIDE { | 980 virtual void RunOnTargetThread() OVERRIDE { |
968 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); | 981 space_ = get_disk_space_fn_(profile_path_); |
969 } | 982 } |
970 | 983 |
971 virtual void Aborted() OVERRIDE { | 984 virtual void Aborted() OVERRIDE { |
972 callback_.Reset(); | 985 callback_.Reset(); |
973 } | 986 } |
974 | 987 |
975 virtual void Completed() OVERRIDE { | 988 virtual void Completed() OVERRIDE { |
976 callback_.Run(kQuotaStatusOk, space_); | 989 callback_.Run(kQuotaStatusOk, space_); |
977 } | 990 } |
978 | 991 |
979 private: | 992 private: |
980 FilePath profile_path_; | 993 FilePath profile_path_; |
981 int64 space_; | 994 int64 space_; |
| 995 GetAvailableDiskSpaceFn get_disk_space_fn_; |
982 AvailableSpaceCallback callback_; | 996 AvailableSpaceCallback callback_; |
983 }; | 997 }; |
984 | 998 |
985 class QuotaManager::UpdateAccessTimeTask | 999 class QuotaManager::UpdateAccessTimeTask |
986 : public QuotaManager::DatabaseTaskBase { | 1000 : public QuotaManager::DatabaseTaskBase { |
987 public: | 1001 public: |
988 UpdateAccessTimeTask( | 1002 UpdateAccessTimeTask( |
989 QuotaManager* manager, | 1003 QuotaManager* manager, |
990 const GURL& origin, | 1004 const GURL& origin, |
991 StorageType type, | 1005 StorageType type, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 proxy_(new QuotaManagerProxy( | 1207 proxy_(new QuotaManagerProxy( |
1194 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), | 1208 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), |
1195 db_disabled_(false), | 1209 db_disabled_(false), |
1196 eviction_disabled_(false), | 1210 eviction_disabled_(false), |
1197 io_thread_(io_thread), | 1211 io_thread_(io_thread), |
1198 db_thread_(db_thread), | 1212 db_thread_(db_thread), |
1199 temporary_quota_initialized_(false), | 1213 temporary_quota_initialized_(false), |
1200 temporary_quota_override_(-1), | 1214 temporary_quota_override_(-1), |
1201 desired_available_space_(-1), | 1215 desired_available_space_(-1), |
1202 special_storage_policy_(special_storage_policy), | 1216 special_storage_policy_(special_storage_policy), |
1203 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 1217 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 1218 get_disk_space_fn_(&base::SysInfo::AmountOfFreeDiskSpace) { |
1204 } | 1219 } |
1205 | 1220 |
1206 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { | 1221 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { |
1207 LazyInitialize(); | 1222 LazyInitialize(); |
1208 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); | 1223 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); |
1209 get_usage_info->Start(); | 1224 get_usage_info->Start(); |
1210 } | 1225 } |
1211 | 1226 |
1212 void QuotaManager::GetUsageAndQuota( | 1227 void QuotaManager::GetUsageAndQuota( |
1213 const GURL& origin, StorageType type, | 1228 const GURL& origin, StorageType type, |
1214 const GetUsageAndQuotaCallback& callback) { | 1229 const GetUsageAndQuotaCallback& callback) { |
1215 GetUsageAndQuotaInternal(origin, type, false /* global */, | 1230 GetUsageAndQuotaInternal( |
1216 base::Bind(&CallGetUsageAndQuotaCallback, | 1231 origin, type, false /* global */, |
1217 callback, IsStorageUnlimited(origin))); | 1232 base::Bind(&CallGetUsageAndQuotaCallback, callback, |
| 1233 IsStorageUnlimited(origin), IsInstalledApp(origin))); |
1218 } | 1234 } |
1219 | 1235 |
1220 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { | 1236 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { |
1221 if (is_incognito_) { | 1237 if (is_incognito_) { |
1222 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota); | 1238 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota); |
1223 return; | 1239 return; |
1224 } | 1240 } |
1225 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start(); | 1241 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start(); |
1226 } | 1242 } |
1227 | 1243 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 | 1850 |
1835 QuotaManagerProxy::QuotaManagerProxy( | 1851 QuotaManagerProxy::QuotaManagerProxy( |
1836 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1852 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
1837 : manager_(manager), io_thread_(io_thread) { | 1853 : manager_(manager), io_thread_(io_thread) { |
1838 } | 1854 } |
1839 | 1855 |
1840 QuotaManagerProxy::~QuotaManagerProxy() { | 1856 QuotaManagerProxy::~QuotaManagerProxy() { |
1841 } | 1857 } |
1842 | 1858 |
1843 } // namespace quota | 1859 } // namespace quota |
OLD | NEW |