field_trial.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license
  5. // that can be found in the LICENSE file in the root of the source
  6. // tree. An additional intellectual property rights grant can be found
  7. // in the file PATENTS. All contributing project authors may
  8. // be found in the AUTHORS file in the root of the source tree.
  9. //
  10. #ifndef SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
  11. #define SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
  12. #include <string>
  13. // Field trials allow webrtc clients (such as Chrome) to turn on feature code
  14. // in binaries out in the field and gather information with that.
  15. //
  16. // By default WebRTC provides an implementation of field trials that can be
  17. // found in system_wrappers/source/field_trial.cc. If clients want to provide
  18. // a custom version, they will have to:
  19. //
  20. // 1. Compile WebRTC defining the preprocessor macro
  21. // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT (if GN is used this can be achieved
  22. // by setting the GN arg rtc_exclude_field_trial_default to true).
  23. // 2. Provide an implementation of:
  24. // std::string webrtc::field_trial::FindFullName(const std::string& trial).
  25. //
  26. // They are designed to wire up directly to chrome field trials and to speed up
  27. // developers by reducing the need to wire APIs to control whether a feature is
  28. // on/off. E.g. to experiment with a new method that could lead to a different
  29. // trade-off between CPU/bandwidth:
  30. //
  31. // 1 - Develop the feature with default behaviour off:
  32. //
  33. // if (FieldTrial::FindFullName("WebRTCExperimentMethod2") == "Enabled")
  34. // method2();
  35. // else
  36. // method1();
  37. //
  38. // 2 - Once the changes are rolled to chrome, the new code path can be
  39. // controlled as normal chrome field trials.
  40. //
  41. // 3 - Evaluate the new feature and clean the code paths.
  42. //
  43. // Notes:
  44. // - NOT every feature is a candidate to be controlled by this mechanism as
  45. // it may require negotiation between involved parties (e.g. SDP).
  46. //
  47. // TODO(andresp): since chrome --force-fieldtrials does not marks the trial
  48. // as active it does not get propagated to the renderer process. For now one
  49. // needs to push a config with start_active:true or run a local finch
  50. // server.
  51. //
  52. // TODO(andresp): find out how to get bots to run tests with trials enabled.
  53. namespace webrtc {
  54. namespace field_trial {
  55. // Returns the group name chosen for the named trial, or the empty string
  56. // if the trial does not exists.
  57. //
  58. // Note: To keep things tidy append all the trial names with WebRTC.
  59. std::string FindFullName(const std::string& name);
  60. // Convenience method, returns true iff FindFullName(name) return a string that
  61. // starts with "Enabled".
  62. // TODO(tommi): Make sure all implementations support this.
  63. inline bool IsEnabled(const char* name) {
  64. return FindFullName(name).find("Enabled") == 0;
  65. }
  66. // Convenience method, returns true iff FindFullName(name) return a string that
  67. // starts with "Disabled".
  68. inline bool IsDisabled(const char* name) {
  69. return FindFullName(name).find("Disabled") == 0;
  70. }
  71. // Optionally initialize field trial from a string.
  72. // This method can be called at most once before any other call into webrtc.
  73. // E.g. before the peer connection factory is constructed.
  74. // Note: trials_string must never be destroyed.
  75. void InitFieldTrialsFromString(const char* trials_string);
  76. const char* GetFieldTrialString();
  77. #ifndef WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
  78. // Validates the given field trial string.
  79. bool FieldTrialsStringIsValid(const char* trials_string);
  80. // Merges two field trial strings.
  81. //
  82. // If a key (trial) exists twice with conflicting values (groups), the value
  83. // in 'second' takes precedence.
  84. // Shall only be called with valid FieldTrial strings.
  85. std::string MergeFieldTrialsStrings(const char* first, const char* second);
  86. #endif // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
  87. } // namespace field_trial
  88. } // namespace webrtc
  89. #endif // SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_