Skip to content

Commit 5080492

Browse files
christine-hollingsworthChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Quota Internals (chrome://quota-internals-2): Migrate Quota Internals to Typescript
Changes: - Migrates existing JS code in content/browser/resources/quota to TS. Bug: 1189595 Change-Id: Iab594c46145fa4563e86a3579ac9680c38b6f90a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3373881 Reviewed-by: Rebekah Potter <[email protected]> Reviewed-by: Victor Costan <[email protected]> Reviewed-by: John Abd-El-Malek <[email protected]> Commit-Queue: Christine Smith <[email protected]> Cr-Commit-Position: refs/heads/main@{#967428}
1 parent 0543d27 commit 5080492

13 files changed

+186
-98
lines changed

chrome/chrome_paks.gni

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ template("chrome_extra_paks") {
102102
"$root_gen_dir/components/autofill/core/browser/autofill_address_rewriter_resources.pak",
103103
"$root_gen_dir/components/components_resources.pak",
104104
"$root_gen_dir/content/content_resources.pak",
105+
"$root_gen_dir/content/quota_internals_resources.pak",
105106
"$root_gen_dir/mojo/public/js/mojo_bindings_resources.pak",
106107
"$root_gen_dir/net/net_resources.pak",
107108
"$root_gen_dir/skia/skia_resources.pak",
@@ -119,6 +120,7 @@ template("chrome_extra_paks") {
119120
"//components/autofill/core/browser:autofill_address_rewriter_resources",
120121
"//components/resources",
121122
"//content:content_resources",
123+
"//content/browser/resources/quota:resources",
122124
"//mojo/public/js:resources",
123125
"//net:net_resources",
124126
"//skia:skia_resources",

content/browser/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ source_set("browser") {
116116
"//content/browser/payments:payment_app_proto",
117117
"//content/browser/prerender:mojo_bindings",
118118
"//content/browser/process_internals:mojo_bindings",
119+
"//content/browser/resources:resources",
119120
"//content/browser/resources/media:resources",
120121
"//content/browser/webrtc/resources",
121122
"//content/common",

content/browser/quota/quota_internals_ui.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "content/browser/quota/quota_internals_ui.h"
66

77
#include "content/browser/renderer_host/render_frame_host_impl.h"
8-
#include "content/grit/dev_ui_content_resources.h"
8+
#include "content/grit/quota_internals_resources.h"
9+
#include "content/grit/quota_internals_resources_map.h"
910
#include "content/public/browser/render_frame_host.h"
1011
#include "content/public/browser/web_contents.h"
1112
#include "content/public/browser/web_ui.h"
@@ -19,11 +20,10 @@ QuotaInternalsUI::QuotaInternalsUI(WebUI* web_ui) : WebUIController(web_ui) {
1920
WebUIDataSource* source =
2021
WebUIDataSource::Create(kChromeUIQuotaInternalsHost);
2122

22-
source->AddResourcePath("quota_internals.mojom-webui.js",
23-
IDR_QUOTA_INTERNALS_MOJOM_JS);
24-
source->AddResourcePath("quota_internals.js", IDR_QUOTA_INTERNALS_JS);
25-
source->AddResourcePath("quota-internals", IDR_QUOTA_INTERNALS_HTML);
26-
source->SetDefaultResource(IDR_QUOTA_INTERNALS_HTML);
23+
source->AddResourcePaths(
24+
base::make_span(kQuotaInternalsResources, kQuotaInternalsResourcesSize));
25+
26+
source->SetDefaultResource(IDR_QUOTA_INTERNALS_QUOTA_INTERNALS_HTML);
2727

2828
source->OverrideContentSecurityPolicy(
2929
network::mojom::CSPDirectiveName::ScriptSrc,

content/browser/resources/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import("//third_party/closure_compiler/compile_js.gni")
66

7+
group("resources") {
8+
public_deps = [ "quota:resources" ]
9+
}
10+
711
if (enable_js_type_check) {
812
group("closure_compile") {
913
deps = [
1014
"attribution_reporting:closure_compile",
1115
"histograms:closure_compile",
1216
"process:closure_compile",
13-
"quota:closure_compile",
1417
]
1518
}
1619
}

content/browser/resources/quota/BUILD.gn

+61-20
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,70 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
import("//third_party/closure_compiler/compile_js.gni")
5+
import("//chrome/common/features.gni")
6+
import("//tools/grit/grit_rule.gni")
7+
import("//tools/grit/preprocess_if_expr.gni")
8+
import("//tools/polymer/html_to_js.gni")
9+
import("//tools/typescript/ts_library.gni")
610
import("//ui/webui/resources/tools/generate_grd.gni")
711

8-
js_type_check("closure_compile") {
9-
closure_flags = default_closure_args + mojom_js_args + [
10-
"js_module_root=" + rebase_path(".", root_build_dir),
11-
"js_module_root=" + rebase_path(
12-
"$root_gen_dir/mojom-webui/storage/browser/quota",
13-
root_build_dir),
14-
]
15-
deps = [ ":quota_internals" ]
12+
generate_grd("build_grd") {
13+
grd_prefix = "quota_internals"
14+
out_grd = "$target_gen_dir/resources.grd"
15+
input_files = [ "quota_internals.html" ]
16+
input_files_base_dir = rebase_path(".", "//")
17+
18+
deps = [ ":build_ts" ]
19+
manifest_files = [ "$target_gen_dir/tsconfig.manifest" ]
20+
}
21+
22+
preprocess_if_expr("preprocess_mojo") {
23+
deps = [ "//storage/browser/quota:mojo_bindings_webui_js" ]
24+
in_folder = "$root_gen_dir/mojom-webui/storage/browser/quota/"
25+
out_folder = "$target_gen_dir"
26+
in_files = [ "quota_internals.mojom-webui.js" ]
1627
}
1728

18-
js_library("quota_internals") {
19-
sources = [ "quota_internals.js" ]
20-
deps = [
21-
"//storage/browser/quota:mojo_bindings_webui_js",
22-
"//ui/webui/resources/js:assert.m",
23-
"//ui/webui/resources/js:util.m",
24-
"//ui/webui/resources/js/cr:event_target.m",
25-
"//ui/webui/resources/js/cr:ui.m",
26-
"//ui/webui/resources/js/cr/ui:array_data_model.m",
27-
"//ui/webui/resources/js/cr/ui:tabs",
28-
"//ui/webui/resources/js/cr/ui:tree",
29+
preprocess_if_expr("preprocess_proxy") {
30+
in_folder = "./"
31+
out_folder = "$target_gen_dir"
32+
in_files = [ "quota_internals_browser_proxy.ts" ]
33+
}
34+
35+
grit("resources") {
36+
defines = chrome_grit_defines
37+
38+
# These arguments are needed since the grd is generated at build time.
39+
enable_input_discovery_for_gn_analyze = false
40+
source = "$target_gen_dir/resources.grd"
41+
deps = [ ":build_grd" ]
42+
43+
outputs = [
44+
"grit/quota_internals_resources.h",
45+
"grit/quota_internals_resources_map.cc",
46+
"grit/quota_internals_resources_map.h",
47+
"quota_internals_resources.pak",
48+
]
49+
output_dir = "$root_gen_dir/content"
50+
}
51+
52+
html_to_js("web_components") {
53+
js_files = [ "quota_internals.ts" ]
54+
}
55+
56+
ts_library("build_ts") {
57+
root_dir = "$target_gen_dir"
58+
out_dir = "$target_gen_dir/tsc"
59+
tsconfig_base = "tsconfig_base.json"
60+
in_files = [
61+
"quota_internals.ts",
62+
"quota_internals_browser_proxy.ts",
63+
"quota_internals.mojom-webui.js",
64+
]
65+
deps = [ "//ui/webui/resources:library" ]
66+
extra_deps = [
67+
":preprocess_mojo",
68+
":preprocess_proxy",
69+
":web_components",
2970
]
3071
}

content/browser/resources/quota/quota_internals.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
88
<link rel="stylesheet" href="chrome://resources/css/roboto.css">
99
<link rel="stylesheet" href="quota_internals.css">
10-
<script type="module" src="quota_internals.js"></script>
10+
<script type="module" src="quota_internals.js" defer></script>
1111
</head>
1212
<body>
1313
<h1>Quota Internals 2</h1>

content/browser/resources/quota/quota_internals.js

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2022 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import {QuotaInternalsBrowserProxy} from './quota_internals_browser_proxy.js';
6+
7+
function getProxy(): QuotaInternalsBrowserProxy {
8+
return QuotaInternalsBrowserProxy.getInstance();
9+
}
10+
11+
async function renderDiskAvailability() {
12+
const result = await getProxy().getDiskAvailability();
13+
14+
const rowTemplate: HTMLTemplateElement =
15+
document.body.querySelector<HTMLTemplateElement>('#listener-row')!;
16+
const tableBody: HTMLTableElement =
17+
document.body.querySelector<HTMLTableElement>('#listeners-tbody')!;
18+
const listenerRowTemplate: HTMLTemplateElement =
19+
rowTemplate.cloneNode(true) as HTMLTemplateElement;
20+
const listenerRow = listenerRowTemplate.content;
21+
22+
const availableSpaceBytes =
23+
(Number(result.availableSpace) / (1024 ** 3)).toFixed(2);
24+
const totalSpaceBytes = (Number(result.totalSpace) / (1024 ** 3)).toFixed(2);
25+
26+
listenerRow.querySelector('.total-space')!.textContent =
27+
`${totalSpaceBytes} GB`;
28+
listenerRow.querySelector('.available-space')!.textContent =
29+
`${availableSpaceBytes} GB`;
30+
31+
tableBody.append(listenerRow);
32+
}
33+
34+
async function renderEvictionStats() {
35+
const result = await getProxy().getStatistics();
36+
37+
const rowTemplate: HTMLTemplateElement =
38+
document.body.querySelector<HTMLTemplateElement>('#eviction-row')!;
39+
const tableBody: HTMLTableElement =
40+
document.body.querySelector<HTMLTableElement>('#eviction-tbody')!;
41+
const evictionRowTemplate: HTMLTemplateElement =
42+
rowTemplate.cloneNode(true) as HTMLTemplateElement;
43+
const evictionRow = evictionRowTemplate.content;
44+
45+
evictionRow.querySelector('.errors-on-getting-usage-and-quota')!.textContent =
46+
result.evictionStatistics['errors-on-getting-usage-and-quota'];
47+
evictionRow.querySelector('.evicted-buckets')!.textContent =
48+
result.evictionStatistics['evicted-buckets'];
49+
evictionRow.querySelector('.eviction-rounds')!.textContent =
50+
result.evictionStatistics['eviction-rounds'];
51+
evictionRow.querySelector('.skipped-eviction-rounds')!.textContent =
52+
result.evictionStatistics['skipped-eviction-rounds'];
53+
54+
tableBody.appendChild(evictionRow);
55+
}
56+
57+
document.addEventListener('DOMContentLoaded', () => {
58+
renderDiskAvailability();
59+
renderEvictionStats();
60+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2022 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import {QuotaInternalsHandler, QuotaInternalsHandlerRemote} from './quota_internals.mojom-webui.js';
6+
7+
type GetDiskAvailabilityResult = {
8+
totalSpace: bigint, availableSpace: bigint;
9+
};
10+
11+
type GetStatisticsResult = {
12+
evictionStatistics: {
13+
'errors-on-getting-usage-and-quota': string,
14+
'evicted-buckets': string,
15+
'eviction-rounds': string,
16+
'skipped-eviction-rounds': string
17+
}
18+
};
19+
20+
export class QuotaInternalsBrowserProxy {
21+
private handler = QuotaInternalsHandler.getRemote();
22+
23+
getDiskAvailability(): Promise<GetDiskAvailabilityResult> {
24+
return this.handler.getDiskAvailability();
25+
}
26+
27+
getStatistics(): Promise<GetStatisticsResult> {
28+
return this.handler.getStatistics();
29+
}
30+
31+
static getInstance(): QuotaInternalsBrowserProxy {
32+
return instance || (instance = new QuotaInternalsBrowserProxy());
33+
}
34+
}
35+
36+
let instance: QuotaInternalsBrowserProxy|null = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../../../tools/typescript/tsconfig_base.json",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"noUncheckedIndexedAccess": false,
6+
"noUnusedLocals": false,
7+
"strictPropertyInitialization": false
8+
}
9+
}

content/dev_ui_content_resources.grd

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ files that belong there instead.
3737
<include name="IDR_PROCESS_INTERNALS_MOJO_JS" file="${root_gen_dir}/mojom-webui/content/browser/process_internals/process_internals.mojom-webui.js" use_base_dir="false" type="BINDATA" />
3838
<include name="IDR_PROCESS_INTERNALS_CSS" file="browser/resources/process/process_internals.css" type="BINDATA" />
3939
<include name="IDR_PROCESS_INTERNALS_JS" file="browser/resources/process/process_internals.js" type="BINDATA" />
40-
<include name="IDR_QUOTA_INTERNALS_HTML" file="browser/resources/quota/quota_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
41-
<include name="IDR_QUOTA_INTERNALS_JS" file="browser/resources/quota/quota_internals.js" type="BINDATA" />
42-
<include name="IDR_QUOTA_INTERNALS_CSS" file="browser/resources/quota/quota_internals.css" type="BINDATA" />
43-
<include name="IDR_QUOTA_INTERNALS_MOJOM_JS" file="${root_gen_dir}/mojom-webui/storage/browser/quota/quota_internals.mojom-webui.js" use_base_dir="false" type="BINDATA" />
4440
<include name="IDR_SERVICE_WORKER_INTERNALS_HTML" file="browser/resources/service_worker/serviceworker_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
4541
<include name="IDR_SERVICE_WORKER_INTERNALS_JS" file="browser/resources/service_worker/serviceworker_internals.js" type="BINDATA" />
4642
<include name="IDR_SERVICE_WORKER_INTERNALS_CSS" file="browser/resources/service_worker/serviceworker_internals.css" type="BINDATA" />

content/shell/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ repack("pak") {
416416
"$root_gen_dir/content/browser/webrtc/resources/webrtc_internals_resources.pak",
417417
"$root_gen_dir/content/content_resources.pak",
418418
"$root_gen_dir/content/dev_ui_content_resources.pak",
419+
"$root_gen_dir/content/quota_internals_resources.pak",
419420
"$root_gen_dir/content/shell/shell_resources.pak",
420421
"$root_gen_dir/content/test/web_ui_mojo_test_resources.pak",
421422
"$root_gen_dir/mojo/public/js/mojo_bindings_resources.pak",
@@ -438,6 +439,7 @@ repack("pak") {
438439
"//content:content_resources",
439440
"//content:dev_ui_content_resources",
440441
"//content/app/resources",
442+
"//content/browser/resources:resources",
441443
"//content/browser/resources/media:resources",
442444
"//content/browser/webrtc/resources",
443445
"//content/test:web_ui_mojo_test_resources",

tools/gritsettings/resource_ids.spec

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@
384384
"META": {"sizes": {"includes": [10],}},
385385
"includes": [2580],
386386
},
387+
"<(SHARED_INTERMEDIATE_DIR)/content/browser/resources/quota/resources.grd": {
388+
"META": {"sizes": {"includes": [10],}},
389+
"includes": [2590],
390+
},
387391
"<(SHARED_INTERMEDIATE_DIR)/content/browser/webrtc/resources/resources.grd": {
388392
"META": {"sizes": {"includes": [20],}},
389393
"includes": [2600],

0 commit comments

Comments
 (0)