Commit c74f09ab authored by Tim Zheng's avatar Tim Zheng Committed by Commit Bot

Add "scaled" property to Crostini app registration.

This new property is used to record a user's preference for display
window scaling. When it's true the app window will be scaled up. This is
used to adjustment some older Linux apps that don't show well on HiDPI
displays.

BUG=chromium:839242
TEST=Unit tests added.

Change-Id: I6bf49b814d4467f09af9143c237d5a4e3984168d
Reviewed-on: https://chromium-review.googlesource.com/1232196Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Commit-Queue: Tim Zheng <timzheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592585}
parent 594a5bf2
......@@ -48,6 +48,7 @@ constexpr char kAppCommentKey[] = "comment";
constexpr char kAppMimeTypesKey[] = "mime_types";
constexpr char kAppNameKey[] = "name";
constexpr char kAppNoDisplayKey[] = "no_display";
constexpr char kAppScaledKey[] = "scaled";
constexpr char kAppStartupWMClassKey[] = "startup_wm_class";
constexpr char kAppStartupNotifyKey[] = "startup_notify";
constexpr char kAppInstallTimeKey[] = "install_time";
......@@ -316,6 +317,16 @@ base::Time CrostiniRegistryService::Registration::LastLaunchTime() const {
return GetTime(pref_, kAppLastLaunchTimeKey);
}
bool CrostiniRegistryService::Registration::IsScaled() const {
if (pref_.is_none())
return false;
const base::Value* scaled =
pref_.FindKeyOfType(kAppScaledKey, base::Value::Type::BOOLEAN);
if (!scaled)
return false;
return scaled->GetBool();
}
// We store in prefs all the localized values for given fields (formatted with
// undescores, e.g. 'fr' or 'en_US'), but users of the registry don't need to
// deal with this.
......@@ -756,6 +767,23 @@ void CrostiniRegistryService::SetCurrentTime(base::Value* dictionary,
dictionary->SetKey(key, base::Value(base::Int64ToString(time)));
}
void CrostiniRegistryService::SetAppScaled(const std::string& app_id,
bool scaled) {
DCHECK_NE(app_id, kCrostiniTerminalId);
DictionaryPrefUpdate update(prefs_, prefs::kCrostiniRegistry);
base::DictionaryValue* apps = update.Get();
base::Value* app = apps->FindKey(app_id);
if (!app) {
LOG(ERROR)
<< "Tried to set display scaled property on the app with this app_id "
<< app_id << " that doesn't exist in the registry.";
return;
}
app->SetKey(kAppScaledKey, base::Value(scaled));
}
void CrostiniRegistryService::RequestIcon(const std::string& app_id,
ui::ScaleFactor scale_factor) {
// Ignore requests for app_id that isn't registered.
......
......@@ -88,6 +88,9 @@ class CrostiniRegistryService : public KeyedService {
base::Time InstallTime() const;
base::Time LastLaunchTime() const;
// Whether this app should scale up when displayed.
bool IsScaled() const;
private:
std::string LocalizedString(base::StringPiece key) const;
......@@ -172,6 +175,9 @@ class CrostiniRegistryService : public KeyedService {
// Serializes the current time and stores it in |dictionary|.
void SetCurrentTime(base::Value* dictionary, const char* key) const;
// Set the display scaled setting of the |app_id| to |scaled|.
void SetAppScaled(const std::string& app_id, bool scaled);
void SetClockForTesting(base::Clock* clock) { clock_ = clock; }
private:
......
......@@ -423,4 +423,34 @@ TEST_F(CrostiniRegistryServiceTest, GetCrostiniAppIdNameSkipNoDisplay) {
EXPECT_EQ(service()->GetCrostiniShelfAppId(&window_app_id, nullptr),
CrostiniTestHelper::GenerateAppId("app2", "vm", "container"));
}
TEST_F(CrostiniRegistryServiceTest, IsScaledReturnFalseWhenNotSet) {
std::string app_id =
CrostiniTestHelper::GenerateAppId("app", "vm", "container");
ApplicationList app_list =
CrostiniTestHelper::BasicAppList("app", "vm", "container");
service()->UpdateApplicationList(app_list);
base::Optional<CrostiniRegistryService::Registration> registration =
service()->GetRegistration(app_id);
EXPECT_TRUE(registration.has_value());
EXPECT_FALSE(registration.value().IsScaled());
}
TEST_F(CrostiniRegistryServiceTest, SetScaledWorks) {
std::string app_id =
CrostiniTestHelper::GenerateAppId("app", "vm", "container");
ApplicationList app_list =
CrostiniTestHelper::BasicAppList("app", "vm", "container");
service()->UpdateApplicationList(app_list);
service()->SetAppScaled(app_id, true);
base::Optional<CrostiniRegistryService::Registration> registration =
service()->GetRegistration(app_id);
EXPECT_TRUE(registration.has_value());
EXPECT_TRUE(registration.value().IsScaled());
service()->SetAppScaled(app_id, false);
registration = service()->GetRegistration(app_id);
EXPECT_TRUE(registration.has_value());
EXPECT_FALSE(registration.value().IsScaled());
}
} // namespace crostini
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