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

Side by Side Diff: base/metrics/field_trial.h

Issue 2449143002: Actually update FieldTrialEntry's activated field (Closed)
Patch Set: address comments Created 4 years, 1 month 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 | « no previous file | base/metrics/field_trial.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // FieldTrial is a class for handling details of statistical experiments 5 // FieldTrial is a class for handling details of statistical experiments
6 // performed by actual users in the field (i.e., in a shipped or beta product). 6 // performed by actual users in the field (i.e., in a shipped or beta product).
7 // All code is called exclusively on the UI thread currently. 7 // All code is called exclusively on the UI thread currently.
8 // 8 //
9 // The simplest example is an experiment to see whether one of two options 9 // The simplest example is an experiment to see whether one of two options
10 // produces "better" results across our user population. In that scenario, UMA 10 // produces "better" results across our user population. In that scenario, UMA
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // untouched. 259 // untouched.
260 bool GetActiveGroup(ActiveGroup* active_group) const; 260 bool GetActiveGroup(ActiveGroup* active_group) const;
261 261
262 // Returns the trial name and selected group name for this field trial via 262 // Returns the trial name and selected group name for this field trial via
263 // the output parameter |field_trial_state|, but only if the trial has not 263 // the output parameter |field_trial_state|, but only if the trial has not
264 // been disabled. In that case, true is returned and |field_trial_state| is 264 // been disabled. In that case, true is returned and |field_trial_state| is
265 // filled in; otherwise, the result is false and |field_trial_state| is left 265 // filled in; otherwise, the result is false and |field_trial_state| is left
266 // untouched. 266 // untouched.
267 bool GetState(State* field_trial_state); 267 bool GetState(State* field_trial_state);
268 268
269 // Adds the field trial to the allocator whose memory is to be shared with
270 // child processes. Assumes the calling code has a lock around the call to
271 // this function, since the check for the allocator is not thread-safe.
272 void AddToAllocatorWhileLocked(
273 base::SharedPersistentMemoryAllocator* allocator);
274
275 // Returns the group_name. A winner need not have been chosen. 269 // Returns the group_name. A winner need not have been chosen.
276 std::string group_name_internal() const { return group_name_; } 270 std::string group_name_internal() const { return group_name_; }
277 271
278 // The name of the field trial, as can be found via the FieldTrialList. 272 // The name of the field trial, as can be found via the FieldTrialList.
279 const std::string trial_name_; 273 const std::string trial_name_;
280 274
281 // The maximum sum of all probabilities supplied, which corresponds to 100%. 275 // The maximum sum of all probabilities supplied, which corresponds to 100%.
282 // This is the scaling factor used to adjust supplied probabilities. 276 // This is the scaling factor used to adjust supplied probabilities.
283 const Probability divisor_; 277 const Probability divisor_;
284 278
(...skipping 27 matching lines...) Expand all
312 // appropriate. 306 // appropriate.
313 bool forced_; 307 bool forced_;
314 308
315 // Specifies whether the group choice has been reported to observers. 309 // Specifies whether the group choice has been reported to observers.
316 bool group_reported_; 310 bool group_reported_;
317 311
318 // Whether this trial is registered with the global FieldTrialList and thus 312 // Whether this trial is registered with the global FieldTrialList and thus
319 // should notify it when its group is queried. 313 // should notify it when its group is queried.
320 bool trial_registered_; 314 bool trial_registered_;
321 315
316 // Reference to related field trial struct and data in shared memory.
317 SharedPersistentMemoryAllocator::Reference ref_;
318
322 // When benchmarking is enabled, field trials all revert to the 'default' 319 // When benchmarking is enabled, field trials all revert to the 'default'
323 // group. 320 // group.
324 static bool enable_benchmarking_; 321 static bool enable_benchmarking_;
325 322
326 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 323 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
327 }; 324 };
328 325
329 //------------------------------------------------------------------------------ 326 //------------------------------------------------------------------------------
330 // Class with a list of all active field trials. A trial is active if it has 327 // Class with a list of all active field trials. A trial is active if it has
331 // been registered, which includes evaluating its state based on its probaility. 328 // been registered, which includes evaluating its state based on its probaility.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // to being part of some specific field_group (and hence the group_name is 513 // to being part of some specific field_group (and hence the group_name is
517 // also finalized for that field_trial). 514 // also finalized for that field_trial).
518 static void AddObserver(Observer* observer); 515 static void AddObserver(Observer* observer);
519 516
520 // Remove an observer. 517 // Remove an observer.
521 static void RemoveObserver(Observer* observer); 518 static void RemoveObserver(Observer* observer);
522 519
523 // Notify all observers that a group has been finalized for |field_trial|. 520 // Notify all observers that a group has been finalized for |field_trial|.
524 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 521 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
525 522
523 // Activate the corresponding field trial entry struct in shared memory.
524 static void ActivateFieldTrialEntry(FieldTrial* field_trial);
525
526 // Return the number of active field trials. 526 // Return the number of active field trials.
527 static size_t GetFieldTrialCount(); 527 static size_t GetFieldTrialCount();
528 528
529 // Adds the field trial to the allocator.
530 static void AddToAllocator(FieldTrial* field_trial);
Alexei Svitkine (slow) 2016/10/25 21:12:29 I don't think these should be in the public API, s
lawrencewu 2016/10/26 13:43:15 Hmm, I'm not sure that solves the problem of addin
Alexei Svitkine (slow) 2016/10/26 14:49:02 Ah right. Well, ok how about just having: OnGrou
lawrencewu 2016/10/26 15:41:38 Sounds good, done.
531
529 private: 532 private:
530 // Allow tests to access our innards for testing purposes. 533 // Allow tests to access our innards for testing purposes.
531 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 534 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
532 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 535 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
533 536
534 // Expects a mapped piece of shared memory |shm| that was created from the 537 // Expects a mapped piece of shared memory |shm| that was created from the
535 // browser process's field_trial_allocator and shared via the command line. 538 // browser process's field_trial_allocator and shared via the command line.
536 // This function recreates the allocator, iterates through all the field 539 // This function recreates the allocator, iterates through all the field
537 // trials in it, and creates them via CreateFieldTrial(). 540 // trials in it, and creates them via CreateFieldTrial().
538 static void CreateTrialsFromSharedMemory( 541 static void CreateTrialsFromSharedMemory(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 // Entropy provider to be used for one-time randomized field trials. If NULL, 579 // Entropy provider to be used for one-time randomized field trials. If NULL,
577 // one-time randomization is not supported. 580 // one-time randomization is not supported.
578 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 581 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
579 582
580 // List of observers to be notified when a group is selected for a FieldTrial. 583 // List of observers to be notified when a group is selected for a FieldTrial.
581 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 584 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
582 585
583 // Allocator used to instantiate field trial in child processes. In the 586 // Allocator used to instantiate field trial in child processes. In the
584 // future, we may want to move this to a more generic place if we want to 587 // future, we may want to move this to a more generic place if we want to
585 // start passing more data other than field trials. 588 // start passing more data other than field trials.
586 std::unique_ptr<base::SharedPersistentMemoryAllocator> 589 std::unique_ptr<SharedPersistentMemoryAllocator> field_trial_allocator_ =
587 field_trial_allocator_ = nullptr; 590 nullptr;
588 591
589 #if defined(OS_WIN) 592 #if defined(OS_WIN)
590 // Readonly copy of the handle to the allocator. Needs to be a member variable 593 // Readonly copy of the handle to the allocator. Needs to be a member variable
591 // because it's needed from both CopyFieldTrialStateToFlags() and 594 // because it's needed from both CopyFieldTrialStateToFlags() and
592 // AppendFieldTrialHandleIfNeeded(). 595 // AppendFieldTrialHandleIfNeeded().
593 HANDLE readonly_allocator_handle_ = nullptr; 596 HANDLE readonly_allocator_handle_ = nullptr;
594 #endif 597 #endif
595 598
596 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 599 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
597 }; 600 };
598 601
599 } // namespace base 602 } // namespace base
600 603
601 #endif // BASE_METRICS_FIELD_TRIAL_H_ 604 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698