<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { AbstractInitializer } from 'vs/platform/userDataSync/common/abstractSynchronizer';
import { ExtensionsInitializer } from 'vs/platform/userDataSync/common/extensionsSync';
import { GlobalStateInitializer } from 'vs/platform/userDataSync/common/globalStateSync';
import { KeybindingsInitializer } from 'vs/platform/userDataSync/common/keybindingsSync';
import { SettingsInitializer } from 'vs/platform/userDataSync/common/settingsSync';
import { SnippetsInitializer } from 'vs/platform/userDataSync/common/snippetsSync';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { UserDataSyncStoreClient } from 'vs/platform/userDataSync/common/userDataSyncStoreService';
import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { CONFIGURATION_SYNC_STORE_KEY } from 'vs/platform/userDataSync/common/userDataSync';
import { URI } from 'vs/base/common/uri';
import { getAuthenticationSession } from 'vs/workbench/services/authentication/browser/authenticationService';

export function initializeUserData(
	environmentService: IWorkbenchEnvironmentService,
	fileService: IFileService,
	storageService: IStorageService,
	productService: IProductService,
	requestService: IRequestService,
	logService: ILogService,
): Promise<void> {
	const initializers: AbstractInitializer[] = [
		new SettingsInitializer(fileService, environmentService, logService),
		new KeybindingsInitializer(fileService, environmentService, logService),
		new SnippetsInitializer(fileService, environmentService, logService),
		new GlobalStateInitializer(storageService, fileService, environmentService, logService),
	];
	return initialize(initializers, 'user data', environmentService, fileService, storageService, productService, requestService, logService);
}

export function initializeExtensions(instantiationService: IInstantiationService): Promise<void> {
	return instantiationService.invokeFunction(accessor => {
		return initialize([instantiationService.createInstance(ExtensionsInitializer)], 'extensions',
			accessor.get(IWorkbenchEnvironmentService),
			accessor.get(IFileService),
			accessor.get(IStorageService),
			accessor.get(IProductService),
			accessor.get(IRequestService),
			accessor.get(ILogService));
	});
}

async function initialize(
	initializers: AbstractInitializer[],
	userDataLabel: string,
	environmentService: IWorkbenchEnvironmentService,
	fileService: IFileService,
	storageService: IStorageService,
	productService: IProductService,
	requestService: IRequestService,
	logService: ILogService,
): Promise<void> {

	if (!environmentService.options?.enableSyncByDefault) {
		logService.trace(`Skipping initializing ${userDataLabel} as sync is not enabled by default`);
		return;
	}

	if (!storageService.isNew(StorageScope.WORKSPACE)) {
		logService.trace(`Skipping initializing ${userDataLabel} as workspace was opened before`);
		return;
	}

	const userDataSyncStore = productService[CONFIGURATION_SYNC_STORE_KEY];
	if (!userDataSyncStore) {
		logService.trace(`Skipping initializing ${userDataLabel} as sync service is not provided`);
		return;
	}

	if (!environmentService.options?.credentialsProvider) {
		return;
	}
<commit_msg>also check if application was opened before<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { AbstractInitializer } from 'vs/platform/userDataSync/common/abstractSynchronizer';
import { ExtensionsInitializer } from 'vs/platform/userDataSync/common/extensionsSync';
import { GlobalStateInitializer } from 'vs/platform/userDataSync/common/globalStateSync';
import { KeybindingsInitializer } from 'vs/platform/userDataSync/common/keybindingsSync';
import { SettingsInitializer } from 'vs/platform/userDataSync/common/settingsSync';
import { SnippetsInitializer } from 'vs/platform/userDataSync/common/snippetsSync';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { UserDataSyncStoreClient } from 'vs/platform/userDataSync/common/userDataSyncStoreService';
import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { CONFIGURATION_SYNC_STORE_KEY } from 'vs/platform/userDataSync/common/userDataSync';
import { URI } from 'vs/base/common/uri';
import { getAuthenticationSession } from 'vs/workbench/services/authentication/browser/authenticationService';

export function initializeUserData(
	environmentService: IWorkbenchEnvironmentService,
	fileService: IFileService,
	storageService: IStorageService,
	productService: IProductService,
	requestService: IRequestService,
	logService: ILogService,
): Promise<void> {
	const initializers: AbstractInitializer[] = [
		new SettingsInitializer(fileService, environmentService, logService),
		new KeybindingsInitializer(fileService, environmentService, logService),
		new SnippetsInitializer(fileService, environmentService, logService),
		new GlobalStateInitializer(storageService, fileService, environmentService, logService),
	];
	return initialize(initializers, 'user data', environmentService, fileService, storageService, productService, requestService, logService);
}

export function initializeExtensions(instantiationService: IInstantiationService): Promise<void> {
	return instantiationService.invokeFunction(accessor => {
		return initialize([instantiationService.createInstance(ExtensionsInitializer)], 'extensions',
			accessor.get(IWorkbenchEnvironmentService),
			accessor.get(IFileService),
			accessor.get(IStorageService),
			accessor.get(IProductService),
			accessor.get(IRequestService),
			accessor.get(ILogService));
	});
}

async function initialize(
	initializers: AbstractInitializer[],
	userDataLabel: string,
	environmentService: IWorkbenchEnvironmentService,
	fileService: IFileService,
	storageService: IStorageService,
	productService: IProductService,
	requestService: IRequestService,
	logService: ILogService,
): Promise<void> {

	if (!environmentService.options?.enableSyncByDefault) {
		logService.trace(`Skipping initializing ${userDataLabel} as sync is not enabled by default`);
		return;
	}

	if (!storageService.isNew(StorageScope.GLOBAL)) {
		logService.trace(`Skipping initializing ${userDataLabel} as application was opened before`);
		return;
	}

	if (!storageService.isNew(StorageScope.WORKSPACE)) {
		logService.trace(`Skipping initializing ${userDataLabel} as workspace was opened before`);
		return;
	}

	const userDataSyncStore = productService[CONFIGURATION_SYNC_STORE_KEY];
	if (!userDataSyncStore) {
		logService.trace(`Skipping initializing ${userDataLabel} as sync service is not provided`);
		return;
	}

	if (!environmentService.options?.credentialsProvider) {
		return;
	}

{'fraction_non_alphanumeric': 0.1393543617545589, 'fraction_numerical': 0.0, 'mean_word_length': 5.243846153846154, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789461', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2108, 'n_words': 447}