src/vs/platform/policy/node/nativeManagedSettingsService.ts

141 LOC · 133 covered · 8 uncovered · 26 ranges · 12 concepts · 6 introducers · 7 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/policy/common/nativeManagedSettingsIpc.ts · 79 LOCcommon/nativeManagedSett…nativeManagedSettingsService.test|title=NativeManagedSettingsService keeps raw managed settings while definitions are unchanged|occurrence=1 · 0 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.ts ×2 · 6 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService removes raw managed settings whose definitions are no longer watched|occurrence=1 · 0 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.ts ×2 · 7 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.ts ×11 · 45 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsIpc.ts ×1 · 2 introduced LOCnativeManagedSettingsIpc…nativeManagedSettingsIpc.ts ×3 · 7 introduced LOCnativeManagedSettingsIpc…nativeManagedSettingsIpc.ts ×5 · 12 introduced LOCnativeManagedSettingsIpc…nativeManagedSettingsService.test|title=NativeManagedSettingsService does not create the watcher until a managed-settings policy definition is registered|occurrence=1 · 0 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.ts ×1 · 2 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsService.ts ×3 · 11 introduced LOCnativeManagedSettingsSer…nativeManagedSettingsIpc.ts ×7 · 105 introduced LOCnativeManagedSettingsIpc…nativeManagedSettingsService.test|title=NativeManagedSettingsService channel client keeps newer event state when initial snapshot resolves later|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService channel client keeps newer event state when initial snapshot resolves later|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService channel client updatePolicyDefinitions updates cache without firing change event|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService channel client updatePolicyDefinitions updates cache without firing change event|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService clears stale watcher values when managed-settings definitions are removed|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService clears stale watcher values when managed-settings definitions are removed|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService does not create the watcher until a managed-settings policy definition is registered|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService does not create the watcher until a managed-settings policy definition is registered|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService keeps raw managed settings while definitions are unchanged|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService keeps raw managed settings while definitions are unchanged|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService removes raw managed settings whose definitions are no longer watched|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService removes raw managed settings whose definitions are no longer watched|occurrence=1nativeManagedSettingsSer…nativeManagedSettingsService.test|title=NativeManagedSettingsService watches managed-settings keys from policy definitions and exposes raw managed settings|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/policy/test/node/nativeManagedSettingsService.test|title=NativeManagedSettingsService watches managed-settings keys from policy definitions and exposes raw managed settings|occurrence=1nativeManagedSettingsSer…Focused file · src/vs/platform/policy/node/nativeManagedSettingsService.ts · 141 LOCnode/nativeManagedSettin…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- nativeManagedSettingsIpc.ts ×7
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Throttler } from '../../../base/common/async.js';
7 > import { IStringDictionary } from '../../../base/common/collections.js';
8 > import { Emitter } from '../../../base/common/event.js';
9 > import { Disposable, MutableDisposable } from '../../../base/common/lifecycle.js';
10 > import { equals } from '../../../base/common/objects.js';
11 > import { IManagedSettingsPolicyDefinitions, ManagedSettingsData } from '../../../base/common/policy.js';
12 > import { ILogService } from '../../log/common/log.js';
13 > import { collectManagedSettingsDefinitions, INativeManagedSettingsService } from '../common/copilotManagedSettings.js';
14 > import { PolicyDefinition, PolicyValue } from '../common/policy.js';
15 > import type { Watcher } from '@vscode/policy-watcher';
16 >
17 > export interface INativePolicyWatcherOptions {
18 > readonly registryPath?: string;
19 > }
20 >
21 > export type NativePolicyWatcherFactory = (
22 > productName: string,
23 > policies: Record<string, { type: 'string' | 'number' | 'boolean' }>,
24 > onDidChange: (update: Record<string, PolicyValue | undefined>) => void,
25 > options?: INativePolicyWatcherOptions,
26 > ) => Watcher;
27 >
28 > export class NativeManagedSettingsService extends Disposable implements INativeManagedSettingsService {
29 >
30 > readonly _serviceBrand: undefined;
31 >
32 > private readonly throttler = this._register(new Throttler());
33 > private readonly watcher = this._register(new MutableDisposable<Watcher>());
34 > private readonly managedSettingsValues = new Map<string, PolicyValue>();
35 > private watchedSettings: IManagedSettingsPolicyDefinitions = {};
36 >
37 > private readonly _onDidChangeManagedSettings = this._register(new Emitter<ManagedSettingsData>());
38 > readonly onDidChangeManagedSettings = this._onDidChangeManagedSettings.event;
39 >
40 > get managedSettings(): ManagedSettingsData {
41 > return Object.fromEntries(this.managedSettingsValues);
42 > }
43 >
44 > constructor(
45 > @ILogService private readonly logService: ILogService, nativeManagedSettingsService.ts ×3
46 > private readonly productName: string,
47 > private readonly watcherOptions?: INativePolicyWatcherOptions,
48 > private readonly watcherFactory?: NativePolicyWatcherFactory,
49 > ) {
50 > super();
51 > }
53 > async updatePolicyDefinitions(policyDefinitions: IStringDictionary<PolicyDefinition>): Promise<ManagedSettingsData> {
54 > const managedSettings = collectManagedSettingsDefinitions(policyDefinitions); nativeManagedSettingsService.ts ×3
55 >
56 > if (equals(this.watchedSettings, managedSettings)) {
57 > return this.managedSettings; nativeManagedSettingsService.ts ×1
58 > }
60 > this.watchedSettings = managedSettings;
61 > const changed = this.pruneManagedSettingsValues();
62 > await this.updateWatcher();
63 > if (changed) {
64 > this._onDidChangeManagedSettings.fire(this.managedSettings); nativeManagedSettingsService.ts ×2
65 > }
66 > return this.managedSettings; nativeManagedSettingsService.ts ×11
69 > private pruneManagedSettingsValues(): boolean {
70 > let changed = false; nativeManagedSettingsService.ts ×11
71 > for (const key of this.managedSettingsValues.keys()) {
72 > if (!this.watchedSettings[key]) { nativeManagedSettingsService.ts ×2
73 > this.managedSettingsValues.delete(key);
74 > changed = true;
75 > }
76 > }
78 > }
80 > private async updateWatcher(): Promise<void> {
81 > const managedSettingDefinitions = this.getManagedSettingDefinitions(); nativeManagedSettingsService.ts ×11
82 > this.logService.trace(`NativeManagedSettingsService#updateWatcher - Found ${Object.keys(managedSettingDefinitions).length} managed-settings definitions`);
83 > if (Object.keys(managedSettingDefinitions).length === 0) {
84 > this.watcher.clear(); nativeManagedSettingsService.ts ×2
85 > const hadManagedSettings = this.managedSettingsValues.size > 0;
86 > this.managedSettingsValues.clear();
87 > if (hadManagedSettings) {
88 this._onDidChangeManagedSettings.fire(this.managedSettings);
89 }
91 > }
93 > const { createWatcher } = this.watcherFactory ? { createWatcher: this.watcherFactory } : (await import('@vscode/policy-watcher') as { createWatcher: NativePolicyWatcherFactory });
94 await this.throttler.queue(() => new Promise<void>((c, e) => {
96 > this.logService.trace(`Creating native managed-settings watcher for productName ${this.productName}`);
97 > this.watcher.value = createWatcher(this.productName, managedSettingDefinitions, update => {
98 > this._onDidManagedSettingsChange(update as Record<string, PolicyValue | undefined>);
99 > c();
100 > }, this.watcherOptions);
101 > } catch (err) {
102 this.logService.error(`NativeManagedSettingsService#updateWatcher - Error creating watcher:`, err);
103 e(err);
104 }
105 }));
108 > /**
109 > * Project the internal {@link IManagedSettingsPolicyDefinitions} (readonly, and free to grow
110 > * extra fields) down to the minimal `{ type }` payload the external `@vscode/policy-watcher`
111 > * native module expects. Deliberately a fresh, narrowly-typed copy rather than handing the
112 > * watcher our internal state: it decouples the two shapes so a future field on
113 > * `IManagedSettingPolicyDefinition` cannot silently leak across the native boundary.
114 > */
115 > private getManagedSettingDefinitions(): Record<string, { type: 'string' | 'number' | 'boolean' }> {
116 > const definitions: Record<string, { type: 'string' | 'number' | 'boolean' }> = {}; nativeManagedSettingsService.ts ×11
117 > for (const key in this.watchedSettings) {
118 > definitions[key] = { type: this.watchedSettings[key].type };
119 > }
120 > return definitions;
121 > }
123 > private _onDidManagedSettingsChange(update: Record<string, PolicyValue | undefined>): void {
124 > this.logService.trace(`NativeManagedSettingsService#_onDidManagedSettingsChange - Updated managed-settings values: ${JSON.stringify(update)}`); nativeManagedSettingsService.ts ×11
125 >
126 > let changed = false;
127 > for (const [key, value] of Object.entries(update)) {
128 > if (value === undefined) {
129 changed = this.managedSettingsValues.delete(key) || changed;
131 > if (this.managedSettingsValues.get(key) !== value) {
132 > this.managedSettingsValues.set(key, value);
133 > changed = true;
134 > }
135 > }
136 > }
137 > if (changed) {
138 > this._onDidChangeManagedSettings.fire(this.managedSettings);
139 > }
140 > }