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/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/strings/string_number_conversions.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 17 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
18 #include "chrome/browser/android/data_usage/external_data_use_observer.h" | 18 #include "chrome/browser/android/data_usage/external_data_use_observer.h" |
19 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 19 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
20 #include "chrome/browser/profiles/profile.h" | |
21 #include "chrome/browser/profiles/profile_manager.h" | |
22 #include "chrome/browser/signin/signin_manager_factory.h" | |
23 #include "components/signin/core/browser/signin_manager.h" | |
20 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
21 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
22 #include "jni/ExternalDataUseObserver_jni.h" | 26 #include "jni/ExternalDataUseObserver_jni.h" |
23 | 27 |
24 using base::android::ConvertUTF8ToJavaString; | 28 using base::android::ConvertUTF8ToJavaString; |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
28 // Name of the external data use observer synthetic field trial, enabled and | 32 // Name of the external data use observer synthetic field trial, enabled and |
29 // disabled groups. | 33 // disabled groups. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 bool should_register) const { | 208 bool should_register) const { |
205 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
206 DCHECK(!j_external_data_use_observer_.is_null()); | 210 DCHECK(!j_external_data_use_observer_.is_null()); |
207 | 211 |
208 io_task_runner_->PostTask( | 212 io_task_runner_->PostTask( |
209 FROM_HERE, | 213 FROM_HERE, |
210 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, | 214 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, |
211 external_data_use_observer_, should_register)); | 215 external_data_use_observer_, should_register)); |
212 | 216 |
213 variations::VariationID variation_id = GetGoogleVariationID(); | 217 variations::VariationID variation_id = GetGoogleVariationID(); |
214 if (variation_id != variations::EMPTY_ID) { | 218 Profile* profile = ProfileManager::GetActiveUserProfile(); |
tbansal1
2016/11/17 18:09:31
Comment for this method says "As such avoid
// u
Raj
2016/11/17 18:46:30
Using GetLastUsedProfile() instead, which is very
| |
219 DCHECK(profile); | |
220 const SigninManager* signin_manager = | |
221 SigninManagerFactory::GetForProfileIfExists(profile); | |
222 if (variation_id != variations::EMPTY_ID && signin_manager && | |
223 signin_manager->IsAuthenticated()) { | |
215 // Set variation id for the enabled group if |should_register| is true. | 224 // Set variation id for the enabled group if |should_register| is true. |
216 // Otherwise clear the variation id for the enabled group by setting to | 225 // Otherwise clear the variation id for the enabled group by setting to |
217 // EMPTY_ID. | 226 // EMPTY_ID. |
218 variations::AssociateGoogleVariationID( | 227 variations::AssociateGoogleVariationID( |
219 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, | 228 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, |
220 kSyntheticFieldTrialEnabledGroup, | 229 kSyntheticFieldTrialEnabledGroup, |
221 should_register ? variation_id : variations::EMPTY_ID); | 230 should_register ? variation_id : variations::EMPTY_ID); |
222 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | 231 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( |
223 kSyntheticFieldTrial, should_register | 232 kSyntheticFieldTrial, should_register |
224 ? kSyntheticFieldTrialEnabledGroup | 233 ? kSyntheticFieldTrialEnabledGroup |
225 : kSyntheticFieldTrialDisabledGroup); | 234 : kSyntheticFieldTrialDisabledGroup); |
226 } | 235 } |
227 } | 236 } |
228 | 237 |
229 bool RegisterExternalDataUseObserver(JNIEnv* env) { | 238 bool RegisterExternalDataUseObserver(JNIEnv* env) { |
230 return RegisterNativesImpl(env); | 239 return RegisterNativesImpl(env); |
231 } | 240 } |
232 | 241 |
233 } // namespace android | 242 } // namespace android |
234 | 243 |
235 } // namespace chrome | 244 } // namespace chrome |
OLD | NEW |