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(
for (const auto& itr : *pending_hosts) {
const std::string& host = itr.first;
StorageType type = itr.second;
quota_manager_->GetHostUsage(
quota_manager_->GetHostUsageWithBreakdown(
host, type,
base::BindOnce(&BrowsingDataQuotaHelperImpl::GotHostUsage,
weak_factory_.GetWeakPtr(), quota_info, completion, host,
......@@ -122,11 +122,13 @@ void BrowsingDataQuotaHelperImpl::OnGetOriginsComplete(
}
}
void BrowsingDataQuotaHelperImpl::GotHostUsage(QuotaInfoMap* quota_info,
base::OnceClosure completion,
const std::string& host,
StorageType type,
int64_t usage) {
void BrowsingDataQuotaHelperImpl::GotHostUsage(
QuotaInfoMap* quota_info,
base::OnceClosure completion,
const std::string& host,
StorageType type,
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
switch (type) {
case StorageType::kTemporary:
......
......@@ -61,7 +61,8 @@ class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper {
base::OnceClosure completion,
const std::string& host,
blink::mojom::StorageType type,
int64_t usage);
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown);
// Called when all QuotaManager::GetHostUsage requests are complete.
void OnGetHostsUsageComplete(FetchResultCallback callback,
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/ui/webui/quota_internals/quota_internals_handler.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_types.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"
using blink::mojom::StorageType;
......@@ -155,9 +156,11 @@ void QuotaInternalsProxy::DidDumpOriginInfoTable(
ReportPerOriginInfo(origin_info);
}
void QuotaInternalsProxy::DidGetHostUsage(const std::string& host,
StorageType type,
int64_t usage) {
void QuotaInternalsProxy::DidGetHostUsage(
const std::string& host,
StorageType type,
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown) {
DCHECK(type == StorageType::kTemporary || type == StorageType::kPersistent ||
type == StorageType::kSyncable);
......@@ -215,7 +218,7 @@ void QuotaInternalsProxy::VisitHost(const std::string& host, StorageType type) {
void QuotaInternalsProxy::GetHostUsage(const std::string& host,
StorageType type) {
DCHECK(quota_manager_.get());
quota_manager_->GetHostUsage(
quota_manager_->GetHostUsageWithBreakdown(
host, type,
base::BindOnce(&QuotaInternalsProxy::DidGetHostUsage,
weak_factory_.GetWeakPtr(), host, type));
......
......@@ -70,7 +70,8 @@ class QuotaInternalsProxy
void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries);
void DidGetHostUsage(const std::string& host,
blink::mojom::StorageType type,
int64_t usage);
int64_t usage,
blink::mojom::UsageBreakdownPtr usage_breakdown);
// Helper. Called on IO Thread.
void RequestPerOriginInfo(blink::mojom::StorageType type);
......
......@@ -1153,15 +1153,6 @@ void QuotaManager::GetGlobalUsage(StorageType type,
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(
const std::string& host,
StorageType type,
......
......@@ -229,9 +229,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
QuotaCallback callback);
void GetGlobalUsage(blink::mojom::StorageType type,
GlobalUsageCallback callback);
void GetHostUsage(const std::string& host,
blink::mojom::StorageType type,
UsageCallback callback);
void GetHostUsageWithBreakdown(const std::string& host,
blink::mojom::StorageType type,
UsageWithBreakdownCallback callback);
......
......@@ -24,13 +24,6 @@ void DidGetGlobalUsageForLimitedGlobalUsage(UsageCallback callback,
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
struct UsageTracker::AccumulateInfo {
......@@ -128,14 +121,6 @@ void UsageTracker::GetGlobalUsage(GlobalUsageCallback callback) {
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(
const std::string& host,
UsageWithBreakdownCallback callback) {
......
......@@ -53,7 +53,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) UsageTracker
void GetGlobalLimitedUsage(UsageCallback callback);
void GetGlobalUsage(GlobalUsageCallback callback);
void GetHostUsage(const std::string& host, UsageCallback callback);
void GetHostUsageWithBreakdown(const std::string& host,
UsageWithBreakdownCallback callback);
void UpdateUsageCache(QuotaClientType client_type,
......
......@@ -177,16 +177,7 @@ class UsageTrackerTest : public testing::Test {
EXPECT_TRUE(done);
}
void GetHostUsage(const std::string& host, int64_t* usage) {
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(
std::pair<int64_t, blink::mojom::UsageBreakdownPtr> GetHostUsageWithBreakdown(
const std::string& host) {
int64_t usage;
blink::mojom::UsageBreakdownPtr usage_breakdown;
......@@ -241,7 +232,6 @@ class UsageTrackerTest : public testing::Test {
TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) {
int64_t usage = 0;
int64_t unlimited_usage = 0;
int64_t host_usage = 0;
blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected =
blink::mojom::UsageBreakdown::New();
GetGlobalUsage(&usage, &unlimited_usage);
......@@ -254,38 +244,34 @@ TEST_F(UsageTrackerTest, GrantAndRevokeUnlimitedStorage) {
UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown_expected->fileSystem = 100;
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);
GrantUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage);
EXPECT_EQ(100, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown = GetHostUsageWithBreakdown(host);
EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
RevokeUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
GetHostUsageBreakdown(host);
GetHostUsageWithBreakdown(host);
EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
}
TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
int64_t usage = 0;
int64_t unlimited_usage = 0;
int64_t host_usage = 0;
blink::mojom::UsageBreakdownPtr host_usage_breakdown_expected =
blink::mojom::UsageBreakdown::New();
......@@ -294,22 +280,20 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown_expected->fileSystem = 100;
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);
UpdateUsageWithoutNotification(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(100, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(100, host_usage);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown = GetHostUsageWithBreakdown(host);
EXPECT_EQ(100, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
GrantUnlimitedStoragePolicy(origin);
......@@ -318,33 +302,30 @@ TEST_F(UsageTrackerTest, CacheDisabledClientTest) {
UpdateUsageWithoutNotification(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(400, usage);
EXPECT_EQ(400, unlimited_usage);
EXPECT_EQ(400, host_usage);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown_expected->fileSystem = 400;
EXPECT_EQ(400, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
RevokeUnlimitedStoragePolicy(origin);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(400, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(400, host_usage);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown = GetHostUsageWithBreakdown(host);
EXPECT_EQ(400, host_usage_breakdown.first);
EXPECT_EQ(host_usage_breakdown_expected, host_usage_breakdown.second);
SetUsageCacheEnabled(origin, true);
UpdateUsage(origin, 100);
GetGlobalUsage(&usage, &unlimited_usage);
GetHostUsage(host, &host_usage);
EXPECT_EQ(500, usage);
EXPECT_EQ(0, unlimited_usage);
EXPECT_EQ(500, host_usage);
host_usage_breakdown = GetHostUsageBreakdown(host);
host_usage_breakdown = GetHostUsageWithBreakdown(host);
host_usage_breakdown_expected->fileSystem = 500;
EXPECT_EQ(500, host_usage_breakdown.first);
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