Skip to content

Commit

Permalink
Include translation strings for input keywords of System Info Card pr…
Browse files Browse the repository at this point in the history
…ovider

Bug: b/263994165
Change-Id: Ie874498d500b4b585b6d89698f50347f43816ab6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4328370
Reviewed-by: Tony Yeoman <tby@chromium.org>
Commit-Queue: Lauren Commeignes <laurencom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1119777}
  • Loading branch information
Lauren Commeignes authored and Chromium LUCI CQ committed Mar 21, 2023
1 parent b1808b8 commit 2179af0
Show file tree
Hide file tree
Showing 27 changed files with 237 additions and 58 deletions.
57 changes: 57 additions & 0 deletions ash/ash_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,63 @@ Style notes:
<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>
<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
</message>
<message name="IDS_ASH_STORAGE_KEYWORD_FOR_LAUNCHER" desc="Keyword of storage in launcher search that should trigger a storage answer card result.">
storage
</message>
<message name="IDS_ASH_STORAGE_USE_KEYWORD_FOR_LAUNCHER" desc="Keyword of storage use in launcher search that should trigger a storage answer card result.">
storage use
</message>
<message name="IDS_ASH_CPU_KEYWORD_FOR_LAUNCHER" desc="Keyword of cpu in launcher search that should trigger a CPU answer card result.">
cpu
</message>
<message name="IDS_ASH_CPU_USAGE_KEYWORD_FOR_LAUNCHER" desc="Keyword of cpu usage in launcher search that should trigger a CPU answer card result.">
cpu usage
</message>
<message name="IDS_ASH_DEVICE_SLOW_KEYWORD_FOR_LAUNCHER" desc="Keyword of device slow in launcher search that should trigger a CPU answer card result.">
device slow
</message>
<message name="IDS_ASH_WHY_IS_MY_DEVICE_SLOW_KEYWORD_FOR_LAUNCHER" desc="Keyword of why is my device slow in launcher search that should trigger a CPU answer card result.">
why is my device slow
</message>
<message name="IDS_ASH_MEMORY_KEYWORD_FOR_LAUNCHER" desc="Keyword of memory in launcher search that should trigger a memory answer card result.">
memory
</message>
<message name="IDS_ASH_MEMORY_USAGE_KEYWORD_FOR_LAUNCHER" desc="Keyword of memory usage in launcher search that should trigger a memory answer card result.">
memory usage
</message>
<message name="IDS_ASH_RAM_KEYWORD_FOR_LAUNCHER" desc="Keyword of ram (random access memory) in launcher search that should trigger a memory answer card result.">
ram
</message>
<message name="IDS_ASH_RANDOM_ACCESS_MEMORY_KEYWORD_FOR_LAUNCHER" desc="Keyword of random access memory in launcher search that should trigger a memory answer card result.">
random access memory
</message>
<message name="IDS_ASH_RAM_USAGE_KEYWORD_FOR_LAUNCHER" desc="Keyword of ram usage in launcher search that should trigger a memory answer card result.">
ram usage
</message>
<message name="IDS_ASH_ACTIVITY_MONITOR_KEYWORD_FOR_LAUNCHER" desc="Keyword of activity monitor in launcher search that should trigger a memory answer card result.">
actvity monitor
</message>
<message name="IDS_ASH_BATTERY_KEYWORD_FOR_LAUNCHER" desc="Keyword of battery in launcher search that should trigger a battery answer card result.">
battery
</message>
<message name="IDS_ASH_BATTERY_LIFE_KEYWORD_FOR_LAUNCHER" desc="Keyword of battery life in launcher search that should trigger a battery answer card result.">
battery life
</message>
<message name="IDS_ASH_BATTERY_HEALTH_KEYWORD_FOR_LAUNCHER" desc="Keyword of battery health in launcher search that should trigger a battery answer card result.">
battery health
</message>
<message name="IDS_ASH_VERSION_KEYWORD_FOR_LAUNCHER" desc="Keyword of version in launcher search that should trigger a version answer card result.">
version
</message>
<message name="IDS_ASH_MY_DEVICE_KEYWORD_FOR_LAUNCHER" desc="Keyword of my device in launcher search that should trigger a version answer card result.">
my device
</message>
<message name="IDS_ASH_ABOUT_KEYWORD_FOR_LAUNCHER" desc="Keyword of about in launcher search that should trigger a version answer card result.">
about
</message>

