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

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

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: address comments Created 4 years 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault); 221 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_NonDefault);
222 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes); 222 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes);
223 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability); 223 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DoesNotSurpassTotalProbability);
224 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, 224 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest,
225 DoNotAddSimulatedFieldTrialsToAllocator); 225 DoNotAddSimulatedFieldTrialsToAllocator);
226 226
227 friend class base::FieldTrialList; 227 friend class base::FieldTrialList;
228 228
229 friend class RefCounted<FieldTrial>; 229 friend class RefCounted<FieldTrial>;
230 230
231 friend class FieldTrialParamAssociator;
232
231 // This is the group number of the 'default' group when a choice wasn't forced 233 // This is the group number of the 'default' group when a choice wasn't forced
232 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that 234 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that
233 // consumers don't use it by mistake in cases where the group was forced. 235 // consumers don't use it by mistake in cases where the group was forced.
234 static const int kDefaultGroupNumber; 236 static const int kDefaultGroupNumber;
235 237
236 // Creates a field trial with the specified parameters. Group assignment will 238 // Creates a field trial with the specified parameters. Group assignment will
237 // be done based on |entropy_value|, which must have a range of [0, 1). 239 // be done based on |entropy_value|, which must have a range of [0, 1).
238 FieldTrial(const std::string& trial_name, 240 FieldTrial(const std::string& trial_name,
239 Probability total_probability, 241 Probability total_probability,
240 const std::string& default_group_name, 242 const std::string& default_group_name,
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // Grabs the lock if necessary and adds the field trial to the allocator. This 545 // Grabs the lock if necessary and adds the field trial to the allocator. This
544 // should only be called from FinalizeGroupChoice(). 546 // should only be called from FinalizeGroupChoice().
545 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); 547 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial);
546 548
547 // Notify all observers that a group has been finalized for |field_trial|. 549 // Notify all observers that a group has been finalized for |field_trial|.
548 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 550 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
549 551
550 // Return the number of active field trials. 552 // Return the number of active field trials.
551 static size_t GetFieldTrialCount(); 553 static size_t GetFieldTrialCount();
552 554
555 // Gets the parameters for |field_trial| from shared memory and stores them in
556 // |params|.
557 static bool GetParamsFromSharedMemory(
558 FieldTrial* field_trial,
559 std::map<std::string, std::string>* params);
560
561 // Clears all the params in the allocator.
562 static void ClearParamsFromSharedMemoryForTesting();
563
553 private: 564 private:
554 // Allow tests to access our innards for testing purposes. 565 // Allow tests to access our innards for testing purposes.
555 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 566 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
556 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 567 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
557 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, 568 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest,
558 DoNotAddSimulatedFieldTrialsToAllocator); 569 DoNotAddSimulatedFieldTrialsToAllocator);
570 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams);
559 571
560 #if defined(OS_WIN) 572 #if defined(OS_WIN)
561 // Takes in |handle| that should have been retrieved from the command line and 573 // Takes in |handle| that should have been retrieved from the command line and
562 // creates a SharedMemoryHandle from it, and then calls 574 // creates a SharedMemoryHandle from it, and then calls
563 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. 575 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
564 static bool CreateTrialsFromWindowsHandle(HANDLE handle); 576 static bool CreateTrialsFromWindowsHandle(HANDLE handle);
565 #endif 577 #endif
566 578
567 // Expects a mapped piece of shared memory |shm| that was created from the 579 // Expects a mapped piece of shared memory |shm| that was created from the
568 // browser process's field_trial_allocator and shared via the command line. 580 // browser process's field_trial_allocator and shared via the command line.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 614
603 static FieldTrialList* global_; // The singleton of this class. 615 static FieldTrialList* global_; // The singleton of this class.
604 616
605 // This will tell us if there is an attempt to register a field 617 // This will tell us if there is an attempt to register a field
606 // trial or check if one-time randomization is enabled without 618 // trial or check if one-time randomization is enabled without
607 // creating the FieldTrialList. This is not an error, unless a 619 // creating the FieldTrialList. This is not an error, unless a
608 // FieldTrialList is created after that. 620 // FieldTrialList is created after that.
609 static bool used_without_global_; 621 static bool used_without_global_;
610 622
611 // Lock for access to registered_. 623 // Lock for access to registered_.
612 base::Lock lock_; 624 Lock lock_;
613 RegistrationMap registered_; 625 RegistrationMap registered_;
614 626
615 std::map<std::string, std::string> seen_states_; 627 std::map<std::string, std::string> seen_states_;
616 628
617 // Entropy provider to be used for one-time randomized field trials. If NULL, 629 // Entropy provider to be used for one-time randomized field trials. If NULL,
618 // one-time randomization is not supported. 630 // one-time randomization is not supported.
619 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 631 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
620 632
621 // List of observers to be notified when a group is selected for a FieldTrial. 633 // List of observers to be notified when a group is selected for a FieldTrial.
622 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 634 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
(...skipping 13 matching lines...) Expand all
636 648
637 // Tracks whether CreateTrialsFromCommandLine() has been called. 649 // Tracks whether CreateTrialsFromCommandLine() has been called.
638 bool create_trials_from_command_line_called_ = false; 650 bool create_trials_from_command_line_called_ = false;
639 651
640 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 652 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
641 }; 653 };
642 654
643 } // namespace base 655 } // namespace base
644 656
645 #endif // BASE_METRICS_FIELD_TRIAL_H_ 657 #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