OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 int64 host_usage_; | 283 int64 host_usage_; |
284 QuotaStatusCode quota_status_; | 284 QuotaStatusCode quota_status_; |
285 CallbackList callbacks_; | 285 CallbackList callbacks_; |
286 CallbackList unlimited_callbacks_; | 286 CallbackList unlimited_callbacks_; |
287 int waiting_callbacks_; | 287 int waiting_callbacks_; |
288 ScopedCallbackFactory<UsageAndQuotaDispatcherTask> callback_factory_; | 288 ScopedCallbackFactory<UsageAndQuotaDispatcherTask> callback_factory_; |
289 | 289 |
290 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaDispatcherTask); | 290 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaDispatcherTask); |
291 }; | 291 }; |
292 | 292 |
| 293 class QuotaManager::GetUsageInfoTask : public QuotaTask { |
| 294 private: |
| 295 typedef QuotaManager::GetUsageInfoTask self_type; |
| 296 |
| 297 public: |
| 298 GetUsageInfoTask( |
| 299 QuotaManager* manager, |
| 300 GetUsageInfoCallback* callback) |
| 301 : QuotaTask(manager), |
| 302 callback_(callback), |
| 303 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 304 } |
| 305 protected: |
| 306 virtual void Run() OVERRIDE { |
| 307 remaining_trackers_ = 2; |
| 308 // This will populate cached hosts and usage info. |
| 309 manager()->GetUsageTracker(kStorageTypeTemporary)->GetGlobalUsage( |
| 310 callback_factory_.NewCallback(&GetUsageInfoTask::DidGetGlobalUsage)); |
| 311 manager()->GetUsageTracker(kStorageTypePersistent)->GetGlobalUsage( |
| 312 callback_factory_.NewCallback(&GetUsageInfoTask::DidGetGlobalUsage)); |
| 313 } |
| 314 |
| 315 virtual void Completed() OVERRIDE { |
| 316 callback_->Run(entries_); |
| 317 DeleteSoon(); |
| 318 } |
| 319 |
| 320 virtual void Aborted() OVERRIDE { |
| 321 callback_->Run(UsageInfoEntries()); |
| 322 DeleteSoon(); |
| 323 } |
| 324 |
| 325 private: |
| 326 void AddEntries(StorageType type, UsageTracker* tracker) { |
| 327 std::map<std::string, int64> host_usage; |
| 328 tracker->GetCachedHostsUsage(&host_usage); |
| 329 for (std::map<std::string, int64>::const_iterator iter = host_usage.begin(); |
| 330 iter != host_usage.end(); |
| 331 ++iter) { |
| 332 entries_.push_back(UsageInfo(iter->first, type, iter->second)); |
| 333 } |
| 334 if (--remaining_trackers_ == 0) |
| 335 CallCompleted(); |
| 336 } |
| 337 |
| 338 void DidGetGlobalUsage(StorageType type, int64, int64) { |
| 339 AddEntries(type, manager()->GetUsageTracker(type)); |
| 340 } |
| 341 |
| 342 QuotaManager* manager() const { |
| 343 return static_cast<QuotaManager*>(observer()); |
| 344 } |
| 345 |
| 346 scoped_ptr<GetUsageInfoCallback> callback_; |
| 347 UsageInfoEntries entries_; |
| 348 base::ScopedCallbackFactory<GetUsageInfoTask> callback_factory_; |
| 349 int remaining_trackers_; |
| 350 |
| 351 DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask); |
| 352 }; |
| 353 |
293 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporary | 354 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporary |
294 : public QuotaManager::UsageAndQuotaDispatcherTask { | 355 : public QuotaManager::UsageAndQuotaDispatcherTask { |
295 public: | 356 public: |
296 UsageAndQuotaDispatcherTaskForTemporary( | 357 UsageAndQuotaDispatcherTaskForTemporary( |
297 QuotaManager* manager, const std::string& host) | 358 QuotaManager* manager, const std::string& host) |
298 : UsageAndQuotaDispatcherTask(manager, host, kStorageTypeTemporary) {} | 359 : UsageAndQuotaDispatcherTask(manager, host, kStorageTypeTemporary) {} |
299 | 360 |
300 protected: | 361 protected: |
301 virtual void RunBody() OVERRIDE { | 362 virtual void RunBody() OVERRIDE { |
302 manager()->temporary_usage_tracker_->GetGlobalUsage( | 363 manager()->temporary_usage_tracker_->GetGlobalUsage( |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 | 1018 |
958 QuotaManager::~QuotaManager() { | 1019 QuotaManager::~QuotaManager() { |
959 DCHECK(io_thread_->BelongsToCurrentThread()); | 1020 DCHECK(io_thread_->BelongsToCurrentThread()); |
960 proxy_->manager_ = NULL; | 1021 proxy_->manager_ = NULL; |
961 std::for_each(clients_.begin(), clients_.end(), | 1022 std::for_each(clients_.begin(), clients_.end(), |
962 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 1023 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
963 if (database_.get()) | 1024 if (database_.get()) |
964 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 1025 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
965 } | 1026 } |
966 | 1027 |
| 1028 void QuotaManager::GetUsageInfo(GetUsageInfoCallback* callback) { |
| 1029 LazyInitialize(); |
| 1030 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); |
| 1031 get_usage_info->Start(); |
| 1032 } |
| 1033 |
967 void QuotaManager::GetUsageAndQuota( | 1034 void QuotaManager::GetUsageAndQuota( |
968 const GURL& origin, StorageType type, | 1035 const GURL& origin, StorageType type, |
969 GetUsageAndQuotaCallback* callback_ptr) { | 1036 GetUsageAndQuotaCallback* callback_ptr) { |
970 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); | 1037 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); |
971 LazyInitialize(); | 1038 LazyInitialize(); |
972 | 1039 |
973 if (type == kStorageTypeUnknown) { | 1040 if (type == kStorageTypeUnknown) { |
974 // Quota only supports temporary/persistent types. | 1041 // Quota only supports temporary/persistent types. |
975 callback->Run(kQuotaErrorNotSupported, 0, 0); | 1042 callback->Run(kQuotaErrorNotSupported, 0, 0); |
976 return; | 1043 return; |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 | 1634 |
1568 QuotaManagerProxy::QuotaManagerProxy( | 1635 QuotaManagerProxy::QuotaManagerProxy( |
1569 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1636 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
1570 : manager_(manager), io_thread_(io_thread) { | 1637 : manager_(manager), io_thread_(io_thread) { |
1571 } | 1638 } |
1572 | 1639 |
1573 QuotaManagerProxy::~QuotaManagerProxy() { | 1640 QuotaManagerProxy::~QuotaManagerProxy() { |
1574 } | 1641 } |
1575 | 1642 |
1576 } // namespace quota | 1643 } // namespace quota |
OLD | NEW |