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 { ThrottledDelayer } from '../../../base/common/async.js';
7
>
import { Emitter, Event } from '../../../base/common/event.js';
8
>
import { Disposable } from '../../../base/common/lifecycle.js';
9
>
import { equals } from '../../../base/common/objects.js';
10
>
import { ManagedSettingsData } from '../../../base/common/policy.js';
11
>
import { isObject } from '../../../base/common/types.js';
12
>
import { URI } from '../../../base/common/uri.js';
13
>
import { FileOperationError, FileOperationResult, IFileService } from '../../files/common/files.js';
14
>
import { ILogService } from '../../log/common/log.js';
15
>
import { IFileManagedSettingsService, normalizeManagedSettings, RawManagedSettingsData } from './copilotManagedSettings.js';
16
>
17
>
/**
18
>
* Upper bound on the size of `managed-settings.json` we will read into the main process. A
19
>
* legitimate settings file is a few KB; capping the read keeps a malformed or hostile file on the
20
>
* (externally writable, privileged) well-known path from OOM-ing the main process. `readFile`
21
>
* throws `FILE_TOO_LARGE` past this, which `refresh()` treats like any other read failure.
22
>
*/
23
>
const MANAGED_SETTINGS_MAX_FILE_SIZE = 1024 * 1024; // 1 MB
24
>
25
>
export class FileManagedSettingsService extends Disposable implements IFileManagedSettingsService {
26
>
27
>
readonly _serviceBrand: undefined;
28
>
29
>
private _rawManagedSettings: RawManagedSettingsData = {};
30
>
get rawManagedSettings(): RawManagedSettingsData { return this._rawManagedSettings; }
31
>
32
>
private _managedSettings: ManagedSettingsData = {};
33
>
get managedSettings(): ManagedSettingsData { return this._managedSettings; }
34
>
35
>
private readonly _onDidChangeRawManagedSettings = this._register(new Emitter<RawManagedSettingsData>());
36
>
readonly onDidChangeRawManagedSettings = this._onDidChangeRawManagedSettings.event;
37
>
38
>
private readonly _onDidChangeManagedSettings = this._register(new Emitter<ManagedSettingsData>());
39
>
readonly onDidChangeManagedSettings = this._onDidChangeManagedSettings.event;
40
>
41
>
private readonly throttledDelayer = this._register(new ThrottledDelayer(500));
42
>
43
>
constructor(
44
private readonly file: URI,
45
@IFileService private readonly fileService: IFileService,