<message name="IDS_ASH_TOAST_DISMISS_BUTTON" desc="The text button shown in toasts to close the toast immediately without waiting timeout.">
DISMISS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8c6c2e41794fa277ddcb4261e58d5270a83a18c9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e6dcc98a5ef502ac5ef669f6168c959bc90d1603
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d68346a3193329711d0e20b21a1f4ec7b66c4b3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
25bc4f09b2d82d6314ec2c483c109f29552a1911
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e10073cb71a35a651d6e25911f082b6dd3d93e0c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d7dd831dbbb3368a784bb6a66ddaa35caa6dae85
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8c77bfe9f2540f74f7067010f6bffe3fbc362fbb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
502ab51908363a54d9f59ed430796827754eebe4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
96ea1ce8e5f706bdf7ce4302c66cc8c25a868e07
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
61fe13759ed89be0a0ef75a4d7063ad9db1df523
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c8ea9d0f94bd2f1f42efb0ad6f2c97eb073f0dc1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
68da1349daac782ab963c7cbf391a2baf64040f2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ede0ffde3b7eee3c855825a68082b98d29680e86
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
efe0166c3b7c1e057d90035e2aac998823af0345
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a82eaacf692f4ce8290534a5f67cc90235aa987c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1deb3eb9fa99a8a5b144f2ce21dbb15057366fb9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
964eae4172a80caea4c15c77a91fe250cbf3853b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
49d403cb6bb9436e2ecdbf497bcfcb115dc55c3d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
89fdec36e3fbf5e6b6f07d9d419fb1aa6c52b0d5
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ SystemInfoCardProvider::SystemInfoCardProvider(Profile* profile)
browsing_data_size_calculator_(profile),
apps_size_calculator_(profile),
crostini_size_calculator_(profile),
profile_(profile) {
profile_(profile),
keywords_(GetSystemInfoKeywordVector()) {
DCHECK(profile_);
ash::cros_healthd::ServiceConnection::GetInstance()->BindProbeService(
probe_service_.BindNewPipeAndPassReceiver());
Expand All @@ -93,67 +94,41 @@ SystemInfoCardProvider::~SystemInfoCardProvider() {
}

void SystemInfoCardProvider::Start(const std::u16string& query) {
// TODO(b/263994165): Replace with complete implementation with keywords
// stored in translation unit.
std::vector<std::u16string> memory_keywords = {
u"memory", u"memory usage", u"ram", u"ram usage", u"activity monitor"};
for (const std::u16string& keyword : memory_keywords) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateMemoryUsage();
break;
double max_relevance = 0;
SystemInfoKeywordInput* most_relevant_keyword_input;
for (SystemInfoKeywordInput& keyword_input : keywords_) {
double relevance = CalculateRelevance(query, keyword_input.GetKeyword());
if (relevance > kRelevanceThreshold && relevance > max_relevance) {
max_relevance = relevance;
most_relevant_keyword_input = &keyword_input;
}
}

std::vector<std::u16string> cpu_keywords = {
u"cpu", u"cpu usage", u"device slow", u"why is my device slow"};
for (const std::u16string& keyword : cpu_keywords) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateCpuUsage();
break;
}
}

std::vector<std::u16string> battery_keywords = {u"battery", u"battery life",
u"battery health"};
for (const std::u16string& keyword : battery_keywords) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateBatteryInfo();
break;
}
}

std::vector<std::u16string> version_keywords = {u"version", u"my device",
u"about"};
for (const std::u16string& keyword : version_keywords) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateChromeOsVersion();
break;
}
}

