| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include <set> | 62 #include <set> |
| 63 #include <string> | 63 #include <string> |
| 64 #include <vector> | 64 #include <vector> |
| 65 | 65 |
| 66 #include "base/base_export.h" | 66 #include "base/base_export.h" |
| 67 #include "base/command_line.h" | 67 #include "base/command_line.h" |
| 68 #include "base/gtest_prod_util.h" | 68 #include "base/gtest_prod_util.h" |
| 69 #include "base/macros.h" | 69 #include "base/macros.h" |
| 70 #include "base/memory/ref_counted.h" | 70 #include "base/memory/ref_counted.h" |
| 71 #include "base/memory/shared_memory.h" | 71 #include "base/memory/shared_memory.h" |
| 72 #include "base/metrics/field_trial_param_associator.h" |
| 72 #include "base/metrics/persistent_memory_allocator.h" | 73 #include "base/metrics/persistent_memory_allocator.h" |
| 73 #include "base/observer_list_threadsafe.h" | 74 #include "base/observer_list_threadsafe.h" |
| 74 #include "base/process/launch.h" | 75 #include "base/process/launch.h" |
| 75 #include "base/strings/string_piece.h" | 76 #include "base/strings/string_piece.h" |
| 76 #include "base/synchronization/lock.h" | 77 #include "base/synchronization/lock.h" |
| 77 #include "base/time/time.h" | 78 #include "base/time/time.h" |
| 78 | 79 |
| 79 namespace base { | 80 namespace base { |
| 80 | 81 |
| 81 class FieldTrialList; | 82 class FieldTrialList; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // Returns the group number chosen for the named trial, or | 422 // Returns the group number chosen for the named trial, or |
| 422 // FieldTrial::kNotFinalized if the trial does not exist. | 423 // FieldTrial::kNotFinalized if the trial does not exist. |
| 423 static int FindValue(const std::string& trial_name); | 424 static int FindValue(const std::string& trial_name); |
| 424 | 425 |
| 425 // Returns the group name chosen for the named trial, or the empty string if | 426 // Returns the group name chosen for the named trial, or the empty string if |
| 426 // the trial does not exist. The first call of this function on a given field | 427 // the trial does not exist. The first call of this function on a given field |
| 427 // trial will mark it as active, so that its state will be reported with usage | 428 // trial will mark it as active, so that its state will be reported with usage |
| 428 // metrics, crashes, etc. | 429 // metrics, crashes, etc. |
| 429 static std::string FindFullName(const std::string& trial_name); | 430 static std::string FindFullName(const std::string& trial_name); |
| 430 | 431 |
| 432 static bool FindParams(const std::string& trial_name, |
| 433 FieldTrialParamAssociator::FieldTrialParams* params); |
| 434 |
| 431 // Returns true if the named trial has been registered. | 435 // Returns true if the named trial has been registered. |
| 432 static bool TrialExists(const std::string& trial_name); | 436 static bool TrialExists(const std::string& trial_name); |
| 433 | 437 |
| 434 // Returns true if the named trial exists and has been activated. | 438 // Returns true if the named trial exists and has been activated. |
| 435 static bool IsTrialActive(const std::string& trial_name); | 439 static bool IsTrialActive(const std::string& trial_name); |
| 436 | 440 |
| 437 // Creates a persistent representation of active FieldTrial instances for | 441 // Creates a persistent representation of active FieldTrial instances for |
| 438 // resurrection in another process. This allows randomization to be done in | 442 // resurrection in another process. This allows randomization to be done in |
| 439 // one process, and secondary processes can be synchronized on the result. | 443 // one process, and secondary processes can be synchronized on the result. |
| 440 // The resulting string contains the name and group name pairs of all | 444 // 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... |
| 532 // Notify all observers that a group has been finalized for |field_trial|. | 536 // Notify all observers that a group has been finalized for |field_trial|. |
| 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); |
| 546 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams); |
| 542 | 547 |
| 543 // Expects a mapped piece of shared memory |shm| that was created from the | 548 // 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. | 549 // browser process's field_trial_allocator and shared via the command line. |
| 545 // This function recreates the allocator, iterates through all the field | 550 // This function recreates the allocator, iterates through all the field |
| 546 // trials in it, and creates them via CreateFieldTrial(). | 551 // trials in it, and creates them via CreateFieldTrial(). |
| 547 static void CreateTrialsFromSharedMemory( | 552 static void CreateTrialsFromSharedMemory( |
| 548 std::unique_ptr<base::SharedMemory> shm); | 553 std::unique_ptr<base::SharedMemory> shm); |
| 549 | 554 |
| 550 // Instantiate the field trial allocator, add all existing field trials to it, | 555 // Instantiate the field trial allocator, add all existing field trials to it, |
| 551 // and duplicates its handle to a read-only handle, which gets stored in | 556 // and duplicates its handle to a read-only handle, which gets stored in |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 // AppendFieldTrialHandleIfNeeded(). | 613 // AppendFieldTrialHandleIfNeeded(). |
| 609 HANDLE readonly_allocator_handle_ = nullptr; | 614 HANDLE readonly_allocator_handle_ = nullptr; |
| 610 #endif | 615 #endif |
| 611 | 616 |
| 612 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 617 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
| 613 }; | 618 }; |
| 614 | 619 |
| 615 } // namespace base | 620 } // namespace base |
| 616 | 621 |
| 617 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 622 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
| OLD | NEW |