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 25 matching lines...) Expand all Loading... |
36 namespace quota { | 36 namespace quota { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const int64 kMBytes = 1024 * 1024; | 40 const int64 kMBytes = 1024 * 1024; |
41 const int kMinutesInMilliSeconds = 60 * 1000; | 41 const int kMinutesInMilliSeconds = 60 * 1000; |
42 | 42 |
43 const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour | 43 const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour |
44 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% | 44 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% |
45 | 45 |
| 46 void DidGetUsageAndQuota( |
| 47 base::SequencedTaskRunner* original_task_runner, |
| 48 const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, |
| 49 QuotaStatusCode status, int64 usage, int64 quota) { |
| 50 if (!original_task_runner->RunsTasksOnCurrentThread()) { |
| 51 original_task_runner->PostTask( |
| 52 FROM_HERE, |
| 53 base::Bind(&DidGetUsageAndQuota, |
| 54 make_scoped_refptr(original_task_runner), |
| 55 callback, status, usage, quota)); |
| 56 return; |
| 57 } |
| 58 callback.Run(status, usage, quota); |
| 59 } |
| 60 |
46 } // namespace | 61 } // namespace |
47 | 62 |
48 // Arbitrary for now, but must be reasonably small so that | 63 // Arbitrary for now, but must be reasonably small so that |
49 // in-memory databases can fit. | 64 // in-memory databases can fit. |
50 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. | 65 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. |
51 const int64 QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; | 66 const int64 QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; |
52 | 67 |
53 const int64 QuotaManager::kNoLimit = kint64max; | 68 const int64 QuotaManager::kNoLimit = kint64max; |
54 | 69 |
55 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20% | 70 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20% |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 io_thread_->PostTask( | 1688 io_thread_->PostTask( |
1674 FROM_HERE, | 1689 FROM_HERE, |
1675 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, | 1690 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, |
1676 client_id, origin, type, enabled)); | 1691 client_id, origin, type, enabled)); |
1677 return; | 1692 return; |
1678 } | 1693 } |
1679 if (manager_) | 1694 if (manager_) |
1680 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); | 1695 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); |
1681 } | 1696 } |
1682 | 1697 |
| 1698 void QuotaManagerProxy::GetUsageAndQuota( |
| 1699 base::SequencedTaskRunner* original_task_runner, |
| 1700 const GURL& origin, |
| 1701 StorageType type, |
| 1702 const GetUsageAndQuotaCallback& callback) { |
| 1703 if (!io_thread_->BelongsToCurrentThread()) { |
| 1704 io_thread_->PostTask( |
| 1705 FROM_HERE, |
| 1706 base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, |
| 1707 make_scoped_refptr(original_task_runner), |
| 1708 origin, type, callback)); |
| 1709 return; |
| 1710 } |
| 1711 if (!manager_) { |
| 1712 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); |
| 1713 return; |
| 1714 } |
| 1715 manager_->GetUsageAndQuota( |
| 1716 origin, type, |
| 1717 base::Bind(&DidGetUsageAndQuota, |
| 1718 make_scoped_refptr(original_task_runner), callback)); |
| 1719 } |
| 1720 |
1683 QuotaManager* QuotaManagerProxy::quota_manager() const { | 1721 QuotaManager* QuotaManagerProxy::quota_manager() const { |
1684 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); | 1722 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); |
1685 return manager_; | 1723 return manager_; |
1686 } | 1724 } |
1687 | 1725 |
1688 QuotaManagerProxy::QuotaManagerProxy( | 1726 QuotaManagerProxy::QuotaManagerProxy( |
1689 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 1727 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) |
1690 : manager_(manager), io_thread_(io_thread) { | 1728 : manager_(manager), io_thread_(io_thread) { |
1691 } | 1729 } |
1692 | 1730 |
1693 QuotaManagerProxy::~QuotaManagerProxy() { | 1731 QuotaManagerProxy::~QuotaManagerProxy() { |
1694 } | 1732 } |
1695 | 1733 |
1696 } // namespace quota | 1734 } // namespace quota |
OLD | NEW |