0

Update Storage Answer Card in Launcher to use bar chart

Bug: b/288050813
Change-Id: Icda071594aee15f44ab1226f0f18d06ea5716208
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4626404
Commit-Queue: Lauren Commeignes <laurencom@chromium.org>
Reviewed-by: Dmitry Grebenyuk <dgrebenyuk@google.com>
Cr-Commit-Position: refs/heads/main@{#1160474}
This commit is contained in:
Lauren Commeignes
2023-06-21 04:55:18 +00:00
committed by Chromium LUCI CQ
parent bcc174ba2e
commit 5c6f311af8
5 changed files with 17 additions and 73 deletions

@ -2005,8 +2005,8 @@ Style notes:
<message name="IDS_ASH_BATTERY_STATUS_IN_LAUNCHER_DESCRIPTION" desc="Message content for the description of the battery answer card, showing the battery health percentage and the cycle count.">
Battery health <ph name="BATTERY_HEALTH_PERCENTAGE">$1<ex>97</ex></ph>% | Cycle count <ph name="CYCLE_COUNT">$2<ex>15</ex></ph>
</message>
<message name="IDS_ASH_STORAGE_STATUS_IN_LAUNCHER_TITLE" desc="Message content for the title of the storage answer card, showing the amount of storage currently in use and the total storage size.">
<ph name="STORAGE_IN_USE_SIZE">$1<ex>65 GB</ex></ph> in use / <ph name="STORAGE_TOTAL_SIZE">$2<ex>124 GB</ex></ph>
<message name="IDS_ASH_STORAGE_STATUS_IN_LAUNCHER_DESCRIPTION" desc="Message content for the description of the storage answer card, showing the amount of storage currently in use and the total storage size.">
Storage <ph name="STORAGE_IN_USE_SIZE">$1<ex>65 GB</ex></ph> in use | <ph name="STORAGE_TOTAL_SIZE">$2<ex>124 GB</ex></ph> total
</message>
<message name="IDS_ASH_STORAGE_MANAGEMENT_KEYWORD_FOR_LAUNCHER" desc="Keyword of storage management in launcher search that should trigger a storage answer card result.">
storage management

@ -0,0 +1 @@
5820bfbb9034e5276313d84c83c2f3ce04089915

@ -1 +0,0 @@
33dd78ccb992c03e4677ccd57bccbf1a5ae0aff9

@ -56,7 +56,7 @@ using ::chromeos::settings::mojom::kAboutChromeOsSectionPath;
using ::chromeos::settings::mojom::kStorageSubpagePath;
using AnswerCardInfo = ::ash::SystemInfoAnswerCardData;
constexpr double kRelevanceThreshold = 0.64;
constexpr double kRelevanceThreshold = 0.79;
double ConvertKBtoBytes(uint32_t amount) {
return static_cast<double>(amount) * 1024;
@ -471,30 +471,6 @@ void SystemInfoCardProvider::OnStorageInfoUpdated() {
NOTREACHED() << "Unable to retrieve total or available disk space";
return;
}
int64_t system_bytes = 0;
for (int i = 0; i < SizeCalculator::kCalculationTypeCount; ++i) {
const int64_t total_bytes_for_current_item =
std::max(storage_items_total_bytes_[i], static_cast<int64_t>(0));
// The total amount of disk space counts positively towards system's size.
if (i == static_cast<int>(SizeCalculator::CalculationType::kTotal)) {
if (total_bytes_for_current_item <= 0) {
return;
}
system_bytes += total_bytes_for_current_item;
continue;
}
// All other items are subtracted from the total amount of disk space.
if (i == static_cast<int>(SizeCalculator::CalculationType::kAvailable) &&
total_bytes_for_current_item < 0) {
return;
}
system_bytes -= total_bytes_for_current_item;
}
const int system_space_index =
static_cast<int>(SizeCalculator::CalculationType::kSystem);
storage_items_total_bytes_[system_space_index] = system_bytes;
CreateStorageAnswerCard();
}
@ -508,39 +484,14 @@ void SystemInfoCardProvider::CreateStorageAnswerCard() {
int64_t in_use_bytes = total_bytes - available_bytes;
std::u16string in_use_size = ui::FormatBytes(in_use_bytes);
std::u16string total_size = ui::FormatBytes(total_bytes);
std::u16string title = l10n_util::GetStringFUTF16(
IDS_ASH_STORAGE_STATUS_IN_LAUNCHER_TITLE, in_use_size, total_size);
std::map<ash::SearchResultSystemInfoStorageType, int64_t>
storage_type_to_size = {
{ash::SearchResultSystemInfoStorageType::kMyFiles,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kMyFiles)]},
{ash::SearchResultSystemInfoStorageType::kDriveOfflineFiles,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kDriveOfflineFiles)]},
{ash::SearchResultSystemInfoStorageType::kBrowsingData,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kBrowsingData)]},
{ash::SearchResultSystemInfoStorageType::kAppsExtensions,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kAppsExtensions)]},
{ash::SearchResultSystemInfoStorageType::kCrostini,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kCrostini)]},
{ash::SearchResultSystemInfoStorageType::kOtherUsers,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kOtherUsers)]},
{ash::SearchResultSystemInfoStorageType::kSystem,
storage_items_total_bytes_[static_cast<int>(
SizeCalculator::CalculationType::kSystem)]},
{ash::SearchResultSystemInfoStorageType::kTotal, total_bytes}};
std::u16string description = l10n_util::GetStringFUTF16(
IDS_ASH_STORAGE_STATUS_IN_LAUNCHER_DESCRIPTION, in_use_size, total_size);
AnswerCardInfo answer_card_info(storage_type_to_size);
AnswerCardInfo answer_card_info(in_use_bytes * 100 / total_bytes);
SearchProvider::Results new_results;
new_results.emplace_back(std::make_unique<SystemInfoAnswerResult>(
profile_, last_query_, kStorageSubpagePath, os_settings_icon_, relevance_,
title,
/*description=*/u"",
/*title=*/u"", description,
SystemInfoAnswerResult::SystemInfoCategory::kSettings, answer_card_info));
SwapResults(&new_results);
}

