Commit 4dd48188 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

Quota: Remove GetHostUsage() in favor of GetHostUsageWithBreakdown().

GetHostUsage() is implemented as GetHostUsageWithBreakdown() plus an
adapter callback that strips the extra information. This CL removes
GetHostUsage(). A future CL will rename GetHostUsageWithBreakdown() to
GetHostUsage().

Bug: 1016065
Change-Id: I0df6dd00c47556c3557afa97cdc022c75c3293b8
Tbr: dullweber
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2281727Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJarryd Goodman <jarrydg@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785977}
parent b02c3e9d
...@@ -114,7 +114,7 @@ void BrowsingDataQuotaHelperImpl::OnGetOriginsComplete( ...@@ -114,7 +114,7 @@ void BrowsingDataQuotaHelperImpl::OnGetOriginsComplete(
for (const auto& itr : *pending_hosts) { for (const auto& itr : *pending_hosts) {
const std::string& host = itr.first; const std::string& host = itr.first;
StorageType type = itr.second; StorageType type = itr.second;
quota_manager_->GetHostUsage( quota_manager_->GetHostUsageWithBreakdown(
host, type, host, type,
base::BindOnce(&BrowsingDataQuotaHelperImpl::GotHostUsage, base::BindOnce(&BrowsingDataQuotaHelperImpl::GotHostUsage,
weak_factory_.GetWeakPtr(), quota_info, completion, host, weak_factory_.GetWeakPtr(), quota_info, completion, host,
...@@ -122,11 +122,13 @@ void BrowsingDataQuotaHelperImpl::OnGetOriginsComplete( ...@@ -122,11 +122,13 @@ void BrowsingDataQuotaHelperImpl::OnGetOriginsComplete(
} }
} }
void BrowsingDataQuotaHelperImpl::GotHostUsage(QuotaInfoMap* quota_info, void BrowsingDataQuotaHelperImpl::GotHostUsage(
base::OnceClosure completion, QuotaInfoMap* quota_info,
const std::string& host, base::OnceClosure completion,
StorageType type, const std::string& host,
int64_t usage) { StorageType type,
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
switch (type) { switch (type) {
case StorageType::kTemporary: case StorageType::kTemporary:
......
...@@ -61,7 +61,8 @@ class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper { ...@@ -61,7 +61,8 @@ class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper {
base::OnceClosure completion, base::OnceClosure completion,
const std::string& host, const std::string& host,
blink::mojom::StorageType type, blink::mojom::StorageType type,
int64_t usage); int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown);
// Called when all QuotaManager::GetHostUsage requests are complete. // Called when all QuotaManager::GetHostUsage requests are complete.
void OnGetHostsUsageComplete(FetchResultCallback callback, void OnGetHostsUsageComplete(FetchResultCallback callback,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/ui/webui/quota_internals/quota_internals_handler.h" #include "chrome/browser/ui/webui/quota_internals/quota_internals_handler.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h" #include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h"
#include "url/origin.h" #include "url/origin.h"
using blink::mojom::StorageType; using blink::mojom::StorageType;
...@@ -155,9 +156,11 @@ void QuotaInternalsProxy::DidDumpOriginInfoTable( ...@@ -155,9 +156,11 @@ void QuotaInternalsProxy::DidDumpOriginInfoTable(
ReportPerOriginInfo(origin_info); ReportPerOriginInfo(origin_info);
} }
void QuotaInternalsProxy::DidGetHostUsage(const std::string& host, void QuotaInternalsProxy::DidGetHostUsage(
StorageType type, const std::string& host,
int64_t usage) { StorageType type,
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown) {
DCHECK(type == StorageType::kTemporary || type == StorageType::kPersistent || DCHECK(type == StorageType::kTemporary || type == StorageType::kPersistent ||
type == StorageType::kSyncable); type == StorageType::kSyncable);
...@@ -215,7 +218,7 @@ void QuotaInternalsProxy::VisitHost(const std::string& host, StorageType type) { ...@@ -215,7 +218,7 @@ void QuotaInternalsProxy::VisitHost(const std::string& host, StorageType type) {
void QuotaInternalsProxy::GetHostUsage(const std::string& host, void QuotaInternalsProxy::GetHostUsage(const std::string& host,
StorageType type) { StorageType type) {
DCHECK(quota_manager_.get()); DCHECK(quota_manager_.get());
quota_manager_->GetHostUsage( quota_manager_->GetHostUsageWithBreakdown(
host, type, host, type,
base::BindOnce(&QuotaInternalsProxy::DidGetHostUsage, base::BindOnce(&QuotaInternalsProxy::DidGetHostUsage,
weak_factory_.GetWeakPtr(), host, type)); weak_factory_.GetWeakPtr(), host, type));
......
...@@ -70,7 +70,8 @@ class QuotaInternalsProxy ...@@ -70,7 +70,8 @@ class QuotaInternalsProxy
void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries); void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries);
void DidGetHostUsage(const std::string& host, void DidGetHostUsage(const std::string& host,
blink::mojom::StorageType type, blink::mojom::StorageType type,
int64_t usage); int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown);
// Helper. Called on IO Thread. // Helper. Called on IO Thread.
void RequestPerOriginInfo(blink::mojom::StorageType type); void RequestPerOriginInfo(blink::mojom::StorageType type);
......
...@@ -1153,15 +1153,6 @@ void QuotaManager::GetGlobalUsage(StorageType type, ...@@ -1153,15 +1153,6 @@ void QuotaManager::GetGlobalUsage(StorageType type,
GetUsageTracker(type)->GetGlobalUsage(std::move(callback)); GetUsageTracker(type)->GetGlobalUsage(std::move(callback));
} }
void QuotaManager::GetHostUsage(const std::string& host,
StorageType type,
UsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
LazyInitialize();
DCHECK(GetUsageTracker(type));
GetUsageTracker(type)->GetHostUsage(host, std::move(callback));
}
void QuotaManager::GetHostUsageWithBreakdown( void QuotaManager::GetHostUsageWithBreakdown(
const std::string& host, const std::string& host,
StorageType type, StorageType type,
......
...@@ -229,9 +229,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager ...@@ -229,9 +229,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
QuotaCallback callback); QuotaCallback callback);
void GetGlobalUsage(blink::mojom::StorageType type, void GetGlobalUsage(blink::mojom::StorageType type,
GlobalUsageCallback callback); GlobalUsageCallback callback);
void GetHostUsage(const std::string& host,
blink::mojom::StorageType type,
UsageCallback callback);
void GetHostUsageWithBreakdown(const std::string& host, void GetHostUsageWithBreakdown(const std::string& host,
blink::mojom::StorageType type, blink::mojom::StorageType type,
UsageWithBreakdownCallback callback); UsageWithBreakdownCallback callback);
......
...@@ -24,13 +24,6 @@ void DidGetGlobalUsageForLimitedGlobalUsage(UsageCallback callback, ...@@ -24,13 +24,6 @@ void DidGetGlobalUsageForLimitedGlobalUsage(UsageCallback callback,
std::move(callback).Run(total_global_usage - global_unlimited_usage); std::move(callback).Run(total_global_usage - global_unlimited_usage);
} }
void StripUsageWithBreakdownCallback(
UsageCallback callback,
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown) {
std::move(callback).Run(usage);
}
} // namespace } // namespace
struct UsageTracker::AccumulateInfo { struct UsageTracker::AccumulateInfo {
...@@ -128,14 +121,6 @@ void UsageTracker::GetGlobalUsage(GlobalUsageCallback callback) { ...@@ -128,14 +121,6 @@ void UsageTracker::GetGlobalUsage(GlobalUsageCallback callback) {
accumulator.Run(0, 0); accumulator.Run(0, 0);
} }
void UsageTracker::GetHostUsage(const std::string& host,
UsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
UsageTracker::GetHostUsageWithBreakdown(
host,
base::BindOnce(&StripUsageWithBreakdownCallback, std::move(callback)));
}
void UsageTracker::GetHostUsageWithBreakdown( void UsageTracker::GetHostUsageWithBreakdown(
const std::string& host, const std::string& host,
UsageWithBreakdownCallback callback) { UsageWithBreakdownCallback callback) {
......
...@@ -53,7 +53,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) UsageTracker ...@@ -53,7 +53,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) UsageTracker
void GetGlobalLimitedUsage(UsageCallback callback); void GetGlobalLimitedUsage(UsageCallback callback);
void GetGlobalUsage(GlobalUsageCallback callback); void GetGlobalUsage(GlobalUsageCallback callback);
void GetHostUsage(const std::string& host, UsageCallback callback);
void GetHostUsageWithBreakdown(const std::string& host, void GetHostUsageWithBreakdown(const std::string& host,
UsageWithBreakdownCallback callback); UsageWithBreakdownCallback callback);
void UpdateUsageCache(QuotaClientType client_type, void UpdateUsageCache(QuotaClientType client_type,
......
...@@ -177,16 +177,7 @@ class UsageTrackerTest : public testing::Test { ...@@ -177,16 +177,7 @@ class UsageTrackerTest : public testing::Test {
EXPECT_TRUE(done); EXPECT_TRUE(done);
} }
void GetHostUsage(const std::string& host, int64_t* usage) { std::pair<int64_t, blink::mojom::UsageBreakdownPtr> GetHostUsageWithBreakdown(
bool done = false;
usage_tracker_.GetHostUsage(host,
base::BindOnce(&DidGetUsage, &done, usage));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
}
std::pair<int64_t, blink::mojom::UsageBreakdownPtr> GetHostUsageBreakdown(
const std::string& host) { const std::string& host) {
int64_t usage; int64_t usage;
blink::mojom::UsageBreakdownPtr usage_breakdown; blink::mojom::UsageBreakdownPtr usage_breakdown;
...@@ -241,7 +232,6 @@ class UsageTrackerTest : public testing::Test { ...@@ -241,7 +232,6 @@ class UsageTrackerTest : public testing::Test {
TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) { TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) {
int64_t usage = 0; int64_t usage = 0;
int64_t unlimited_usage = 0; int64_t unlimited_usage = 0;
int64_t host_usage = 0;
blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected = blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected =
blink::mojom::UsageBreakdown::New(); blink::mojom::UsageBreakdown::New();
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
...@@ -254,38 +244,34 @@ TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) { ...@@ -254,38 +244,34 @@ TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) {
UpdateUsage(origin, 100); UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage); EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown_expected->fileSystem = 100; host_usage_breakdown_expected->fileSystem = 100;
std::pair<int64_t, blink::mojom::UsageBreakdownPtr> host_usage_breakdown = std::pair<int64_t, blink::mojom::UsageBreakdownPtr> host_usage_breakdown =
GetHostUsageBreakdown(host); GetHostUsageWithBreakdown(host);
EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
GrantUnlimitedStoragePolicy(origin); GrantUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage); EXPECT_EQ(100, usage);
EXPECT_EQ(100, unlimited_usage); EXPECT_EQ(100, unlimited_usage);
EXPECT_EQ(100, host_usage); host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown = GetHostUsageBreakdown(host); EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
RevokeUnlimitedStoragePolicy(origin); RevokeUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage); EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage); GetHostUsageWithBreakdown(host);
GetHostUsageBreakdown(host); EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
} }
TEST_F(UsageTrackerTest, CacheDisabledClientTest) { TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
int64_t usage = 0; int64_t usage = 0;
int64_t unlimited_usage = 0; int64_t unlimited_usage = 0;
int64_t host_usage = 0;
blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected = blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected =
blink::mojom::UsageBreakdown::New(); blink::mojom::UsageBreakdown::New();
...@@ -294,22 +280,20 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) { ...@@ -294,22 +280,20 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
UpdateUsage(origin, 100); UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage); EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown_expected->fileSystem = 100; host_usage_breakdown_expected->fileSystem = 100;
std::pair<int64_t, blink::mojom::UsageBreakdownPtr> host_usage_breakdown = std::pair<int64_t, blink::mojom::UsageBreakdownPtr> host_usage_breakdown =
GetHostUsageBreakdown(host); GetHostUsageWithBreakdown(host);
EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
UpdateUsageWithoutNotification(origin, 100); UpdateUsageWithoutNotification(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage); EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage); host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown = GetHostUsageBreakdown(host); EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
GrantUnlimitedStoragePolicy(origin); GrantUnlimitedStoragePolicy(origin);
...@@ -318,33 +302,30 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) { ...@@ -318,33 +302,30 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
UpdateUsageWithoutNotification(origin, 100); UpdateUsageWithoutNotification(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(400, usage); EXPECT_EQ(400, usage);
EXPECT_EQ(400, unlimited_usage); EXPECT_EQ(400, unlimited_usage);
EXPECT_EQ(400, host_usage); host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown_expected->fileSystem = 400; host_usage_breakdown_expected->fileSystem = 400;
EXPECT_EQ(400, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
RevokeUnlimitedStoragePolicy(origin); RevokeUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(400, usage); EXPECT_EQ(400, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(400, host_usage); host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown = GetHostUsageBreakdown(host); EXPECT_EQ(400, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
SetUsageCacheEnabled(origin, true); SetUsageCacheEnabled(origin, true);
UpdateUsage(origin, 100); UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage); GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(500, usage); EXPECT_EQ(500, usage);
EXPECT_EQ(0, unlimited_usage); EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(500, host_usage); host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown_expected->fileSystem = 500; host_usage_breakdown_expected->fileSystem = 500;
EXPECT_EQ(500, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second); EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment