OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/quota/quota_manager.h" | 5 #include "storage/browser/quota/quota_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 bool GetLRUOriginOnDBThread(StorageType type, | 143 bool GetLRUOriginOnDBThread(StorageType type, |
144 std::set<GURL>* exceptions, | 144 std::set<GURL>* exceptions, |
145 SpecialStoragePolicy* policy, | 145 SpecialStoragePolicy* policy, |
146 GURL* url, | 146 GURL* url, |
147 QuotaDatabase* database) { | 147 QuotaDatabase* database) { |
148 DCHECK(database); | 148 DCHECK(database); |
149 database->GetLRUOrigin(type, *exceptions, policy, url); | 149 database->GetLRUOrigin(type, *exceptions, policy, url); |
150 return true; | 150 return true; |
151 } | 151 } |
152 | 152 |
| 153 bool GetDurableOnDBThread(const GURL& origin, |
| 154 bool* durable, |
| 155 QuotaDatabase* database) { |
| 156 DCHECK(database); |
| 157 return database->GetDurabilityForOrigin(origin, durable); |
| 158 } |
| 159 |
153 bool DeleteOriginInfoOnDBThread(const GURL& origin, | 160 bool DeleteOriginInfoOnDBThread(const GURL& origin, |
154 StorageType type, | 161 StorageType type, |
155 QuotaDatabase* database) { | 162 QuotaDatabase* database) { |
156 DCHECK(database); | 163 DCHECK(database); |
157 return database->DeleteOriginInfo(origin, type); | 164 return database->DeleteOriginInfo(origin, type); |
158 } | 165 } |
159 | 166 |
160 bool InitializeTemporaryOriginsInfoOnDBThread(const std::set<GURL>* origins, | 167 bool InitializeTemporaryOriginsInfoOnDBThread(const std::set<GURL>* origins, |
161 QuotaDatabase* database) { | 168 QuotaDatabase* database) { |
162 DCHECK(database); | 169 DCHECK(database); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 716 |
710 class QuotaManager::GetModifiedSinceHelper { | 717 class QuotaManager::GetModifiedSinceHelper { |
711 public: | 718 public: |
712 bool GetModifiedSinceOnDBThread(StorageType type, | 719 bool GetModifiedSinceOnDBThread(StorageType type, |
713 base::Time modified_since, | 720 base::Time modified_since, |
714 QuotaDatabase* database) { | 721 QuotaDatabase* database) { |
715 DCHECK(database); | 722 DCHECK(database); |
716 return database->GetOriginsModifiedSince(type, &origins_, modified_since); | 723 return database->GetOriginsModifiedSince(type, &origins_, modified_since); |
717 } | 724 } |
718 | 725 |
| 726 |
719 void DidGetModifiedSince(const base::WeakPtr<QuotaManager>& manager, | 727 void DidGetModifiedSince(const base::WeakPtr<QuotaManager>& manager, |
720 const GetOriginsCallback& callback, | 728 const GetOriginsCallback& callback, |
721 StorageType type, | 729 StorageType type, |
722 bool success) { | 730 bool success) { |
723 if (!manager) { | 731 if (!manager) { |
724 // The operation was aborted. | 732 // The operation was aborted. |
725 callback.Run(std::set<GURL>(), type); | 733 callback.Run(std::set<GURL>(), type); |
726 return; | 734 return; |
727 } | 735 } |
728 manager->DidDatabaseWork(success); | 736 manager->DidDatabaseWork(success); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 void QuotaManager::GetUsageAndQuotaForWebApps( | 833 void QuotaManager::GetUsageAndQuotaForWebApps( |
826 const GURL& origin, | 834 const GURL& origin, |
827 StorageType type, | 835 StorageType type, |
828 const GetUsageAndQuotaCallback& callback) { | 836 const GetUsageAndQuotaCallback& callback) { |
829 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 837 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
830 tracked_objects::ScopedTracker tracking_profile( | 838 tracked_objects::ScopedTracker tracking_profile( |
831 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 839 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
832 "477117 QuotaManager::GetUsageAndQuotaForWebApps")); | 840 "477117 QuotaManager::GetUsageAndQuotaForWebApps")); |
833 if (type != kStorageTypeTemporary && | 841 if (type != kStorageTypeTemporary && |
834 type != kStorageTypePersistent && | 842 type != kStorageTypePersistent && |
| 843 type != kStorageTypeDurable && |
835 type != kStorageTypeSyncable) { | 844 type != kStorageTypeSyncable) { |
836 callback.Run(kQuotaErrorNotSupported, 0, 0); | 845 callback.Run(kQuotaErrorNotSupported, 0, 0); |
837 return; | 846 return; |
838 } | 847 } |
839 | 848 |
840 DCHECK(origin == origin.GetOrigin()); | 849 DCHECK(origin == origin.GetOrigin()); |
841 LazyInitialize(); | 850 LazyInitialize(); |
842 | 851 |
843 bool unlimited = IsStorageUnlimited(origin, type); | 852 bool unlimited = IsStorageUnlimited(origin, type); |
844 bool can_query_disk_size = CanQueryDiskSize(origin); | 853 bool can_query_disk_size = CanQueryDiskSize(origin); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 weak_factory_.GetWeakPtr(), | 1051 weak_factory_.GetWeakPtr(), |
1043 host, | 1052 host, |
1044 base::Owned(quota_ptr))); | 1053 base::Owned(quota_ptr))); |
1045 } | 1054 } |
1046 | 1055 |
1047 void QuotaManager::SetPersistentHostQuota(const std::string& host, | 1056 void QuotaManager::SetPersistentHostQuota(const std::string& host, |
1048 int64 new_quota, | 1057 int64 new_quota, |
1049 const QuotaCallback& callback) { | 1058 const QuotaCallback& callback) { |
1050 LazyInitialize(); | 1059 LazyInitialize(); |
1051 if (host.empty()) { | 1060 if (host.empty()) { |
| 1061 LOG(ERROR) << "Calling with kQuotaErrorNotSupported"; |
1052 // This could happen if we are called on file:///. | 1062 // This could happen if we are called on file:///. |
1053 callback.Run(kQuotaErrorNotSupported, 0); | 1063 callback.Run(kQuotaErrorNotSupported, 0); |
1054 return; | 1064 return; |
1055 } | 1065 } |
1056 | 1066 |
1057 if (new_quota < 0) { | 1067 if (new_quota < 0) { |
1058 callback.Run(kQuotaErrorInvalidModification, -1); | 1068 callback.Run(kQuotaErrorInvalidModification, -1); |
1059 return; | 1069 return; |
1060 } | 1070 } |
1061 | 1071 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 // For syncable storage we should always enforce quota (since the | 1146 // For syncable storage we should always enforce quota (since the |
1137 // quota must be capped by the server limit). | 1147 // quota must be capped by the server limit). |
1138 if (type == kStorageTypeSyncable) | 1148 if (type == kStorageTypeSyncable) |
1139 return false; | 1149 return false; |
1140 if (type == kStorageTypeQuotaNotManaged) | 1150 if (type == kStorageTypeQuotaNotManaged) |
1141 return true; | 1151 return true; |
1142 return special_storage_policy_.get() && | 1152 return special_storage_policy_.get() && |
1143 special_storage_policy_->IsStorageUnlimited(origin); | 1153 special_storage_policy_->IsStorageUnlimited(origin); |
1144 } | 1154 } |
1145 | 1155 |
| 1156 void QuotaManager::GetDurability(const GURL& origin, |
| 1157 const GetDurabilityCallback& callback) { |
| 1158 LazyInitialize(); |
| 1159 LOG(ERROR) << "Got into QuotaManager::GetDurability"; |
| 1160 |
| 1161 // if db is hosed, do something with callback |
| 1162 |
| 1163 bool* is_durable = new bool; |
| 1164 PostTaskAndReplyWithResultForDBThread( |
| 1165 FROM_HERE, |
| 1166 base::Bind(&GetDurableOnDBThread, |
| 1167 origin, |
| 1168 base::Unretained(is_durable)), |
| 1169 base::Bind(&QuotaManager::DidGetDurability, |
| 1170 weak_factory_.GetWeakPtr(), |
| 1171 callback, |
| 1172 base::Owned(is_durable))); |
| 1173 } |
| 1174 |
1146 void QuotaManager::GetOriginsModifiedSince(StorageType type, | 1175 void QuotaManager::GetOriginsModifiedSince(StorageType type, |
1147 base::Time modified_since, | 1176 base::Time modified_since, |
1148 const GetOriginsCallback& callback) { | 1177 const GetOriginsCallback& callback) { |
1149 LazyInitialize(); | 1178 LazyInitialize(); |
1150 GetModifiedSinceHelper* helper = new GetModifiedSinceHelper; | 1179 GetModifiedSinceHelper* helper = new GetModifiedSinceHelper; |
1151 PostTaskAndReplyWithResultForDBThread( | 1180 PostTaskAndReplyWithResultForDBThread( |
1152 FROM_HERE, | 1181 FROM_HERE, |
1153 base::Bind(&GetModifiedSinceHelper::GetModifiedSinceOnDBThread, | 1182 base::Bind(&GetModifiedSinceHelper::GetModifiedSinceOnDBThread, |
1154 base::Unretained(helper), | 1183 base::Unretained(helper), |
1155 type, | 1184 type, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 switch (type) { | 1291 switch (type) { |
1263 case kStorageTypeTemporary: | 1292 case kStorageTypeTemporary: |
1264 return temporary_usage_tracker_.get(); | 1293 return temporary_usage_tracker_.get(); |
1265 case kStorageTypePersistent: | 1294 case kStorageTypePersistent: |
1266 return persistent_usage_tracker_.get(); | 1295 return persistent_usage_tracker_.get(); |
1267 case kStorageTypeSyncable: | 1296 case kStorageTypeSyncable: |
1268 return syncable_usage_tracker_.get(); | 1297 return syncable_usage_tracker_.get(); |
1269 case kStorageTypeQuotaNotManaged: | 1298 case kStorageTypeQuotaNotManaged: |
1270 return NULL; | 1299 return NULL; |
1271 case kStorageTypeUnknown: | 1300 case kStorageTypeUnknown: |
| 1301 case kStorageTypeDurable: |
1272 NOTREACHED(); | 1302 NOTREACHED(); |
1273 } | 1303 } |
1274 return NULL; | 1304 return NULL; |
1275 } | 1305 } |
1276 | 1306 |
1277 void QuotaManager::GetCachedOrigins( | 1307 void QuotaManager::GetCachedOrigins( |
1278 StorageType type, std::set<GURL>* origins) { | 1308 StorageType type, std::set<GURL>* origins) { |
1279 DCHECK(origins); | 1309 DCHECK(origins); |
1280 LazyInitialize(); | 1310 LazyInitialize(); |
1281 DCHECK(GetUsageTracker(type)); | 1311 DCHECK(GetUsageTracker(type)); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 } | 1629 } |
1600 | 1630 |
1601 void QuotaManager::DidGetAvailableSpace(int64 space) { | 1631 void QuotaManager::DidGetAvailableSpace(int64 space) { |
1602 available_space_callbacks_.Run(kQuotaStatusOk, space); | 1632 available_space_callbacks_.Run(kQuotaStatusOk, space); |
1603 } | 1633 } |
1604 | 1634 |
1605 void QuotaManager::DidDatabaseWork(bool success) { | 1635 void QuotaManager::DidDatabaseWork(bool success) { |
1606 db_disabled_ = !success; | 1636 db_disabled_ = !success; |
1607 } | 1637 } |
1608 | 1638 |
| 1639 void QuotaManager::DidGetDurability(const GetDurabilityCallback& callback, |
| 1640 const bool* durable, |
| 1641 bool success) { |
| 1642 DidDatabaseWork(success); |
| 1643 if (!success) { |
| 1644 NOTREACHED() << "Add a test for this"; |
| 1645 callback.Run(kQuotaErrorInvalidAccess, false /*durability*/); |
| 1646 return; |
| 1647 } |
| 1648 callback.Run(kQuotaStatusOk, *durable); |
| 1649 } |
| 1650 |
1609 void QuotaManager::DeleteOnCorrectThread() const { | 1651 void QuotaManager::DeleteOnCorrectThread() const { |
1610 if (!io_thread_->BelongsToCurrentThread() && | 1652 if (!io_thread_->BelongsToCurrentThread() && |
1611 io_thread_->DeleteSoon(FROM_HERE, this)) { | 1653 io_thread_->DeleteSoon(FROM_HERE, this)) { |
1612 return; | 1654 return; |
1613 } | 1655 } |
1614 delete this; | 1656 delete this; |
1615 } | 1657 } |
1616 | 1658 |
1617 void QuotaManager::PostTaskAndReplyWithResultForDBThread( | 1659 void QuotaManager::PostTaskAndReplyWithResultForDBThread( |
1618 const tracked_objects::Location& from_here, | 1660 const tracked_objects::Location& from_here, |
1619 const base::Callback<bool(QuotaDatabase*)>& task, | 1661 const base::Callback<bool(QuotaDatabase*)>& task, |
1620 const base::Callback<void(bool)>& reply) { | 1662 const base::Callback<void(bool)>& reply) { |
1621 // Deleting manager will post another task to DB thread to delete | 1663 // Deleting manager will post another task to DB thread to delete |
1622 // |database_|, therefore we can be sure that database_ is alive when this | 1664 // |database_|, therefore we can be sure that database_ is alive when this |
1623 // task runs. | 1665 // task runs. |
1624 base::PostTaskAndReplyWithResult( | 1666 base::PostTaskAndReplyWithResult( |
1625 db_thread_.get(), | 1667 db_thread_.get(), |
1626 from_here, | 1668 from_here, |
1627 base::Bind(task, base::Unretained(database_.get())), | 1669 base::Bind(task, base::Unretained(database_.get())), |
1628 reply); | 1670 reply); |
1629 } | 1671 } |
1630 | 1672 |
1631 } // namespace storage | 1673 } // namespace storage |
OLD | NEW |