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 #368 from jrburke/bug1098289-email-request-sync
Browse files Browse the repository at this point in the history
Bug 1098289 - Migrate Email to use navigator.sync (RequestSync) API (Phase1) r=asuth
  • Loading branch information
jrburke committed Feb 11, 2015
2 parents 9c2f521 + 6e0cfd2 commit dc1bdad
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 153 deletions.
17 changes: 13 additions & 4 deletions Makefile
Expand Up @@ -74,13 +74,22 @@ download-b2g: b2g
gaia-symlink:
echo "You need to create a symlink 'gaia-symlink' pointing at the gaia dir"

SYS=$(shell uname -s)
B2GBD := b2g-builddir-symlink
ifeq ($(wildcard b2g-bindir-symlink),)
B2GBIND := $(B2GBD)/dist/bin
RUNB2G := $(B2GBIND)/b2g
B2GBIND := $(B2GBD)/dist/bin
RUNB2G := $(B2GBIND)/b2g
else
B2GBIND := b2g-bindir-symlink
RUNB2G := $(B2GBIND)/b2g-bin
# OS X has trouble launching the executable via the symlink, gets a "Couldn't
# load XPCOM" error, so resolve the symlink first. Do not generically use
# readlink on all platforms, since it behaves slightly differently, and only
# the OS X platform seems to exhibit this problem.
ifeq ($(SYS),Darwin)
B2GBIND=`readlink b2g-bindir-symlink`
else
B2GBIND := b2g-bindir-symlink
endif
RUNB2G := $(B2GBIND)/b2g-bin
endif

ARBPLD=arbpl-dir-symlink
Expand Down
35 changes: 18 additions & 17 deletions js/cronsync.js
Expand Up @@ -10,7 +10,7 @@
* server for general responsiveness and so the user can use the device
* offline.
*
* We use mozAlarm to schedule ourselves to wake up when our next
* We use navigator.sync 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, _logParent) {
this.sendCronSync = $router.registerSimple('cronsync', function(data) {
var args = data.args;
switch (data.cmd) {
case 'alarm':
debug('received an alarm via a message handler');
this.onAlarm.apply(this, args);
case 'requestSync':
debug('received a requestSync via a message handler');
this.onRequestSync.apply(this, args);
break;
case 'syncEnsured':
debug('received an syncEnsured via a message handler');
Expand All @@ -194,9 +194,9 @@ CronSync.prototype = {
* Makes sure there is a sync timer set up for all accounts.
*/
ensureSync: function() {
// Only execute ensureSync if it is not already in progress.
// Otherwise, due to async timing of mozAlarm setting, could
// end up with two alarms for the same ID.
// 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
// tasks for the same ID.
if (!this._completedEnsureSync)
return;

Expand Down Expand Up @@ -352,8 +352,8 @@ CronSync.prototype = {
}.bind(this));
},

onAlarm: function(accountIds) {
this._LOG.alarmFired(accountIds);
onRequestSync: function(accountIds) {
this._LOG.requestSyncFired(accountIds);

if (!accountIds)
return;
Expand All @@ -367,7 +367,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 alarms correctly.
// an account deletion that did not clean up any sync tasks correctly.
accountIds.forEach(function(id) {
accounts.some(function(account) {
if (account.id === id) {
Expand All @@ -381,10 +381,10 @@ CronSync.prototype = {
// Flip switch to say account syncing is in progress.
this._syncAccountsDone = false;

// Make sure next alarm is set up. In the case of a cold start
// Make sure next sync 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 alarm is set up,
// app is already running, need to be sure next sync 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 @@ -444,8 +444,9 @@ CronSync.prototype = {

/**
* Checks for "sync all done", which means the ensureSync call completed, and
* 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.
* new sync tasks 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.
*/
_checkSyncDone: function() {
if (!this._completedEnsureSync || !this._syncAccountsDone)
Expand All @@ -462,9 +463,9 @@ CronSync.prototype = {

/**
* Called from cronsync-main once ensureSync as set
* any alarms needed. Need to wait for it before
* any sync tasks needed. Need to wait for it before
* signaling sync is done because otherwise the app
* could get closed down before the alarm additions
* could get closed down before the sync task additions
* succeed.
*/
onSyncEnsured: function() {
Expand All @@ -483,7 +484,7 @@ var LOGFAB = exports.LOGFAB = $log.register($module, {
CronSync: {
type: $log.DAEMON,
events: {
alarmFired: { accountIds: false },
requestSyncFired: { accountIds: false },
killSlices: { count: false },
syncSkipped: { id: true },
},
Expand Down
2 changes: 1 addition & 1 deletion js/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 mozAlarms status
* Main: 'hello' => worker with online status and navigator.sync status
* Worker: Creates MailUniverse
* Worker 'mailbridge'.'hello' => main
* Main: Creates MailAPI, sends event to UI
Expand Down

0 comments on commit dc1bdad

Please sign in to comment.