From 9022a32d3ce5109f1397b01bfa90d1b8b0799d07 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Tue, 31 May 2016 14:16:04 -0700 Subject: [PATCH] Bug 1273689 - Move session measurement calls to CorePingDelegate. r=sebastian MozReview-Commit-ID: EPLUd5Uq0Pc --HG-- extra : rebase_source : ad7f650414c15ac44b64acb371a04f3cfea3d0e2 --- .../base/java/org/mozilla/gecko/BrowserApp.java | 12 ------------ .../TelemetryCorePingUploadDelegate.java | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index 5e15d229c1c3..4ba88899b0ca 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -79,7 +79,6 @@ import org.mozilla.gecko.tabs.TabsPanel; import org.mozilla.gecko.telemetry.TelemetryUploadService; import org.mozilla.gecko.telemetry.TelemetryCorePingUploadDelegate; import org.mozilla.gecko.telemetry.measurements.SearchCountMeasurements; -import org.mozilla.gecko.telemetry.measurements.SessionMeasurements; import org.mozilla.gecko.toolbar.AutocompleteHandler; import org.mozilla.gecko.toolbar.BrowserToolbar; import org.mozilla.gecko.toolbar.BrowserToolbar.TabEditingState; @@ -316,8 +315,6 @@ public class BrowserApp extends GeckoApp @NonNull private SearchEngineManager mSearchEngineManager; // Contains reference to Context - DO NOT LEAK! - private final SessionMeasurements mSessionMeasurements = new SessionMeasurements(); - private boolean mHasResumed; @Override @@ -1001,7 +998,6 @@ public class BrowserApp extends GeckoApp // Needed for Adjust to get accurate session measurements AdjustConstants.getAdjustHelper().onResume(); - mSessionMeasurements.recordSessionStart(); if (!mHasResumed) { EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this, @@ -1026,10 +1022,6 @@ public class BrowserApp extends GeckoApp // Needed for Adjust to get accurate session measurements AdjustConstants.getAdjustHelper().onPause(); - // onStart/onStop is ideal over onResume/onPause. However, onStop is not guaranteed to be called and - // dealing with that possibility adds a lot of complexity that we don't want to handle at this point. - mSessionMeasurements.recordSessionEnd(this); - if (mHasResumed) { // Register for Prompt:ShowTop so we can foreground this activity even if it's hidden. EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this, @@ -3915,10 +3907,6 @@ public class BrowserApp extends GeckoApp return mSearchEngineManager; } - public SessionMeasurements getSessionMeasurementDelegate() { - return mSessionMeasurements; - } - // For use from tests only. @RobocopTarget public ReadingListHelper getReadingListHelper() { diff --git a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingUploadDelegate.java b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingUploadDelegate.java index ee2bcf5c1c54..09967ce0847f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingUploadDelegate.java +++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingUploadDelegate.java @@ -34,6 +34,7 @@ public class TelemetryCorePingUploadDelegate extends BrowserAppDelegate { "Gecko" + TelemetryCorePingUploadDelegate.class.getSimpleName(), 0, 23); private TelemetryDispatcher telemetryDispatcher; // lazy + private final SessionMeasurements sessionMeasurements = new SessionMeasurements(); @Override public void onStart(final BrowserApp browserApp) { @@ -49,6 +50,18 @@ public class TelemetryCorePingUploadDelegate extends BrowserAppDelegate { searchEngineManager.getEngine(new UploadTelemetryCorePingCallback(browserApp)); } + @Override + public void onResume(BrowserApp browserApp) { + sessionMeasurements.recordSessionStart(); + } + + @Override + public void onPause(BrowserApp browserApp) { + // onStart/onStop is ideal over onResume/onPause. However, onStop is not guaranteed to be called and + // dealing with that possibility adds a lot of complexity that we don't want to handle at this point. + sessionMeasurements.recordSessionEnd(browserApp); + } + @WorkerThread // via constructor private TelemetryDispatcher getTelemetryDispatcher(final BrowserApp browserApp) { if (telemetryDispatcher == null) { @@ -107,7 +120,7 @@ public class TelemetryCorePingUploadDelegate extends BrowserAppDelegate { // Each profile can have different telemetry data so we intentionally grab the shared prefs for the profile. final SharedPreferences sharedPrefs = getSharedPreferences(activity); final SessionMeasurements.SessionMeasurementsContainer sessionMeasurementsContainer = - activity.getSessionMeasurementDelegate().getAndResetSessionMeasurements(activity); + sessionMeasurements.getAndResetSessionMeasurements(activity); final TelemetryCorePingBuilder pingBuilder = new TelemetryCorePingBuilder(activity) .setClientID(clientID) .setDefaultSearchEngine(TelemetryCorePingBuilder.getEngineIdentifier(engine))