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 #32908 from jrburke/bug1219853-email-alarm-sync
Browse files Browse the repository at this point in the history
Bug 1219853 - [email] Go back to mozAlarms instead of request-sync r=asuth
  • Loading branch information
jrburke committed Oct 31, 2015
2 parents 450a30a + 7869bdd commit ec142ce
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 153 deletions.
2 changes: 1 addition & 1 deletion apps/email/docs/startup.md
Expand Up @@ -28,7 +28,7 @@ The localStorage values are stamped with the signature of the app files, since c

4) It continues to listen for mozSetMessageHandler entry point messages, and dispatches to handlers that have registered to `window.globalOnAppMessage`. `mail_app` calls `globalOnAppMessage`. The startupData is returned from calls to `globalOnAppMessage`, so this is how `mail_app` knows what startup entry point and view are suggested by `html_cache_restore`.

`html_cache_restore` will **not** listen for mozSetMessageHandler messagesfor request-sync messages, because wake locks need to be acquired in that case, and given the complexity of that need, it relies on cronsync-main to do that work. `html_cache_restore` does detect if it was started from a request-sync message, but only uses that it setting up the startup state.
`html_cache_restore` will **not** listen for mozSetMessageHandler messagesfor alarm messages, because wake locks need to be acquired in that case, and given the complexity of that need, it relies on cronsync-main to do that work. `html_cache_restore` does detect if it was started from a alarm message, but only uses that it setting up the startup state.

## config

Expand Down
3 changes: 0 additions & 3 deletions apps/email/js/cards/settings_debug.html
Expand Up @@ -64,9 +64,6 @@ <h1 class="header-label">Debug Magic</h1>
href="#"
class="tng-dbg-fastsync">Enable faster sync options</button>

<button data-event="click:showSyncs"
href="#">Show sync tasks in logcat</button>

<button data-event="click:resetStartupCache"
href="#">Reset startup cache</button>
</section>
Expand Down
27 changes: 1 addition & 26 deletions apps/email/js/cards/settings_debug.js
Expand Up @@ -43,32 +43,7 @@ return [
},

fastSync: function() {
_secretDebug.fastSync = [100000, 200000];
},

showSyncs: function() {
var navSync = navigator.sync;
if (!navSync) {
console.error('navigator.sync not available');
return;
}

navSync.registrations().then(function(regs) {
console.log('navigator.sync registrations count: ', regs.length);
regs.forEach(function(reg) {
console.log('Registered task: ' + reg.task);
Object.keys(reg).forEach(function(key) {
if (key === 'data') {
console.log(key + ': ' + JSON.stringify(reg[key]));
} else {
console.log(key + ': ' + reg[key]);
}
});
console.log('-----------');
});
}, function(err) {
console.error('navigator.sync.registrations failed: ', err);
});
_secretDebug.fastSync = [20000, 60000];
},

resetStartupCache: function() {
Expand Down
26 changes: 13 additions & 13 deletions apps/email/js/ext/cronsync.js
Expand Up @@ -10,7 +10,7 @@
* server for general responsiveness and so the user can use the device
* offline.
*
* We use navigator.sync to schedule ourselves to wake up when our next
* We use mozAlarm to schedule ourselves to wake up when our next
* synchronization should occur.
*
* All synchronization occurs in parallel because we want the interval that we
Expand Down Expand Up @@ -166,9 +166,9 @@ function CronSync(universe) {
this.sendCronSync = $router.registerSimple('cronsync', function(data) {
var args = data.args;
switch (data.cmd) {
case 'requestSync':
debug('received a requestSync via a message handler');
this.onRequestSync.apply(this, args);
case 'alarm':
debug('received an alarm via a message handler');
this.onAlarm.apply(this, args);
break;
case 'syncEnsured':
debug('received an syncEnsured via a message handler');
Expand All @@ -195,7 +195,7 @@ CronSync.prototype = {
*/
ensureSync: function() {
// Only execute ensureSync if it is not already in progress. Otherwise, due
// to async timing of navigator.sync setting, could end up with two sync
// to async timing of mozAlarm setting, could end up with two sync
// tasks for the same ID.
if (!this._completedEnsureSync)
return;
Expand Down Expand Up @@ -354,8 +354,8 @@ CronSync.prototype = {
}.bind(this));
},

onRequestSync: function(accountIds) {
logic(this, 'requestSyncFired', { accountIds: accountIds });
onAlarm: function(accountIds) {
logic(this, 'alarmFired', { accountIds: accountIds });

if (!accountIds)
return;
Expand All @@ -369,7 +369,7 @@ CronSync.prototype = {
this._universe.__notifyStartedCronSync(accountIds);

// Make sure the acount IDs are still valid. This is to protect agains
// an account deletion that did not clean up any sync tasks correctly.
// an account deletion that did not clean up any alarms correctly.
accountIds.forEach(function(id) {
accounts.some(function(account) {
if (account.id === id) {
Expand All @@ -383,10 +383,10 @@ CronSync.prototype = {
// Flip switch to say account syncing is in progress.
this._syncAccountsDone = false;

// Make sure next sync is set up. In the case of a cold start
// Make sure next alarm is set up. In the case of a cold start
// background sync, this is a bit redundant in that the startup
// of the mailuniverse would trigger this work. However, if the
// app is already running, need to be sure next sync is set up,
// app is already running, need to be sure next alarm is set up,
// so ensure the next sync is set up here. Do it here instead of
// after a sync in case an error in sync would prevent the next
// sync from getting scheduled.
Expand Down Expand Up @@ -446,7 +446,7 @@ CronSync.prototype = {

/**
* Checks for "sync all done", which means the ensureSync call completed, and
* new sync tasks for next sync are set, and the account syncs have finished.
* new alarms for next sync are set, and the account syncs have finished.
* If those two things are true, then notify the universe that the sync is
* done.
*/
Expand All @@ -465,9 +465,9 @@ CronSync.prototype = {

/**
* Called from cronsync-main once ensureSync as set
* any sync tasks needed. Need to wait for it before
* any alarms needed. Need to wait for it before
* signaling sync is done because otherwise the app
* could get closed down before the sync task additions
* could get closed down before the alarm additions
* succeed.
*/
onSyncEnsured: function() {
Expand Down
2 changes: 1 addition & 1 deletion apps/email/js/ext/main-frame-setup.js
Expand Up @@ -5,7 +5,7 @@
* Main: Spawns worker
* Worker: Loads core JS
* Worker: 'hello' => main
* Main: 'hello' => worker with online status and navigator.sync status
* Main: 'hello' => worker with online status and mozAlarms status
* Worker: Creates MailUniverse
* Worker 'mailbridge'.'hello' => main
* Main: Creates MailAPI, sends event to UI
Expand Down

0 comments on commit ec142ce

Please sign in to comment.