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

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

Issue 2449143002: Actually update FieldTrialEntry's activated field (Closed)
Patch Set: add to the allocator if it's null 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') | base/metrics/field_trial.cc » ('J')
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 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. 271 // this function, since the check for the allocator is not thread-safe.
272 void AddToAllocatorWhileLocked( 272 void AddToAllocatorWhileLocked(SharedPersistentMemoryAllocator* allocator);
273 base::SharedPersistentMemoryAllocator* allocator);
274 273
275 // Returns the group_name. A winner need not have been chosen. 274 // Returns the group_name. A winner need not have been chosen.
276 std::string group_name_internal() const { return group_name_; } 275 std::string group_name_internal() const { return group_name_; }
277 276
278 // The name of the field trial, as can be found via the FieldTrialList. 277 // The name of the field trial, as can be found via the FieldTrialList.
279 const std::string trial_name_; 278 const std::string trial_name_;
280 279
281 // The maximum sum of all probabilities supplied, which corresponds to 100%. 280 // The maximum sum of all probabilities supplied, which corresponds to 100%.
282 // This is the scaling factor used to adjust supplied probabilities. 281 // This is the scaling factor used to adjust supplied probabilities.
283 const Probability divisor_; 282 const Probability divisor_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 bool group_reported_; 315 bool group_reported_;
317 316
318 // Whether this trial is registered with the global FieldTrialList and thus 317 // Whether this trial is registered with the global FieldTrialList and thus
319 // should notify it when its group is queried. 318 // should notify it when its group is queried.
320 bool trial_registered_; 319 bool trial_registered_;
321 320
322 // When benchmarking is enabled, field trials all revert to the 'default' 321 // When benchmarking is enabled, field trials all revert to the 'default'
323 // group. 322 // group.
324 static bool enable_benchmarking_; 323 static bool enable_benchmarking_;
325 324
325 // Reference to related field trial struct and data in shared memory.
326 SharedPersistentMemoryAllocator::Reference ref_;
Alexei Svitkine (slow) 2016/10/25 19:18:53 Nit: Move this above the static var above - so all
lawrencewu 2016/10/25 20:27:33 Done.
327
326 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 328 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
327 }; 329 };
328 330
329 //------------------------------------------------------------------------------ 331 //------------------------------------------------------------------------------
330 // Class with a list of all active field trials. A trial is active if it has 332 // 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. 333 // been registered, which includes evaluating its state based on its probaility.
332 // Only one instance of this class exists. 334 // Only one instance of this class exists.
333 class BASE_EXPORT FieldTrialList { 335 class BASE_EXPORT FieldTrialList {
334 public: 336 public:
335 // Year that is guaranteed to not be expired when instantiating a field trial 337 // Year that is guaranteed to not be expired when instantiating a field trial
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 521
520 // Remove an observer. 522 // Remove an observer.
521 static void RemoveObserver(Observer* observer); 523 static void RemoveObserver(Observer* observer);
522 524
523 // Notify all observers that a group has been finalized for |field_trial|. 525 // Notify all observers that a group has been finalized for |field_trial|.
524 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 526 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
525 527
526 // Return the number of active field trials. 528 // Return the number of active field trials.
527 static size_t GetFieldTrialCount(); 529 static size_t GetFieldTrialCount();
528 530
531 // Return the field trial allocator (for adding to it).
532 static SharedPersistentMemoryAllocator* GetFieldTrialAllocator();
533
529 private: 534 private:
530 // Allow tests to access our innards for testing purposes. 535 // Allow tests to access our innards for testing purposes.
531 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 536 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
532 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 537 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
533 538
534 // Expects a mapped piece of shared memory |shm| that was created from the 539 // 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. 540 // browser process's field_trial_allocator and shared via the command line.
536 // This function recreates the allocator, iterates through all the field 541 // This function recreates the allocator, iterates through all the field
537 // trials in it, and creates them via CreateFieldTrial(). 542 // trials in it, and creates them via CreateFieldTrial().
538 static void CreateTrialsFromSharedMemory( 543 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, 581 // Entropy provider to be used for one-time randomized field trials. If NULL,
577 // one-time randomization is not supported. 582 // one-time randomization is not supported.
578 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 583 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
579 584
580 // List of observers to be notified when a group is selected for a FieldTrial. 585 // List of observers to be notified when a group is selected for a FieldTrial.
581 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 586 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
582 587
583 // Allocator used to instantiate field trial in child processes. In the 588 // 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 589 // 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. 590 // start passing more data other than field trials.
586 std::unique_ptr<base::SharedPersistentMemoryAllocator> 591 std::unique_ptr<SharedPersistentMemoryAllocator> field_trial_allocator_ =
587 field_trial_allocator_ = nullptr; 592 nullptr;
588 593
589 #if defined(OS_WIN) 594 #if defined(OS_WIN)
590 // Readonly copy of the handle to the allocator. Needs to be a member variable 595 // Readonly copy of the handle to the allocator. Needs to be a member variable
591 // because it's needed from both CopyFieldTrialStateToFlags() and 596 // because it's needed from both CopyFieldTrialStateToFlags() and
592 // AppendFieldTrialHandleIfNeeded(). 597 // AppendFieldTrialHandleIfNeeded().
593 HANDLE readonly_allocator_handle_ = nullptr; 598 HANDLE readonly_allocator_handle_ = nullptr;
594 #endif 599 #endif
595 600
596 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 601 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
597 }; 602 };
598 603
599 } // namespace base 604 } // namespace base
600 605
601 #endif // BASE_METRICS_FIELD_TRIAL_H_ 606 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698