|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 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 { CancellationToken } from 'vs/base/common/cancellation'; |
| 7 | +import { IRequestContext, IRequestOptions } from 'vs/base/parts/request/common/request'; |
| 8 | +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
| 9 | +import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services'; |
| 10 | +import { ILogService } from 'vs/platform/log/common/log'; |
| 11 | +import { RequestService } from 'vs/platform/request/browser/requestService'; |
| 12 | +import { IRequestService } from 'vs/platform/request/common/request'; |
| 13 | +import { RequestChannelClient } from 'vs/platform/request/common/requestIpc'; |
| 14 | + |
| 15 | +export class SharedProcessRequestService implements IRequestService { |
| 16 | + |
| 17 | + declare readonly _serviceBrand: undefined; |
| 18 | + |
| 19 | + private readonly browserRequestService: IRequestService; |
| 20 | + private readonly mainRequestService: IRequestService; |
| 21 | + |
| 22 | + constructor( |
| 23 | + mainProcessService: IMainProcessService, |
| 24 | + private readonly configurationService: IConfigurationService, |
| 25 | + private readonly logService: ILogService, |
| 26 | + ) { |
| 27 | + this.browserRequestService = new RequestService(configurationService, logService); |
| 28 | + this.mainRequestService = new RequestChannelClient(mainProcessService.getChannel('request')); |
| 29 | + } |
| 30 | + |
| 31 | + request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> { |
| 32 | + return this.getRequestService().request(options, token); |
| 33 | + } |
| 34 | + |
| 35 | + async resolveProxy(url: string): Promise<string | undefined> { |
| 36 | + return this.getRequestService().resolveProxy(url); |
| 37 | + } |
| 38 | + |
| 39 | + private getRequestService(): IRequestService { |
| 40 | + if (this.configurationService.getValue('developer.sharedProcess.useBrowserRequestService') === true) { |
| 41 | + this.logService.trace('Using browser request service'); |
| 42 | + return this.browserRequestService; |
| 43 | + } |
| 44 | + this.logService.trace('Using main request service'); |
| 45 | + return this.mainRequestService; |
| 46 | + } |
| 47 | +} |
0 commit comments