Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32851 from ferjm/bug1219275.sync.session
Browse files Browse the repository at this point in the history
Bug 1219275 - Session is not kept between reboots. r=michielbdejong
  • Loading branch information
ferjm committed Oct 29, 2015
2 parents 82d65ca + e223713 commit 6da0ea1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
53 changes: 34 additions & 19 deletions tv_apps/smart-system/js/sync_manager.js
Expand Up @@ -88,24 +88,6 @@
SyncStateMachine.sync();
});

// Settings listeners.
['sync.collections.bookmarks.enabled',
'sync.collections.history.enabled',
'sync.collections.passwords.enabled',
'sync.collections.bookmarks.readonly',
'sync.collections.history.readonly',
'sync.collections.passwords.readonly',
'sync.server.url',
'sync.scheduler.interval',
'sync.scheduler.wifionly',
'sync.fxa.audience'].forEach(setting => {
SettingsListener.observe(setting, false, enabled => {
this.debug('Observed ' + setting + ' changed to ' + enabled);
enabled ? this.settings.set(setting, enabled)
: this.settings.delete(setting);
});
});

// SyncStateMachine event listeners.
['ondisabled',
'ondisabling',
Expand All @@ -127,7 +109,11 @@
window.addEventListener('appterminated',
this.onappterminatedListener);

this.initStore().then(() => {
// We need to wait until getting the initial value for all settings.
this.observeSettings().then(() => {
this.debug('All settings observed');
return this.initStore();
}).then(() => {
this.debug('Sync.state setting initial value', this.state);
// SyncStateMachine starts by default with 'disabled', so we can
// request to enable sync or stay in the disabled state.
Expand Down Expand Up @@ -501,6 +487,35 @@

/** Helpers **/

observeSettings: function() {
var setSettingObserver = setting => {
return new Promise(resolve => {
SettingsListener.observe(setting, false, enabled => {
this.debug('Observed ' + setting + ' changed to ' + enabled);
enabled ? this.settings.set(setting, enabled)
: this.settings.delete(setting);
resolve();
});
});
};

var promises = [];
['sync.collections.bookmarks.enabled',
'sync.collections.history.enabled',
'sync.collections.passwords.enabled',
'sync.collections.bookmarks.readonly',
'sync.collections.history.readonly',
'sync.collections.passwords.readonly',
'sync.server.url',
'sync.scheduler.interval',
'sync.scheduler.wifionly',
'sync.fxa.audience'].forEach(setting => {
promises.push(setSettingObserver(setting));
});

return Promise.all(promises);
},

initStore: function() {
var promises = [];
[SYNC_STATE,
Expand Down
3 changes: 3 additions & 0 deletions tv_apps/smart-system/test/unit/sync_manager_test.js
Expand Up @@ -153,6 +153,9 @@ suite('smart-system/SyncManager >', () => {
this.sinon.stub(syncManager, 'trySync', () => {
return Promise.resolve();
});
this.sinon.stub(syncManager, 'observeSettings', () => {
return Promise.resolve();
});
syncManager.start().then(done);
});
});
Expand Down

0 comments on commit 6da0ea1

Please sign in to comment.