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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 namespace chrome { | 58 namespace chrome { |
59 | 59 |
60 namespace android { | 60 namespace android { |
61 | 61 |
62 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge() | 62 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge() |
63 : construct_time_(base::TimeTicks::Now()), | 63 : construct_time_(base::TimeTicks::Now()), |
64 is_first_matching_rule_fetch_(true) { | 64 is_first_matching_rule_fetch_(true), |
| 65 register_google_variation_id_(false) { |
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
66 | 67 |
67 // Detach from IO thread since rest of ExternalDataUseObserverBridge lives on | 68 // Detach from IO thread since rest of ExternalDataUseObserverBridge lives on |
68 // the UI thread. | 69 // the UI thread. |
69 thread_checker_.DetachFromThread(); | 70 thread_checker_.DetachFromThread(); |
70 } | 71 } |
71 | 72 |
72 ExternalDataUseObserverBridge::~ExternalDataUseObserverBridge() { | 73 ExternalDataUseObserverBridge::~ExternalDataUseObserverBridge() { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
74 if (j_external_data_use_observer_.is_null()) | 75 if (j_external_data_use_observer_.is_null()) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver( | 204 void ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver( |
204 bool should_register) const { | 205 bool should_register) const { |
205 DCHECK(thread_checker_.CalledOnValidThread()); | 206 DCHECK(thread_checker_.CalledOnValidThread()); |
206 DCHECK(!j_external_data_use_observer_.is_null()); | 207 DCHECK(!j_external_data_use_observer_.is_null()); |
207 | 208 |
208 io_task_runner_->PostTask( | 209 io_task_runner_->PostTask( |
209 FROM_HERE, | 210 FROM_HERE, |
210 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, | 211 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, |
211 external_data_use_observer_, should_register)); | 212 external_data_use_observer_, should_register)); |
212 | 213 |
| 214 if (!register_google_variation_id_) |
| 215 return; |
| 216 |
213 variations::VariationID variation_id = GetGoogleVariationID(); | 217 variations::VariationID variation_id = GetGoogleVariationID(); |
| 218 |
214 if (variation_id != variations::EMPTY_ID) { | 219 if (variation_id != variations::EMPTY_ID) { |
215 // Set variation id for the enabled group if |should_register| is true. | 220 // 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 | 221 // Otherwise clear the variation id for the enabled group by setting to |
217 // EMPTY_ID. | 222 // EMPTY_ID. |
218 variations::AssociateGoogleVariationID( | 223 variations::AssociateGoogleVariationID( |
219 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, | 224 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, |
220 kSyntheticFieldTrialEnabledGroup, | 225 kSyntheticFieldTrialEnabledGroup, |
221 should_register ? variation_id : variations::EMPTY_ID); | 226 should_register ? variation_id : variations::EMPTY_ID); |
222 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | 227 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( |
223 kSyntheticFieldTrial, should_register | 228 kSyntheticFieldTrial, should_register |
224 ? kSyntheticFieldTrialEnabledGroup | 229 ? kSyntheticFieldTrialEnabledGroup |
225 : kSyntheticFieldTrialDisabledGroup); | 230 : kSyntheticFieldTrialDisabledGroup); |
226 } | 231 } |
227 } | 232 } |
228 | 233 |
| 234 void ExternalDataUseObserverBridge::SetRegisterGoogleVariationID( |
| 235 bool register_google_variation_id) { |
| 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 237 register_google_variation_id_ = register_google_variation_id; |
| 238 } |
| 239 |
229 bool RegisterExternalDataUseObserver(JNIEnv* env) { | 240 bool RegisterExternalDataUseObserver(JNIEnv* env) { |
230 return RegisterNativesImpl(env); | 241 return RegisterNativesImpl(env); |
231 } | 242 } |
232 | 243 |
233 } // namespace android | 244 } // namespace android |
234 | 245 |
235 } // namespace chrome | 246 } // namespace chrome |
OLD | NEW |