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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); |
253 | 253 |
| 254 // Implements FinalizeGroupChoice() with the added flexibility of being |
| 255 // deadlock-free if |is_locked| is true and the caller is holding a lock. |
| 256 void FinalizeGroupChoiceImpl(bool is_locked); |
| 257 |
254 // Returns the trial name and selected group name for this field trial via | 258 // 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 | 259 // 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 | 260 // 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| | 261 // 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 | 262 // is filled in; otherwise, the result is false and |active_group| is left |
259 // untouched. | 263 // untouched. |
260 bool GetActiveGroup(ActiveGroup* active_group) const; | 264 bool GetActiveGroup(ActiveGroup* active_group) const; |
261 | 265 |
262 // Returns the trial name and selected group name for this field trial via | 266 // 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 | 267 // 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 | 268 // 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 | 269 // filled in; otherwise, the result is false and |field_trial_state| is left |
266 // untouched. | 270 // untouched. |
267 bool GetState(State* field_trial_state); | 271 bool GetState(State* field_trial_state); |
268 | 272 |
| 273 // Does the same thing as above, but is deadlock-free if the caller is holding |
| 274 // a lock. |
| 275 bool GetStateWhileLocked(State* field_trial_state); |
| 276 |
269 // Returns the group_name. A winner need not have been chosen. | 277 // Returns the group_name. A winner need not have been chosen. |
270 std::string group_name_internal() const { return group_name_; } | 278 std::string group_name_internal() const { return group_name_; } |
271 | 279 |
272 // The name of the field trial, as can be found via the FieldTrialList. | 280 // The name of the field trial, as can be found via the FieldTrialList. |
273 const std::string trial_name_; | 281 const std::string trial_name_; |
274 | 282 |
275 // The maximum sum of all probabilities supplied, which corresponds to 100%. | 283 // The maximum sum of all probabilities supplied, which corresponds to 100%. |
276 // This is the scaling factor used to adjust supplied probabilities. | 284 // This is the scaling factor used to adjust supplied probabilities. |
277 const Probability divisor_; | 285 const Probability divisor_; |
278 | 286 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const std::string& group_name); | 518 const std::string& group_name); |
511 | 519 |
512 // Add an observer to be notified when a field trial is irrevocably committed | 520 // 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 | 521 // to being part of some specific field_group (and hence the group_name is |
514 // also finalized for that field_trial). | 522 // also finalized for that field_trial). |
515 static void AddObserver(Observer* observer); | 523 static void AddObserver(Observer* observer); |
516 | 524 |
517 // Remove an observer. | 525 // Remove an observer. |
518 static void RemoveObserver(Observer* observer); | 526 static void RemoveObserver(Observer* observer); |
519 | 527 |
520 // Grabs the lock and adds the field trial to the allocator. This should only | 528 // Grabs the lock if necessary and adds the field trial to the allocator. This |
521 // be called from FinalizeGroupChoice(). | 529 // should only be called from FinalizeGroupChoice(). |
522 static void OnGroupFinalized(FieldTrial* field_trial); | 530 static void OnGroupFinalized(bool is_locked, FieldTrial* field_trial); |
523 | 531 |
524 // Notify all observers that a group has been finalized for |field_trial|. | 532 // Notify all observers that a group has been finalized for |field_trial|. |
525 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); | 533 static void NotifyFieldTrialGroupSelection(FieldTrial* field_trial); |
526 | 534 |
527 // Return the number of active field trials. | 535 // Return the number of active field trials. |
528 static size_t GetFieldTrialCount(); | 536 static size_t GetFieldTrialCount(); |
529 | 537 |
530 private: | 538 private: |
531 // Allow tests to access our innards for testing purposes. | 539 // Allow tests to access our innards for testing purposes. |
532 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); | 540 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 // AppendFieldTrialHandleIfNeeded(). | 608 // AppendFieldTrialHandleIfNeeded(). |
601 HANDLE readonly_allocator_handle_ = nullptr; | 609 HANDLE readonly_allocator_handle_ = nullptr; |
602 #endif | 610 #endif |
603 | 611 |
604 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); | 612 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); |
605 }; | 613 }; |
606 | 614 |
607 } // namespace base | 615 } // namespace base |
608 | 616 |
609 #endif // BASE_METRICS_FIELD_TRIAL_H_ | 617 #endif // BASE_METRICS_FIELD_TRIAL_H_ |
OLD | NEW |