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

Side by Side Diff: webkit/quota/quota_manager.cc

Issue 10826270: QuotaManager: Return the remaining free disk space as quota. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup 2. Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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
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 kint64max;
kinuko 2012/08/20 04:04:44 nit: kint64max -> kNoLimit since that's what we ch
James Hawkins 2012/08/22 18:51:36 Done.
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
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
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) {
kinuko 2012/08/20 04:04:44 nit: maybe DCHECK(get_disk_space_fn) here?
James Hawkins 2012/08/22 18:51:36 Done.
961 } 973 }
962 974
963 protected: 975 protected:
964 virtual ~AvailableSpaceQueryTask() {} 976 virtual ~AvailableSpaceQueryTask() {}
965 977
966 // QuotaThreadTask: 978 // QuotaThreadTask:
967 virtual void RunOnTargetThread() OVERRIDE { 979 virtual void RunOnTargetThread() OVERRIDE {
968 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); 980 space_ = get_disk_space_fn_(profile_path_);
969 } 981 }
970 982
971 virtual void Aborted() OVERRIDE { 983 virtual void Aborted() OVERRIDE {
972 callback_.Reset(); 984 callback_.Reset();
973 } 985 }
974 986
975 virtual void Completed() OVERRIDE { 987 virtual void Completed() OVERRIDE {
976 callback_.Run(kQuotaStatusOk, space_); 988 callback_.Run(kQuotaStatusOk, space_);
977 } 989 }
978 990
979 private: 991 private:
980 FilePath profile_path_; 992 FilePath profile_path_;
981 int64 space_; 993 int64 space_;
994 GetAvailableDiskSpaceFn get_disk_space_fn_;
982 AvailableSpaceCallback callback_; 995 AvailableSpaceCallback callback_;
983 }; 996 };
984 997
985 class QuotaManager::UpdateAccessTimeTask 998 class QuotaManager::UpdateAccessTimeTask
986 : public QuotaManager::DatabaseTaskBase { 999 : public QuotaManager::DatabaseTaskBase {
987 public: 1000 public:
988 UpdateAccessTimeTask( 1001 UpdateAccessTimeTask(
989 QuotaManager* manager, 1002 QuotaManager* manager,
990 const GURL& origin, 1003 const GURL& origin,
991 StorageType type, 1004 StorageType type,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 proxy_(new QuotaManagerProxy( 1206 proxy_(new QuotaManagerProxy(
1194 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), 1207 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)),
1195 db_disabled_(false), 1208 db_disabled_(false),
1196 eviction_disabled_(false), 1209 eviction_disabled_(false),
1197 io_thread_(io_thread), 1210 io_thread_(io_thread),
1198 db_thread_(db_thread), 1211 db_thread_(db_thread),
1199 temporary_quota_initialized_(false), 1212 temporary_quota_initialized_(false),
1200 temporary_quota_override_(-1), 1213 temporary_quota_override_(-1),
1201 desired_available_space_(-1), 1214 desired_available_space_(-1),
1202 special_storage_policy_(special_storage_policy), 1215 special_storage_policy_(special_storage_policy),
1203 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 1216 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
1217 get_disk_space_fn_(&base::SysInfo::AmountOfFreeDiskSpace) {
1204 } 1218 }
1205 1219
1206 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 1220 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
1207 LazyInitialize(); 1221 LazyInitialize();
1208 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 1222 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
1209 get_usage_info->Start(); 1223 get_usage_info->Start();
1210 } 1224 }
1211 1225
1212 void QuotaManager::GetUsageAndQuota( 1226 void QuotaManager::GetUsageAndQuota(
1213 const GURL& origin, StorageType type, 1227 const GURL& origin, StorageType type,
1214 const GetUsageAndQuotaCallback& callback) { 1228 const GetUsageAndQuotaCallback& callback) {
1215 GetUsageAndQuotaInternal(origin, type, false /* global */, 1229 GetUsageAndQuotaInternal(
1216 base::Bind(&CallGetUsageAndQuotaCallback, 1230 origin, type, false /* global */,
1217 callback, IsStorageUnlimited(origin))); 1231 base::Bind(&CallGetUsageAndQuotaCallback, callback,
1232 IsStorageUnlimited(origin), IsInstalledApp(origin)));
1218 } 1233 }
1219 1234
1220 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { 1235 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
1221 if (is_incognito_) { 1236 if (is_incognito_) {
1222 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota); 1237 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota);
1223 return; 1238 return;
1224 } 1239 }
1225 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start(); 1240 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start();
1226 } 1241 }
1227 1242
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 1849
1835 QuotaManagerProxy::QuotaManagerProxy( 1850 QuotaManagerProxy::QuotaManagerProxy(
1836 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) 1851 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread)
1837 : manager_(manager), io_thread_(io_thread) { 1852 : manager_(manager), io_thread_(io_thread) {
1838 } 1853 }
1839 1854
1840 QuotaManagerProxy::~QuotaManagerProxy() { 1855 QuotaManagerProxy::~QuotaManagerProxy() {
1841 } 1856 }
1842 1857
1843 } // namespace quota 1858 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698