Skip to content

Commit

Permalink
personalization: consolidate loadTimeData.getBoolean
Browse files Browse the repository at this point in the history
Add new file load_time_booleans.ts and move all loadTimeData.getBoolean
accesses into that file. Make all loadTimeData boolean properties
consistent as properties on polymer elements.

BUG=none
TEST=browser_tests --gtest_filter=*PersonalizationApp*

Change-Id: If296106f5e1b4269a96dd93041e03141258169c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4211454
Commit-Queue: Jeffrey Young <cowmoo@google.com>
Reviewed-by: Jerry Liu <pzliu@chromium.org>
Reviewed-by: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1100515}
  • Loading branch information
cwmoo740 authored and Chromium LUCI CQ committed Feb 2, 2023
1 parent 62911c1 commit 194e21f
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 82 deletions.
1 change: 1 addition & 0 deletions ash/webui/personalization_app/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ non_web_component_files = [
"js/keyboard_backlight/keyboard_backlight_observer.ts",
"js/keyboard_backlight/keyboard_backlight_reducers.ts",
"js/keyboard_backlight/keyboard_backlight_state.ts",
"js/load_time_booleans.ts",
"js/personalization_actions.ts",
"js/personalization_app.ts",
"js/personalization_metrics_logger.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* polymer element.
*/

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {Url} from 'chrome://resources/mojo/url/mojom/url.mojom-webui.js';
import {PolymerElementProperties} from 'chrome://resources/polymer/v3_0/polymer/interfaces.js';

import {isAmbientModeManaged, isPersonalizationJellyEnabled} from '../load_time_booleans.js';
import {setErrorAction} from '../personalization_actions.js';
import {AmbientModeAlbum, TopicSource} from '../personalization_app.mojom-webui.js';
import {WithPersonalizationStore} from '../personalization_store.js';
Expand Down Expand Up @@ -61,13 +61,13 @@ export class AmbientPreviewBase extends WithPersonalizationStore {
isPersonalizationJellyEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isPersonalizationJellyEnabled');
return isPersonalizationJellyEnabled();
},
},
isAmbientModeManaged_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isAmbientModeManaged');
return isAmbientModeManaged();
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
[[getAlbumDescription_(topicSource_, previewAlbums_)]]
</span>
</h3>
<div id="buttonContainer" hidden$="[[!isScreenSaverPreviewEnabled_()]]">
<div id="buttonContainer" hidden$="[[!isScreenSaverPreviewEnabled_]]">
<cr-button
class$="[[getScreenSaverPreviewClass_(ambientUiVisibility_)]]"
on-click="startScreenSaverPreview_">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import './ambient_zero_state_svg_element.js';
import '../../css/common.css.js';
import '../../css/cros_button_style.css.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';

import {isScreenSaverPreviewEnabled} from '../load_time_booleans.js';
import {AmbientUiVisibility} from '../personalization_app.mojom-webui.js';

import {startScreenSaverPreview} from './ambient_controller.js';
Expand Down Expand Up @@ -49,11 +48,18 @@ export class AmbientPreviewSmall extends AmbientPreviewBase {
type: Number,
value: null,
},
isScreenSaverPreviewEnabled_: {
type: Boolean,
value() {
return isScreenSaverPreviewEnabled();
},
},
};
}

private screenSaverPreviewActive_: boolean;
private ambientUiVisibility_: AmbientUiVisibility|null;
private isScreenSaverPreviewEnabled_: boolean;