@ -779,8 +779,8 @@ TEST_F(SystemInfoCardProviderTest, Storage) {
int64_t in_use_bytes = rounded_total_size - available_bytes;
std::u16string in_use_size = ui::FormatBytes(in_use_bytes);
std::u16string total_size = ui::FormatBytes(rounded_total_size);
std::u16string result_title =
base::StrCat({in_use_size, u" in use / ", total_size});
std::u16string result_description = base::StrCat(
{u"Storage ", in_use_size, u" in use | ", total_size, u" total"});
StartSearch(u"storage");
@ -794,29 +794,22 @@ TEST_F(SystemInfoCardProviderTest, Storage) {
ash::AppListSearchResultType::kSystemInfo);
EXPECT_EQ(results()[0]->metrics_type(), ash::SYSTEM_INFO);
EXPECT_EQ(results()[0]->system_info_answer_card_data()->display_type,
ash::SystemInfoAnswerCardDisplayType::kMultiElementBarChart);
auto storage_type_to_size =
results()[0]->system_info_answer_card_data()->storage_type_to_size;
EXPECT_EQ(
ui::FormatBytes(
storage_type_to_size[ash::SearchResultSystemInfoStorageType::kTotal]),
total_size);
EXPECT_EQ(
ui::FormatBytes(storage_type_to_size
[ash::SearchResultSystemInfoStorageType::kMyFiles]),
ui::FormatBytes(kMountPathBytes + kAndroidPathBytes +
kDownloadsPathBytes));
ash::SystemInfoAnswerCardDisplayType::kBarChart);
auto found_bar_chart_percentage =
results()[0]->system_info_answer_card_data()->bar_chart_percentage;
auto expected_bar_chart_percentage = in_use_bytes * 100 / rounded_total_size;
EXPECT_EQ(expected_bar_chart_percentage, found_bar_chart_percentage);
ASSERT_EQ(results()[0]->title_text_vector().size(), 1u);
const auto& title = results()[0]->title_text_vector()[0];
ASSERT_EQ(title.GetType(), ash::SearchResultTextItemType::kString);
EXPECT_EQ(title.GetText(), result_title);
EXPECT_EQ(title.GetText(), u"");
EXPECT_TRUE(title.GetTextTags().empty());
ASSERT_EQ(results()[0]->details_text_vector().size(), 1u);
const auto& details = results()[0]->details_text_vector()[0];
ASSERT_EQ(details.GetType(), ash::SearchResultTextItemType::kString);
EXPECT_EQ(details.GetText(), u"");
EXPECT_EQ(details.GetText(), result_description);
EXPECT_TRUE(details.GetTextTags().empty());
}