Chromium Code Reviews| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } else { | 184 } else { |
| 185 usage = quota_and_usage.usage; | 185 usage = quota_and_usage.usage; |
| 186 quota = quota_and_usage.quota; | 186 quota = quota_and_usage.quota; |
| 187 } | 187 } |
| 188 | 188 |
| 189 callback.Run(status, usage, quota); | 189 callback.Run(status, usage, quota); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void CallQuotaCallback( | 192 void CallQuotaCallback( |
| 193 const QuotaCallback& callback, | 193 const QuotaCallback& callback, |
| 194 StorageType type, | |
| 195 QuotaStatusCode status, | 194 QuotaStatusCode status, |
| 196 const QuotaAndUsage& quota_and_usage) { | 195 const QuotaAndUsage& quota_and_usage) { |
| 197 callback.Run(status, type, quota_and_usage.quota); | 196 callback.Run(status, quota_and_usage.quota); |
| 198 } | 197 } |
| 199 | 198 |
| 200 // This class is for posting GetUsage/GetQuota tasks, gathering | 199 // This class is for posting GetUsage/GetQuota tasks, gathering |
| 201 // results and dispatching GetAndQuota callbacks. | 200 // results and dispatching GetAndQuota callbacks. |
| 202 // This class is self-destructed. | 201 // This class is self-destructed. |
| 203 class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask { | 202 class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask { |
| 204 public: | 203 public: |
| 205 typedef UsageAndQuotaDispatcherCallback Callback; | 204 typedef UsageAndQuotaDispatcherCallback Callback; |
| 206 typedef std::deque<Callback> CallbackList; | 205 typedef std::deque<Callback> CallbackList; |
| 207 | 206 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 GlobalUsageCallback NewWaitableGlobalUsageCallback() { | 351 GlobalUsageCallback NewWaitableGlobalUsageCallback() { |
| 353 ++waiting_callbacks_; | 352 ++waiting_callbacks_; |
| 354 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage, | 353 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage, |
| 355 weak_factory_.GetWeakPtr()); | 354 weak_factory_.GetWeakPtr()); |
| 356 } | 355 } |
| 357 UsageCallback NewWaitableHostUsageCallback() { | 356 UsageCallback NewWaitableHostUsageCallback() { |
| 358 ++waiting_callbacks_; | 357 ++waiting_callbacks_; |
| 359 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, | 358 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, |
| 360 weak_factory_.GetWeakPtr(), host(), type()); | 359 weak_factory_.GetWeakPtr(), host(), type()); |
| 361 } | 360 } |
| 362 HostQuotaCallback NewWaitableHostQuotaCallback() { | 361 QuotaCallback NewWaitableQuotaCallback() { |
|
kinuko
2012/09/21 08:18:32
Could we preserve this method name (since we're ac
calvinlo
2012/09/21 10:24:01
Done.
| |
| 363 ++waiting_callbacks_; | 362 ++waiting_callbacks_; |
| 364 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, | 363 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, |
| 365 weak_factory_.GetWeakPtr(), host(), type()); | 364 weak_factory_.GetWeakPtr(), host(), type()); |
| 366 } | 365 } |
| 367 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { | 366 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { |
| 368 ++waiting_callbacks_; | 367 ++waiting_callbacks_; |
| 369 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, | 368 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, |
| 370 weak_factory_.GetWeakPtr()); | 369 weak_factory_.GetWeakPtr()); |
| 371 } | 370 } |
| 372 | 371 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 public: | 506 public: |
| 508 UsageAndQuotaDispatcherTaskForPersistent( | 507 UsageAndQuotaDispatcherTaskForPersistent( |
| 509 QuotaManager* manager, const HostAndType& host_and_type) | 508 QuotaManager* manager, const HostAndType& host_and_type) |
| 510 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} | 509 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} |
| 511 | 510 |
| 512 protected: | 511 protected: |
| 513 virtual void RunBody() OVERRIDE { | 512 virtual void RunBody() OVERRIDE { |
| 514 manager()->GetUsageTracker(type())->GetHostUsage( | 513 manager()->GetUsageTracker(type())->GetHostUsage( |
| 515 host(), NewWaitableHostUsageCallback()); | 514 host(), NewWaitableHostUsageCallback()); |
| 516 manager()->GetPersistentHostQuota( | 515 manager()->GetPersistentHostQuota( |
| 517 host(), NewWaitableHostQuotaCallback()); | 516 host(), NewWaitableQuotaCallback()); |
| 518 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); | 517 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); |
| 519 } | 518 } |
| 520 | 519 |
| 521 virtual void DispatchCallbacks() OVERRIDE { | 520 virtual void DispatchCallbacks() OVERRIDE { |
| 522 CallCallbacksAndClear(quota_status(), | 521 CallCallbacksAndClear(quota_status(), |
| 523 host_usage(), host_usage(), host_quota(), | 522 host_usage(), host_usage(), host_quota(), |
| 524 available_space()); | 523 available_space()); |
| 525 } | 524 } |
| 526 }; | 525 }; |
| 527 | 526 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 db_thread_, | 967 db_thread_, |
| 969 FROM_HERE, | 968 FROM_HERE, |
| 970 base::Bind(get_disk_space_fn_, profile_path_), | 969 base::Bind(get_disk_space_fn_, profile_path_), |
| 971 base::Bind(&QuotaManager::DidGetAvailableSpace, | 970 base::Bind(&QuotaManager::DidGetAvailableSpace, |
| 972 weak_factory_.GetWeakPtr(), | 971 weak_factory_.GetWeakPtr(), |
| 973 callback)); | 972 callback)); |
| 974 } | 973 } |
| 975 | 974 |
| 976 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { | 975 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { |
| 977 if (temporary_quota_override_ > 0) { | 976 if (temporary_quota_override_ > 0) { |
| 978 callback.Run(kQuotaStatusOk, kStorageTypeTemporary, | 977 callback.Run(kQuotaStatusOk, temporary_quota_override_); |
| 979 temporary_quota_override_); | |
| 980 return; | 978 return; |
| 981 } | 979 } |
| 982 GetUsageAndQuotaInternal( | 980 GetUsageAndQuotaInternal( |
| 983 GURL(), kStorageTypeTemporary, true /* global */, | 981 GURL(), kStorageTypeTemporary, true /* global */, |
| 984 base::Bind(&CallQuotaCallback, callback, kStorageTypeTemporary)); | 982 base::Bind(&CallQuotaCallback, callback)); |
| 985 } | 983 } |
| 986 | 984 |
| 987 void QuotaManager::SetTemporaryGlobalOverrideQuota( | 985 void QuotaManager::SetTemporaryGlobalOverrideQuota( |
| 988 int64 new_quota, const QuotaCallback& callback) { | 986 int64 new_quota, const QuotaCallback& callback) { |
| 989 LazyInitialize(); | 987 LazyInitialize(); |
| 990 | 988 |
| 991 if (new_quota < 0) { | 989 if (new_quota < 0) { |
| 992 if (!callback.is_null()) | 990 if (!callback.is_null()) |
| 993 callback.Run(kQuotaErrorInvalidModification, | 991 callback.Run(kQuotaErrorInvalidModification, -1); |
| 994 kStorageTypeTemporary, -1); | |
| 995 return; | 992 return; |
| 996 } | 993 } |
| 997 | 994 |
| 998 if (db_disabled_) { | 995 if (db_disabled_) { |
| 999 if (callback.is_null()) | 996 if (callback.is_null()) |
| 1000 callback.Run(kQuotaErrorInvalidAccess, | 997 callback.Run(kQuotaErrorInvalidAccess, -1); |
| 1001 kStorageTypeTemporary, -1); | |
| 1002 return; | 998 return; |
| 1003 } | 999 } |
| 1004 | 1000 |
| 1005 int64* new_quota_ptr = new int64(new_quota); | 1001 int64* new_quota_ptr = new int64(new_quota); |
| 1006 PostTaskAndReplyWithResultForDBThread( | 1002 PostTaskAndReplyWithResultForDBThread( |
| 1007 FROM_HERE, | 1003 FROM_HERE, |
| 1008 base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread, | 1004 base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread, |
| 1009 base::Unretained(new_quota_ptr)), | 1005 base::Unretained(new_quota_ptr)), |
| 1010 base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota, | 1006 base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota, |
| 1011 weak_factory_.GetWeakPtr(), | 1007 weak_factory_.GetWeakPtr(), |
| 1012 callback, | 1008 callback, |
| 1013 base::Owned(new_quota_ptr))); | 1009 base::Owned(new_quota_ptr))); |
| 1014 } | 1010 } |
| 1015 | 1011 |
| 1016 void QuotaManager::GetPersistentHostQuota(const std::string& host, | 1012 void QuotaManager::GetPersistentHostQuota(const std::string& host, |
| 1017 const HostQuotaCallback& callback) { | 1013 const QuotaCallback& callback) { |
| 1018 LazyInitialize(); | 1014 LazyInitialize(); |
| 1019 if (host.empty()) { | 1015 if (host.empty()) { |
| 1020 // This could happen if we are called on file:///. | 1016 // This could happen if we are called on file:///. |
| 1021 // TODO(kinuko) We may want to respect --allow-file-access-from-files | 1017 // TODO(kinuko) We may want to respect --allow-file-access-from-files |
| 1022 // command line switch. | 1018 // command line switch. |
| 1023 callback.Run(kQuotaStatusOk, 0); | 1019 callback.Run(kQuotaStatusOk, 0); |
| 1024 return; | 1020 return; |
| 1025 } | 1021 } |
| 1026 | 1022 |
| 1027 int64* quota_ptr = new int64(0); | 1023 int64* quota_ptr = new int64(0); |
| 1028 PostTaskAndReplyWithResultForDBThread( | 1024 PostTaskAndReplyWithResultForDBThread( |
| 1029 FROM_HERE, | 1025 FROM_HERE, |
| 1030 base::Bind(&GetPersistentHostQuotaOnDBThread, | 1026 base::Bind(&GetPersistentHostQuotaOnDBThread, |
| 1031 host, | 1027 host, |
| 1032 base::Unretained(quota_ptr)), | 1028 base::Unretained(quota_ptr)), |
| 1033 base::Bind(&QuotaManager::DidGetPersistentHostQuota, | 1029 base::Bind(&QuotaManager::DidGetPersistentHostQuota, |
| 1034 weak_factory_.GetWeakPtr(), | 1030 weak_factory_.GetWeakPtr(), |
| 1035 callback, | 1031 callback, |
| 1036 host, | 1032 host, |
| 1037 base::Owned(quota_ptr))); | 1033 base::Owned(quota_ptr))); |
| 1038 } | 1034 } |
| 1039 | 1035 |
| 1040 void QuotaManager::SetPersistentHostQuota(const std::string& host, | 1036 void QuotaManager::SetPersistentHostQuota(const std::string& host, |
| 1041 int64 new_quota, | 1037 int64 new_quota, |
| 1042 const HostQuotaCallback& callback) { | 1038 const QuotaCallback& callback) { |
| 1043 LazyInitialize(); | 1039 LazyInitialize(); |
| 1044 if (host.empty()) { | 1040 if (host.empty()) { |
| 1045 // This could happen if we are called on file:///. | 1041 // This could happen if we are called on file:///. |
| 1046 callback.Run(kQuotaErrorNotSupported, 0); | 1042 callback.Run(kQuotaErrorNotSupported, 0); |
| 1047 return; | 1043 return; |
| 1048 } | 1044 } |
| 1049 if (new_quota < 0) { | 1045 if (new_quota < 0) { |
| 1050 callback.Run(kQuotaErrorInvalidModification, -1); | 1046 callback.Run(kQuotaErrorInvalidModification, -1); |
| 1051 return; | 1047 return; |
| 1052 } | 1048 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1485 QuotaStatusCode status = kQuotaErrorInvalidAccess; | 1481 QuotaStatusCode status = kQuotaErrorInvalidAccess; |
| 1486 DidDatabaseWork(success); | 1482 DidDatabaseWork(success); |
| 1487 if (success) { | 1483 if (success) { |
| 1488 temporary_quota_override_ = *new_quota; | 1484 temporary_quota_override_ = *new_quota; |
| 1489 status = kQuotaStatusOk; | 1485 status = kQuotaStatusOk; |
| 1490 } | 1486 } |
| 1491 | 1487 |
| 1492 if (callback.is_null()) | 1488 if (callback.is_null()) |
| 1493 return; | 1489 return; |
| 1494 | 1490 |
| 1495 callback.Run(status, kStorageTypeTemporary, *new_quota); | 1491 callback.Run(status, *new_quota); |
| 1496 } | 1492 } |
| 1497 | 1493 |
| 1498 void QuotaManager::DidGetPersistentHostQuota(const HostQuotaCallback& callback, | 1494 void QuotaManager::DidGetPersistentHostQuota(const QuotaCallback& callback, |
| 1499 const std::string& host, | 1495 const std::string& host, |
| 1500 const int64* quota, | 1496 const int64* quota, |
| 1501 bool success) { | 1497 bool success) { |
| 1502 DidDatabaseWork(success); | 1498 DidDatabaseWork(success); |
| 1503 callback.Run(kQuotaStatusOk, *quota); | 1499 callback.Run(kQuotaStatusOk, *quota); |
| 1504 } | 1500 } |
| 1505 | 1501 |
| 1506 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, | 1502 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, |
| 1507 const HostQuotaCallback& callback, | 1503 const QuotaCallback& callback, |
| 1508 const int64* new_quota, | 1504 const int64* new_quota, |
| 1509 bool success) { | 1505 bool success) { |
| 1510 DidDatabaseWork(success); | 1506 DidDatabaseWork(success); |
| 1511 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota); | 1507 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota); |
| 1512 } | 1508 } |
| 1513 | 1509 |
| 1514 void QuotaManager::DidInitialize(int64* temporary_quota_override, | 1510 void QuotaManager::DidInitialize(int64* temporary_quota_override, |
| 1515 int64* desired_available_space, | 1511 int64* desired_available_space, |
| 1516 bool success) { | 1512 bool success) { |
| 1517 temporary_quota_override_ = *temporary_quota_override; | 1513 temporary_quota_override_ = *temporary_quota_override; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 if (origins_in_use_.find(*origin) != origins_in_use_.end() || | 1546 if (origins_in_use_.find(*origin) != origins_in_use_.end() || |
| 1551 access_notified_origins_.find(*origin) != access_notified_origins_.end()) | 1547 access_notified_origins_.find(*origin) != access_notified_origins_.end()) |
| 1552 lru_origin_callback_.Run(GURL()); | 1548 lru_origin_callback_.Run(GURL()); |
| 1553 else | 1549 else |
| 1554 lru_origin_callback_.Run(*origin); | 1550 lru_origin_callback_.Run(*origin); |
| 1555 access_notified_origins_.clear(); | 1551 access_notified_origins_.clear(); |
| 1556 lru_origin_callback_.Reset(); | 1552 lru_origin_callback_.Reset(); |
| 1557 } | 1553 } |
| 1558 | 1554 |
| 1559 void QuotaManager::DidGetInitialTemporaryGlobalQuota( | 1555 void QuotaManager::DidGetInitialTemporaryGlobalQuota( |
| 1560 QuotaStatusCode status, StorageType type, int64 quota_unused) { | 1556 QuotaStatusCode status, int64 quota_unused) { |
| 1561 DCHECK_EQ(type, kStorageTypeTemporary); | |
| 1562 | |
| 1563 if (eviction_disabled_) | 1557 if (eviction_disabled_) |
| 1564 return; | 1558 return; |
| 1565 | 1559 |
| 1566 std::set<GURL>* origins = new std::set<GURL>; | 1560 std::set<GURL>* origins = new std::set<GURL>; |
| 1567 temporary_usage_tracker_->GetCachedOrigins(origins); | 1561 temporary_usage_tracker_->GetCachedOrigins(origins); |
| 1568 // This will call the StartEviction() when initial origin registration | 1562 // This will call the StartEviction() when initial origin registration |
| 1569 // is completed. | 1563 // is completed. |
| 1570 PostTaskAndReplyWithResultForDBThread( | 1564 PostTaskAndReplyWithResultForDBThread( |
| 1571 FROM_HERE, | 1565 FROM_HERE, |
| 1572 base::Bind(&InitializeTemporaryOriginsInfoOnDBThread, | 1566 base::Bind(&InitializeTemporaryOriginsInfoOnDBThread, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1694 | 1688 |
| 1695 QuotaManagerProxy::QuotaManagerProxy( | 1689 QuotaManagerProxy::QuotaManagerProxy( |
| 1696 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1690 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
| 1697 : manager_(manager), io_thread_(io_thread) { | 1691 : manager_(manager), io_thread_(io_thread) { |
| 1698 } | 1692 } |
| 1699 | 1693 |
| 1700 QuotaManagerProxy::~QuotaManagerProxy() { | 1694 QuotaManagerProxy::~QuotaManagerProxy() { |
| 1701 } | 1695 } |
| 1702 | 1696 |
| 1703 } // namespace quota | 1697 } // namespace quota |
| OLD | NEW |