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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 #include <stddef.h> | 57 #include <stddef.h> |
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/gtest_prod_util.h" | 68 #include "base/gtest_prod_util.h" |
68 #include "base/macros.h" | 69 #include "base/macros.h" |
69 #include "base/memory/ref_counted.h" | 70 #include "base/memory/ref_counted.h" |
71 #include "base/memory/shared_memory.h" | |
70 #include "base/observer_list_threadsafe.h" | 72 #include "base/observer_list_threadsafe.h" |
71 #include "base/strings/string_piece.h" | 73 #include "base/strings/string_piece.h" |
72 #include "base/synchronization/lock.h" | 74 #include "base/synchronization/lock.h" |
73 #include "base/time/time.h" | 75 #include "base/time/time.h" |
74 | 76 |
75 namespace base { | 77 namespace base { |
76 | 78 |
77 class FieldTrialList; | 79 class FieldTrialList; |
78 | 80 |
79 class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { | 81 class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 // used in a non-browser process, to carry randomly selected state in a | 459 // used in a non-browser process, to carry randomly selected state in a |
458 // browser process into this non-browser process, but could also be invoked | 460 // browser process into this non-browser process, but could also be invoked |
459 // through a command line argument to the browser process. Created field | 461 // through a command line argument to the browser process. Created field |
460 // trials will be marked "used" for the purposes of active trial reporting | 462 // trials will be marked "used" for the purposes of active trial reporting |
461 // if they are prefixed with |kActivationMarker|. Trial names in | 463 // if they are prefixed with |kActivationMarker|. Trial names in |
462 // |ignored_trial_names| are ignored when parsing |trials_string|. | 464 // |ignored_trial_names| are ignored when parsing |trials_string|. |
463 static bool CreateTrialsFromString( | 465 static bool CreateTrialsFromString( |
464 const std::string& trials_string, | 466 const std::string& trials_string, |
465 const std::set<std::string>& ignored_trial_names); | 467 const std::set<std::string>& ignored_trial_names); |
466 | 468 |
469 // If using shared memory to pass around the list of field trials, then | |
Alexei Svitkine (slow)
2016/10/06 13:45:30
The first sentence should describe what the functi
lawrencewu
2016/10/06 20:14:57
Done.
| |
470 // expects |field_trial_handle_switch| argument to | |
471 // contain the shared memory handle, and it opens the handle, reads the memory | |
472 // and creates the trials. | |
473 // If not, then create the trials as before (using the kForceFieldTrials | |
474 // switch). Needs the |field_trial_handle_switch| argument to be passed in | |
475 // since base/ can't depend on content. | |
476 static void CreateTrialsFromCommandLine( | |
477 const base::CommandLine cmd_line, | |
Alexei Svitkine (slow)
2016/10/06 13:45:30
Pass by const& - otherwise you're copying the obje
lawrencewu
2016/10/06 20:14:57
Done.
| |
478 const char* field_trial_handle_switch); | |
479 | |
480 // Adds a switch to the command line containing the field trial state as a | |
481 // string (if not using shared memory to share field trial state), or the | |
482 // shared memory handle + length. | |
483 // Needs the |field_trial_handle_switch| argument to be passed in since base/ | |
484 // can't depend on content. | |
485 static std::unique_ptr<base::SharedMemory> CopyFieldTrialStateToSharedMemory( | |
486 base::CommandLine* cmd_line, | |
487 const char* field_trial_handle_switch); | |
488 | |
467 // Create a FieldTrial with the given |name| and using 100% probability for | 489 // Create a FieldTrial with the given |name| and using 100% probability for |
468 // the FieldTrial, force FieldTrial to have the same group string as | 490 // the FieldTrial, force FieldTrial to have the same group string as |
469 // |group_name|. This is commonly used in a non-browser process, to carry | 491 // |group_name|. This is commonly used in a non-browser process, to carry |
470 // randomly selected state in a browser process into this non-browser process. | 492 // randomly selected state in a browser process into this non-browser process. |
471 // It returns NULL if there is a FieldTrial that is already registered with | 493 // It returns NULL if there is a FieldTrial that is already registered with |
472 // the same |name| but has different finalized group string (|group_name|). | 494 // the same |name| but has different finalized group string (|group_name|). |
473 static FieldTrial* CreateFieldTrial(const std::string& name, | 495 static FieldTrial* CreateFieldTrial(const std::string& name, |
474 const std::string& group_name); | 496 const std::string& group_name); |
475 | 497 |
476 // Add an observer to be notified when a field trial is irrevocably committed | 498 // Add an observer to be notified when a field trial is irrevocably committed |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 | 546 |
525 // List of observers to be notified when a group is selected for a FieldTrial. | 547 // List of observers to be notified when a group is selected for a FieldTrial. |
526 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 548 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
527 | 549 |
528 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 550 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
529 }; | 551 }; |
530 | 552 |
531 } // namespace base | 553 } // namespace base |
532 | 554 |
533 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 555 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |