cast_features.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROMECAST_BASE_CAST_FEATURES_H_
  5. #define CHROMECAST_BASE_CAST_FEATURES_H_
  6. #include <cstdint>
  7. #include <memory>
  8. #include <string>
  9. #include <unordered_set>
  10. #include <vector>
  11. #include "base/feature_list.h"
  12. #include "base/values.h"
  13. namespace chromecast {
  14. // Add Cast Features here.
  15. extern const base::Feature kAllowUserMediaAccess;
  16. extern const base::Feature kEnableQuic;
  17. extern const base::Feature kTripleBuffer720;
  18. extern const base::Feature kSingleBuffer;
  19. extern const base::Feature kDisableIdleSocketsCloseOnMemoryPressure;
  20. extern const base::Feature kEnableGeneralAudienceBrowsing;
  21. extern const base::Feature kEnableSideGesturePassThrough;
  22. extern const base::Feature kEnableChromeAudioManagerAndroid;
  23. extern const base::Feature kEnableCastAudioOutputDevice;
  24. // Get an iterable list of all of the cast features for checking all features as
  25. // a collection.
  26. const std::vector<const base::Feature*>& GetFeatures();
  27. // Below are utilities needed by the Cast receiver to persist feature
  28. // information. Client code which is simply querying the status of a feature
  29. // will not need to use these utilities.
  30. // Initialize the global base::FeatureList instance, taking into account
  31. // overrides from DCS and the command line. |dcs_features| and
  32. // |dcs_experiment_ids| are read from the PrefService in the browser process.
  33. // |cmd_line_enable_features| and |cmd_line_disable_features| should be passed
  34. // to this function, unmodified from the command line. |extra_enable_features|
  35. // should contain any extra features to be enabled.
  36. //
  37. // This function should be called before the browser's main loop. After this is
  38. // called, the other functions in this file may be called on any thread.
  39. // TODO(juke): Keep type info of params by passing in base::flat_map and
  40. // std::vector instead of base::Value.
  41. void InitializeFeatureList(const base::Value::Dict& dcs_features,
  42. const base::Value::List& dcs_experiment_ids,
  43. const std::string& cmd_line_enable_features,
  44. const std::string& cmd_line_disable_features,
  45. const std::string& extra_enable_features,
  46. const std::string& extra_disable_features);
  47. // Determine whether or not a feature is enabled. This replaces
  48. // base::FeatureList::IsEnabled for Cast builds.
  49. bool IsFeatureEnabled(const base::Feature& feature);
  50. // Given a dictionary of features, create a copy that is ready to be persisted
  51. // to disk. Encodes all values as strings, which is how the FieldTrial
  52. // classes expect the param data.
  53. base::Value::Dict GetOverriddenFeaturesForStorage(
  54. const base::Value::Dict& features);
  55. // Query the set of experiment ids set for this run. Intended only for metrics
  56. // reporting. Must be called after InitializeFeatureList(). May be called on any
  57. // thread.
  58. const std::unordered_set<int32_t>& GetDCSExperimentIds();
  59. // Reset static state to ensure clean unittests. For tests only.
  60. void ResetCastFeaturesForTesting();
  61. // Set the response to GetFeatures(). Calls to this function should
  62. // be cleaned up by a call to ResetCastFeaturesForTesting() otherwise
  63. // your test will leak the overridden feature state.
  64. void SetFeaturesForTest(std::vector<const base::Feature*> features);
  65. } // namespace chromecast
  66. #endif // CHROMECAST_BASE_CAST_FEATURES_H_