summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android/metrics/variations_session.cc
blob: b9cac1e50efa9a5cf14959af9231b2da3fef3a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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