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

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

Issue 2834463005: Fix race with google variation ID registration (Closed)
Patch Set: rebased Created 3 years, 8 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/browser/android/data_usage/external_data_use_observer_bridge.h ('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/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 namespace chrome { 57 namespace chrome {
58 58
59 namespace android { 59 namespace android {
60 60
61 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge() 61 ExternalDataUseObserverBridge::ExternalDataUseObserverBridge()
62 : construct_time_(base::TimeTicks::Now()), 62 : construct_time_(base::TimeTicks::Now()),
63 is_first_matching_rule_fetch_(true), 63 is_first_matching_rule_fetch_(true) {
64 register_google_variation_id_(false) {
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
66 65
67 // Detach from IO thread since rest of ExternalDataUseObserverBridge lives on 66 // Detach from IO thread since rest of ExternalDataUseObserverBridge lives on
68 // the UI thread. 67 // the UI thread.
69 thread_checker_.DetachFromThread(); 68 thread_checker_.DetachFromThread();
70 } 69 }
71 70
72 ExternalDataUseObserverBridge::~ExternalDataUseObserverBridge() { 71 ExternalDataUseObserverBridge::~ExternalDataUseObserverBridge() {
73 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
74 if (j_external_data_use_observer_.is_null()) 73 if (j_external_data_use_observer_.is_null())
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 200
202 void ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver( 201 void ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver(
203 bool should_register) const { 202 bool should_register) const {
204 DCHECK(thread_checker_.CalledOnValidThread()); 203 DCHECK(thread_checker_.CalledOnValidThread());
205 DCHECK(!j_external_data_use_observer_.is_null()); 204 DCHECK(!j_external_data_use_observer_.is_null());
206 205
207 io_task_runner_->PostTask( 206 io_task_runner_->PostTask(
208 FROM_HERE, 207 FROM_HERE,
209 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, 208 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver,
210 external_data_use_observer_, should_register)); 209 external_data_use_observer_, should_register));
210 }
211 211
212 if (!register_google_variation_id_) 212 void ExternalDataUseObserverBridge::RegisterGoogleVariationID(
213 return; 213 bool should_register) {
214 214 DCHECK(thread_checker_.CalledOnValidThread());
215 variations::VariationID variation_id = GetGoogleVariationID(); 215 variations::VariationID variation_id = GetGoogleVariationID();
216 216
217 if (variation_id != variations::EMPTY_ID) { 217 if (variation_id != variations::EMPTY_ID) {
218 // Set variation id for the enabled group if |should_register| is true. 218 // Set variation id for the enabled group if |should_register| is true.
219 // Otherwise clear the variation id for the enabled group by setting to 219 // Otherwise clear the variation id for the enabled group by setting to
220 // EMPTY_ID. 220 // EMPTY_ID.
221 variations::AssociateGoogleVariationID( 221 if (should_register) {
222 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial, 222 variations::AssociateGoogleVariationID(
223 kSyntheticFieldTrialEnabledGroup, 223 variations::GOOGLE_WEB_PROPERTIES, kSyntheticFieldTrial,
224 should_register ? variation_id : variations::EMPTY_ID); 224 kSyntheticFieldTrialEnabledGroup, variation_id);
225 }
225 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( 226 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
226 kSyntheticFieldTrial, should_register 227 kSyntheticFieldTrial, should_register
227 ? kSyntheticFieldTrialEnabledGroup 228 ? kSyntheticFieldTrialEnabledGroup
228 : kSyntheticFieldTrialDisabledGroup); 229 : kSyntheticFieldTrialDisabledGroup);
229 } 230 }
230 } 231 }
231 232
232 void ExternalDataUseObserverBridge::SetRegisterGoogleVariationID(
233 bool register_google_variation_id) {
234 DCHECK(thread_checker_.CalledOnValidThread());
235 register_google_variation_id_ = register_google_variation_id;
236 }
237
238 bool RegisterExternalDataUseObserver(JNIEnv* env) { 233 bool RegisterExternalDataUseObserver(JNIEnv* env) {
239 return RegisterNativesImpl(env); 234 return RegisterNativesImpl(env);
240 } 235 }
241 236
242 } // namespace android 237 } // namespace android
243 238
244 } // namespace chrome 239 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/data_usage/external_data_use_observer_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698