Commit 82af6f6b authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Upstream VariationsSession

BUG=428904

Review URL: https://codereview.chromium.org/1024993003

Cr-Commit-Position: refs/heads/master@{#321891}
parent 87b5f2ec
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.metrics;
import android.content.Context;
/**
* Sets up communication with the VariationsService. This is primarily used for
* triggering seed fetches on application startup.
*/
public class VariationsSession {
private boolean mInitialized;
private String mRestrictMode;
/**
* Triggers to the native VariationsService that the application has entered the foreground.
*/
public void start(Context context) {
if (!mInitialized) {
mInitialized = true;
// Check the restrict mode only once initially to avoid doing extra work each time the
// app enters foreground.
mRestrictMode = getRestrictMode(context);
}
nativeStartVariationsSession(mRestrictMode);
}
/**
* Returns the value of the "restrict" URL param that the variations service should use for
* variation seed requests.
*/
protected String getRestrictMode(Context context) {
return "";
}
private native void nativeStartVariationsSession(String restrictMode);
}
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "chrome/browser/android/metrics/uma_bridge.h" #include "chrome/browser/android/metrics/uma_bridge.h"
#include "chrome/browser/android/metrics/uma_session_stats.h" #include "chrome/browser/android/metrics/uma_session_stats.h"
#include "chrome/browser/android/metrics/uma_utils.h" #include "chrome/browser/android/metrics/uma_utils.h"
#include "chrome/browser/android/metrics/variations_session.h"
#include "chrome/browser/android/most_visited_sites.h" #include "chrome/browser/android/most_visited_sites.h"
#include "chrome/browser/android/new_tab_page_prefs.h" #include "chrome/browser/android/new_tab_page_prefs.h"
#include "chrome/browser/android/omnibox/answers_image_bridge.h" #include "chrome/browser/android/omnibox/answers_image_bridge.h"
...@@ -248,6 +249,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = { ...@@ -248,6 +249,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{"UmaSessionStats", RegisterUmaSessionStats}, {"UmaSessionStats", RegisterUmaSessionStats},
{"UrlUtilities", RegisterUrlUtilities}, {"UrlUtilities", RegisterUrlUtilities},
{"Variations", variations::android::RegisterVariations}, {"Variations", variations::android::RegisterVariations},
{"VariationsSession", chrome::android::RegisterVariationsSession},
{"WarmupManager", RegisterWarmupManager}, {"WarmupManager", RegisterWarmupManager},
{"WebsitePreferenceBridge", RegisterWebsitePreferenceBridge}, {"WebsitePreferenceBridge", RegisterWebsitePreferenceBridge},
{"WebsiteSettingsPopupAndroid", {"WebsiteSettingsPopupAndroid",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/metrics/variations_session.h"
#include "base/android/jni_string.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/variations/variations_service.h"
#include "jni/VariationsSession_jni.h"
namespace {
// Tracks whether VariationsService::OnAppEnterForeground() has been called
// previously, in order to set the restrict mode param before the first call.
bool g_on_app_enter_foreground_called = false;
} // namespace
static void StartVariationsSession(JNIEnv* env,
jobject obj,
jstring jrestrict_mode) {
DCHECK(g_browser_process);
chrome_variations::VariationsService* variations_service =
g_browser_process->variations_service();
// Triggers an OnAppEnterForeground on the VariationsService. This may fetch
// a new seed.
if (variations_service) {
std::string restrict_mode =
base::android::ConvertJavaStringToUTF8(env, jrestrict_mode);
if (!restrict_mode.empty() && !g_on_app_enter_foreground_called)
variations_service->SetRestrictMode(restrict_mode);
variations_service->OnAppEnterForeground();
g_on_app_enter_foreground_called = true;
}
}
namespace chrome {
namespace android {
// Register native methods
bool RegisterVariationsSession(JNIEnv* env) { return RegisterNativesImpl(env); }
} // namespace android
} // namespace chrome
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_METRICS_VARIATIONS_SESSION_H_
#define CHROME_BROWSER_ANDROID_METRICS_VARIATIONS_SESSION_H_
#include <jni.h>
namespace chrome {
namespace android {
// Registers the native methods through jni.
bool RegisterVariationsSession(JNIEnv* env);
} // namespace android
} // namespace chrome
#endif // CHROME_BROWSER_ANDROID_METRICS_VARIATIONS_SESSION_H_
...@@ -117,6 +117,8 @@ ...@@ -117,6 +117,8 @@
'browser/android/metrics/uma_session_stats.h', 'browser/android/metrics/uma_session_stats.h',
'browser/android/metrics/uma_utils.cc', 'browser/android/metrics/uma_utils.cc',
'browser/android/metrics/uma_utils.h', 'browser/android/metrics/uma_utils.h',
'browser/android/metrics/variations_session.cc',
'browser/android/metrics/variations_session.h',
'browser/android/most_visited_sites.cc', 'browser/android/most_visited_sites.cc',
'browser/android/most_visited_sites.h', 'browser/android/most_visited_sites.h',
'browser/android/new_tab_page_prefs.cc', 'browser/android/new_tab_page_prefs.cc',
...@@ -1638,6 +1640,7 @@ ...@@ -1638,6 +1640,7 @@
'android/java/src/org/chromium/chrome/browser/metrics/UmaBridge.java', 'android/java/src/org/chromium/chrome/browser/metrics/UmaBridge.java',
'android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java', 'android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java',
'android/java/src/org/chromium/chrome/browser/metrics/UmaUtils.java', 'android/java/src/org/chromium/chrome/browser/metrics/UmaUtils.java',
'android/java/src/org/chromium/chrome/browser/metrics/VariationsSession.java',
'android/java/src/org/chromium/chrome/browser/NavigationPopup.java', 'android/java/src/org/chromium/chrome/browser/NavigationPopup.java',
'android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java', 'android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java',
'android/java/src/org/chromium/chrome/browser/infobar/DownloadOverwriteInfoBar.java', 'android/java/src/org/chromium/chrome/browser/infobar/DownloadOverwriteInfoBar.java',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment