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

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

Issue 2501283002: Refactor field_trial.cc (Closed)
Patch Set: git rebase-update 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Save); 212 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Save);
213 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll); 213 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll);
214 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore); 214 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore);
215 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff); 215 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff);
216 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn); 216 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn);
217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default); 217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default);
218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault); 218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault);
219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes); 219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes);
220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability); 220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability);
221 221
222 typedef SharedPersistentMemoryAllocator::Reference FieldTrialRef;
223
222 friend class base::FieldTrialList; 224 friend class base::FieldTrialList;
223 225
224 friend class RefCounted<FieldTrial>; 226 friend class RefCounted<FieldTrial>;
225 227
226 // This is the group number of the 'default' group when a choice wasn't forced 228 // This is the group number of the 'default' group when a choice wasn't forced
227 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that 229 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that
228 // consumers don't use it by mistake in cases where the group was forced. 230 // consumers don't use it by mistake in cases where the group was forced.
229 static const int kDefaultGroupNumber; 231 static const int kDefaultGroupNumber;
230 232
231 // Creates a field trial with the specified parameters. Group assignment will 233 // Creates a field trial with the specified parameters. Group assignment will
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 bool forced_; 317 bool forced_;
316 318
317 // Specifies whether the group choice has been reported to observers. 319 // Specifies whether the group choice has been reported to observers.
318 bool group_reported_; 320 bool group_reported_;
319 321
320 // Whether this trial is registered with the global FieldTrialList and thus 322 // Whether this trial is registered with the global FieldTrialList and thus
321 // should notify it when its group is queried. 323 // should notify it when its group is queried.
322 bool trial_registered_; 324 bool trial_registered_;
323 325
324 // Reference to related field trial struct and data in shared memory. 326 // Reference to related field trial struct and data in shared memory.
325 SharedPersistentMemoryAllocator::Reference ref_; 327 FieldTrialRef ref_;
326 328
327 // When benchmarking is enabled, field trials all revert to the 'default' 329 // When benchmarking is enabled, field trials all revert to the 'default'
328 // group. 330 // group.
329 static bool enable_benchmarking_; 331 static bool enable_benchmarking_;
330 332
331 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 333 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
332 }; 334 };
333 335
334 //------------------------------------------------------------------------------ 336 //------------------------------------------------------------------------------
335 // Class with a list of all active field trials. A trial is active if it has 337 // Class with a list of all active field trials. A trial is active if it has
336 // been registered, which includes evaluating its state based on its probaility. 338 // been registered, which includes evaluating its state based on its probaility.
337 // Only one instance of this class exists. 339 // Only one instance of this class exists.
338 class BASE_EXPORT FieldTrialList { 340 class BASE_EXPORT FieldTrialList {
339 public: 341 public:
342 typedef SharedPersistentMemoryAllocator FieldTrialAllocator;
343
340 // Year that is guaranteed to not be expired when instantiating a field trial 344 // Year that is guaranteed to not be expired when instantiating a field trial
341 // via |FactoryGetFieldTrial()|. Set to two years from the build date. 345 // via |FactoryGetFieldTrial()|. Set to two years from the build date.
342 static int kNoExpirationYear; 346 static int kNoExpirationYear;
343 347
344 // Observer is notified when a FieldTrial's group is selected. 348 // Observer is notified when a FieldTrial's group is selected.
345 class BASE_EXPORT Observer { 349 class BASE_EXPORT Observer {
346 public: 350 public:
347 // Notify observers when FieldTrials's group is selected. 351 // Notify observers when FieldTrials's group is selected.
348 virtual void OnFieldTrialGroupFinalized(const std::string& trial_name, 352 virtual void OnFieldTrialGroupFinalized(const std::string& trial_name,
349 const std::string& group_name) = 0; 353 const std::string& group_name) = 0;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 537 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
534 538
535 // Return the number of active field trials. 539 // Return the number of active field trials.
536 static size_t GetFieldTrialCount(); 540 static size_t GetFieldTrialCount();
537 541
538 private: 542 private:
539 // Allow tests to access our innards for testing purposes. 543 // Allow tests to access our innards for testing purposes.
540 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 544 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
541 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 545 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
542 546
547 #if defined(OS_WIN)
548 // Takes in |handle| that should have been retrieved from the command line and
549 // creates a SharedMemoryHandle from it, and then calls
550 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
551 static bool CreateTrialsFromWindowsHandle(HANDLE handle);
552 #endif
553
543 // Expects a mapped piece of shared memory |shm| that was created from the 554 // Expects a mapped piece of shared memory |shm| that was created from the
544 // browser process's field_trial_allocator and shared via the command line. 555 // browser process's field_trial_allocator and shared via the command line.
545 // This function recreates the allocator, iterates through all the field 556 // This function recreates the allocator, iterates through all the field
546 // trials in it, and creates them via CreateFieldTrial(). Returns true if 557 // trials in it, and creates them via CreateFieldTrial(). Returns true if
547 // successful and false otherwise. 558 // successful and false otherwise.
548 static bool CreateTrialsFromSharedMemory( 559 static bool CreateTrialsFromSharedMemory(
549 std::unique_ptr<base::SharedMemory> shm); 560 std::unique_ptr<base::SharedMemory> shm);
550 561
551 // Instantiate the field trial allocator, add all existing field trials to it, 562 // Instantiate the field trial allocator, add all existing field trials to it,
552 // and duplicates its handle to a read-only handle, which gets stored in 563 // and duplicates its handle to a read-only handle, which gets stored in
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // one-time randomization is not supported. 605 // one-time randomization is not supported.
595 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 606 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
596 607
597 // List of observers to be notified when a group is selected for a FieldTrial. 608 // List of observers to be notified when a group is selected for a FieldTrial.
598 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 609 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
599 610
600 // Allocator in shared memory containing field trial data. Used in both 611 // Allocator in shared memory containing field trial data. Used in both
601 // browser and child processes, but readonly in the child. 612 // browser and child processes, but readonly in the child.
602 // In the future, we may want to move this to a more generic place if we want 613 // In the future, we may want to move this to a more generic place if we want
603 // to start passing more data other than field trials. 614 // to start passing more data other than field trials.
604 std::unique_ptr<SharedPersistentMemoryAllocator> field_trial_allocator_ = 615 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr;
605 nullptr;
606 616
607 #if defined(OS_WIN) 617 #if defined(OS_WIN)
608 // Readonly copy of the handle to the allocator. Needs to be a member variable 618 // Readonly copy of the handle to the allocator. Needs to be a member variable
609 // because it's needed from both CopyFieldTrialStateToFlags() and 619 // because it's needed from both CopyFieldTrialStateToFlags() and
610 // AppendFieldTrialHandleIfNeeded(). 620 // AppendFieldTrialHandleIfNeeded().
611 HANDLE readonly_allocator_handle_ = nullptr; 621 HANDLE readonly_allocator_handle_ = nullptr;
612 #endif 622 #endif
613 623
614 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 624 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
615 }; 625 };
616 626
617 } // namespace base 627 } // namespace base
618 628
619 #endif // BASE_METRICS_FIELD_TRIAL_H_ 629 #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