override connectedCallback() {
super.connectedCallback();
Expand All @@ -66,10 +72,6 @@ export class AmbientPreviewSmall extends AmbientPreviewBase {
return this.ambientUiVisibility_ === AmbientUiVisibility.kPreview;
}

private isScreenSaverPreviewEnabled_() {
return loadTimeData.getBoolean('isScreenSaverPreviewEnabled');
}

private startScreenSaverPreview_(event: Event) {
event.stopPropagation();
startScreenSaverPreview(getAmbientProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import './animation_theme_list_element.js';
import './toggle_row_element.js';
import './topic_source_list_element.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assert} from 'chrome://resources/js/assert_ts.js';
import {afterNextRender} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {isAmbientModeAllowed, isPersonalizationJellyEnabled} from '../load_time_booleans.js';
import {AmbientModeAlbum, AnimationTheme, TemperatureUnit, TopicSource} from '../personalization_app.mojom-webui.js';
import {isAmbientModeAllowed, Paths} from '../personalization_router_element.js';
import {Paths} from '../personalization_router_element.js';
import {WithPersonalizationStore} from '../personalization_store.js';

import {setAmbientModeEnabled} from './ambient_controller.js';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class AmbientSubpage extends WithPersonalizationStore {
isPersonalizationJellyEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isPersonalizationJellyEnabled');
return isPersonalizationJellyEnabled();
},
},
};
Expand Down
52 changes: 52 additions & 0 deletions ash/webui/personalization_app/resources/js/load_time_booleans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

/**
* @fileoverview Getters for all of the loadTimeData booleans used throughout
* personalization app.
* @see //ash/webui/personalization_app/personalization_app_ui.cc
* Export them as functions so they reload the values when overridden in test.
*/

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';

export function isFullScreenPreviewEnabled() {
return loadTimeData.getBoolean('fullScreenPreviewEnabled');
}

export function isGooglePhotosIntegrationEnabled() {
return loadTimeData.getBoolean('isGooglePhotosIntegrationEnabled');
}

export function isGooglePhotosSharedAlbumsEnabled() {
return loadTimeData.getBoolean('isGooglePhotosSharedAlbumsEnabled');
}

export function isDarkLightModeEnabled() {
return loadTimeData.getBoolean('isDarkLightModeEnabled');
}

export function isAmbientModeAllowed() {
return loadTimeData.getBoolean('isAmbientModeAllowed');
}

export function isRgbKeyboardSupported() {
return loadTimeData.getBoolean('isRgbKeyboardSupported');
}

export function isJellyEnabled() {
return loadTimeData.getBoolean('isJellyEnabled');
}

export function isScreenSaverPreviewEnabled() {
return loadTimeData.getBoolean('isScreenSaverPreviewEnabled');
}

export function isPersonalizationJellyEnabled() {
return loadTimeData.getBoolean('isPersonalizationJellyEnabled');
}

export function isAmbientModeManaged() {
return loadTimeData.getBoolean('isAmbientModeManaged');
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import './wallpaper/index.js';
import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {startColorChangeUpdater} from 'chrome://resources/cr_components/color_change_listener/colors_css_updater.js';

import {isJellyEnabled} from './load_time_booleans.js';
import {emptyState} from './personalization_state.js';
import {PersonalizationStore} from './personalization_store.js';

Expand Down Expand Up @@ -123,7 +124,7 @@ if (link) {
}
document.title = loadTimeData.getString('personalizationTitle');

if (loadTimeData.getBoolean('isJellyEnabled')) {
if (isJellyEnabled()) {
// After the Jelly experiment is launched, add the link directly to
// `index.html`.
const link = document.createElement('link');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
</user-preview>
<div id="middle">
<wallpaper-preview>
<template is="dom-if" if="[[isDarkLightModeEnabled_()]]">
<template is="dom-if" if="[[isDarkLightModeEnabled_]]">
<personalization-theme></personalization-theme>
</template>
</wallpaper-preview>
<template is="dom-if" if="[[isAmbientModeAllowed_()]]">
<template is="dom-if" if="[[isAmbientModeAllowed_]]">
<ambient-preview-large>
</ambient-preview-large>
</template>
</div>
<template is="dom-if" if="[[isRgbKeyboardSupported_()]]">
<template is="dom-if" if="[[isRgbKeyboardSupported_]]">
<keyboard-backlight></keyboard-backlight>
</template>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

import './ambient/ambient_preview_large_element.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';

import {isAmbientModeAllowed, isDarkLightModeEnabled, isRgbKeyboardSupported} from './load_time_booleans.js';
import {getTemplate} from './personalization_main_element.html.js';
import {isAmbientModeAllowed} from './personalization_router_element.js';
import {WithPersonalizationStore} from './personalization_store.js';

export class PersonalizationMain extends WithPersonalizationStore {
Expand All @@ -27,20 +25,26 @@ export class PersonalizationMain extends WithPersonalizationStore {
static get properties() {
return {
path: String,
isDarkLightModeEnabled_: {
type: Boolean,
value() {
return isDarkLightModeEnabled();
},
},
isAmbientModeAllowed_: {
type: Boolean,
value() {
return isAmbientModeAllowed();
},
},
isRgbKeyboardSupported_: {
type: Boolean,
value() {
return isRgbKeyboardSupported();
},
},
};
}

private isDarkLightModeEnabled_(): boolean {
return loadTimeData.getBoolean('isDarkLightModeEnabled');
}

private isAmbientModeAllowed_(): boolean {
return isAmbientModeAllowed();
}

private isRgbKeyboardSupported_(): boolean {
return loadTimeData.getBoolean('isRgbKeyboardSupported');
}
}

customElements.define(PersonalizationMain.is, PersonalizationMain);
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import 'chrome://resources/polymer/v3_0/iron-location/iron-location.js';
import 'chrome://resources/polymer/v3_0/iron-location/iron-query-params.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assert} from 'chrome://resources/ash/common/assert.js';
import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {isAmbientModeAllowed} from './load_time_booleans.js';
import {GooglePhotosAlbum, TopicSource, WallpaperCollection} from './personalization_app.mojom-webui.js';
import {logPersonalizationPathUMA} from './personalization_metrics_logger.js';
import {getTemplate} from './personalization_router_element.html.js';
Expand All @@ -29,10 +30,6 @@ export enum Paths {
USER = '/user',
}

export function isAmbientModeAllowed(): boolean {
return loadTimeData.getBoolean('isAmbientModeAllowed');
}

export function isPathValid(path: string|null): boolean {
return !!path && Object.values(Paths).includes(path as Paths);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assert} from 'chrome://resources/js/assert_ts.js';

import {isGooglePhotosIntegrationEnabled} from './load_time_booleans.js';
import {PersonalizationStore} from './personalization_store.js';
import {setFullscreenEnabledAction} from './wallpaper/wallpaper_actions.js';
import {getWallpaperProvider} from './wallpaper/wallpaper_interface_provider.js';
Expand All @@ -19,10 +19,6 @@ function enterFullscreen() {
store.dispatch(setFullscreenEnabledAction(true));
}

function isGooglePhotosIntegrationEnabled(): boolean {
return loadTimeData.getBoolean('isGooglePhotosIntegrationEnabled');
}

function makeTransparent() {
const wallpaperProvider = getWallpaperProvider();
wallpaperProvider.makeTransparent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js';
import '../../css/common.css.js';
import '../../css/cros_button_style.css.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js';
import {IronA11yKeysElement} from 'chrome://resources/polymer/v3_0/iron-a11y-keys/iron-a11y-keys.js';
import {IronSelectorElement} from 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js';

import {isJellyEnabled} from '../load_time_booleans.js';
import {WithPersonalizationStore} from '../personalization_store.js';
import {isSelectionEvent} from '../utils.js';

Expand Down Expand Up @@ -56,7 +56,9 @@ export class PersonalizationThemeElement extends WithPersonalizationStore {
},
isJellyEnabled_: {
type: Boolean,
value: loadTimeData.getBoolean('isJellyEnabled'),
value() {
return isJellyEnabled();
},
},

/** The button currently highlighted by keyboard navigation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import 'chrome://resources/polymer/v3_0/iron-scroll-threshold/iron-scroll-thresh
import '../../css/wallpaper.css.js';
import '../../css/common.css.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assert} from 'chrome://resources/js/assert_ts.js';
import {IronListElement} from 'chrome://resources/polymer/v3_0/iron-list/iron-list.js';
import {IronScrollThresholdElement} from 'chrome://resources/polymer/v3_0/iron-scroll-threshold/iron-scroll-threshold.js';
import {afterNextRender} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {isGooglePhotosSharedAlbumsEnabled} from '../load_time_booleans.js';
import {dismissErrorAction, setErrorAction} from '../personalization_actions.js';
import {GooglePhotosAlbum, WallpaperProviderInterface} from '../personalization_app.mojom-webui.js';
import {PersonalizationRouter} from '../personalization_router_element.js';
Expand Down Expand Up @@ -88,7 +88,7 @@ export class GooglePhotosAlbums extends WithPersonalizationStore {
isSharedAlbumsEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isGooglePhotosSharedAlbumsEnabled');
return isGooglePhotosSharedAlbumsEnabled();
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import 'chrome://resources/cr_elements/cr_button/cr_button.js';
import '../../css/wallpaper.css.js';
import '../../css/common.css.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assertNotReached} from 'chrome://resources/js/assert_ts.js';

import {isGooglePhotosSharedAlbumsEnabled} from '../load_time_booleans.js';
import {GooglePhotosAlbum, GooglePhotosEnablementState, GooglePhotosPhoto, WallpaperProviderInterface} from '../personalization_app.mojom-webui.js';
import {Paths, PersonalizationRouter} from '../personalization_router_element.js';
import {WithPersonalizationStore} from '../personalization_store.js';
Expand Down Expand Up @@ -96,7 +96,7 @@ export class GooglePhotosCollection extends WithPersonalizationStore {
isSharedAlbumsEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isGooglePhotosSharedAlbumsEnabled');
return isGooglePhotosSharedAlbumsEnabled();
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import 'chrome://resources/polymer/v3_0/iron-scroll-threshold/iron-scroll-thresh
import '../../css/wallpaper.css.js';
import '../../css/common.css.js';

import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {assert} from 'chrome://resources/js/assert_ts.js';
import {IronListElement} from 'chrome://resources/polymer/v3_0/iron-list/iron-list.js';
import {IronScrollThresholdElement} from 'chrome://resources/polymer/v3_0/iron-scroll-threshold/iron-scroll-threshold.js';
import {afterNextRender} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {isGooglePhotosSharedAlbumsEnabled} from '../load_time_booleans.js';
import {dismissErrorAction, setErrorAction} from '../personalization_actions.js';
import {CurrentWallpaper, GooglePhotosAlbum, GooglePhotosPhoto, WallpaperProviderInterface, WallpaperType} from '../personalization_app.mojom-webui.js';
import {PersonalizationStateError} from '../personalization_state.js';
Expand Down Expand Up @@ -83,7 +83,7 @@ export class GooglePhotosPhotosByAlbumId extends WithPersonalizationStore {
isSharedAlbumsEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isGooglePhotosSharedAlbumsEnabled');
return isGooglePhotosSharedAlbumsEnabled();
},
},

Expand Down

0 comments on commit 194e21f

Please sign in to comment.