std::vector<std::u16string> storage_keywords = {u"storage", u"storage use",
u"storage management"};
for (const std::u16string& keyword : storage_keywords) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
// Do not calculate the storage size again if already calculated
// recently.
if (max_relevance > kRelevanceThreshold) {
relevance_ = max_relevance;
switch (most_relevant_keyword_input->GetInputType()) {
case SystemInfoInputType::kMemory:
UpdateMemoryUsage();
break;
case SystemInfoInputType::kCPU:
UpdateCpuUsage();
break;
case SystemInfoInputType::kVersion:
UpdateChromeOsVersion();
break;
// Do not calculate the storage size again if already
// calculated recently.
// TODO(b/263994165): Add in a refresh period here.
relevance_ = relevance;
if (!calculation_state_.all()) {
UpdateStorageInfo();
} else {
CreateStorageAnswerCard();
}
break;
case SystemInfoInputType::kStorage:
if (!calculation_state_.all()) {
UpdateStorageInfo();
} else {
CreateStorageAnswerCard();
}
break;
case SystemInfoInputType::kBattery:
UpdateBatteryInfo();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

#include <bitset>
#include <memory>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "chrome/browser/ash/app_list/search/search_provider.h"
#include "chrome/browser/ash/app_list/search/system_info/battery_health.h"
#include "chrome/browser/ash/app_list/search/system_info/cpu_data.h"
#include "chrome/browser/ash/app_list/search/system_info/cpu_usage_data.h"
#include "chrome/browser/ash/app_list/search/system_info/system_info_keyword_input.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/settings/ash/calculator/size_calculator.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
Expand Down Expand Up @@ -106,6 +108,7 @@ class SystemInfoCardProvider : public SearchProvider,
std::unique_ptr<BatteryHealth> battery_health_{nullptr};
gfx::ImageSkia os_settings_icon_;
gfx::ImageSkia diagnostics_icon_;
std::vector<SystemInfoKeywordInput> keywords_;

base::WeakPtrFactory<SystemInfoCardProvider> weak_factory_{this};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/app_list/search/system_info/system_info_keyword_input.h"

namespace app_list {

SystemInfoKeywordInput::SystemInfoKeywordInput(SystemInfoInputType input_type,
std::u16string keyword)
: input_type_(input_type), keyword_(keyword) {}

SystemInfoInputType SystemInfoKeywordInput::GetInputType() {
return input_type_;
}
std::u16string SystemInfoKeywordInput::GetKeyword() {
return keyword_;
}

} // namespace app_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_APP_LIST_SEARCH_SYSTEM_INFO_SYSTEM_INFO_KEYWORD_INPUT_H_
#define CHROME_BROWSER_ASH_APP_LIST_SEARCH_SYSTEM_INFO_SYSTEM_INFO_KEYWORD_INPUT_H_

#include <string>

namespace app_list {

// This enum represents which type of System Info will be displayed.
enum class SystemInfoInputType { kCPU, kVersion, kMemory, kBattery, kStorage };

struct SystemInfoKeywordInput {
SystemInfoKeywordInput() = default;
SystemInfoKeywordInput(SystemInfoInputType input_type,
std::u16string keyword);

~SystemInfoKeywordInput() = default;

SystemInfoInputType GetInputType();
std::u16string GetKeyword();

private:
SystemInfoInputType input_type_;
std::u16string keyword_;
};

} // namespace app_list

#endif // CHROME_BROWSER_ASH_APP_LIST_SEARCH_SYSTEM_INFO_SYSTEM_INFO_KEYWORD_INPUT_H_
66 changes: 66 additions & 0 deletions chrome/browser/ash/app_list/search/system_info/system_info_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ash/app_list/search/system_info/system_info_util.h"

#include <string>
#include <vector>

#include "ash/public/cpp/power_utils.h"
#include "ash/strings/grit/ash_strings.h"
Expand Down Expand Up @@ -279,4 +280,69 @@ void PopulatePowerStatus(const power_manager::PowerSupplyProperties& proto,
battery_health.SetBatteryPercentage(percent);
}

std::vector<SystemInfoKeywordInput> GetSystemInfoKeywordVector() {
return {
SystemInfoKeywordInput(
SystemInfoInputType::kVersion,
l10n_util::GetStringUTF16(IDS_ASH_VERSION_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kVersion,
l10n_util::GetStringUTF16(IDS_ASH_MY_DEVICE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kVersion,
l10n_util::GetStringUTF16(IDS_ASH_ABOUT_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kBattery,
l10n_util::GetStringUTF16(IDS_ASH_BATTERY_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kBattery,
l10n_util::GetStringUTF16(IDS_ASH_BATTERY_LIFE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(SystemInfoInputType::kBattery,
l10n_util::GetStringUTF16(
IDS_ASH_BATTERY_HEALTH_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(IDS_ASH_MEMORY_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(IDS_ASH_MEMORY_USAGE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(IDS_ASH_RAM_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(
IDS_ASH_RANDOM_ACCESS_MEMORY_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(IDS_ASH_RAM_USAGE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kMemory,
l10n_util::GetStringUTF16(
IDS_ASH_ACTIVITY_MONITOR_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kStorage,
l10n_util::GetStringUTF16(
IDS_ASH_STORAGE_MANAGEMENT_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kStorage,
l10n_util::GetStringUTF16(IDS_ASH_STORAGE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kStorage,
l10n_util::GetStringUTF16(IDS_ASH_STORAGE_USE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kCPU,
l10n_util::GetStringUTF16(IDS_ASH_CPU_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kCPU,
l10n_util::GetStringUTF16(IDS_ASH_CPU_USAGE_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kCPU,
l10n_util::GetStringUTF16(IDS_ASH_DEVICE_SLOW_KEYWORD_FOR_LAUNCHER)),
SystemInfoKeywordInput(
SystemInfoInputType::kCPU,
l10n_util::GetStringUTF16(
IDS_ASH_WHY_IS_MY_DEVICE_SLOW_KEYWORD_FOR_LAUNCHER))};
}

} // namespace app_list

0 comments on commit 2179af0

Please sign in to comment.