mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
remove debug logging from sync operations
This commit is contained in:
parent
fd538494c0
commit
b48c86a572
@ -785,21 +785,15 @@ var bg_isBackground = true,
|
|||||||
|
|
||||||
function fullSync(override) {
|
function fullSync(override) {
|
||||||
override = override || false;
|
override = override || false;
|
||||||
log('check fullSync - ' + override);
|
|
||||||
bg_syncService.getLastSync(function (lastSync) {
|
bg_syncService.getLastSync(function (lastSync) {
|
||||||
log('got last sync - ' + lastSync);
|
|
||||||
var syncInternal = 6 * 60 * 60 * 1000; // 6 hours
|
var syncInternal = 6 * 60 * 60 * 1000; // 6 hours
|
||||||
var lastSyncAgo = new Date() - lastSync;
|
var lastSyncAgo = new Date() - lastSync;
|
||||||
log('lastSyncAgo - ' + lastSyncAgo);
|
|
||||||
if (override || !lastSync || lastSyncAgo >= syncInternal) {
|
if (override || !lastSync || lastSyncAgo >= syncInternal) {
|
||||||
log('let\'s do the fullSync');
|
|
||||||
bg_syncService.fullSync(override || false, function () {
|
bg_syncService.fullSync(override || false, function () {
|
||||||
log('done with fullSync');
|
|
||||||
scheduleNextSync();
|
scheduleNextSync();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log('don\'t need to sync right now');
|
|
||||||
scheduleNextSync();
|
scheduleNextSync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -807,21 +801,12 @@ var bg_isBackground = true,
|
|||||||
|
|
||||||
function scheduleNextSync() {
|
function scheduleNextSync() {
|
||||||
if (syncTimeout) {
|
if (syncTimeout) {
|
||||||
log('clearing syncTimeout');
|
|
||||||
clearTimeout(syncTimeout);
|
clearTimeout(syncTimeout);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
log('don\'t need to clear syncTimeout');
|
|
||||||
}
|
|
||||||
|
|
||||||
log('scheduleNextSync');
|
|
||||||
syncTimeout = setTimeout(fullSync, 5 * 60 * 1000); // check every 5 minutes
|
syncTimeout = setTimeout(fullSync, 5 * 60 * 1000); // check every 5 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(msg) {
|
|
||||||
console.log(new Date() + ' - Background: ' + msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bootstrap
|
// Bootstrap
|
||||||
|
|
||||||
bg_environmentService.setUrlsFromStorage(function () {
|
bg_environmentService.setUrlsFromStorage(function () {
|
||||||
|
@ -116,10 +116,8 @@ function initApiService() {
|
|||||||
// Account APIs
|
// Account APIs
|
||||||
|
|
||||||
ApiService.prototype.getAccountRevisionDate = function (success, error) {
|
ApiService.prototype.getAccountRevisionDate = function (success, error) {
|
||||||
log('getAccountRevisionDate invoked');
|
|
||||||
var self = this;
|
var self = this;
|
||||||
handleTokenState(self).then(function (tokenHeader) {
|
handleTokenState(self).then(function (tokenHeader) {
|
||||||
log('Revision Date API Call');
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: self.baseUrl + '/accounts/revision-date',
|
url: self.baseUrl + '/accounts/revision-date',
|
||||||
@ -133,7 +131,6 @@ function initApiService() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function (jqXHR) {
|
}, function (jqXHR) {
|
||||||
log('Error handling token state for Revision Date API Call');
|
|
||||||
handleError(error, jqXHR, true, self);
|
handleError(error, jqXHR, true, self);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -455,7 +452,7 @@ function initApiService() {
|
|||||||
|
|
||||||
function handleError(errorCallback, jqXHR, tokenError, self) {
|
function handleError(errorCallback, jqXHR, tokenError, self) {
|
||||||
if (jqXHR && (tokenError && jqXHR.status === 400) || jqXHR.status === 401 || jqXHR.status === 403) {
|
if (jqXHR && (tokenError && jqXHR.status === 400) || jqXHR.status === 401 || jqXHR.status === 403) {
|
||||||
log('Logging out. Reason: Status ' + jqXHR.status + '.');
|
console.log('API Service: Logging out. Reason: Status ' + jqXHR.status + '.');
|
||||||
console.log(jqXHR);
|
console.log(jqXHR);
|
||||||
if (self && self.logoutCallback) {
|
if (self && self.logoutCallback) {
|
||||||
self.logoutCallback(true, function () { });
|
self.logoutCallback(true, function () { });
|
||||||
@ -473,20 +470,14 @@ function initApiService() {
|
|||||||
function handleTokenState(self) {
|
function handleTokenState(self) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
self.tokenService.getToken(function (accessToken) {
|
self.tokenService.getToken(function (accessToken) {
|
||||||
log('Got access token');
|
|
||||||
|
|
||||||
if (!self.tokenService.tokenNeedsRefresh()) {
|
if (!self.tokenService.tokenNeedsRefresh()) {
|
||||||
log('Token doesn\'t need refreshing');
|
|
||||||
resolveTokenQs(accessToken, deferred);
|
resolveTokenQs(accessToken, deferred);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Token needs refresh');
|
|
||||||
|
|
||||||
doRefreshToken(self, function (response) {
|
doRefreshToken(self, function (response) {
|
||||||
var tokenResponse = new IdentityTokenResponse(response);
|
var tokenResponse = new IdentityTokenResponse(response);
|
||||||
self.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken, function () {
|
self.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken, function () {
|
||||||
log('New token set.');
|
|
||||||
resolveTokenQs(tokenResponse.accessToken, deferred);
|
resolveTokenQs(tokenResponse.accessToken, deferred);
|
||||||
});
|
});
|
||||||
}, function (jqXHR) {
|
}, function (jqXHR) {
|
||||||
@ -500,13 +491,10 @@ function initApiService() {
|
|||||||
function doRefreshToken(self, success, error) {
|
function doRefreshToken(self, success, error) {
|
||||||
self.tokenService.getRefreshToken(function (refreshToken) {
|
self.tokenService.getRefreshToken(function (refreshToken) {
|
||||||
if (!refreshToken || refreshToken === '') {
|
if (!refreshToken || refreshToken === '') {
|
||||||
log('No existing refresh token.');
|
|
||||||
error();
|
error();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Got existing refresh token. Do refresh call.');
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: self.identityBaseUrl + '/connect/token',
|
url: self.identityBaseUrl + '/connect/token',
|
||||||
@ -518,11 +506,9 @@ function initApiService() {
|
|||||||
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
|
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
log('Successfully refreshed.');
|
|
||||||
success(response);
|
success(response);
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
log('Error refreshing.');
|
|
||||||
error(jqXHR);
|
error(jqXHR);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -530,13 +516,8 @@ function initApiService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolveTokenQs(token, deferred) {
|
function resolveTokenQs(token, deferred) {
|
||||||
log('Resolving token.');
|
|
||||||
deferred.resolve({
|
deferred.resolve({
|
||||||
'Authorization': 'Bearer ' + token
|
'Authorization': 'Bearer ' + token
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(msg) {
|
|
||||||
console.log(new Date() + ' - API Service: ' + msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,31 +19,24 @@ function initSyncService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
log('fullSync');
|
|
||||||
|
|
||||||
self.syncStarted();
|
self.syncStarted();
|
||||||
self.userService.isAuthenticated(function (isAuthenticated) {
|
self.userService.isAuthenticated(function (isAuthenticated) {
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
log('is not authenticated');
|
|
||||||
self.syncCompleted(false);
|
self.syncCompleted(false);
|
||||||
callback(false);
|
callback(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('is authenticated');
|
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
needsSyncing(self, forceSync, function (needsSync, skipped) {
|
needsSyncing(self, forceSync, function (needsSync, skipped) {
|
||||||
log('needsSyncing result: ' + needsSync + ', ' + skipped);
|
|
||||||
|
|
||||||
if (skipped) {
|
if (skipped) {
|
||||||
log('skipped');
|
|
||||||
self.syncCompleted(false);
|
self.syncCompleted(false);
|
||||||
callback(false);
|
callback(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needsSync) {
|
if (!needsSync) {
|
||||||
log('doesn\'t need sync');
|
|
||||||
self.setLastSync(now, function () {
|
self.setLastSync(now, function () {
|
||||||
self.syncCompleted(false);
|
self.syncCompleted(false);
|
||||||
callback(false);
|
callback(false);
|
||||||
@ -51,27 +44,20 @@ function initSyncService() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('starting sync');
|
|
||||||
self.userService.getUserId(function (userId) {
|
self.userService.getUserId(function (userId) {
|
||||||
self.apiService.getSync(function (response) {
|
self.apiService.getSync(function (response) {
|
||||||
log('sync profile');
|
|
||||||
syncProfile(self, response.profile).then(function () {
|
syncProfile(self, response.profile).then(function () {
|
||||||
log('sync folders');
|
|
||||||
return syncFolders(self, userId, response.folders);
|
return syncFolders(self, userId, response.folders);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
log('sync ciphers');
|
|
||||||
return syncCiphers(self, userId, response.ciphers);
|
return syncCiphers(self, userId, response.ciphers);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
log('sync settings');
|
|
||||||
return syncSettings(self, userId, response.domains);
|
return syncSettings(self, userId, response.domains);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
log('all done with the syncs - ' + now);
|
|
||||||
self.setLastSync(now, function () {
|
self.setLastSync(now, function () {
|
||||||
self.syncCompleted(true);
|
self.syncCompleted(true);
|
||||||
callback(true);
|
callback(true);
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
log('and error happened during the syncs');
|
|
||||||
self.syncCompleted(false);
|
self.syncCompleted(false);
|
||||||
callback(false);
|
callback(false);
|
||||||
});
|
});
|
||||||
@ -87,27 +73,21 @@ function initSyncService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (forceSync) {
|
if (forceSync) {
|
||||||
log('needs sync since force');
|
|
||||||
callback(true, false);
|
callback(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('getting revision date from api');
|
|
||||||
self.apiService.getAccountRevisionDate(function (response) {
|
self.apiService.getAccountRevisionDate(function (response) {
|
||||||
var accountRevisionDate = new Date(response);
|
var accountRevisionDate = new Date(response);
|
||||||
log('account last revised: ' + accountRevisionDate);
|
|
||||||
self.getLastSync(function (lastSync) {
|
self.getLastSync(function (lastSync) {
|
||||||
if (lastSync && accountRevisionDate <= lastSync) {
|
if (lastSync && accountRevisionDate <= lastSync) {
|
||||||
log('already synced since this revision date');
|
|
||||||
callback(false, false);
|
callback(false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('we haven\'t synced since this revision');
|
|
||||||
callback(true, false);
|
callback(true, false);
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
log('there was an error getting the account revision date');
|
|
||||||
callback(false, true);
|
callback(false, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -204,21 +184,15 @@ function initSyncService() {
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(msg) {
|
|
||||||
console.log(new Date() + ' - Sync Service: ' + msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncService.prototype.getLastSync = function (callback) {
|
SyncService.prototype.getLastSync = function (callback) {
|
||||||
if (!callback || typeof callback !== 'function') {
|
if (!callback || typeof callback !== 'function') {
|
||||||
throw 'callback function required';
|
throw 'callback function required';
|
||||||
}
|
}
|
||||||
|
|
||||||
log('getting last sync');
|
|
||||||
this.userService.getUserId(function (userId) {
|
this.userService.getUserId(function (userId) {
|
||||||
var lastSyncKey = 'lastSync_' + userId;
|
var lastSyncKey = 'lastSync_' + userId;
|
||||||
chrome.storage.local.get(lastSyncKey, function (obj) {
|
chrome.storage.local.get(lastSyncKey, function (obj) {
|
||||||
var lastSync = obj[lastSyncKey];
|
var lastSync = obj[lastSyncKey];
|
||||||
log('done getting last sync: ' + lastSync);
|
|
||||||
if (lastSync) {
|
if (lastSync) {
|
||||||
callback(new Date(lastSync));
|
callback(new Date(lastSync));
|
||||||
}
|
}
|
||||||
@ -240,9 +214,7 @@ function initSyncService() {
|
|||||||
var obj = {};
|
var obj = {};
|
||||||
obj[lastSyncKey] = date.toJSON();
|
obj[lastSyncKey] = date.toJSON();
|
||||||
|
|
||||||
log('setting last sync');
|
|
||||||
chrome.storage.local.set(obj, function () {
|
chrome.storage.local.set(obj, function () {
|
||||||
log('done setting last sync');
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -251,12 +223,10 @@ function initSyncService() {
|
|||||||
SyncService.prototype.syncStarted = function () {
|
SyncService.prototype.syncStarted = function () {
|
||||||
this.syncInProgress = true;
|
this.syncInProgress = true;
|
||||||
chrome.runtime.sendMessage({ command: 'syncStarted' });
|
chrome.runtime.sendMessage({ command: 'syncStarted' });
|
||||||
log('sync started');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SyncService.prototype.syncCompleted = function (successfully) {
|
SyncService.prototype.syncCompleted = function (successfully) {
|
||||||
this.syncInProgress = false;
|
this.syncInProgress = false;
|
||||||
chrome.runtime.sendMessage({ command: 'syncCompleted', successfully: successfully });
|
chrome.runtime.sendMessage({ command: 'syncCompleted', successfully: successfully });
|
||||||
log('sync completed');
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user