Avoid racing reads from storage that could cause pairing data to be wiped

This commit is contained in:
Cameron Gutman 2018-03-28 00:33:41 -07:00
parent 6c457fe56d
commit ddd7310e38

View File

@ -185,8 +185,16 @@ function updateBitrateField() {
} }
function moduleDidLoad() { function moduleDidLoad() {
if(!myUniqueid) { // load the HTTP cert and unique ID if we have one.
console.warn('%c[index.js, moduleDidLoad]', 'color: green;', 'Failed to get uniqueId. We should have already generated one. Regenerating...'); chrome.storage.sync.get('cert', function(savedCert) {
if (savedCert.cert != null) { // we have a saved cert
pairingCert = savedCert.cert;
}
chrome.storage.sync.get('uniqueid', function(savedUniqueid) {
if (savedUniqueid.uniqueid != null) { // we have a saved uniqueid
myUniqueid = savedUniqueid.uniqueid;
} else {
myUniqueid = uniqueid(); myUniqueid = uniqueid();
storeData('uniqueid', myUniqueid, null); storeData('uniqueid', myUniqueid, null);
} }
@ -214,6 +222,8 @@ function moduleDidLoad() {
console.error('%c[index.js, moduleDidLoad]', 'color: green;', 'Failed httpInit! Returned error was: ', failedInit); console.error('%c[index.js, moduleDidLoad]', 'color: green;', 'Failed httpInit! Returned error was: ', failedInit);
}); });
} }
});
});
} }
// pair to the given NvHTTP host object. Returns whether pairing was successful. // pair to the given NvHTTP host object. Returns whether pairing was successful.
@ -870,22 +880,6 @@ function onWindowLoad(){
updateBitrateField(); updateBitrateField();
}); });
// load the HTTP cert if we have one.
chrome.storage.sync.get('cert', function(savedCert) {
if (savedCert.cert != null) { // we have a saved cert
pairingCert = savedCert.cert;
}
});
chrome.storage.sync.get('uniqueid', function(savedUniqueid) {
if (savedUniqueid.uniqueid != null) { // we have a saved uniqueid
myUniqueid = savedUniqueid.uniqueid;
} else {
myUniqueid = uniqueid();
storeData('uniqueid', myUniqueid, null);
}
});
// load previously connected hosts, which have been killed into an object, and revive them back into a class // load previously connected hosts, which have been killed into an object, and revive them back into a class
chrome.storage.sync.get('hosts', function(previousValue) { chrome.storage.sync.get('hosts', function(previousValue) {
hosts = previousValue.hosts != null ? previousValue.hosts : {}; hosts = previousValue.hosts != null ? previousValue.hosts : {};