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

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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll); 216 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SaveAll);
217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore); 217 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore);
218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff); 218 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOff);
219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn); 219 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedTurnFeatureOn);
220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default); 220 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, SetForcedChangeDefault_Default);
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 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory);
226 227
227 friend class base::FieldTrialList; 228 friend class base::FieldTrialList;
228 229
229 friend class RefCounted<FieldTrial>; 230 friend class RefCounted<FieldTrial>;
230 231
231 // This is the group number of the 'default' group when a choice wasn't forced 232 // 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 233 // 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. 234 // consumers don't use it by mistake in cases where the group was forced.
234 static const int kDefaultGroupNumber; 235 static const int kDefaultGroupNumber;
235 236
(...skipping 307 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 544 // Grabs the lock if necessary and adds the field trial to the allocator. This
544 // should only be called from FinalizeGroupChoice(). 545 // should only be called from FinalizeGroupChoice().
545 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); 546 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial);
546 547
547 // Notify all observers that a group has been finalized for |field_trial|. 548 // Notify all observers that a group has been finalized for |field_trial|.
548 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 549 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
549 550
550 // Return the number of active field trials. 551 // Return the number of active field trials.
551 static size_t GetFieldTrialCount(); 552 static size_t GetFieldTrialCount();
552 553
554 // Gets the parameters for |field_trial| from shared memory and stores them in
555 // |params|. This is only exposed for use by FieldTrialParamAssociator and
556 // shouldn't be used by anything else.
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);
571 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory);
559 572
560 #if defined(OS_WIN) 573 #if defined(OS_WIN)
561 // Takes in |handle| that should have been retrieved from the command line and 574 // Takes in |handle| that should have been retrieved from the command line and
562 // creates a SharedMemoryHandle from it, and then calls 575 // creates a SharedMemoryHandle from it, and then calls
563 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. 576 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
564 static bool CreateTrialsFromWindowsHandle(HANDLE handle); 577 static bool CreateTrialsFromWindowsHandle(HANDLE handle);
565 #endif 578 #endif
566 579
567 // Expects a mapped piece of shared memory |shm| that was created from the 580 // 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. 581 // browser process's field_trial_allocator and shared via the command line.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 static void Register(FieldTrial* trial); 614 static void Register(FieldTrial* trial);
602 615
603 static FieldTrialList* global_; // The singleton of this class. 616 static FieldTrialList* global_; // The singleton of this class.
604 617
605 // This will tell us if there is an attempt to register a field 618 // This will tell us if there is an attempt to register a field
606 // trial or check if one-time randomization is enabled without 619 // trial or check if one-time randomization is enabled without
607 // creating the FieldTrialList. This is not an error, unless a 620 // creating the FieldTrialList. This is not an error, unless a
608 // FieldTrialList is created after that. 621 // FieldTrialList is created after that.
609 static bool used_without_global_; 622 static bool used_without_global_;
610 623
611 // Lock for access to registered_. 624 // Lock for access to registered_ and field_trial_allocator_.
612 base::Lock lock_; 625 Lock lock_;
613 RegistrationMap registered_; 626 RegistrationMap registered_;
614 627
615 std::map<std::string, std::string> seen_states_; 628 std::map<std::string, std::string> seen_states_;
616 629
617 // Entropy provider to be used for one-time randomized field trials. If NULL, 630 // Entropy provider to be used for one-time randomized field trials. If NULL,
618 // one-time randomization is not supported. 631 // one-time randomization is not supported.
619 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 632 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
620 633
621 // List of observers to be notified when a group is selected for a FieldTrial. 634 // List of observers to be notified when a group is selected for a FieldTrial.
622 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 635 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
(...skipping 13 matching lines...) Expand all
636 649
637 // Tracks whether CreateTrialsFromCommandLine() has been called. 650 // Tracks whether CreateTrialsFromCommandLine() has been called.
638 bool create_trials_from_command_line_called_ = false; 651 bool create_trials_from_command_line_called_ = false;
639 652
640 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 653 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
641 }; 654 };
642 655
643 } // namespace base 656 } // namespace base
644 657
645 #endif // BASE_METRICS_FIELD_TRIAL_H_ 658 #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