1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-01 00:10:39 +02:00

remove debug logging from sync operations

This commit is contained in:
Kyle Spearrin 2017-09-20 12:33:18 -04:00
parent fd538494c0
commit b48c86a572
3 changed files with 1 additions and 65 deletions

View File

@ -785,21 +785,15 @@ var bg_isBackground = true,
function fullSync(override) {
override = override || false;
log('check fullSync - ' + override);
bg_syncService.getLastSync(function (lastSync) {
log('got last sync - ' + lastSync);
var syncInternal = 6 * 60 * 60 * 1000; // 6 hours
var lastSyncAgo = new Date() - lastSync;
log('lastSyncAgo - ' + lastSyncAgo);
if (override || !lastSync || lastSyncAgo >= syncInternal) {
log('let\'s do the fullSync');
bg_syncService.fullSync(override || false, function () {
log('done with fullSync');
scheduleNextSync();
});
}
else {
log('don\'t need to sync right now');
scheduleNextSync();
}
});
@ -807,21 +801,12 @@ var bg_isBackground = true,
function scheduleNextSync() {
if (syncTimeout) {
log('clearing syncTimeout');
clearTimeout(syncTimeout);
}
else {
log('don\'t need to clear syncTimeout');
}
log('scheduleNextSync');
syncTimeout = setTimeout(fullSync, 5 * 60 * 1000); // check every 5 minutes
}
function log(msg) {
console.log(new Date() + ' - Background: ' + msg);
}
// Bootstrap
bg_environmentService.setUrlsFromStorage(function () {

View File

@ -116,10 +116,8 @@ function initApiService() {
// Account APIs
ApiService.prototype.getAccountRevisionDate = function (success, error) {
log('getAccountRevisionDate invoked');
var self = this;
handleTokenState(self).then(function (tokenHeader) {
log('Revision Date API Call');
$.ajax({
type: 'GET',
url: self.baseUrl + '/accounts/revision-date',
@ -133,7 +131,6 @@ function initApiService() {
}
});
}, function (jqXHR) {
log('Error handling token state for Revision Date API Call');
handleError(error, jqXHR, true, self);
});
};
@ -455,7 +452,7 @@ function initApiService() {
function handleError(errorCallback, jqXHR, tokenError, self) {
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);
if (self && self.logoutCallback) {
self.logoutCallback(true, function () { });
@ -473,20 +470,14 @@ function initApiService() {
function handleTokenState(self) {
var deferred = Q.defer();
self.tokenService.getToken(function (accessToken) {
log('Got access token');
if (!self.tokenService.tokenNeedsRefresh()) {
log('Token doesn\'t need refreshing');
resolveTokenQs(accessToken, deferred);
return;
}
log('Token needs refresh');
doRefreshToken(self, function (response) {
var tokenResponse = new IdentityTokenResponse(response);
self.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken, function () {
log('New token set.');
resolveTokenQs(tokenResponse.accessToken, deferred);
});
}, function (jqXHR) {
@ -500,13 +491,10 @@ function initApiService() {
function doRefreshToken(self, success, error) {
self.tokenService.getRefreshToken(function (refreshToken) {
if (!refreshToken || refreshToken === '') {
log('No existing refresh token.');
error();
return;
}
log('Got existing refresh token. Do refresh call.');
$.ajax({
type: 'POST',
url: self.identityBaseUrl + '/connect/token',
@ -518,11 +506,9 @@ function initApiService() {
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
dataType: 'json',
success: function (response) {
log('Successfully refreshed.');
success(response);
},
error: function (jqXHR, textStatus, errorThrown) {
log('Error refreshing.');
error(jqXHR);
}
});
@ -530,13 +516,8 @@ function initApiService() {
}
function resolveTokenQs(token, deferred) {
log('Resolving token.');
deferred.resolve({
'Authorization': 'Bearer ' + token
});
}
function log(msg) {
console.log(new Date() + ' - API Service: ' + msg);
}
}

View File

@ -19,31 +19,24 @@ function initSyncService() {
}
var self = this;
log('fullSync');
self.syncStarted();
self.userService.isAuthenticated(function (isAuthenticated) {
if (!isAuthenticated) {
log('is not authenticated');
self.syncCompleted(false);
callback(false);
return;
}
log('is authenticated');
var now = new Date();
needsSyncing(self, forceSync, function (needsSync, skipped) {
log('needsSyncing result: ' + needsSync + ', ' + skipped);
if (skipped) {
log('skipped');
self.syncCompleted(false);
callback(false);
return;
}
if (!needsSync) {
log('doesn\'t need sync');
self.setLastSync(now, function () {
self.syncCompleted(false);
callback(false);
@ -51,27 +44,20 @@ function initSyncService() {
return;
}
log('starting sync');
self.userService.getUserId(function (userId) {
self.apiService.getSync(function (response) {
log('sync profile');
syncProfile(self, response.profile).then(function () {
log('sync folders');
return syncFolders(self, userId, response.folders);
}).then(function () {
log('sync ciphers');
return syncCiphers(self, userId, response.ciphers);
}).then(function () {
log('sync settings');
return syncSettings(self, userId, response.domains);
}).then(function () {
log('all done with the syncs - ' + now);
self.setLastSync(now, function () {
self.syncCompleted(true);
callback(true);
});
}, function () {
log('and error happened during the syncs');
self.syncCompleted(false);
callback(false);
});
@ -87,27 +73,21 @@ function initSyncService() {
}
if (forceSync) {
log('needs sync since force');
callback(true, false);
return;
}
log('getting revision date from api');
self.apiService.getAccountRevisionDate(function (response) {
var accountRevisionDate = new Date(response);
log('account last revised: ' + accountRevisionDate);
self.getLastSync(function (lastSync) {
if (lastSync && accountRevisionDate <= lastSync) {
log('already synced since this revision date');
callback(false, false);
return;
}
log('we haven\'t synced since this revision');
callback(true, false);
});
}, function () {
log('there was an error getting the account revision date');
callback(false, true);
});
}
@ -204,21 +184,15 @@ function initSyncService() {
return deferred.promise;
}
function log(msg) {
console.log(new Date() + ' - Sync Service: ' + msg);
}
SyncService.prototype.getLastSync = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
log('getting last sync');
this.userService.getUserId(function (userId) {
var lastSyncKey = 'lastSync_' + userId;
chrome.storage.local.get(lastSyncKey, function (obj) {
var lastSync = obj[lastSyncKey];
log('done getting last sync: ' + lastSync);
if (lastSync) {
callback(new Date(lastSync));
}
@ -240,9 +214,7 @@ function initSyncService() {
var obj = {};
obj[lastSyncKey] = date.toJSON();
log('setting last sync');
chrome.storage.local.set(obj, function () {
log('done setting last sync');
callback();
});
});
@ -251,12 +223,10 @@ function initSyncService() {
SyncService.prototype.syncStarted = function () {
this.syncInProgress = true;
chrome.runtime.sendMessage({ command: 'syncStarted' });
log('sync started');
};
SyncService.prototype.syncCompleted = function (successfully) {
this.syncInProgress = false;
chrome.runtime.sendMessage({ command: 'syncCompleted', successfully: successfully });
log('sync completed');
};
}