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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Marks this trial as having been registered with the FieldTrialList. Must be | 242 // Marks this trial as having been registered with the FieldTrialList. Must be |
243 // called no more than once and before any |group()| calls have occurred. | 243 // called no more than once and before any |group()| calls have occurred. |
244 void SetTrialRegistered(); | 244 void SetTrialRegistered(); |
245 | 245 |
246 // Sets the chosen group name and number. | 246 // Sets the chosen group name and number. |
247 void SetGroupChoice(const std::string& group_name, int number); | 247 void SetGroupChoice(const std::string& group_name, int number); |
248 | 248 |
249 // Ensures that a group is chosen, if it hasn't yet been. The field trial | 249 // Ensures that a group is chosen, if it hasn't yet been. The field trial |
250 // might yet be disabled, so this call will *not* notify observers of the | 250 // might yet be disabled, so this call will *not* notify observers of the |
251 // status. | 251 // status. |
252 void FinalizeGroupChoice(); | 252 void FinalizeGroupChoice(bool is_locked); |
253 | 253 |
254 // Returns the trial name and selected group name for this field trial via | 254 // Returns the trial name and selected group name for this field trial via |
255 // the output parameter |active_group|, but only if the group has already | 255 // the output parameter |active_group|, but only if the group has already |
256 // been chosen and has been externally observed via |group()| and the trial | 256 // been chosen and has been externally observed via |group()| and the trial |
257 // has not been disabled. In that case, true is returned and |active_group| | 257 // has not been disabled. In that case, true is returned and |active_group| |
258 // is filled in; otherwise, the result is false and |active_group| is left | 258 // is filled in; otherwise, the result is false and |active_group| is left |
259 // untouched. | 259 // untouched. |
260 bool GetActiveGroup(ActiveGroup* active_group) const; | 260 bool GetActiveGroup(ActiveGroup* active_group) const; |
261 | 261 |
262 // Returns the trial name and selected group name for this field trial via | 262 // Returns the trial name and selected group name for this field trial via |
263 // the output parameter |field_trial_state|, but only if the trial has not | 263 // the output parameter |field_trial_state|, but only if the trial has not |
264 // been disabled. In that case, true is returned and |field_trial_state| is | 264 // been disabled. In that case, true is returned and |field_trial_state| is |
265 // filled in; otherwise, the result is false and |field_trial_state| is left | 265 // filled in; otherwise, the result is false and |field_trial_state| is left |
266 // untouched. | 266 // untouched. |
267 bool GetState(State* field_trial_state); | 267 bool GetState(State* field_trial_state); |
268 | 268 |
| 269 // Does the same thing as above, but is deadlock-free if the caller is holding |
| 270 // a lock. |
| 271 bool GetStateWhileLocked(State* field_trial_state); |
| 272 |
269 // Returns the group_name. A winner need not have been chosen. | 273 // Returns the group_name. A winner need not have been chosen. |
270 std::string group_name_internal() const { return group_name_; } | 274 std::string group_name_internal() const { return group_name_; } |
271 | 275 |
272 // The name of the field trial, as can be found via the FieldTrialList. | 276 // The name of the field trial, as can be found via the FieldTrialList. |
273 const std::string trial_name_; | 277 const std::string trial_name_; |
274 | 278 |
275 // The maximum sum of all probabilities supplied, which corresponds to 100%. | 279 // The maximum sum of all probabilities supplied, which corresponds to 100%. |
276 // This is the scaling factor used to adjust supplied probabilities. | 280 // This is the scaling factor used to adjust supplied probabilities. |
277 const Probability divisor_; | 281 const Probability divisor_; |
278 | 282 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const std::string& group_name); | 514 const std::string& group_name); |
511 | 515 |
512 // Add an observer to be notified when a field trial is irrevocably committed | 516 // Add an observer to be notified when a field trial is irrevocably committed |
513 // to being part of some specific field_group (and hence the group_name is | 517 // to being part of some specific field_group (and hence the group_name is |
514 // also finalized for that field_trial). | 518 // also finalized for that field_trial). |
515 static void AddObserver(Observer* observer); | 519 static void AddObserver(Observer* observer); |
516 | 520 |
517 // Remove an observer. | 521 // Remove an observer. |
518 static void RemoveObserver(Observer* observer); | 522 static void RemoveObserver(Observer* observer); |
519 | 523 |
520 // Grabs the lock and adds the field trial to the allocator. This should only | 524 // Grabs the lock if necessary and adds the field trial to the allocator. This |
521 // be called from FinalizeGroupChoice(). | 525 // should only be called from FinalizeGroupChoice(). |
522 static void OnGroupFinalized(FieldTrial* field_trial); | 526 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); |
523 | 527 |
524 // Notify all observers that a group has been finalized for |field_trial|. | 528 // Notify all observers that a group has been finalized for |field_trial|. |
525 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); | 529 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); |
526 | 530 |
527 // Return the number of active field trials. | 531 // Return the number of active field trials. |
528 static size_t GetFieldTrialCount(); | 532 static size_t GetFieldTrialCount(); |
529 | 533 |
530 private: | 534 private: |
531 // Allow tests to access our innards for testing purposes. | 535 // Allow tests to access our innards for testing purposes. |
532 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); | 536 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 // AppendFieldTrialHandleIfNeeded(). | 604 // AppendFieldTrialHandleIfNeeded(). |
601 HANDLE readonly_allocator_handle_ = nullptr; | 605 HANDLE readonly_allocator_handle_ = nullptr; |
602 #endif | 606 #endif |
603 | 607 |
604 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 608 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
605 }; | 609 }; |
606 | 610 |
607 } // namespace base | 611 } // namespace base |
608 | 612 |
609 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 613 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |