| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | 222 typedef SharedPersistentMemoryAllocator::Reference FieldTrialRef; |
| 223 | 223 |
| 224 friend class base::FieldTrialList; | 224 friend class base::FieldTrialList; |
| 225 | 225 |
| 226 friend class RefCounted<FieldTrial>; | 226 friend class RefCounted<FieldTrial>; |
| 227 | 227 |
| 228 friend class FieldTrialParamAssociator; |
| 229 |
| 228 // This is the group number of the 'default' group when a choice wasn't forced | 230 // This is the group number of the 'default' group when a choice wasn't forced |
| 229 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that | 231 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that |
| 230 // consumers don't use it by mistake in cases where the group was forced. | 232 // consumers don't use it by mistake in cases where the group was forced. |
| 231 static const int kDefaultGroupNumber; | 233 static const int kDefaultGroupNumber; |
| 232 | 234 |
| 233 // Creates a field trial with the specified parameters. Group assignment will | 235 // Creates a field trial with the specified parameters. Group assignment will |
| 234 // be done based on |entropy_value|, which must have a range of [0, 1). | 236 // be done based on |entropy_value|, which must have a range of [0, 1). |
| 235 FieldTrial(const std::string& trial_name, | 237 FieldTrial(const std::string& trial_name, |
| 236 Probability total_probability, | 238 Probability total_probability, |
| 237 const std::string& default_group_name, | 239 const std::string& default_group_name, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // Returns the group number chosen for the named trial, or | 427 // Returns the group number chosen for the named trial, or |
| 426 // FieldTrial::kNotFinalized if the trial does not exist. | 428 // FieldTrial::kNotFinalized if the trial does not exist. |
| 427 static int FindValue(const std::string& trial_name); | 429 static int FindValue(const std::string& trial_name); |
| 428 | 430 |
| 429 // Returns the group name chosen for the named trial, or the empty string if | 431 // Returns the group name chosen for the named trial, or the empty string if |
| 430 // the trial does not exist. The first call of this function on a given field | 432 // the trial does not exist. The first call of this function on a given field |
| 431 // trial will mark it as active, so that its state will be reported with usage | 433 // trial will mark it as active, so that its state will be reported with usage |
| 432 // metrics, crashes, etc. | 434 // metrics, crashes, etc. |
| 433 static std::string FindFullName(const std::string& trial_name); | 435 static std::string FindFullName(const std::string& trial_name); |
| 434 | 436 |
| 437 // Looks in the allocator for |field_trial|'s params via its ref_, and stores |
| 438 // it in |params|. |
| 439 static bool GetParamsFromSharedMemory( |
| 440 FieldTrial* field_trial, |
| 441 std::map<std::string, std::string>* params); |
| 442 |
| 443 // Clears all the params in the allocator. |
| 444 static void ClearParamsFromSharedMemoryForTesting(); |
| 445 |
| 435 // Returns true if the named trial has been registered. | 446 // Returns true if the named trial has been registered. |
| 436 static bool TrialExists(const std::string& trial_name); | 447 static bool TrialExists(const std::string& trial_name); |
| 437 | 448 |
| 438 // Returns true if the named trial exists and has been activated. | 449 // Returns true if the named trial exists and has been activated. |
| 439 static bool IsTrialActive(const std::string& trial_name); | 450 static bool IsTrialActive(const std::string& trial_name); |
| 440 | 451 |
| 441 // Creates a persistent representation of active FieldTrial instances for | 452 // Creates a persistent representation of active FieldTrial instances for |
| 442 // resurrection in another process. This allows randomization to be done in | 453 // resurrection in another process. This allows randomization to be done in |
| 443 // one process, and secondary processes can be synchronized on the result. | 454 // one process, and secondary processes can be synchronized on the result. |
| 444 // The resulting string contains the name and group name pairs of all | 455 // The resulting string contains the name and group name pairs of all |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // Notify all observers that a group has been finalized for |field_trial|. | 547 // Notify all observers that a group has been finalized for |field_trial|. |
| 537 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); | 548 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); |
| 538 | 549 |
| 539 // Return the number of active field trials. | 550 // Return the number of active field trials. |
| 540 static size_t GetFieldTrialCount(); | 551 static size_t GetFieldTrialCount(); |
| 541 | 552 |
| 542 private: | 553 private: |
| 543 // Allow tests to access our innards for testing purposes. | 554 // Allow tests to access our innards for testing purposes. |
| 544 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); | 555 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); |
| 545 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); | 556 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); |
| 557 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams); |
| 546 | 558 |
| 547 #if defined(OS_WIN) | 559 #if defined(OS_WIN) |
| 548 // Takes in |handle| that should have been retrieved from the command line and | 560 // Takes in |handle| that should have been retrieved from the command line and |
| 549 // creates a SharedMemoryHandle from it, and then calls | 561 // creates a SharedMemoryHandle from it, and then calls |
| 550 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. | 562 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. |
| 551 static bool CreateTrialsFromWindowsHandle(HANDLE handle); | 563 static bool CreateTrialsFromWindowsHandle(HANDLE handle); |
| 552 #endif | 564 #endif |
| 553 | 565 |
| 554 // Expects a mapped piece of shared memory |shm| that was created from the | 566 // Expects a mapped piece of shared memory |shm| that was created from the |
| 555 // browser process's field_trial_allocator and shared via the command line. | 567 // browser process's field_trial_allocator and shared via the command line. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 601 |
| 590 static FieldTrialList* global_; // The singleton of this class. | 602 static FieldTrialList* global_; // The singleton of this class. |
| 591 | 603 |
| 592 // This will tell us if there is an attempt to register a field | 604 // This will tell us if there is an attempt to register a field |
| 593 // trial or check if one-time randomization is enabled without | 605 // trial or check if one-time randomization is enabled without |
| 594 // creating the FieldTrialList. This is not an error, unless a | 606 // creating the FieldTrialList. This is not an error, unless a |
| 595 // FieldTrialList is created after that. | 607 // FieldTrialList is created after that. |
| 596 static bool used_without_global_; | 608 static bool used_without_global_; |
| 597 | 609 |
| 598 // Lock for access to registered_. | 610 // Lock for access to registered_. |
| 599 base::Lock lock_; | 611 Lock lock_; |
| 600 RegistrationMap registered_; | 612 RegistrationMap registered_; |
| 601 | 613 |
| 602 std::map<std::string, std::string> seen_states_; | 614 std::map<std::string, std::string> seen_states_; |
| 603 | 615 |
| 604 // Entropy provider to be used for one-time randomized field trials. If NULL, | 616 // Entropy provider to be used for one-time randomized field trials. If NULL, |
| 605 // one-time randomization is not supported. | 617 // one-time randomization is not supported. |
| 606 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; | 618 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; |
| 607 | 619 |
| 608 // List of observers to be notified when a group is selected for a FieldTrial. | 620 // List of observers to be notified when a group is selected for a FieldTrial. |
| 609 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 621 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 620 // AppendFieldTrialHandleIfNeeded(). | 632 // AppendFieldTrialHandleIfNeeded(). |
| 621 HANDLE readonly_allocator_handle_ = nullptr; | 633 HANDLE readonly_allocator_handle_ = nullptr; |
| 622 #endif | 634 #endif |
| 623 | 635 |
| 624 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 636 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
| 625 }; | 637 }; |
| 626 | 638 |
| 627 } // namespace base | 639 } // namespace base |
| 628 | 640 |
| 629 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 641 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
| OLD | NEW |