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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 229 |
230 void DidGetHostUsage(const std::string& host, StorageType type, int64 usage) { | 230 void DidGetHostUsage(const std::string& host, StorageType type, int64 usage) { |
231 DCHECK_EQ(this->host(), host); | 231 DCHECK_EQ(this->host(), host); |
232 DCHECK_EQ(this->type(), type); | 232 DCHECK_EQ(this->type(), type); |
233 if (quota_status_ == kQuotaStatusUnknown) | 233 if (quota_status_ == kQuotaStatusUnknown) |
234 quota_status_ = kQuotaStatusOk; | 234 quota_status_ = kQuotaStatusOk; |
235 host_usage_ = usage; | 235 host_usage_ = usage; |
236 CheckCompleted(); | 236 CheckCompleted(); |
237 } | 237 } |
238 | 238 |
239 void DidGetHostQuota(QuotaStatusCode status, | 239 void DidGetHostQuota(const std::string& host, |
240 const std::string& host, | |
241 StorageType type, | 240 StorageType type, |
| 241 QuotaStatusCode status, |
242 int64 host_quota) { | 242 int64 host_quota) { |
243 DCHECK_EQ(this->host(), host); | 243 DCHECK_EQ(this->host(), host); |
244 DCHECK_EQ(this->type(), type); | 244 DCHECK_EQ(this->type(), type); |
245 if (quota_status_ == kQuotaStatusUnknown || quota_status_ == kQuotaStatusOk) | 245 if (quota_status_ == kQuotaStatusUnknown || quota_status_ == kQuotaStatusOk) |
246 quota_status_ = status; | 246 quota_status_ = status; |
247 host_quota_ = host_quota; | 247 host_quota_ = host_quota; |
248 CheckCompleted(); | 248 CheckCompleted(); |
249 } | 249 } |
250 | 250 |
251 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { | 251 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 weak_factory_.GetWeakPtr()); | 355 weak_factory_.GetWeakPtr()); |
356 } | 356 } |
357 UsageCallback NewWaitableHostUsageCallback() { | 357 UsageCallback NewWaitableHostUsageCallback() { |
358 ++waiting_callbacks_; | 358 ++waiting_callbacks_; |
359 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, | 359 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, |
360 weak_factory_.GetWeakPtr(), host(), type()); | 360 weak_factory_.GetWeakPtr(), host(), type()); |
361 } | 361 } |
362 HostQuotaCallback NewWaitableHostQuotaCallback() { | 362 HostQuotaCallback NewWaitableHostQuotaCallback() { |
363 ++waiting_callbacks_; | 363 ++waiting_callbacks_; |
364 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, | 364 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, |
365 weak_factory_.GetWeakPtr()); | 365 weak_factory_.GetWeakPtr(), host(), type()); |
366 } | 366 } |
367 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { | 367 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { |
368 ++waiting_callbacks_; | 368 ++waiting_callbacks_; |
369 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, | 369 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, |
370 weak_factory_.GetWeakPtr()); | 370 weak_factory_.GetWeakPtr()); |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 private: | 374 private: |
375 void CheckCompleted() { | 375 void CheckCompleted() { |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 base::Owned(new_quota_ptr))); | 1013 base::Owned(new_quota_ptr))); |
1014 } | 1014 } |
1015 | 1015 |
1016 void QuotaManager::GetPersistentHostQuota(const std::string& host, | 1016 void QuotaManager::GetPersistentHostQuota(const std::string& host, |
1017 const HostQuotaCallback& callback) { | 1017 const HostQuotaCallback& callback) { |
1018 LazyInitialize(); | 1018 LazyInitialize(); |
1019 if (host.empty()) { | 1019 if (host.empty()) { |
1020 // This could happen if we are called on file:///. | 1020 // This could happen if we are called on file:///. |
1021 // TODO(kinuko) We may want to respect --allow-file-access-from-files | 1021 // TODO(kinuko) We may want to respect --allow-file-access-from-files |
1022 // command line switch. | 1022 // command line switch. |
1023 callback.Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); | 1023 callback.Run(kQuotaStatusOk, 0); |
1024 return; | 1024 return; |
1025 } | 1025 } |
1026 | 1026 |
1027 int64* quota_ptr = new int64(0); | 1027 int64* quota_ptr = new int64(0); |
1028 PostTaskAndReplyWithResultForDBThread( | 1028 PostTaskAndReplyWithResultForDBThread( |
1029 FROM_HERE, | 1029 FROM_HERE, |
1030 base::Bind(&GetPersistentHostQuotaOnDBThread, | 1030 base::Bind(&GetPersistentHostQuotaOnDBThread, |
1031 host, | 1031 host, |
1032 base::Unretained(quota_ptr)), | 1032 base::Unretained(quota_ptr)), |
1033 base::Bind(&QuotaManager::DidGetPersistentHostQuota, | 1033 base::Bind(&QuotaManager::DidGetPersistentHostQuota, |
1034 weak_factory_.GetWeakPtr(), | 1034 weak_factory_.GetWeakPtr(), |
1035 callback, | 1035 callback, |
1036 host, | 1036 host, |
1037 base::Owned(quota_ptr))); | 1037 base::Owned(quota_ptr))); |
1038 } | 1038 } |
1039 | 1039 |
1040 void QuotaManager::SetPersistentHostQuota(const std::string& host, | 1040 void QuotaManager::SetPersistentHostQuota(const std::string& host, |
1041 int64 new_quota, | 1041 int64 new_quota, |
1042 const HostQuotaCallback& callback) { | 1042 const HostQuotaCallback& callback) { |
1043 LazyInitialize(); | 1043 LazyInitialize(); |
1044 if (host.empty()) { | 1044 if (host.empty()) { |
1045 // This could happen if we are called on file:///. | 1045 // This could happen if we are called on file:///. |
1046 callback.Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); | 1046 callback.Run(kQuotaErrorNotSupported, 0); |
1047 return; | 1047 return; |
1048 } | 1048 } |
1049 if (new_quota < 0) { | 1049 if (new_quota < 0) { |
1050 callback.Run(kQuotaErrorInvalidModification, | 1050 callback.Run(kQuotaErrorInvalidModification, -1); |
1051 host, kStorageTypePersistent, -1); | |
1052 return; | 1051 return; |
1053 } | 1052 } |
1054 | 1053 |
1055 if (db_disabled_) { | 1054 if (db_disabled_) { |
1056 callback.Run(kQuotaErrorInvalidAccess, | 1055 callback.Run(kQuotaErrorInvalidAccess, -1); |
1057 host, kStorageTypePersistent, -1); | |
1058 return; | 1056 return; |
1059 } | 1057 } |
1060 | 1058 |
1061 int64* new_quota_ptr = new int64(new_quota); | 1059 int64* new_quota_ptr = new int64(new_quota); |
1062 PostTaskAndReplyWithResultForDBThread( | 1060 PostTaskAndReplyWithResultForDBThread( |
1063 FROM_HERE, | 1061 FROM_HERE, |
1064 base::Bind(&SetPersistentHostQuotaOnDBThread, | 1062 base::Bind(&SetPersistentHostQuotaOnDBThread, |
1065 host, | 1063 host, |
1066 base::Unretained(new_quota_ptr)), | 1064 base::Unretained(new_quota_ptr)), |
1067 base::Bind(&QuotaManager::DidSetPersistentHostQuota, | 1065 base::Bind(&QuotaManager::DidSetPersistentHostQuota, |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 return; | 1493 return; |
1496 | 1494 |
1497 callback.Run(status, kStorageTypeTemporary, *new_quota); | 1495 callback.Run(status, kStorageTypeTemporary, *new_quota); |
1498 } | 1496 } |
1499 | 1497 |
1500 void QuotaManager::DidGetPersistentHostQuota(const HostQuotaCallback& callback, | 1498 void QuotaManager::DidGetPersistentHostQuota(const HostQuotaCallback& callback, |
1501 const std::string& host, | 1499 const std::string& host, |
1502 const int64* quota, | 1500 const int64* quota, |
1503 bool success) { | 1501 bool success) { |
1504 DidDatabaseWork(success); | 1502 DidDatabaseWork(success); |
1505 callback.Run(kQuotaStatusOk, host, kStorageTypePersistent, *quota); | 1503 callback.Run(kQuotaStatusOk, *quota); |
1506 } | 1504 } |
1507 | 1505 |
1508 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, | 1506 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, |
1509 const HostQuotaCallback& callback, | 1507 const HostQuotaCallback& callback, |
1510 const int64* new_quota, | 1508 const int64* new_quota, |
1511 bool success) { | 1509 bool success) { |
1512 DidDatabaseWork(success); | 1510 DidDatabaseWork(success); |
1513 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, | 1511 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota); |
1514 host, kStorageTypePersistent, *new_quota); | |
1515 } | 1512 } |
1516 | 1513 |
1517 void QuotaManager::DidInitialize(int64* temporary_quota_override, | 1514 void QuotaManager::DidInitialize(int64* temporary_quota_override, |
1518 int64* desired_available_space, | 1515 int64* desired_available_space, |
1519 bool success) { | 1516 bool success) { |
1520 temporary_quota_override_ = *temporary_quota_override; | 1517 temporary_quota_override_ = *temporary_quota_override; |
1521 desired_available_space_ = *desired_available_space; | 1518 desired_available_space_ = *desired_available_space; |
1522 temporary_quota_initialized_ = true; | 1519 temporary_quota_initialized_ = true; |
1523 DidDatabaseWork(success); | 1520 DidDatabaseWork(success); |
1524 | 1521 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 | 1694 |
1698 QuotaManagerProxy::QuotaManagerProxy( | 1695 QuotaManagerProxy::QuotaManagerProxy( |
1699 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1696 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
1700 : manager_(manager), io_thread_(io_thread) { | 1697 : manager_(manager), io_thread_(io_thread) { |
1701 } | 1698 } |
1702 | 1699 |
1703 QuotaManagerProxy::~QuotaManagerProxy() { | 1700 QuotaManagerProxy::~QuotaManagerProxy() { |
1704 } | 1701 } |
1705 | 1702 |
1706 } // namespace quota | 1703 } // namespace quota |
OLD | NEW |