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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // handle or command line argument. A bit of a misnomer since on POSIX we | 502 // handle or command line argument. A bit of a misnomer since on POSIX we |
502 // simply get the trials from opening |fd_key| if using shared memory. On | 503 // simply get the trials from opening |fd_key| if using shared memory. On |
503 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to | 504 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to |
504 // contain the shared memory handle that contains the field trial allocator. | 505 // contain the shared memory handle that contains the field trial allocator. |
505 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed | 506 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed |
506 // in since base/ can't depend on content/. | 507 // in since base/ can't depend on content/. |
507 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, | 508 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, |
508 const char* field_trial_handle_switch, | 509 const char* field_trial_handle_switch, |
509 int fd_key); | 510 int fd_key); |
510 | 511 |
| 512 // Creates base::Feature overrides from the command line by first trying to |
| 513 // use shared memory and then falling back to the command line if it fails. |
| 514 static void CreateFeaturesFromCommandLine( |
| 515 const base::CommandLine& command_line, |
| 516 const char* enable_features_switch, |
| 517 const char* disable_features_switch, |
| 518 FeatureList* feature_list); |
| 519 |
511 #if defined(OS_WIN) | 520 #if defined(OS_WIN) |
512 // On Windows, we need to explicitly pass down any handles to be inherited. | 521 // On Windows, we need to explicitly pass down any handles to be inherited. |
513 // This function adds the shared memory handle to field trial state to the | 522 // This function adds the shared memory handle to field trial state to the |
514 // list of handles to be inherited. | 523 // list of handles to be inherited. |
515 static void AppendFieldTrialHandleIfNeeded( | 524 static void AppendFieldTrialHandleIfNeeded( |
516 base::HandlesToInheritVector* handles); | 525 base::HandlesToInheritVector* handles); |
517 #elif defined(OS_POSIX) | 526 #elif defined(OS_POSIX) |
518 // On POSIX, we also need to explicitly pass down this file descriptor that | 527 // On POSIX, we also need to explicitly pass down this file descriptor that |
519 // should be shared with the child process. Returns kInvalidPlatformFile if no | 528 // should be shared with the child process. Returns kInvalidPlatformFile if no |
520 // handle exists or was not initialized properly. | 529 // handle exists or was not initialized properly. |
521 static PlatformFile GetFieldTrialHandle(); | 530 static PlatformFile GetFieldTrialHandle(); |
522 #endif | 531 #endif |
523 | 532 |
524 // Adds a switch to the command line containing the field trial state as a | 533 // Adds a switch to the command line containing the field trial state as a |
525 // string (if not using shared memory to share field trial state), or the | 534 // string (if not using shared memory to share field trial state), or the |
526 // shared memory handle + length. | 535 // shared memory handle + length. |
527 // Needs the |field_trial_handle_switch| argument to be passed in since base/ | 536 // Needs the |field_trial_handle_switch| argument to be passed in since base/ |
528 // can't depend on content/. | 537 // can't depend on content/. |
529 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, | 538 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, |
| 539 const char* enable_features_switch, |
| 540 const char* disable_features_switch, |
530 base::CommandLine* cmd_line); | 541 base::CommandLine* cmd_line); |
531 | 542 |
532 // Create a FieldTrial with the given |name| and using 100% probability for | 543 // Create a FieldTrial with the given |name| and using 100% probability for |
533 // the FieldTrial, force FieldTrial to have the same group string as | 544 // the FieldTrial, force FieldTrial to have the same group string as |
534 // |group_name|. This is commonly used in a non-browser process, to carry | 545 // |group_name|. This is commonly used in a non-browser process, to carry |
535 // randomly selected state in a browser process into this non-browser process. | 546 // randomly selected state in a browser process into this non-browser process. |
536 // It returns NULL if there is a FieldTrial that is already registered with | 547 // It returns NULL if there is a FieldTrial that is already registered with |
537 // the same |name| but has different finalized group string (|group_name|). | 548 // the same |name| but has different finalized group string (|group_name|). |
538 static FieldTrial* CreateFieldTrial(const std::string& name, | 549 static FieldTrial* CreateFieldTrial(const std::string& name, |
539 const std::string& group_name); | 550 const std::string& group_name); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 675 |
665 // Tracks whether CreateTrialsFromCommandLine() has been called. | 676 // Tracks whether CreateTrialsFromCommandLine() has been called. |
666 bool create_trials_from_command_line_called_ = false; | 677 bool create_trials_from_command_line_called_ = false; |
667 | 678 |
668 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 679 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
669 }; | 680 }; |
670 | 681 |
671 } // namespace base | 682 } // namespace base |
672 | 683 |
673 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 684 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |