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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include <stdint.h> | 58 #include <stdint.h> |
59 | 59 |
60 #include <map> | 60 #include <map> |
61 #include <memory> | 61 #include <memory> |
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/feature_list.h" |
68 #include "base/files/file.h" | 69 #include "base/files/file.h" |
69 #include "base/gtest_prod_util.h" | 70 #include "base/gtest_prod_util.h" |
70 #include "base/macros.h" | 71 #include "base/macros.h" |
71 #include "base/memory/ref_counted.h" | 72 #include "base/memory/ref_counted.h" |
72 #include "base/memory/shared_memory.h" | 73 #include "base/memory/shared_memory.h" |
73 #include "base/metrics/persistent_memory_allocator.h" | 74 #include "base/metrics/persistent_memory_allocator.h" |
74 #include "base/observer_list_threadsafe.h" | 75 #include "base/observer_list_threadsafe.h" |
75 #include "base/process/launch.h" | 76 #include "base/process/launch.h" |
76 #include "base/strings/string_piece.h" | 77 #include "base/strings/string_piece.h" |
77 #include "base/synchronization/lock.h" | 78 #include "base/synchronization/lock.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 // handle or command line argument. A bit of a misnomer since on POSIX we | 501 // handle or command line argument. A bit of a misnomer since on POSIX we |
501 // simply get the trials from opening |fd_key| if using shared memory. On | 502 // simply get the trials from opening |fd_key| if using shared memory. On |
502 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to | 503 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to |
503 // contain the shared memory handle that contains the field trial allocator. | 504 // contain the shared memory handle that contains the field trial allocator. |
504 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed | 505 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed |
505 // in since base/ can't depend on content/. | 506 // in since base/ can't depend on content/. |
506 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, | 507 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, |
507 const char* field_trial_handle_switch, | 508 const char* field_trial_handle_switch, |
508 int fd_key); | 509 int fd_key); |
509 | 510 |
| 511 static void CreateFeaturesFromCommandLine( |
| 512 const base::CommandLine& command_line, |
| 513 const char* enable_features_switch, |
| 514 const char* disable_features_switch, |
| 515 std::unique_ptr<FeatureList>& feature_list); |
| 516 |
510 #if defined(OS_WIN) | 517 #if defined(OS_WIN) |
511 // On Windows, we need to explicitly pass down any handles to be inherited. | 518 // On Windows, we need to explicitly pass down any handles to be inherited. |
512 // This function adds the shared memory handle to field trial state to the | 519 // This function adds the shared memory handle to field trial state to the |
513 // list of handles to be inherited. | 520 // list of handles to be inherited. |
514 static void AppendFieldTrialHandleIfNeeded( | 521 static void AppendFieldTrialHandleIfNeeded( |
515 base::HandlesToInheritVector* handles); | 522 base::HandlesToInheritVector* handles); |
516 #elif defined(OS_POSIX) | 523 #elif defined(OS_POSIX) |
517 // On POSIX, we also need to explicitly pass down this file descriptor that | 524 // On POSIX, we also need to explicitly pass down this file descriptor that |
518 // should be shared with the child process. Returns kInvalidPlatformFile if no | 525 // should be shared with the child process. Returns kInvalidPlatformFile if no |
519 // handle exists or was not initialized properly. | 526 // handle exists or was not initialized properly. |
520 static PlatformFile GetFieldTrialHandle(); | 527 static PlatformFile GetFieldTrialHandle(); |
521 #endif | 528 #endif |
522 | 529 |
523 // Adds a switch to the command line containing the field trial state as a | 530 // Adds a switch to the command line containing the field trial state as a |
524 // string (if not using shared memory to share field trial state), or the | 531 // string (if not using shared memory to share field trial state), or the |
525 // shared memory handle + length. | 532 // shared memory handle + length. |
526 // Needs the |field_trial_handle_switch| argument to be passed in since base/ | 533 // Needs the |field_trial_handle_switch| argument to be passed in since base/ |
527 // can't depend on content/. | 534 // can't depend on content/. |
528 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, | 535 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, |
| 536 const char* enable_features_switch, |
| 537 const char* disable_features_switch, |
529 base::CommandLine* cmd_line); | 538 base::CommandLine* cmd_line); |
530 | 539 |
531 // Create a FieldTrial with the given |name| and using 100% probability for | 540 // Create a FieldTrial with the given |name| and using 100% probability for |
532 // the FieldTrial, force FieldTrial to have the same group string as | 541 // the FieldTrial, force FieldTrial to have the same group string as |
533 // |group_name|. This is commonly used in a non-browser process, to carry | 542 // |group_name|. This is commonly used in a non-browser process, to carry |
534 // randomly selected state in a browser process into this non-browser process. | 543 // randomly selected state in a browser process into this non-browser process. |
535 // It returns NULL if there is a FieldTrial that is already registered with | 544 // It returns NULL if there is a FieldTrial that is already registered with |
536 // the same |name| but has different finalized group string (|group_name|). | 545 // the same |name| but has different finalized group string (|group_name|). |
537 static FieldTrial* CreateFieldTrial(const std::string& name, | 546 static FieldTrial* CreateFieldTrial(const std::string& name, |
538 const std::string& group_name); | 547 const std::string& group_name); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 660 |
652 // Tracks whether CreateTrialsFromCommandLine() has been called. | 661 // Tracks whether CreateTrialsFromCommandLine() has been called. |
653 bool create_trials_from_command_line_called_ = false; | 662 bool create_trials_from_command_line_called_ = false; |
654 | 663 |
655 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 664 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
656 }; | 665 }; |
657 | 666 |
658 } // namespace base | 667 } // namespace base |
659 | 668 |
660 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 669 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |