Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: webkit/browser/quota/quota_manager.cc

Issue 136573007: Quota: Factor out (Mock)QuotaManagerProxy into its own file for readability (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/browser/quota/quota_manager.h ('k') | webkit/browser/quota/quota_manager_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/sys_info.h" 22 #include "base/sys_info.h"
23 #include "base/task_runner_util.h" 23 #include "base/task_runner_util.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
26 #include "webkit/browser/quota/quota_database.h" 26 #include "webkit/browser/quota/quota_database.h"
27 #include "webkit/browser/quota/quota_manager_proxy.h"
27 #include "webkit/browser/quota/quota_temporary_storage_evictor.h" 28 #include "webkit/browser/quota/quota_temporary_storage_evictor.h"
28 #include "webkit/browser/quota/usage_tracker.h" 29 #include "webkit/browser/quota/usage_tracker.h"
29 #include "webkit/common/quota/quota_types.h" 30 #include "webkit/common/quota/quota_types.h"
30 31
31 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 32 #define UMA_HISTOGRAM_MBYTES(name, sample) \
32 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 33 UMA_HISTOGRAM_CUSTOM_COUNTS( \
33 (name), static_cast<int>((sample) / kMBytes), \ 34 (name), static_cast<int>((sample) / kMBytes), \
34 1, 10 * 1024 * 1024 /* 10TB */, 100) 35 1, 10 * 1024 * 1024 /* 10TB */, 100)
35 36
36 namespace quota { 37 namespace quota {
37 38
38 namespace { 39 namespace {
39 40
40 const int64 kMBytes = 1024 * 1024; 41 const int64 kMBytes = 1024 * 1024;
41 const int kMinutesInMilliSeconds = 60 * 1000; 42 const int kMinutesInMilliSeconds = 60 * 1000;
42 43
43 const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour 44 const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour
44 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% 45 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33%
45 46
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
61 } // namespace 47 } // namespace
62 48
63 // Arbitrary for now, but must be reasonably small so that 49 // Arbitrary for now, but must be reasonably small so that
64 // in-memory databases can fit. 50 // in-memory databases can fit.
65 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. 51 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this.
66 const int64 QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; 52 const int64 QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes;
67 53
68 const int64 QuotaManager::kNoLimit = kint64max; 54 const int64 QuotaManager::kNoLimit = kint64max;
69 55
70 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20% 56 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20%
(...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 // Deleting manager will post another task to DB thread to delete 1584 // Deleting manager will post another task to DB thread to delete
1599 // |database_|, therefore we can be sure that database_ is alive when this 1585 // |database_|, therefore we can be sure that database_ is alive when this
1600 // task runs. 1586 // task runs.
1601 base::PostTaskAndReplyWithResult( 1587 base::PostTaskAndReplyWithResult(
1602 db_thread_.get(), 1588 db_thread_.get(),
1603 from_here, 1589 from_here,
1604 base::Bind(task, base::Unretained(database_.get())), 1590 base::Bind(task, base::Unretained(database_.get())),
1605 reply); 1591 reply);
1606 } 1592 }
1607 1593
1608 // QuotaManagerProxy ----------------------------------------------------------
1609
1610 void QuotaManagerProxy::RegisterClient(QuotaClient* client) {
1611 if (!io_thread_->BelongsToCurrentThread() &&
1612 io_thread_->PostTask(
1613 FROM_HERE,
1614 base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) {
1615 return;
1616 }
1617
1618 if (manager_)
1619 manager_->RegisterClient(client);
1620 else
1621 client->OnQuotaManagerDestroyed();
1622 }
1623
1624 void QuotaManagerProxy::NotifyStorageAccessed(
1625 QuotaClient::ID client_id,
1626 const GURL& origin,
1627 StorageType type) {
1628 if (!io_thread_->BelongsToCurrentThread()) {
1629 io_thread_->PostTask(
1630 FROM_HERE,
1631 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id,
1632 origin, type));
1633 return;
1634 }
1635
1636 if (manager_)
1637 manager_->NotifyStorageAccessed(client_id, origin, type);
1638 }
1639
1640 void QuotaManagerProxy::NotifyStorageModified(
1641 QuotaClient::ID client_id,
1642 const GURL& origin,
1643 StorageType type,
1644 int64 delta) {
1645 if (!io_thread_->BelongsToCurrentThread()) {
1646 io_thread_->PostTask(
1647 FROM_HERE,
1648 base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id,
1649 origin, type, delta));
1650 return;
1651 }
1652
1653 if (manager_)
1654 manager_->NotifyStorageModified(client_id, origin, type, delta);
1655 }
1656
1657 void QuotaManagerProxy::NotifyOriginInUse(
1658 const GURL& origin) {
1659 if (!io_thread_->BelongsToCurrentThread()) {
1660 io_thread_->PostTask(
1661 FROM_HERE,
1662 base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin));
1663 return;
1664 }
1665
1666 if (manager_)
1667 manager_->NotifyOriginInUse(origin);
1668 }
1669
1670 void QuotaManagerProxy::NotifyOriginNoLongerInUse(
1671 const GURL& origin) {
1672 if (!io_thread_->BelongsToCurrentThread()) {
1673 io_thread_->PostTask(
1674 FROM_HERE,
1675 base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this,
1676 origin));
1677 return;
1678 }
1679 if (manager_)
1680 manager_->NotifyOriginNoLongerInUse(origin);
1681 }
1682
1683 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id,
1684 const GURL& origin,
1685 StorageType type,
1686 bool enabled) {
1687 if (!io_thread_->BelongsToCurrentThread()) {
1688 io_thread_->PostTask(
1689 FROM_HERE,
1690 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this,
1691 client_id, origin, type, enabled));
1692 return;
1693 }
1694 if (manager_)
1695 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled);
1696 }
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
1721 QuotaManager* QuotaManagerProxy::quota_manager() const {
1722 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread());
1723 return manager_;
1724 }
1725
1726 QuotaManagerProxy::QuotaManagerProxy(
1727 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread)
1728 : manager_(manager), io_thread_(io_thread) {
1729 }
1730
1731 QuotaManagerProxy::~QuotaManagerProxy() {
1732 }
1733
1734 } // namespace quota 1594 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/browser/quota/quota_manager.h ('k') | webkit/browser/quota/quota_manager_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698