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 "webkit/browser/quota/quota_manager.h" | 5 #include "webkit/browser/quota/quota_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <functional> | 9 #include <functional> |
10 #include <set> | 10 #include <set> |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 | 941 |
942 HostDataDeleter* deleter = | 942 HostDataDeleter* deleter = |
943 new HostDataDeleter(this, host, type, quota_client_mask, callback); | 943 new HostDataDeleter(this, host, type, quota_client_mask, callback); |
944 deleter->Start(); | 944 deleter->Start(); |
945 } | 945 } |
946 | 946 |
947 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { | 947 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { |
948 if (!available_space_callbacks_.Add(callback)) | 948 if (!available_space_callbacks_.Add(callback)) |
949 return; | 949 return; |
950 | 950 |
951 PostTaskAndReplyWithResult( | 951 PostTaskAndReplyWithResult(db_thread_.get(), |
952 db_thread_, | 952 FROM_HERE, |
953 FROM_HERE, | 953 base::Bind(get_disk_space_fn_, profile_path_), |
954 base::Bind(get_disk_space_fn_, profile_path_), | 954 base::Bind(&QuotaManager::DidGetAvailableSpace, |
955 base::Bind(&QuotaManager::DidGetAvailableSpace, | 955 weak_factory_.GetWeakPtr())); |
956 weak_factory_.GetWeakPtr())); | |
957 } | 956 } |
958 | 957 |
959 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { | 958 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { |
960 LazyInitialize(); | 959 LazyInitialize(); |
961 if (!temporary_quota_initialized_) { | 960 if (!temporary_quota_initialized_) { |
962 db_initialization_callbacks_.Add(base::Bind( | 961 db_initialization_callbacks_.Add(base::Bind( |
963 &QuotaManager::GetTemporaryGlobalQuota, | 962 &QuotaManager::GetTemporaryGlobalQuota, |
964 weak_factory_.GetWeakPtr(), callback)); | 963 weak_factory_.GetWeakPtr(), callback)); |
965 return; | 964 return; |
966 } | 965 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 callback, | 1116 callback, |
1118 type)); | 1117 type)); |
1119 } | 1118 } |
1120 | 1119 |
1121 bool QuotaManager::ResetUsageTracker(StorageType type) { | 1120 bool QuotaManager::ResetUsageTracker(StorageType type) { |
1122 DCHECK(GetUsageTracker(type)); | 1121 DCHECK(GetUsageTracker(type)); |
1123 if (GetUsageTracker(type)->IsWorking()) | 1122 if (GetUsageTracker(type)->IsWorking()) |
1124 return false; | 1123 return false; |
1125 switch (type) { | 1124 switch (type) { |
1126 case kStorageTypeTemporary: | 1125 case kStorageTypeTemporary: |
1127 temporary_usage_tracker_.reset( | 1126 temporary_usage_tracker_.reset(new UsageTracker( |
1128 new UsageTracker(clients_, kStorageTypeTemporary, | 1127 clients_, kStorageTypeTemporary, special_storage_policy_.get())); |
1129 special_storage_policy_)); | |
1130 return true; | 1128 return true; |
1131 case kStorageTypePersistent: | 1129 case kStorageTypePersistent: |
1132 persistent_usage_tracker_.reset( | 1130 persistent_usage_tracker_.reset(new UsageTracker( |
1133 new UsageTracker(clients_, kStorageTypePersistent, | 1131 clients_, kStorageTypePersistent, special_storage_policy_.get())); |
1134 special_storage_policy_)); | |
1135 return true; | 1132 return true; |
1136 case kStorageTypeSyncable: | 1133 case kStorageTypeSyncable: |
1137 syncable_usage_tracker_.reset( | 1134 syncable_usage_tracker_.reset(new UsageTracker( |
1138 new UsageTracker(clients_, kStorageTypeSyncable, | 1135 clients_, kStorageTypeSyncable, special_storage_policy_.get())); |
1139 special_storage_policy_)); | |
1140 return true; | 1136 return true; |
1141 default: | 1137 default: |
1142 NOTREACHED(); | 1138 NOTREACHED(); |
1143 } | 1139 } |
1144 return true; | 1140 return true; |
1145 } | 1141 } |
1146 | 1142 |
1147 QuotaManager::~QuotaManager() { | 1143 QuotaManager::~QuotaManager() { |
1148 proxy_->manager_ = NULL; | 1144 proxy_->manager_ = NULL; |
1149 std::for_each(clients_.begin(), clients_.end(), | 1145 std::for_each(clients_.begin(), clients_.end(), |
(...skipping 13 matching lines...) Expand all Loading... |
1163 DCHECK(io_thread_->BelongsToCurrentThread()); | 1159 DCHECK(io_thread_->BelongsToCurrentThread()); |
1164 if (database_) { | 1160 if (database_) { |
1165 // Initialization seems to be done already. | 1161 // Initialization seems to be done already. |
1166 return; | 1162 return; |
1167 } | 1163 } |
1168 | 1164 |
1169 // Use an empty path to open an in-memory only databse for incognito. | 1165 // Use an empty path to open an in-memory only databse for incognito. |
1170 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() : | 1166 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() : |
1171 profile_path_.AppendASCII(kDatabaseName))); | 1167 profile_path_.AppendASCII(kDatabaseName))); |
1172 | 1168 |
1173 temporary_usage_tracker_.reset( | 1169 temporary_usage_tracker_.reset(new UsageTracker( |
1174 new UsageTracker(clients_, kStorageTypeTemporary, | 1170 clients_, kStorageTypeTemporary, special_storage_policy_.get())); |
1175 special_storage_policy_)); | 1171 persistent_usage_tracker_.reset(new UsageTracker( |
1176 persistent_usage_tracker_.reset( | 1172 clients_, kStorageTypePersistent, special_storage_policy_.get())); |
1177 new UsageTracker(clients_, kStorageTypePersistent, | 1173 syncable_usage_tracker_.reset(new UsageTracker( |
1178 special_storage_policy_)); | 1174 clients_, kStorageTypeSyncable, special_storage_policy_.get())); |
1179 syncable_usage_tracker_.reset( | |
1180 new UsageTracker(clients_, kStorageTypeSyncable, | |
1181 special_storage_policy_)); | |
1182 | 1175 |
1183 int64* temporary_quota_override = new int64(-1); | 1176 int64* temporary_quota_override = new int64(-1); |
1184 int64* desired_available_space = new int64(-1); | 1177 int64* desired_available_space = new int64(-1); |
1185 PostTaskAndReplyWithResultForDBThread( | 1178 PostTaskAndReplyWithResultForDBThread( |
1186 FROM_HERE, | 1179 FROM_HERE, |
1187 base::Bind(&InitializeOnDBThread, | 1180 base::Bind(&InitializeOnDBThread, |
1188 base::Unretained(temporary_quota_override), | 1181 base::Unretained(temporary_quota_override), |
1189 base::Unretained(desired_available_space)), | 1182 base::Unretained(desired_available_space)), |
1190 base::Bind(&QuotaManager::DidInitialize, | 1183 base::Bind(&QuotaManager::DidInitialize, |
1191 weak_factory_.GetWeakPtr(), | 1184 weak_factory_.GetWeakPtr(), |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 int64 usage, | 1326 int64 usage, |
1334 int64 unlimited_usage) { | 1327 int64 unlimited_usage) { |
1335 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); | 1328 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); |
1336 | 1329 |
1337 std::set<GURL> origins; | 1330 std::set<GURL> origins; |
1338 GetCachedOrigins(kStorageTypeTemporary, &origins); | 1331 GetCachedOrigins(kStorageTypeTemporary, &origins); |
1339 | 1332 |
1340 size_t num_origins = origins.size(); | 1333 size_t num_origins = origins.size(); |
1341 size_t protected_origins = 0; | 1334 size_t protected_origins = 0; |
1342 size_t unlimited_origins = 0; | 1335 size_t unlimited_origins = 0; |
1343 CountOriginType(origins, special_storage_policy_, | 1336 CountOriginType(origins, |
1344 &protected_origins, &unlimited_origins); | 1337 special_storage_policy_.get(), |
| 1338 &protected_origins, |
| 1339 &unlimited_origins); |
1345 | 1340 |
1346 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins", | 1341 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins", |
1347 num_origins); | 1342 num_origins); |
1348 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins", | 1343 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins", |
1349 protected_origins); | 1344 protected_origins); |
1350 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins", | 1345 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins", |
1351 unlimited_origins); | 1346 unlimited_origins); |
1352 } | 1347 } |
1353 | 1348 |
1354 void QuotaManager::DidGetPersistentGlobalUsageForHistogram( | 1349 void QuotaManager::DidGetPersistentGlobalUsageForHistogram( |
1355 int64 usage, | 1350 int64 usage, |
1356 int64 unlimited_usage) { | 1351 int64 unlimited_usage) { |
1357 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage); | 1352 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage); |
1358 | 1353 |
1359 std::set<GURL> origins; | 1354 std::set<GURL> origins; |
1360 GetCachedOrigins(kStorageTypePersistent, &origins); | 1355 GetCachedOrigins(kStorageTypePersistent, &origins); |
1361 | 1356 |
1362 size_t num_origins = origins.size(); | 1357 size_t num_origins = origins.size(); |
1363 size_t protected_origins = 0; | 1358 size_t protected_origins = 0; |
1364 size_t unlimited_origins = 0; | 1359 size_t unlimited_origins = 0; |
1365 CountOriginType(origins, special_storage_policy_, | 1360 CountOriginType(origins, |
1366 &protected_origins, &unlimited_origins); | 1361 special_storage_policy_.get(), |
| 1362 &protected_origins, |
| 1363 &unlimited_origins); |
1367 | 1364 |
1368 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", | 1365 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", |
1369 num_origins); | 1366 num_origins); |
1370 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", | 1367 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", |
1371 protected_origins); | 1368 protected_origins); |
1372 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", | 1369 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", |
1373 unlimited_origins); | 1370 unlimited_origins); |
1374 } | 1371 } |
1375 | 1372 |
1376 void QuotaManager::GetLRUOrigin( | 1373 void QuotaManager::GetLRUOrigin( |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 } | 1546 } |
1550 | 1547 |
1551 void QuotaManager::PostTaskAndReplyWithResultForDBThread( | 1548 void QuotaManager::PostTaskAndReplyWithResultForDBThread( |
1552 const tracked_objects::Location& from_here, | 1549 const tracked_objects::Location& from_here, |
1553 const base::Callback<bool(QuotaDatabase*)>& task, | 1550 const base::Callback<bool(QuotaDatabase*)>& task, |
1554 const base::Callback<void(bool)>& reply) { | 1551 const base::Callback<void(bool)>& reply) { |
1555 // Deleting manager will post another task to DB thread to delete | 1552 // Deleting manager will post another task to DB thread to delete |
1556 // |database_|, therefore we can be sure that database_ is alive when this | 1553 // |database_|, therefore we can be sure that database_ is alive when this |
1557 // task runs. | 1554 // task runs. |
1558 base::PostTaskAndReplyWithResult( | 1555 base::PostTaskAndReplyWithResult( |
1559 db_thread_, | 1556 db_thread_.get(), |
1560 from_here, | 1557 from_here, |
1561 base::Bind(task, base::Unretained(database_.get())), | 1558 base::Bind(task, base::Unretained(database_.get())), |
1562 reply); | 1559 reply); |
1563 } | 1560 } |
1564 | 1561 |
1565 // QuotaManagerProxy ---------------------------------------------------------- | 1562 // QuotaManagerProxy ---------------------------------------------------------- |
1566 | 1563 |
1567 void QuotaManagerProxy::RegisterClient(QuotaClient* client) { | 1564 void QuotaManagerProxy::RegisterClient(QuotaClient* client) { |
1568 if (!io_thread_->BelongsToCurrentThread() && | 1565 if (!io_thread_->BelongsToCurrentThread() && |
1569 io_thread_->PostTask( | 1566 io_thread_->PostTask( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 FROM_HERE, | 1643 FROM_HERE, |
1647 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, | 1644 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, |
1648 client_id, origin, type, enabled)); | 1645 client_id, origin, type, enabled)); |
1649 return; | 1646 return; |
1650 } | 1647 } |
1651 if (manager_) | 1648 if (manager_) |
1652 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); | 1649 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); |
1653 } | 1650 } |
1654 | 1651 |
1655 QuotaManager* QuotaManagerProxy::quota_manager() const { | 1652 QuotaManager* QuotaManagerProxy::quota_manager() const { |
1656 DCHECK(!io_thread_ || io_thread_->BelongsToCurrentThread()); | 1653 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); |
1657 return manager_; | 1654 return manager_; |
1658 } | 1655 } |
1659 | 1656 |
1660 QuotaManagerProxy::QuotaManagerProxy( | 1657 QuotaManagerProxy::QuotaManagerProxy( |
1661 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1658 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
1662 : manager_(manager), io_thread_(io_thread) { | 1659 : manager_(manager), io_thread_(io_thread) { |
1663 } | 1660 } |
1664 | 1661 |
1665 QuotaManagerProxy::~QuotaManagerProxy() { | 1662 QuotaManagerProxy::~QuotaManagerProxy() { |
1666 } | 1663 } |
1667 | 1664 |
1668 } // namespace quota | 1665 } // namespace quota |
OLD | NEW |