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

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

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: fix compilation error Created 4 years, 1 month 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 224
225 friend class base::FieldTrialList; 225 friend class base::FieldTrialList;
226 226
227 friend class RefCounted<FieldTrial>; 227 friend class RefCounted<FieldTrial>;
228 228
229 friend class FieldTrialParamAssociator;
230
229 // This is the group number of the 'default' group when a choice wasn't forced 231 // This is the group number of the 'default' group when a choice wasn't forced
230 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that 232 // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that
231 // consumers don't use it by mistake in cases where the group was forced. 233 // consumers don't use it by mistake in cases where the group was forced.
232 static const int kDefaultGroupNumber; 234 static const int kDefaultGroupNumber;
233 235
234 // Creates a field trial with the specified parameters. Group assignment will 236 // Creates a field trial with the specified parameters. Group assignment will
235 // be done based on |entropy_value|, which must have a range of [0, 1). 237 // be done based on |entropy_value|, which must have a range of [0, 1).
236 FieldTrial(const std::string& trial_name, 238 FieldTrial(const std::string& trial_name,
237 Probability total_probability, 239 Probability total_probability,
238 const std::string& default_group_name, 240 const std::string& default_group_name,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 // Returns the group number chosen for the named trial, or 428 // Returns the group number chosen for the named trial, or
427 // FieldTrial::kNotFinalized if the trial does not exist. 429 // FieldTrial::kNotFinalized if the trial does not exist.
428 static int FindValue(const std::string& trial_name); 430 static int FindValue(const std::string& trial_name);
429 431
430 // Returns the group name chosen for the named trial, or the empty string if 432 // Returns the group name chosen for the named trial, or the empty string if
431 // the trial does not exist. The first call of this function on a given field 433 // the trial does not exist. The first call of this function on a given field
432 // trial will mark it as active, so that its state will be reported with usage 434 // trial will mark it as active, so that its state will be reported with usage
433 // metrics, crashes, etc. 435 // metrics, crashes, etc.
434 static std::string FindFullName(const std::string& trial_name); 436 static std::string FindFullName(const std::string& trial_name);
435 437
438 // Looks in the allocator for |field_trial|'s params via its ref_, and stores
439 // it in |params|.
Alexei Svitkine (slow) 2016/11/23 17:23:39 This is talking about implementation detail. Plea
lawrencewu 2016/11/23 19:07:33 Done.
440 static bool GetParamsFromSharedMemory(
441 FieldTrial* field_trial,
442 std::map<std::string, std::string>* params);
443
444 // Clears all the params in the allocator.
445 static void ClearParamsFromSharedMemoryForTesting();
446
436 // Returns true if the named trial has been registered. 447 // Returns true if the named trial has been registered.
437 static bool TrialExists(const std::string& trial_name); 448 static bool TrialExists(const std::string& trial_name);
438 449
439 // Returns true if the named trial exists and has been activated. 450 // Returns true if the named trial exists and has been activated.
440 static bool IsTrialActive(const std::string& trial_name); 451 static bool IsTrialActive(const std::string& trial_name);
441 452
442 // Creates a persistent representation of active FieldTrial instances for 453 // Creates a persistent representation of active FieldTrial instances for
443 // resurrection in another process. This allows randomization to be done in 454 // resurrection in another process. This allows randomization to be done in
444 // one process, and secondary processes can be synchronized on the result. 455 // one process, and secondary processes can be synchronized on the result.
445 // The resulting string contains the name and group name pairs of all 456 // The resulting string contains the name and group name pairs of all
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // 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|.
538 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); 549 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial);
539 550
540 // Return the number of active field trials. 551 // Return the number of active field trials.
541 static size_t GetFieldTrialCount(); 552 static size_t GetFieldTrialCount();
542 553
543 private: 554 private:
544 // Allow tests to access our innards for testing purposes. 555 // Allow tests to access our innards for testing purposes.
545 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 556 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
546 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 557 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
558 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams);
547 559
548 #if defined(OS_WIN) 560 #if defined(OS_WIN)
549 // Takes in |handle| that should have been retrieved from the command line and 561 // Takes in |handle| that should have been retrieved from the command line and
550 // creates a SharedMemoryHandle from it, and then calls 562 // creates a SharedMemoryHandle from it, and then calls
551 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. 563 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
552 static bool CreateTrialsFromWindowsHandle(HANDLE handle); 564 static bool CreateTrialsFromWindowsHandle(HANDLE handle);
553 #endif 565 #endif
554 566
555 // Expects a mapped piece of shared memory |shm| that was created from the 567 // Expects a mapped piece of shared memory |shm| that was created from the
556 // browser process's field_trial_allocator and shared via the command line. 568 // browser process's field_trial_allocator and shared via the command line.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 602
591 static FieldTrialList* global_; // The singleton of this class. 603 static FieldTrialList* global_; // The singleton of this class.
592 604
593 // This will tell us if there is an attempt to register a field 605 // This will tell us if there is an attempt to register a field
594 // trial or check if one-time randomization is enabled without 606 // trial or check if one-time randomization is enabled without
595 // creating the FieldTrialList. This is not an error, unless a 607 // creating the FieldTrialList. This is not an error, unless a
596 // FieldTrialList is created after that. 608 // FieldTrialList is created after that.
597 static bool used_without_global_; 609 static bool used_without_global_;
598 610
599 // Lock for access to registered_. 611 // Lock for access to registered_.
600 base::Lock lock_; 612 Lock lock_;
601 RegistrationMap registered_; 613 RegistrationMap registered_;
602 614
603 std::map<std::string, std::string> seen_states_; 615 std::map<std::string, std::string> seen_states_;
604 616
605 // Entropy provider to be used for one-time randomized field trials. If NULL, 617 // Entropy provider to be used for one-time randomized field trials. If NULL,
606 // one-time randomization is not supported. 618 // one-time randomization is not supported.
607 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_; 619 std::unique_ptr<const FieldTrial::EntropyProvider> entropy_provider_;
608 620
609 // List of observers to be notified when a group is selected for a FieldTrial. 621 // List of observers to be notified when a group is selected for a FieldTrial.
610 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 622 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
(...skipping 10 matching lines...) Expand all
621 // AppendFieldTrialHandleIfNeeded(). 633 // AppendFieldTrialHandleIfNeeded().
622 HANDLE readonly_allocator_handle_ = nullptr; 634 HANDLE readonly_allocator_handle_ = nullptr;
623 #endif 635 #endif
624 636
625 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 637 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
626 }; 638 };
627 639
628 } // namespace base 640 } // namespace base
629 641
630 #endif // BASE_METRICS_FIELD_TRIAL_H_ 642 #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