OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/metrics/variations_session.h" | 5 #include "chrome/browser/android/metrics/variations_session.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "components/variations/service/variations_service.h" | 9 #include "components/variations/service/variations_service.h" |
10 #include "jni/VariationsSession_jni.h" | 10 #include "jni/VariationsSession_jni.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Tracks whether VariationsService::OnAppEnterForeground() has been called | 14 // Tracks whether VariationsService::OnAppEnterForeground() has been called |
15 // previously, in order to set the restrict mode param before the first call. | 15 // previously, in order to set the restrict mode param before the first call. |
16 bool g_on_app_enter_foreground_called = false; | 16 bool g_on_app_enter_foreground_called = false; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 static void StartVariationsSession(JNIEnv* env, | 20 static void StartVariationsSession( |
21 jobject obj, | 21 JNIEnv* env, |
22 jstring jrestrict_mode) { | 22 const JavaParamRef<jobject>& obj, |
| 23 const JavaParamRef<jstring>& jrestrict_mode) { |
23 DCHECK(g_browser_process); | 24 DCHECK(g_browser_process); |
24 | 25 |
25 chrome_variations::VariationsService* variations_service = | 26 chrome_variations::VariationsService* variations_service = |
26 g_browser_process->variations_service(); | 27 g_browser_process->variations_service(); |
27 // Triggers an OnAppEnterForeground on the VariationsService. This may fetch | 28 // Triggers an OnAppEnterForeground on the VariationsService. This may fetch |
28 // a new seed. | 29 // a new seed. |
29 if (variations_service) { | 30 if (variations_service) { |
30 std::string restrict_mode = | 31 std::string restrict_mode = |
31 base::android::ConvertJavaStringToUTF8(env, jrestrict_mode); | 32 base::android::ConvertJavaStringToUTF8(env, jrestrict_mode); |
32 if (!restrict_mode.empty() && !g_on_app_enter_foreground_called) | 33 if (!restrict_mode.empty() && !g_on_app_enter_foreground_called) |
33 variations_service->SetRestrictMode(restrict_mode); | 34 variations_service->SetRestrictMode(restrict_mode); |
34 variations_service->OnAppEnterForeground(); | 35 variations_service->OnAppEnterForeground(); |
35 g_on_app_enter_foreground_called = true; | 36 g_on_app_enter_foreground_called = true; |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 namespace chrome { | 40 namespace chrome { |
40 namespace android { | 41 namespace android { |
41 | 42 |
42 // Register native methods | 43 // Register native methods |
43 bool RegisterVariationsSession(JNIEnv* env) { return RegisterNativesImpl(env); } | 44 bool RegisterVariationsSession(JNIEnv* env) { return RegisterNativesImpl(env); } |
44 | 45 |
45 } // namespace android | 46 } // namespace android |
46 } // namespace chrome | 47 } // namespace chrome |
OLD | NEW |