Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: base/metrics/field_trial.h

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: add missing include Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // Achieves the same thing as CreateTrialsFromString, except wraps the logic
470 // by taking in the trials from the command line, either via shared memory
471 // handle or command line argument.
472 // If using shared memory to pass around the list of field trials, then
473 // expects |field_trial_handle_switch| command line argument to
474 // contain the shared memory handle.
475 // If not, then create the trials as before (using the kForceFieldTrials
476 // switch). Needs the |field_trial_handle_switch| argument to be passed in
477 // since base/ can't depend on content/.
478 static void CreateTrialsFromCommandLine(
479 const base::CommandLine& cmd_line,
480 const char* field_trial_handle_switch);
481
482 // Adds a switch to the command line containing the field trial state as a
483 // string (if not using shared memory to share field trial state), or the
484 // shared memory handle + length.
485 // Needs the |field_trial_handle_switch| argument to be passed in since base/
486 // can't depend on content/.
487 static std::unique_ptr<base::SharedMemory> CopyFieldTrialStateToFlags(
488 const char* field_trial_handle_switch,
489 base::CommandLine* cmd_line);
490
467 // Create a FieldTrial with the given |name| and using 100% probability for 491 // Create a FieldTrial with the given |name| and using 100% probability for
468 // the FieldTrial, force FieldTrial to have the same group string as 492 // 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 493 // |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. 494 // 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 495 // 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|). 496 // the same |name| but has different finalized group string (|group_name|).
473 static FieldTrial* CreateFieldTrial(const std::string& name, 497 static FieldTrial* CreateFieldTrial(const std::string& name,
474 const std::string& group_name); 498 const std::string& group_name);
475 499
476 // Add an observer to be notified when a field trial is irrevocably committed 500 // 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
524 548
525 // List of observers to be notified when a group is selected for a FieldTrial. 549 // List of observers to be notified when a group is selected for a FieldTrial.
526 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 550 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
527 551
528 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 552 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
529 }; 553 };
530 554
531 } // namespace base 555 } // namespace base
532 556
533 #endif // BASE_METRICS_FIELD_TRIAL_H_ 557 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698