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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 static void RemoveObserver(Observer* observer); | 434 static void RemoveObserver(Observer* observer); |
435 | 435 |
436 // Notify all observers that a group has been finalized for |field_trial|. | 436 // Notify all observers that a group has been finalized for |field_trial|. |
437 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); | 437 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); |
438 | 438 |
439 // Return the number of active field trials. | 439 // Return the number of active field trials. |
440 static size_t GetFieldTrialCount(); | 440 static size_t GetFieldTrialCount(); |
441 | 441 |
442 private: | 442 private: |
443 // A map from FieldTrial names to the actual instances. | 443 // A map from FieldTrial names to the actual instances. |
444 typedef std::map<std::string, FieldTrial*> RegistrationList; | 444 typedef std::map<std::string, FieldTrial*> RegistrationMap; |
445 | 445 |
446 // If one-time randomization is enabled, returns a weak pointer to the | 446 // If one-time randomization is enabled, returns a weak pointer to the |
447 // corresponding EntropyProvider. Otherwise, returns NULL. | 447 // corresponding EntropyProvider. Otherwise, returns NULL. |
448 static const FieldTrial::EntropyProvider* | 448 static const FieldTrial::EntropyProvider* |
449 GetEntropyProviderForOneTimeRandomization(); | 449 GetEntropyProviderForOneTimeRandomization(); |
450 | 450 |
451 // Helper function should be called only while holding lock_. | 451 // Helper function should be called only while holding lock_. |
452 FieldTrial* PreLockedFind(const std::string& name); | 452 FieldTrial* PreLockedFind(const std::string& name); |
453 | 453 |
454 // Register() stores a pointer to the given trial in a global map. | 454 // Register() stores a pointer to the given trial in a global map. |
455 // This method also AddRef's the indicated trial. | 455 // This method also AddRef's the indicated trial. |
456 // This should always be called after creating a new FieldTrial instance. | 456 // This should always be called after creating a new FieldTrial instance. |
457 static void Register(FieldTrial* trial); | 457 static void Register(FieldTrial* trial); |
458 | 458 |
459 static FieldTrialList* global_; // The singleton of this class. | 459 static FieldTrialList* global_; // The singleton of this class. |
460 | 460 |
461 // This will tell us if there is an attempt to register a field | 461 // This will tell us if there is an attempt to register a field |
462 // trial or check if one-time randomization is enabled without | 462 // trial or check if one-time randomization is enabled without |
463 // creating the FieldTrialList. This is not an error, unless a | 463 // creating the FieldTrialList. This is not an error, unless a |
464 // FieldTrialList is created after that. | 464 // FieldTrialList is created after that. |
465 static bool used_without_global_; | 465 static bool used_without_global_; |
466 | 466 |
467 // Lock for access to registered_. | 467 // Lock for access to registered_. |
468 base::Lock lock_; | 468 base::Lock lock_; |
469 RegistrationList registered_; | 469 RegistrationMap registered_; |
470 | 470 |
471 // Entropy provider to be used for one-time randomized field trials. If NULL, | 471 // Entropy provider to be used for one-time randomized field trials. If NULL, |
472 // one-time randomization is not supported. | 472 // one-time randomization is not supported. |
473 scoped_ptr<const FieldTrial::EntropyProvider> entropy_provider_; | 473 scoped_ptr<const FieldTrial::EntropyProvider> entropy_provider_; |
474 | 474 |
475 // List of observers to be notified when a group is selected for a FieldTrial. | 475 // List of observers to be notified when a group is selected for a FieldTrial. |
476 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 476 scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
477 | 477 |
478 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 478 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
479 }; | 479 }; |
480 | 480 |
481 } // namespace base | 481 } // namespace base |
482 | 482 |
483 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 483 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |