summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js')
-rw-r--r--chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js162
1 files changed, 79 insertions, 83 deletions
diff --git a/chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js b/chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js
index 17b8ee697bd..6f86f160d4b 100644
--- a/chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js
+++ b/chromium/chrome/browser/resources/welcome/ntp_background/ntp_background_proxy.js
@@ -2,100 +2,96 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-cr.define('welcome', function() {
+import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js';
+import {NtpBackgroundMetricsProxyImpl} from './ntp_background_metrics_proxy.js';
+
+/**
+ * @typedef {{
+ * id: number,
+ * imageUrl: string,
+ * thumbnailClass: string,
+ * title: string,
+ * }}
+ */
+export let NtpBackgroundData;
+
+/** @interface */
+export class NtpBackgroundProxy {
+ /** @return {!Promise} */
+ clearBackground() {}
+
+ /** @return {!Promise<!Array<!NtpBackgroundData>>} */
+ getBackgrounds() {}
+
/**
- * @typedef {{
- * id: number,
- * imageUrl: string,
- * thumbnailClass: string,
- * title: string,
- * }}
+ * @param {string} url
+ * @return {!Promise<void>}
*/
- let NtpBackgroundData;
+ preloadImage(url) {}
+
+ recordBackgroundImageFailedToLoad() {}
- /** @interface */
- class NtpBackgroundProxy {
- clearBackground() {}
+ /** @param {number} loadTime */
+ recordBackgroundImageLoadTime(loadTime) {}
- /** @return {!Promise<!Array<!welcome.NtpBackgroundData>>} */
- getBackgrounds() {}
+ recordBackgroundImageNeverLoaded() {}
- /**
- * @param {string} url
- * @return {!Promise<void>}
- */
- preloadImage(url) {}
+ /** @param {number} id */
+ setBackground(id) {}
+}
+
+/** @implements {NtpBackgroundProxy} */
+export class NtpBackgroundProxyImpl {
+ /** @override */
+ clearBackground() {
+ return sendWithPromise('clearBackground');
+ }
- recordBackgroundImageFailedToLoad() {}
+ /** @override */
+ getBackgrounds() {
+ return sendWithPromise('getBackgrounds');
+ }
- /** @param {number} loadTime */
- recordBackgroundImageLoadTime(loadTime) {}
+ /** @override */
+ preloadImage(url) {
+ return new Promise((resolve, reject) => {
+ const preloadedImage = new Image();
+ preloadedImage.onerror = reject;
+ preloadedImage.onload = resolve;
+ preloadedImage.src = url;
+ });
+ }
- recordBackgroundImageNeverLoaded() {}
+ /** @override */
+ recordBackgroundImageFailedToLoad() {
+ const ntpInteractions =
+ NtpBackgroundMetricsProxyImpl.getInstance().getInteractions();
+ chrome.metricsPrivate.recordEnumerationValue(
+ 'FirstRun.NewUserExperience.NtpBackgroundInteraction',
+ ntpInteractions.BackgroundImageFailedToLoad,
+ Object.keys(ntpInteractions).length);
+ }
- /** @param {number} id */
- setBackground(id) {}
+ /** @override */
+ recordBackgroundImageLoadTime(loadTime) {
+ chrome.metricsPrivate.recordTime(
+ 'FirstRun.NewUserExperience.NtpBackgroundLoadTime', loadTime);
}
- /** @implements {welcome.NtpBackgroundProxy} */
- class NtpBackgroundProxyImpl {
- /** @override */
- clearBackground() {
- return cr.sendWithPromise('clearBackground');
- }
-
- /** @override */
- getBackgrounds() {
- return cr.sendWithPromise('getBackgrounds');
- }
-
- /** @override */
- preloadImage(url) {
- return new Promise((resolve, reject) => {
- const preloadedImage = new Image();
- preloadedImage.onerror = reject;
- preloadedImage.onload = resolve;
- preloadedImage.src = url;
- });
- }
-
- /** @override */
- recordBackgroundImageFailedToLoad() {
- const ntpInteractions =
- welcome.NtpBackgroundMetricsProxyImpl.getInstance().getInteractions();
- chrome.metricsPrivate.recordEnumerationValue(
- 'FirstRun.NewUserExperience.NtpBackgroundInteraction',
- ntpInteractions.BackgroundImageFailedToLoad,
- Object.keys(ntpInteractions).length);
- }
-
- /** @override */
- recordBackgroundImageLoadTime(loadTime) {
- chrome.metricsPrivate.recordTime(
- 'FirstRun.NewUserExperience.NtpBackgroundLoadTime', loadTime);
- }
-
- /** @override */
- recordBackgroundImageNeverLoaded() {
- const ntpInteractions =
- welcome.NtpBackgroundMetricsProxyImpl.getInstance().getInteractions();
- chrome.metricsPrivate.recordEnumerationValue(
- 'FirstRun.NewUserExperience.NtpBackgroundInteraction',
- ntpInteractions.BackgroundImageNeverLoaded,
- Object.keys(ntpInteractions).length);
- }
-
- /** @override */
- setBackground(id) {
- chrome.send('setBackground', [id]);
- }
+ /** @override */
+ recordBackgroundImageNeverLoaded() {
+ const ntpInteractions =
+ NtpBackgroundMetricsProxyImpl.getInstance().getInteractions();
+ chrome.metricsPrivate.recordEnumerationValue(
+ 'FirstRun.NewUserExperience.NtpBackgroundInteraction',
+ ntpInteractions.BackgroundImageNeverLoaded,
+ Object.keys(ntpInteractions).length);
}
- cr.addSingletonGetter(NtpBackgroundProxyImpl);
+ /** @override */
+ setBackground(id) {
+ chrome.send('setBackground', [id]);
+ }
+}
- return {
- NtpBackgroundData: NtpBackgroundData,
- NtpBackgroundProxy: NtpBackgroundProxy,
- NtpBackgroundProxyImpl: NtpBackgroundProxyImpl,
- };
-});
+addSingletonGetter(NtpBackgroundProxyImpl);