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

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: 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
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const FilePath& path,
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 unlimited ? quota_and_usage.unlimited_usage : quota_and_usage.usage;
84 int64 quota = unlimited ? QuotaManager::kNoLimit : quota_and_usage.quota; 85 printf("unlimited: %d\n", unlimited);
86 int64 quota = unlimited ? quota_and_usage.available_disk_space :
kinuko 2012/08/13 14:07:52 (You might be changing this but to make sure) I th
James Hawkins 2012/08/17 21:33:22 I'm attempting to add support for this check now,
87 quota_and_usage.quota;
88 printf("quota: %ld\n", quota);
85 callback.Run(status, usage, quota); 89 callback.Run(status, usage, quota);
86 } 90 }
87 91
88 void CallQuotaCallback( 92 void CallQuotaCallback(
89 const QuotaCallback& callback, 93 const QuotaCallback& callback,
90 StorageType type, 94 StorageType type,
91 QuotaStatusCode status, 95 QuotaStatusCode status,
92 const QuotaAndUsage& quota_and_usage) { 96 const QuotaAndUsage& quota_and_usage) {
93 callback.Run(status, type, quota_and_usage.quota); 97 callback.Run(status, type, quota_and_usage.quota);
94 } 98 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 UsageAndQuotaDispatcherTaskForPersistent( 403 UsageAndQuotaDispatcherTaskForPersistent(
400 QuotaManager* manager, const HostAndType& host_and_type) 404 QuotaManager* manager, const HostAndType& host_and_type)
401 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} 405 : UsageAndQuotaDispatcherTask(manager, host_and_type) {}
402 406
403 protected: 407 protected:
404 virtual void RunBody() OVERRIDE { 408 virtual void RunBody() OVERRIDE {
405 manager()->persistent_usage_tracker_->GetHostUsage( 409 manager()->persistent_usage_tracker_->GetHostUsage(
406 host(), NewWaitableHostUsageCallback()); 410 host(), NewWaitableHostUsageCallback());
407 manager()->GetPersistentHostQuota( 411 manager()->GetPersistentHostQuota(
408 host(), NewWaitableHostQuotaCallback()); 412 host(), NewWaitableHostQuotaCallback());
413 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback());
409 } 414 }
410 415
411 virtual void DispatchCallbacks() OVERRIDE { 416 virtual void DispatchCallbacks() OVERRIDE {
412 CallCallbacksAndClear(quota_status(), 417 CallCallbacksAndClear(quota_status(),
413 host_usage(), host_usage(), host_quota(), 418 host_usage(), host_usage(), host_quota(),
414 available_space()); 419 available_space());
415 } 420 }
416 }; 421 };
417 422
418 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal 423 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 std::set<GURL> origins_; 953 std::set<GURL> origins_;
949 bool has_registered_origins_; 954 bool has_registered_origins_;
950 }; 955 };
951 956
952 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask { 957 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask {
953 public: 958 public:
954 AvailableSpaceQueryTask( 959 AvailableSpaceQueryTask(
955 QuotaManager* manager, 960 QuotaManager* manager,
956 const AvailableSpaceCallback& callback) 961 const AvailableSpaceCallback& callback)
957 : QuotaThreadTask(manager, manager->db_thread_), 962 : QuotaThreadTask(manager, manager->db_thread_),
958 profile_path_(manager->profile_path_), 963 quota_manager_(manager),
959 space_(-1), 964 space_(-1),
960 callback_(callback) { 965 callback_(callback) {
961 } 966 }
962 967
963 protected: 968 protected:
964 virtual ~AvailableSpaceQueryTask() {} 969 virtual ~AvailableSpaceQueryTask() {}
965 970
966 // QuotaThreadTask: 971 // QuotaThreadTask:
967 virtual void RunOnTargetThread() OVERRIDE { 972 virtual void RunOnTargetThread() OVERRIDE {
968 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); 973 space_ = quota_manager_->GetAvailableDiskSpace();
969 } 974 }
970 975
971 virtual void Aborted() OVERRIDE { 976 virtual void Aborted() OVERRIDE {
972 callback_.Reset(); 977 callback_.Reset();
973 } 978 }
974 979
975 virtual void Completed() OVERRIDE { 980 virtual void Completed() OVERRIDE {
976 callback_.Run(kQuotaStatusOk, space_); 981 callback_.Run(kQuotaStatusOk, space_);
977 } 982 }
978 983
979 private: 984 private:
980 FilePath profile_path_; 985 scoped_refptr<QuotaManager> quota_manager_;
981 int64 space_; 986 int64 space_;
982 AvailableSpaceCallback callback_; 987 AvailableSpaceCallback callback_;
983 }; 988 };
984 989
985 class QuotaManager::UpdateAccessTimeTask 990 class QuotaManager::UpdateAccessTimeTask
986 : public QuotaManager::DatabaseTaskBase { 991 : public QuotaManager::DatabaseTaskBase {
987 public: 992 public:
988 UpdateAccessTimeTask( 993 UpdateAccessTimeTask(
989 QuotaManager* manager, 994 QuotaManager* manager,
990 const GURL& origin, 995 const GURL& origin,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1210
1206 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 1211 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
1207 LazyInitialize(); 1212 LazyInitialize();
1208 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 1213 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
1209 get_usage_info->Start(); 1214 get_usage_info->Start();
1210 } 1215 }
1211 1216
1212 void QuotaManager::GetUsageAndQuota( 1217 void QuotaManager::GetUsageAndQuota(
1213 const GURL& origin, StorageType type, 1218 const GURL& origin, StorageType type,
1214 const GetUsageAndQuotaCallback& callback) { 1219 const GetUsageAndQuotaCallback& callback) {
1215 GetUsageAndQuotaInternal(origin, type, false /* global */, 1220 GetUsageAndQuotaInternal(
1216 base::Bind(&CallGetUsageAndQuotaCallback, 1221 origin, type, false /* global */,
1217 callback, IsStorageUnlimited(origin))); 1222 base::Bind(&CallGetUsageAndQuotaCallback, callback,
1223 IsStorageUnlimited(origin), profile_path_));
1218 } 1224 }
1219 1225
1220 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { 1226 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
1221 if (is_incognito_) { 1227 if (is_incognito_) {
1222 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota); 1228 callback.Run(kQuotaStatusOk, kIncognitoDefaultTemporaryQuota);
1223 return; 1229 return;
1224 } 1230 }
1225 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start(); 1231 make_scoped_refptr(new AvailableSpaceQueryTask(this, callback))->Start();
1226 } 1232 }
1227 1233
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1333
1328 void QuotaManager::GetOriginsModifiedSince(StorageType type, 1334 void QuotaManager::GetOriginsModifiedSince(StorageType type,
1329 base::Time modified_since, 1335 base::Time modified_since,
1330 const GetOriginsCallback& callback) { 1336 const GetOriginsCallback& callback) {
1331 LazyInitialize(); 1337 LazyInitialize();
1332 make_scoped_refptr(new GetModifiedSinceTask( 1338 make_scoped_refptr(new GetModifiedSinceTask(
1333 this, type, modified_since, callback))->Start(); 1339 this, type, modified_since, callback))->Start();
1334 } 1340 }
1335 1341
1336 QuotaManager::~QuotaManager() { 1342 QuotaManager::~QuotaManager() {
1343 printf("~QuotaManager\n");
1337 proxy_->manager_ = NULL; 1344 proxy_->manager_ = NULL;
1338 std::for_each(clients_.begin(), clients_.end(), 1345 std::for_each(clients_.begin(), clients_.end(),
1339 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); 1346 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed));
1340 if (database_.get()) 1347 if (database_.get())
1341 db_thread_->DeleteSoon(FROM_HERE, database_.release()); 1348 db_thread_->DeleteSoon(FROM_HERE, database_.release());
1342 } 1349 }
1343 1350
1351 int64 QuotaManager::GetAvailableDiskSpace() const {
1352 return base::SysInfo::AmountOfFreeDiskSpace(profile_path_);
kinuko 2012/08/13 14:07:52 Hmm. How about using a static function pointer (w
1353 }
1354
1344 void QuotaManager::LazyInitialize() { 1355 void QuotaManager::LazyInitialize() {
1345 DCHECK(io_thread_->BelongsToCurrentThread()); 1356 DCHECK(io_thread_->BelongsToCurrentThread());
1346 if (database_.get()) { 1357 if (database_.get()) {
1347 // Initialization seems to be done already. 1358 // Initialization seems to be done already.
1348 return; 1359 return;
1349 } 1360 }
1350 1361
1351 // Use an empty path to open an in-memory only databse for incognito. 1362 // Use an empty path to open an in-memory only databse for incognito.
1352 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() : 1363 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() :
1353 profile_path_.AppendASCII(kDatabaseName))); 1364 profile_path_.AppendASCII(kDatabaseName)));
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 1838
1828 QuotaManagerProxy::QuotaManagerProxy( 1839 QuotaManagerProxy::QuotaManagerProxy(
1829 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) 1840 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread)
1830 : manager_(manager), io_thread_(io_thread) { 1841 : manager_(manager), io_thread_(io_thread) {
1831 } 1842 }
1832 1843
1833 QuotaManagerProxy::~QuotaManagerProxy() { 1844 QuotaManagerProxy::~QuotaManagerProxy() {
1834 } 1845 }
1835 1846
1836 } // namespace quota 1847 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698