@@ -27,6 +27,7 @@ import { equals } from 'vs/base/common/arrays';
2727import { getServiceMachineId } from 'vs/platform/serviceMachineId/common/serviceMachineId' ;
2828import { IStorageService } from 'vs/platform/storage/common/storage' ;
2929import { CancellationToken } from 'vs/base/common/cancellation' ;
30+ import { IHeaders } from 'vs/base/parts/request/common/request' ;
3031
3132type SyncSourceClassification = {
3233 source ?: { classification : 'SystemMetaData' , purpose : 'FeatureInsight' , isMeasurement : true } ;
@@ -75,6 +76,8 @@ export abstract class AbstractSynchroniser extends Disposable {
7576 protected readonly lastSyncResource : URI ;
7677 protected readonly syncResourceLogLabel : string ;
7778
79+ private syncHeaders : IHeaders = { } ;
80+
7881 constructor (
7982 readonly resource : SyncResource ,
8083 @IFileService protected readonly fileService : IFileService ,
@@ -150,39 +153,44 @@ export abstract class AbstractSynchroniser extends Disposable {
150153 }
151154 }
152155
153- async sync ( manifest : IUserDataManifest | null ) : Promise < void > {
154- if ( ! this . isEnabled ( ) ) {
155- if ( this . status !== SyncStatus . Idle ) {
156- await this . stop ( ) ;
156+ async sync ( manifest : IUserDataManifest | null , headers : IHeaders = { } ) : Promise < void > {
157+ try {
158+ this . syncHeaders = { ...headers } ;
159+ if ( ! this . isEnabled ( ) ) {
160+ if ( this . status !== SyncStatus . Idle ) {
161+ await this . stop ( ) ;
162+ }
163+ this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as it is disabled.` ) ;
164+ return ;
165+ }
166+ if ( this . status === SyncStatus . HasConflicts ) {
167+ this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as there are conflicts.` ) ;
168+ return ;
169+ }
170+ if ( this . status === SyncStatus . Syncing ) {
171+ this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as it is running already.` ) ;
172+ return ;
157173 }
158- this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as it is disabled.` ) ;
159- return ;
160- }
161- if ( this . status === SyncStatus . HasConflicts ) {
162- this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as there are conflicts.` ) ;
163- return ;
164- }
165- if ( this . status === SyncStatus . Syncing ) {
166- this . logService . info ( `${ this . syncResourceLogLabel } : Skipped synchronizing ${ this . resource . toLowerCase ( ) } as it is running already.` ) ;
167- return ;
168- }
169-
170- this . logService . trace ( `${ this . syncResourceLogLabel } : Started synchronizing ${ this . resource . toLowerCase ( ) } ...` ) ;
171- this . setStatus ( SyncStatus . Syncing ) ;
172174
173- const lastSyncUserData = await this . getLastSyncUserData ( ) ;
174- const remoteUserData = await this . getLatestRemoteUserData ( manifest , lastSyncUserData ) ;
175+ this . logService . trace ( ` ${ this . syncResourceLogLabel } : Started synchronizing ${ this . resource . toLowerCase ( ) } ...` ) ;
176+ this . setStatus ( SyncStatus . Syncing ) ;
175177
176- let status : SyncStatus = SyncStatus . Idle ;
177- try {
178- status = await this . performSync ( remoteUserData , lastSyncUserData ) ;
179- if ( status === SyncStatus . HasConflicts ) {
180- this . logService . info ( `${ this . syncResourceLogLabel } : Detected conflicts while synchronizing ${ this . resource . toLowerCase ( ) } .` ) ;
181- } else if ( status === SyncStatus . Idle ) {
182- this . logService . trace ( `${ this . syncResourceLogLabel } : Finished synchronizing ${ this . resource . toLowerCase ( ) } .` ) ;
178+ const lastSyncUserData = await this . getLastSyncUserData ( ) ;
179+ const remoteUserData = await this . getLatestRemoteUserData ( manifest , lastSyncUserData ) ;
180+
181+ let status : SyncStatus = SyncStatus . Idle ;
182+ try {
183+ status = await this . performSync ( remoteUserData , lastSyncUserData ) ;
184+ if ( status === SyncStatus . HasConflicts ) {
185+ this . logService . info ( `${ this . syncResourceLogLabel } : Detected conflicts while synchronizing ${ this . resource . toLowerCase ( ) } .` ) ;
186+ } else if ( status === SyncStatus . Idle ) {
187+ this . logService . trace ( `${ this . syncResourceLogLabel } : Finished synchronizing ${ this . resource . toLowerCase ( ) } .` ) ;
188+ }
189+ } finally {
190+ this . setStatus ( status ) ;
183191 }
184192 } finally {
185- this . setStatus ( status ) ;
193+ this . syncHeaders = { } ;
186194 }
187195 }
188196
@@ -446,14 +454,14 @@ export abstract class AbstractSynchroniser extends Disposable {
446454 return { ref : refOrLastSyncData , content } ;
447455 } else {
448456 const lastSyncUserData : IUserData | null = refOrLastSyncData ? { ref : refOrLastSyncData . ref , content : refOrLastSyncData . syncData ? JSON . stringify ( refOrLastSyncData . syncData ) : null } : null ;
449- return this . userDataSyncStoreService . read ( this . resource , lastSyncUserData ) ;
457+ return this . userDataSyncStoreService . read ( this . resource , lastSyncUserData , this . syncHeaders ) ;
450458 }
451459 }
452460
453461 protected async updateRemoteUserData ( content : string , ref : string | null ) : Promise < IRemoteUserData > {
454462 const machineId = await this . currentMachineIdPromise ;
455463 const syncData : ISyncData = { version : this . version , machineId, content } ;
456- ref = await this . userDataSyncStoreService . write ( this . resource , JSON . stringify ( syncData ) , ref ) ;
464+ ref = await this . userDataSyncStoreService . write ( this . resource , JSON . stringify ( syncData ) , ref , this . syncHeaders ) ;
457465 return { ref, syncData } ;
458466 }
459467
0 commit comments