Bug 1291821 - Switch stage duration interval counting to use elapsedRealtime r=rnewman
It is a better fit for interval counting.
MozReview-Commit-ID: LCF0U24MAwF
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/ServerSyncStage.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/ServerSyncStage.java
@@ -1,15 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.stage;
import android.content.Context;
+import android.os.SystemClock;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.EngineSettings;
import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.HTTPFailureException;
import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.NoCollectionKeysSetException;
import org.mozilla.gecko.sync.NonObjectJSONException;
@@ -470,17 +471,17 @@ public abstract class ServerSyncStage ex
Logger.info(LOG_TAG, "Wiping server complete.");
}
@Override
public void execute() throws NoSuchStageException {
final String name = getEngineName();
Logger.debug(LOG_TAG, "Starting execute for " + name);
- stageStartTimestamp = System.currentTimeMillis();
+ stageStartTimestamp = SystemClock.elapsedRealtime();
try {
if (!this.isEnabled()) {
Logger.info(LOG_TAG, "Skipping stage " + name + ".");
session.advance();
return;
}
} catch (MetaGlobalException.MetaGlobalMalformedSyncIDException e) {
@@ -570,17 +571,17 @@ public abstract class ServerSyncStage ex
/**
* We synced this engine! Persist timestamps and advance the session.
*
* @param synchronizer the <code>Synchronizer</code> that succeeded.
*/
@Override
public void onSynchronized(Synchronizer synchronizer) {
- stageCompleteTimestamp = System.currentTimeMillis();
+ stageCompleteTimestamp = SystemClock.elapsedRealtime();
Logger.debug(LOG_TAG, "onSynchronized.");
SynchronizerConfiguration newConfig = synchronizer.save();
if (newConfig != null) {
persistConfig(newConfig);
} else {
Logger.warn(LOG_TAG, "Didn't get configuration from synchronizer after success.");
}
@@ -600,17 +601,17 @@ public abstract class ServerSyncStage ex
* the next sync will include this sync's data), but do advance the session
* (if we didn't get a Retry-After header).
*
* @param synchronizer the <code>Synchronizer</code> that failed.
*/
@Override
public void onSynchronizeFailed(Synchronizer synchronizer,
Exception lastException, String reason) {
- stageCompleteTimestamp = System.currentTimeMillis();
+ stageCompleteTimestamp = SystemClock.elapsedRealtime();
Logger.warn(LOG_TAG, "Synchronize failed: " + reason, lastException);
// This failure could be due to a 503 or a 401 and it could have headers.
// Interrogate the headers but only abort the global session if Retry-After header is set.
if (lastException instanceof HTTPFailureException) {
SyncStorageResponse response = ((HTTPFailureException)lastException).response;
if (response.retryAfterInSeconds() > 0) {
session.handleHTTPError(response, reason); // Calls session.abort().