src/vs/platform/userDataSync/common/userDataAutoSyncService.ts/AutoSync/doSync
class AutoSync:	private async doSync(reason: string, disableCache: boolean, token: CancellationToken): Promise<void> {
		this.logService.info(`Auto Sync: Triggered by ${reason}`);
		this._onDidStartSync.fire();
		let error: Error | undefined;
		try {
			this.syncTask = await this.userDataSyncService.createSyncTask(this.manifest, disableCache);
			if (token.isCancellationRequested) {
				return;
			}
			this.manifest = this.syncTask.manifest;

			// Server has no data but this machine was synced before
			if (this.manifest === null && await this.userDataSyncService.hasPreviouslySynced()) {
				if (this.hasSyncServiceChanged()) {
					if (await this.hasDefaultServiceChanged()) {
						throw new UserDataAutoSyncError(localize('default service changed', "Cannot sync because default service has changed"), UserDataSyncErrorCode.DefaultServiceChanged);
					} else {
						throw new UserDataAutoSyncError(localize('service changed', "Cannot sync because sync service has changed"), UserDataSyncErrorCode.ServiceChanged);
					}
				} else {
					// Sync was turned off in the cloud
					throw new UserDataAutoSyncError(localize('turned off', "Cannot sync because syncing is turned off in the cloud"), UserDataSyncErrorCode.TurnedOff);
				}
			}

			const sessionId = this.storageService.get(sessionIdKey, StorageScope.APPLICATION);
			// Server session is different from client session
			if (sessionId && this.manifest && sessionId !== this.manifest.session) {
				if (this.hasSyncServiceChanged()) {
					if (await this.hasDefaultServiceChanged()) {
						throw new UserDataAutoSyncError(localize('default service changed', "Cannot sync because default service has changed"), UserDataSyncErrorCode.DefaultServiceChanged);
					} else {
						throw new UserDataAutoSyncError(localize('service changed', "Cannot sync because sync service has changed"), UserDataSyncErrorCode.ServiceChanged);
					}
				} else {
					throw new UserDataAutoSyncError(localize('session expired', "Cannot sync because current session is expired"), UserDataSyncErrorCode.SessionExpired);
				}
			}

			const machines = await this.userDataSyncMachinesService.getMachines(this.manifest || undefined);
			// Return if cancellation is requested
			if (token.isCancellationRequested) {
				return;
			}

			const currentMachine = machines.find(machine => machine.isCurrent);
			// Check if sync was turned off from other machine
			if (currentMachine?.disabled) {
				// Throw TurnedOff error
				throw new UserDataAutoSyncError(localize('turned off machine', "Cannot sync because syncing is turned off on this machine from another machine."), UserDataSyncErrorCode.TurnedOff);
			}

			await this.syncTask.run();

			// After syncing, get the manifest if it was not available before
			if (this.manifest === null) {
				try {
					this.manifest = await this.userDataSyncStoreService.manifest(null);
				} catch (error) {
					throw new UserDataAutoSyncError(toErrorMessage(error), error instanceof UserDataSyncError ? error.code : UserDataSyncErrorCode.Unknown);
				}
			}

			// Update local session id
			if (this.manifest && this.manifest.session !== sessionId) {
				this.storageService.store(sessionIdKey, this.manifest.session, StorageScope.APPLICATION, StorageTarget.MACHINE);
			}

			// Return if cancellation is requested
			if (token.isCancellationRequested) {
				return;
			}

			// Add current machine
			if (!currentMachine) {
				await this.userDataSyncMachinesService.addCurrentMachine(this.manifest || undefined);
			}

		} catch (e) {
			this.logService.error(e);
			error = e;
		}

		this._onDidFinishSync.fire(error);
	}