| OLD | NEW |
| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll); | 217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll); |
| 218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore); | 218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore); |
| 219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff); | 219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff); |
| 220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn); | 220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn); |
| 221 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default); | 221 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default); |
| 222 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault); | 222 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault); |
| 223 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes); | 223 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes); |
| 224 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability); | 224 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability); |
| 225 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, | 225 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, |
| 226 DoNotAddSimulatedFieldTrialsToAllocator); | 226 DoNotAddSimulatedFieldTrialsToAllocator); |
| 227 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory); |
| 227 | 228 |
| 228 friend class base::FieldTrialList; | 229 friend class base::FieldTrialList; |
| 229 | 230 |
| 230 friend class RefCounted<FieldTrial>; | 231 friend class RefCounted<FieldTrial>; |
| 231 | 232 |
| 232 // This is the group number of the 'default' group when a choice wasn't forced | 233 // This is the group number of the 'default' group when a choice wasn't forced |
| 233 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that | 234 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that |
| 234 // consumers don't use it by mistake in cases where the group was forced. | 235 // consumers don't use it by mistake in cases where the group was forced. |
| 235 static const int kDefaultGroupNumber; | 236 static const int kDefaultGroupNumber; |
| 236 | 237 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // Grabs the lock if necessary and adds the field trial to the allocator. This | 549 // Grabs the lock if necessary and adds the field trial to the allocator. This |
| 549 // should only be called from FinalizeGroupChoice(). | 550 // should only be called from FinalizeGroupChoice(). |
| 550 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); | 551 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); |
| 551 | 552 |
| 552 // Notify all observers that a group has been finalized for |field_trial|. | 553 // Notify all observers that a group has been finalized for |field_trial|. |
| 553 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); | 554 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); |
| 554 | 555 |
| 555 // Return the number of active field trials. | 556 // Return the number of active field trials. |
| 556 static size_t GetFieldTrialCount(); | 557 static size_t GetFieldTrialCount(); |
| 557 | 558 |
| 559 // Gets the parameters for |field_trial| from shared memory and stores them in |
| 560 // |params|. This is only exposed for use by FieldTrialParamAssociator and |
| 561 // shouldn't be used by anything else. |
| 562 static bool GetParamsFromSharedMemory( |
| 563 FieldTrial* field_trial, |
| 564 std::map<std::string, std::string>* params); |
| 565 |
| 566 // Clears all the params in the allocator. |
| 567 static void ClearParamsFromSharedMemoryForTesting(); |
| 568 |
| 558 private: | 569 private: |
| 559 // Allow tests to access our innards for testing purposes. | 570 // Allow tests to access our innards for testing purposes. |
| 560 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); | 571 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); |
| 561 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); | 572 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); |
| 562 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, | 573 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, |
| 563 DoNotAddSimulatedFieldTrialsToAllocator); | 574 DoNotAddSimulatedFieldTrialsToAllocator); |
| 575 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams); |
| 576 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory); |
| 564 | 577 |
| 565 #if defined(OS_WIN) | 578 #if defined(OS_WIN) |
| 566 // Takes in |handle_switch| from the command line which represents the shared | 579 // Takes in |handle_switch| from the command line which represents the shared |
| 567 // memory handle for field trials, parses it, and creates the field trials. | 580 // memory handle for field trials, parses it, and creates the field trials. |
| 568 // Returns true on success, false on failure. | 581 // Returns true on success, false on failure. |
| 569 static bool CreateTrialsFromHandleSwitch(const std::string& handle_switch); | 582 static bool CreateTrialsFromHandleSwitch(const std::string& handle_switch); |
| 570 #endif | 583 #endif |
| 571 | 584 |
| 572 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MACOSX) && \ | 585 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MACOSX) && \ |
| 573 !defined(OS_ANDROID) | 586 !defined(OS_ANDROID) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 static void Register(FieldTrial* trial); | 631 static void Register(FieldTrial* trial); |
| 619 | 632 |
| 620 static FieldTrialList* global_; // The singleton of this class. | 633 static FieldTrialList* global_; // The singleton of this class. |
| 621 | 634 |
| 622 // This will tell us if there is an attempt to register a field | 635 // This will tell us if there is an attempt to register a field |
| 623 // trial or check if one-time randomization is enabled without | 636 // trial or check if one-time randomization is enabled without |
| 624 // creating the FieldTrialList. This is not an error, unless a | 637 // creating the FieldTrialList. This is not an error, unless a |
| 625 // FieldTrialList is created after that. | 638 // FieldTrialList is created after that. |
| 626 static bool used_without_global_; | 639 static bool used_without_global_; |
| 627 | 640 |
| 628 // Lock for access to registered_. | 641 // Lock for access to registered_ and field_trial_allocator_. |
| 629 base::Lock lock_; | 642 Lock lock_; |
| 630 RegistrationMap registered_; | 643 RegistrationMap registered_; |
| 631 | 644 |
| 632 std::map<std::string, std::string> seen_states_; | 645 std::map<std::string, std::string> seen_states_; |
| 633 | 646 |
| 634 // Entropy provider to be used for one-time randomized field trials. If NULL, | 647 // Entropy provider to be used for one-time randomized field trials. If NULL, |
| 635 // one-time randomization is not supported. | 648 // one-time randomization is not supported. |
| 636 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; | 649 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; |
| 637 | 650 |
| 638 // List of observers to be notified when a group is selected for a FieldTrial. | 651 // List of observers to be notified when a group is selected for a FieldTrial. |
| 639 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 652 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 651 | 664 |
| 652 // Tracks whether CreateTrialsFromCommandLine() has been called. | 665 // Tracks whether CreateTrialsFromCommandLine() has been called. |
| 653 bool create_trials_from_command_line_called_ = false; | 666 bool create_trials_from_command_line_called_ = false; |
| 654 | 667 |
| 655 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 668 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
| 656 }; | 669 }; |
| 657 | 670 |
| 658 } // namespace base | 671 } // namespace base |
| 659 | 672 |
| 660 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 673 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
| OLD | NEW |