Skip to content

Commit 50e335b

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[foundation] Add basic Universe, only instantiating settings for now
This CL adds the basic scaffolding for what will become bootstrapping for DevTools foundation. For now, we instantiate the global Settings instance as this will be required for nearly everything else. The CreationOptions are also not final. For now, they are used to pass in anything "host platform" dependent, but we'll move these behind better types and interfaces as the migration goes on. For now, they are a grab bag of host-dependent dependencies required to instantiate foundation classes. The CL also adds a unit test running both in Node and the browser to make sure we can instantiate a Universe in both. Moving forward, we'll add a DevToolsContext so we can scope these globals. We'll also have a single global DevToolsContext for migration purposes. Bug: 458180550 Change-Id: If1f1b172517ef4e8e3992764cc2f4cf811e24a14 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7124027 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent fde699a commit 50e335b

File tree

12 files changed

+129
-11
lines changed

12 files changed

+129
-11
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ grd_files_bundled_sources = [
393393
"front_end/entrypoints/wasmparser_worker/wasmparser_worker-entrypoint.js",
394394
"front_end/entrypoints/wasmparser_worker/wasmparser_worker.js",
395395
"front_end/entrypoints/worker_app/worker_app.js",
396+
"front_end/foundation/foundation.js",
396397
"front_end/inspector.html",
397398
"front_end/js_app.html",
398399
"front_end/models/ai_assistance/ai_assistance.js",
@@ -1021,6 +1022,7 @@ grd_files_unbundled_sources = [
10211022
"front_end/entrypoints/node_app/app/nodeConnectionsPanel.css.js",
10221023
"front_end/entrypoints/wasmparser_worker/WasmParserWorker.js",
10231024
"front_end/entrypoints/worker_app/WorkerMain.js",
1025+
"front_end/foundation/Universe.js",
10241026
"front_end/generated/ARIAProperties.js",
10251027
"front_end/generated/Deprecation.js",
10261028
"front_end/generated/InspectorBackendCommands.js",

front_end/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ group("foundation_unittests") {
278278
deps = [
279279
"core/common:foundation_unittests",
280280
"core/i18n:foundation_unittests",
281+
"foundation:unittests",
281282
"models/ai_assistance:foundation_unittests",
282283
"models/issues_manager:foundation_unittests",
283284
]

front_end/Tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,11 @@
952952
}
953953

954954
function gotPreferences(prefs) {
955-
Main.Main.instanceForTest.createSettings(prefs);
955+
Common.Settings.Settings.instance({
956+
forceNew: true,
957+
...Main.Main.instanceForTest.createSettingsStorage(prefs),
958+
runSettingsMigration: false,
959+
});
956960

957961
const localSetting = Common.Settings.Settings.instance().createLocalSetting('local', undefined);
958962
test.assertEquals('object', typeof localSetting.get());

front_end/entrypoints/main/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ devtools_module("main") {
2323
"../../core/platform:bundle",
2424
"../../core/protocol_client:bundle",
2525
"../../core/sdk:bundle",
26+
"../../foundation:bundle",
2627
"../../generated:protocol",
2728
"../../models/ai_assistance:bundle",
2829
"../../models/autofill_manager:bundle",

front_end/entrypoints/main/MainImpl.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import * as Platform from '../../core/platform/platform.js';
4141
import * as ProtocolClient from '../../core/protocol_client/protocol_client.js';
4242
import * as Root from '../../core/root/root.js';
4343
import * as SDK from '../../core/sdk/sdk.js';
44+
import * as Foundation from '../../foundation/foundation.js';
4445
import * as AiAssistanceModel from '../../models/ai_assistance/ai_assistance.js';
4546
import * as AutofillManager from '../../models/autofill_manager/autofill_manager.js';
4647
import * as Badges from '../../models/badges/badges.js';
@@ -165,7 +166,14 @@ export class MainImpl {
165166
console.timeStamp('Main._gotPreferences');
166167
this.#initializeGlobalsForLayoutTests();
167168
Object.assign(Root.Runtime.hostConfig, config);
168-
this.createSettings(prefs);
169+
170+
const creationOptions: Foundation.Universe.CreationOptions = {
171+
...this.createSettingsStorage(prefs),
172+
logSettingAccess: VisualLogging.logSettingAccess,
173+
runSettingsMigration: !Host.InspectorFrontendHost.isUnderTest(),
174+
};
175+
new Foundation.Universe.Universe(creationOptions);
176+
169177
await this.requestAndRegisterLocaleData();
170178

171179
Host.userMetrics.syncSetting(Common.Settings.Settings.instance().moduleSetting<boolean>('sync-preferences').get());
@@ -243,7 +251,11 @@ export class MainImpl {
243251
}
244252
}
245253

246-
createSettings(prefs: Record<string, string>): void {
254+
createSettingsStorage(prefs: Record<string, string>): {
255+
syncedStorage: Common.Settings.SettingsStorage,
256+
globalStorage: Common.Settings.SettingsStorage,
257+
localStorage: Common.Settings.SettingsStorage,
258+
} {
247259
this.#initializeExperiments();
248260
let storagePrefix = '';
249261
if (Host.Platform.isCustomDevtoolsFrontend()) {
@@ -287,14 +299,8 @@ export class MainImpl {
287299
// setting can't change storage buckets during a single DevTools session.
288300
const syncedStorage = new Common.Settings.SettingsStorage(prefs, hostSyncedStorage, storagePrefix);
289301
const globalStorage = new Common.Settings.SettingsStorage(prefs, hostUnsyncedStorage, storagePrefix);
290-
Common.Settings.Settings.instance({
291-
forceNew: true,
292-
syncedStorage,
293-
globalStorage,
294-
localStorage,
295-
logSettingAccess: VisualLogging.logSettingAccess,
296-
runSettingsMigration: !Host.InspectorFrontendHost.isUnderTest()
297-
});
302+
303+
return {syncedStorage, globalStorage, localStorage};
298304
}
299305

300306
#initializeExperiments(): void {

front_end/foundation/BUILD.gn

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 The Chromium Authors
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("../../scripts/build/ninja/devtools_entrypoint.gni")
6+
import("../../scripts/build/ninja/devtools_module.gni")
7+
8+
devtools_foundation_module("foundation") {
9+
sources = [ "Universe.ts" ]
10+
11+
deps = [ "../core/common:bundle" ]
12+
}
13+
14+
devtools_entrypoint("bundle") {
15+
entrypoint = "foundation.ts"
16+
17+
deps = [ ":foundation" ]
18+
19+
# IMPORTANT: core/ or models/ must not be added here.
20+
visibility = [
21+
"../../mcp/*",
22+
"../entrypoints/*",
23+
"../panels/*",
24+
"../testing/*",
25+
"../ui/*",
26+
"./*",
27+
]
28+
}
29+
30+
devtools_foundation_module("unittests") {
31+
testonly = true
32+
33+
sources = [ "Universe.test.ts" ]
34+
35+
deps = [
36+
":bundle",
37+
"../core/common:bundle",
38+
]
39+
}

front_end/foundation/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# DevTools foundation
2+
3+
DevTools foundation is the core business logic of DevTools: mainly core/ and models/.
4+
The difference between "foundation" and the rest of DevTools is
5+
that the code is targeted not just for the browser, but also the Node.js runtime.
6+
As such, allowed use of APIs is restricted to what is available in both runtimes.
7+
8+
A `DevToolsUniverse` is a concrete, encapsulated instance of "foundation" scoped
9+
to a single root CDP target. It is valid to create multiple `DevToolsUniverse`
10+
instances simultaneously.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2025 The Chromium Authors
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 * as Common from '../core/common/common.js';
6+
7+
import * as Foundation from './foundation.js';
8+
9+
describe('Universe', () => {
10+
it('can be instantiated', () => {
11+
new Foundation.Universe.Universe({
12+
syncedStorage: new Common.Settings.SettingsStorage({}),
13+
globalStorage: new Common.Settings.SettingsStorage({}),
14+
localStorage: new Common.Settings.SettingsStorage({}),
15+
});
16+
});
17+
});

front_end/foundation/Universe.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The Chromium Authors
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 * as Common from '../core/common/common.js';
6+
7+
export interface CreationOptions {
8+
// Settings things
9+
syncedStorage: Common.Settings.SettingsStorage;
10+
globalStorage: Common.Settings.SettingsStorage;
11+
localStorage: Common.Settings.SettingsStorage;
12+
logSettingAccess?: (name: string, value: number|string|boolean) => Promise<void>;
13+
runSettingsMigration?: boolean;
14+
}
15+
16+
export class Universe {
17+
constructor(options: CreationOptions) {
18+
// TODO(crbug.com/458180550): Store instance on a "DevToolsContext" instead.
19+
// For now the global is fine as we don't anticipate the MCP server to change settings.
20+
Common.Settings.Settings.instance({
21+
forceNew: true,
22+
syncedStorage: options.syncedStorage,
23+
globalStorage: options.globalStorage,
24+
localStorage: options.localStorage,
25+
logSettingAccess: options.logSettingAccess,
26+
runSettingsMigration: options.runSettingsMigration,
27+
});
28+
}
29+
}

front_end/foundation/foundation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2025 The Chromium Authors
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 * as Universe from './Universe.js';
6+
7+
export {Universe};

0 commit comments

Comments
 (0)