Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_observer_bridge.cc

Issue 2294923002: Get GWS ID from field trial (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserver.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/data_usage/external_data_use_observer_bridge.h" 5 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/android/context_utils.h" 10 #include "base/android/context_utils.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_number_conversions.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "chrome/browser/android/data_usage/data_use_tab_model.h" 17 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
17 #include "chrome/browser/android/data_usage/external_data_use_observer.h" 18 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 19 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
19 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "jni/ExternalDataUseObserver_jni.h" 22 #include "jni/ExternalDataUseObserver_jni.h"
22 23
23 using base::android::ConvertUTF8ToJavaString; 24 using base::android::ConvertUTF8ToJavaString;
24 25
25 namespace { 26 namespace {
26 27
27 // Name of the external data use observer synthetic field trial, enabled and 28 // Name of the external data use observer synthetic field trial, enabled and
28 // disabled groups. 29 // disabled groups.
29 const char kSyntheticFieldTrial[] = "SyntheticExternalDataUseObserver"; 30 const char kSyntheticFieldTrial[] = "SyntheticExternalDataUseObserver";
30 const char kSyntheticFieldTrialEnabledGroup[] = "Enabled"; 31 const char kSyntheticFieldTrialEnabledGroup[] = "Enabled";
31 const char kSyntheticFieldTrialDisabledGroup[] = "Disabled"; 32 const char kSyntheticFieldTrialDisabledGroup[] = "Disabled";
32 33
33 // Returns the package name of the control app from the field trial. 34 // Returns the package name of the control app from the field trial.
34 const std::string GetControlAppPackageName() { 35 const std::string GetControlAppPackageName() {
35 return variations::GetVariationParamValue( 36 return variations::GetVariationParamValue(
36 chrome::android::ExternalDataUseObserver:: 37 chrome::android::ExternalDataUseObserver::
37 kExternalDataUseObserverFieldTrial, 38 kExternalDataUseObserverFieldTrial,
38 "control_app_package_name"); 39 "control_app_package_name");
39 } 40 }
40 41
42 // Returns the google variation ID from the field trial.
43 variations::VariationID GetGoogleVariationID() {
44 variations::VariationID variation_id;
45 std::string variation_value = variations::GetVariationParamValue(
46 chrome::android::ExternalDataUseObserver::
47 kExternalDataUseObserverFieldTrial,
48 "variation_id");
49 if (!variation_value.empty() &&
50 static_cast<variations::VariationID>(
sclittle 2016/08/30 20:06:45 nit: this static_cast doesn't really do anything,
Raj 2016/08/30 20:21:09 Done.
51 base::StringToInt(variation_value, &variation_id))) {
52 return variation_id;
53 }
54 return variations::EMPTY_ID;
55 }
56
41 } // namespace 57 } // namespace
42 58
43 namespace chrome { 59 namespace chrome {
44 60
45 namespace android { 61 namespace android {
46 62
47 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge() 63 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge()
48 : construct_time_(base::TimeTicks::Now()), 64 : construct_time_(base::TimeTicks::Now()),
49 is_first_matching_rule_fetch_(true) { 65 is_first_matching_rule_fetch_(true) {
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool should_register) const { 205 bool should_register) const {
190 DCHECK(thread_checker_.CalledOnValidThread()); 206 DCHECK(thread_checker_.CalledOnValidThread());
191 DCHECK(!j_external_data_use_observer_.is_null()); 207 DCHECK(!j_external_data_use_observer_.is_null());
192 208
193 io_task_runner_->PostTask( 209 io_task_runner_->PostTask(
194 FROM_HERE, 210 FROM_HERE,
195 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, 211 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver,
196 external_data_use_observer_, should_register)); 212 external_data_use_observer_, should_register));
197 213
198 // Set or clear the variation id for the enabled group. 214 // Set or clear the variation id for the enabled group.
199 JNIEnv* env = base::android::AttachCurrentThread(); 215 variations::VariationID variation_id = GetGoogleVariationID();
200 variations::AssociateGoogleVariationID( 216 if (variation_id != variations::EMPTY_ID) {
201 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, 217 variations::AssociateGoogleVariationID(
202 kSyntheticFieldTrialEnabledGroup, 218 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial,
203 should_register ? Java_ExternalDataUseObserver_getGoogleVariationID( 219 kSyntheticFieldTrialEnabledGroup,
204 env, j_external_data_use_observer_.obj()) 220 should_register ? variation_id : variations::EMPTY_ID);
sclittle 2016/08/30 20:06:45 So if should_register is false, then this sends EM
Raj 2016/08/30 20:21:09 Added comment. Setting EMPTY_ID, is actually clear
205 : variations::EMPTY_ID); 221 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
206 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( 222 kSyntheticFieldTrial, should_register
207 kSyntheticFieldTrial, should_register 223 ? kSyntheticFieldTrialEnabledGroup
208 ? kSyntheticFieldTrialEnabledGroup 224 : kSyntheticFieldTrialDisabledGroup);
209 : kSyntheticFieldTrialDisabledGroup); 225 }
210 } 226 }
211 227
212 bool RegisterExternalDataUseObserver(JNIEnv* env) { 228 bool RegisterExternalDataUseObserver(JNIEnv* env) {
213 return RegisterNativesImpl(env); 229 return RegisterNativesImpl(env);
214 } 230 }
215 231
216 } // namespace android 232 } // namespace android
217 233
218 } // namespace chrome 234 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserver.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698