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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 return avail_space * kTemporaryQuotaRatioToAvail; | 347 return avail_space * kTemporaryQuotaRatioToAvail; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // Subclasses must call following methods to create a new 'waitable' | 350 // Subclasses must call following methods to create a new 'waitable' |
| 351 // callback, which decrements waiting_callbacks when it is called. | 351 // callback, which decrements waiting_callbacks when it is called. |
| 352 GlobalUsageCallback NewWaitableGlobalUsageCallback() { | 352 GlobalUsageCallback NewWaitableGlobalUsageCallback() { |
| 353 ++waiting_callbacks_; | 353 ++waiting_callbacks_; |
| 354 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage, | 354 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage, |
| 355 weak_factory_.GetWeakPtr()); | 355 weak_factory_.GetWeakPtr()); |
| 356 } | 356 } |
| 357 HostUsageCallback NewWaitableHostUsageCallback() { | 357 HostUsageCallback NewWaitableHostUsageCallback(const std::string& host, |
| 358 quota::StorageType type) { | |
| 358 ++waiting_callbacks_; | 359 ++waiting_callbacks_; |
| 359 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, | 360 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, |
| 360 weak_factory_.GetWeakPtr()); | 361 weak_factory_.GetWeakPtr(), host, type); |
|
kinuko
2012/09/17 19:15:42
looks like we can call host() and type() here rath
calvinlo
2012/09/18 05:59:18
Done.
| |
| 361 } | 362 } |
| 362 HostQuotaCallback NewWaitableHostQuotaCallback() { | 363 HostQuotaCallback NewWaitableHostQuotaCallback() { |
| 363 ++waiting_callbacks_; | 364 ++waiting_callbacks_; |
| 364 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, | 365 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, |
| 365 weak_factory_.GetWeakPtr()); | 366 weak_factory_.GetWeakPtr()); |
| 366 } | 367 } |
| 367 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { | 368 AvailableSpaceCallback NewWaitableAvailableSpaceCallback() { |
| 368 ++waiting_callbacks_; | 369 ++waiting_callbacks_; |
| 369 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, | 370 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetAvailableSpace, |
| 370 weak_factory_.GetWeakPtr()); | 371 weak_factory_.GetWeakPtr()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 public: | 474 public: |
| 474 UsageAndQuotaDispatcherTaskForTemporary( | 475 UsageAndQuotaDispatcherTaskForTemporary( |
| 475 QuotaManager* manager, const HostAndType& host_and_type) | 476 QuotaManager* manager, const HostAndType& host_and_type) |
| 476 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} | 477 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} |
| 477 | 478 |
| 478 protected: | 479 protected: |
| 479 virtual void RunBody() OVERRIDE { | 480 virtual void RunBody() OVERRIDE { |
| 480 manager()->GetUsageTracker(type())->GetGlobalUsage( | 481 manager()->GetUsageTracker(type())->GetGlobalUsage( |
| 481 NewWaitableGlobalUsageCallback()); | 482 NewWaitableGlobalUsageCallback()); |
| 482 manager()->GetUsageTracker(type())->GetHostUsage( | 483 manager()->GetUsageTracker(type())->GetHostUsage( |
| 483 host(), NewWaitableHostUsageCallback()); | 484 host(), NewWaitableHostUsageCallback(host(), type())); |
| 484 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); | 485 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); |
| 485 } | 486 } |
| 486 | 487 |
| 487 virtual void DispatchCallbacks() OVERRIDE { | 488 virtual void DispatchCallbacks() OVERRIDE { |
| 488 // Allow an individual host to utilize a fraction of the total | 489 // Allow an individual host to utilize a fraction of the total |
| 489 // pool available for temp storage. | 490 // pool available for temp storage. |
| 490 int64 host_quota = temporary_global_quota() / kPerHostTemporaryPortion; | 491 int64 host_quota = temporary_global_quota() / kPerHostTemporaryPortion; |
| 491 | 492 |
| 492 // But if total temp usage is over-budget, stop letting new data in | 493 // But if total temp usage is over-budget, stop letting new data in |
| 493 // until we reclaim space. | 494 // until we reclaim space. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 505 class QuotaManager::UsageAndQuotaDispatcherTaskForPersistent | 506 class QuotaManager::UsageAndQuotaDispatcherTaskForPersistent |
| 506 : public QuotaManager::UsageAndQuotaDispatcherTask { | 507 : public QuotaManager::UsageAndQuotaDispatcherTask { |
| 507 public: | 508 public: |
| 508 UsageAndQuotaDispatcherTaskForPersistent( | 509 UsageAndQuotaDispatcherTaskForPersistent( |
| 509 QuotaManager* manager, const HostAndType& host_and_type) | 510 QuotaManager* manager, const HostAndType& host_and_type) |
| 510 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} | 511 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} |
| 511 | 512 |
| 512 protected: | 513 protected: |
| 513 virtual void RunBody() OVERRIDE { | 514 virtual void RunBody() OVERRIDE { |
| 514 manager()->GetUsageTracker(type())->GetHostUsage( | 515 manager()->GetUsageTracker(type())->GetHostUsage( |
| 515 host(), NewWaitableHostUsageCallback()); | 516 host(), NewWaitableHostUsageCallback(host(), type())); |
| 516 manager()->GetPersistentHostQuota( | 517 manager()->GetPersistentHostQuota( |
| 517 host(), NewWaitableHostQuotaCallback()); | 518 host(), NewWaitableHostQuotaCallback()); |
| 518 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); | 519 manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); |
| 519 } | 520 } |
| 520 | 521 |
| 521 virtual void DispatchCallbacks() OVERRIDE { | 522 virtual void DispatchCallbacks() OVERRIDE { |
| 522 CallCallbacksAndClear(quota_status(), | 523 CallCallbacksAndClear(quota_status(), |
| 523 host_usage(), host_usage(), host_quota(), | 524 host_usage(), host_usage(), host_quota(), |
| 524 available_space()); | 525 available_space()); |
| 525 } | 526 } |
| 526 }; | 527 }; |
| 527 | 528 |
| 528 class QuotaManager::UsageAndQuotaDispatcherTaskForSyncable | 529 class QuotaManager::UsageAndQuotaDispatcherTaskForSyncable |
| 529 : public QuotaManager::UsageAndQuotaDispatcherTask { | 530 : public QuotaManager::UsageAndQuotaDispatcherTask { |
| 530 public: | 531 public: |
| 531 UsageAndQuotaDispatcherTaskForSyncable( | 532 UsageAndQuotaDispatcherTaskForSyncable( |
| 532 QuotaManager* manager, const HostAndType& host_and_type) | 533 QuotaManager* manager, const HostAndType& host_and_type) |
| 533 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} | 534 : UsageAndQuotaDispatcherTask(manager, host_and_type) {} |
| 534 | 535 |
| 535 protected: | 536 protected: |
| 536 virtual void RunBody() OVERRIDE { | 537 virtual void RunBody() OVERRIDE { |
| 537 manager()->GetUsageTracker(type())->GetHostUsage( | 538 manager()->GetUsageTracker(type())->GetHostUsage( |
| 538 host(), NewWaitableHostUsageCallback()); | 539 host(), NewWaitableHostUsageCallback(host(), type())); |
| 539 } | 540 } |
| 540 | 541 |
| 541 virtual void DispatchCallbacks() OVERRIDE { | 542 virtual void DispatchCallbacks() OVERRIDE { |
| 542 // TODO(kinuko): We should reflect the backend's actual quota instead | 543 // TODO(kinuko): We should reflect the backend's actual quota instead |
| 543 // of returning a fixed default value. | 544 // of returning a fixed default value. |
| 544 CallCallbacksAndClear(quota_status(), | 545 CallCallbacksAndClear(quota_status(), |
| 545 host_usage(), host_usage(), | 546 host_usage(), host_usage(), |
| 546 kSyncableStorageDefaultHostQuota, | 547 kSyncableStorageDefaultHostQuota, |
| 547 available_space()); | 548 available_space()); |
| 548 } | 549 } |
| (...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 | 1698 |
| 1698 QuotaManagerProxy::QuotaManagerProxy( | 1699 QuotaManagerProxy::QuotaManagerProxy( |
| 1699 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1700 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
| 1700 : manager_(manager), io_thread_(io_thread) { | 1701 : manager_(manager), io_thread_(io_thread) { |
| 1701 } | 1702 } |
| 1702 | 1703 |
| 1703 QuotaManagerProxy::~QuotaManagerProxy() { | 1704 QuotaManagerProxy::~QuotaManagerProxy() { |
| 1704 } | 1705 } |
| 1705 | 1706 |
| 1706 } // namespace quota | 1707 } // namespace quota |
| OLD | NEW |