Skip to content

Commit

Permalink
arc: disk_quota: Migrate IsQuotaSupported from cryptohome to spaced
Browse files Browse the repository at this point in the history
As a part of the effort of deprecating cryptohome's ArcQuota, this CL
changes the implementation of ArcDiskQuotaBridge's IsQuotaSupported from
calling ArcQuota's D-Bus method to calling spaced's new D-Bus method
IsQuotaSupported (added in CL:4607960) and cryptohome's new D-Bus method
GetArcDiskFeatures (added in CL:4671949).

BUG=b:229122701
TEST=ash_components_unittests --gtest_filter="ArcDiskQuotaBridgeTest.*"
TEST=See CL:4671949.

Change-Id: Id28bdd55cc2193643fbb903b3b67cc1f1d7614cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4671773
Commit-Queue: Momoko Hattori <momohatt@chromium.org>
Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: Youkichi Hosoi <youkichihosoi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1175288}
  • Loading branch information
momohatt authored and Chromium LUCI CQ committed Jul 26, 2023
1 parent 1f1ec9b commit 749c471
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions ash/components/arc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ source_set("unit_tests") {
"//chromeos/ash/components/dbus/shill",
"//chromeos/ash/components/dbus/spaced:spaced",
"//chromeos/ash/components/dbus/upstart",
"//chromeos/ash/components/dbus/userdataauth",
"//chromeos/ash/components/disks:test_support",
"//chromeos/ash/components/network:test_support",
"//chromeos/ash/components/policy",
Expand Down
31 changes: 25 additions & 6 deletions ash/components/arc/disk_quota/arc_disk_quota_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/memory/singleton.h"
#include "chromeos/ash/components/dbus/spaced/spaced_client.h"
#include "chromeos/ash/components/dbus/userdataauth/arc_quota_client.h"
#include "chromeos/ash/components/dbus/userdataauth/userdataauth_client.h"

namespace arc {

Expand Down Expand Up @@ -54,6 +55,20 @@ bool IsAndroidProjectId(uint32_t project_id) {
project_id <= kProjectIdForAndroidAppsEnd);
}

void IsQuotaSupportedOnArcDiskHome(
ArcDiskQuotaBridge::IsQuotaSupportedCallback callback) {
ash::SpacedClient::Get()->IsQuotaSupported(
kArcDiskHome,
base::BindOnce(
[](ArcDiskQuotaBridge::IsQuotaSupportedCallback callback,
absl::optional<bool> reply) {
LOG_IF(ERROR, !reply.has_value())
<< "Failed to retrieve result from IsQuotaSupported";
std::move(callback).Run(reply.value_or(false));
},
std::move(callback)));
}

} // namespace

// static
Expand Down Expand Up @@ -83,18 +98,22 @@ void ArcDiskQuotaBridge::SetAccountId(const AccountId& account_id) {
}

void ArcDiskQuotaBridge::IsQuotaSupported(IsQuotaSupportedCallback callback) {
ash::ArcQuotaClient::Get()->GetArcDiskFeatures(
// Whether ARC quota is supported is an AND of the following two booleans:
// * Whether there are no unmounted Android users (from cryptohome)
// * Whether |kArcDiskHome| is mounted with quota enabled (from spaced)
// Query cryptohome first, as the first one is more likely to be false.
ash::UserDataAuthClient::Get()->GetArcDiskFeatures(
user_data_auth::GetArcDiskFeaturesRequest(),
base::BindOnce(
[](IsQuotaSupportedCallback callback,
absl::optional<user_data_auth::GetArcDiskFeaturesReply> reply) {
LOG_IF(ERROR, !reply.has_value())
<< "Failed to retrieve result from IsQuotaSupported call.";
bool result = false;
if (reply.has_value()) {
result = reply->quota_supported();
<< "Failed to retrieve result from GetArcDiskFeatures call.";
if (!reply.has_value() || !reply->quota_supported()) {
std::move(callback).Run(false);
return;
}
std::move(callback).Run(result);
IsQuotaSupportedOnArcDiskHome(std::move(callback));
},
std::move(callback)));
}
Expand Down
39 changes: 37 additions & 2 deletions ash/components/arc/disk_quota/arc_disk_quota_bridge_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "base/test/test_future.h"
#include "chromeos/ash/components/dbus/spaced/fake_spaced_client.h"
#include "chromeos/ash/components/dbus/spaced/spaced_client.h"
#include "chromeos/ash/components/dbus/userdataauth/fake_userdataauth_client.h"
#include "chromeos/ash/components/dbus/userdataauth/userdataauth_client.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -26,9 +28,15 @@ class ArcDiskQuotaBridgeTest : public testing::Test {

ArcDiskQuotaBridge* bridge() { return bridge_; }

void SetUp() override { ash::SpacedClient::InitializeFake(); }
void SetUp() override {
ash::SpacedClient::InitializeFake();
ash::UserDataAuthClient::InitializeFake();
}

void TearDown() override { ash::SpacedClient::Shutdown(); }
void TearDown() override {
ash::UserDataAuthClient::Shutdown();
ash::SpacedClient::Shutdown();
}

private:
content::BrowserTaskEnvironment task_environment_;
Expand All @@ -37,6 +45,33 @@ class ArcDiskQuotaBridgeTest : public testing::Test {
const raw_ptr<ArcDiskQuotaBridge, ExperimentalAsh> bridge_;
};

TEST_F(ArcDiskQuotaBridgeTest, IsQuotaSupported_Supported) {
ash::FakeSpacedClient::Get()->set_quota_supported(true);
ash::FakeUserDataAuthClient::TestApi::Get()->set_arc_quota_supported(true);

base::test::TestFuture<bool> future;
bridge()->IsQuotaSupported(future.GetCallback());
EXPECT_TRUE(future.Get());
}

TEST_F(ArcDiskQuotaBridgeTest, IsQuotaSupported_NotSupportedInSpaced) {
ash::FakeSpacedClient::Get()->set_quota_supported(false);
ash::FakeUserDataAuthClient::TestApi::Get()->set_arc_quota_supported(true);

base::test::TestFuture<bool> future;
bridge()->IsQuotaSupported(future.GetCallback());
EXPECT_FALSE(future.Get());
}

TEST_F(ArcDiskQuotaBridgeTest, IsQuotaSupported_NotSupportedInCryptohome) {
ash::FakeSpacedClient::Get()->set_quota_supported(true);
ash::FakeUserDataAuthClient::TestApi::Get()->set_arc_quota_supported(false);

base::test::TestFuture<bool> future;
bridge()->IsQuotaSupported(future.GetCallback());
EXPECT_FALSE(future.Get());
}

TEST_F(ArcDiskQuotaBridgeTest, GetQuotaCurrentSpaceForUid_Success) {
const std::vector<std::pair<uint32_t, int64_t>>
valid_android_uid_and_expected_space = {
Expand Down

0 comments on commit 749c471

Please sign in to comment.