config.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2021 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 COMPONENTS_SEGMENTATION_PLATFORM_PUBLIC_CONFIG_H_
  5. #define COMPONENTS_SEGMENTATION_PLATFORM_PUBLIC_CONFIG_H_
  6. #include <string>
  7. #include "base/containers/flat_map.h"
  8. #include "base/time/time.h"
  9. #include "components/segmentation_platform/public/constants.h"
  10. #include "components/segmentation_platform/public/input_delegate.h"
  11. #include "components/segmentation_platform/public/model_provider.h"
  12. #include "components/segmentation_platform/public/proto/model_metadata.pb.h"
  13. #include "components/segmentation_platform/public/proto/segmentation_platform.pb.h"
  14. #include "components/segmentation_platform/public/trigger.h"
  15. namespace segmentation_platform {
  16. // Contains various finch configuration params used by the segmentation
  17. // platform.
  18. struct Config {
  19. Config();
  20. ~Config();
  21. // Disallow copy/assign.
  22. Config(const Config& other) = delete;
  23. Config& operator=(const Config& other) = delete;
  24. // The key is used to distinguish between different types of segmentation
  25. // usages. Currently it is mainly used by the segment selector to find the
  26. // discrete mapping and writing results to prefs.
  27. std::string segmentation_key;
  28. // The name used for the segmentation key in UMA filters.
  29. std::string segmentation_uma_name;
  30. // The trigger event type that triggers segment selection. If trigger is
  31. // non-none, |on_demand_execution| must be true.
  32. TriggerType trigger = TriggerType::kNone;
  33. // Time to live for a segment selection. Segment selection can't be changed
  34. // before this duration.
  35. base::TimeDelta segment_selection_ttl;
  36. // Time to live for an unknown segment selection. Unknown selection can't be
  37. // changed before this duration. Note that when this is set to 0, the unknown
  38. // segment selections are IGNORED by the platform when it had valid selection
  39. // in the past. ONLY when this value is positive unknown segments are treated
  40. // as output option after having served other valid segments.
  41. base::TimeDelta unknown_selection_ttl;
  42. // List of segments needed to make a selection.
  43. struct SegmentMetadata {
  44. explicit SegmentMetadata(const std::string& uma_name);
  45. SegmentMetadata(const std::string& uma_name,
  46. std::unique_ptr<ModelProvider> default_provider);
  47. SegmentMetadata(SegmentMetadata&&);
  48. ~SegmentMetadata();
  49. bool operator==(const SegmentMetadata& other) const;
  50. // The name used for this segment in UMA filters.
  51. std::string uma_name;
  52. // The default model or score used when server provided model is
  53. // unavailable.
  54. std::unique_ptr<ModelProvider> default_provider;
  55. };
  56. base::flat_map<proto::SegmentId, std::unique_ptr<SegmentMetadata>> segments;
  57. // The selection only supports returning results from on-demand model
  58. // executions instead of returning result from previous sessions. The
  59. // selection TTLs are ignored in this config.
  60. bool on_demand_execution = false;
  61. // List of custom inputs provided for running the segments. The delegate will
  62. // be invoked for input based on the model metadata's input processing config.
  63. // Note: 2 configs cannot provide input delegates for the same FillPolicy. To
  64. // share the delegate implementation, the delegates need to be provided by
  65. // `SegmentationPlatformServiceFactory`.
  66. base::flat_map<proto::CustomInput::FillPolicy,
  67. std::unique_ptr<processing::InputDelegate>>
  68. input_delegates;
  69. // Helper methods to add segments to `segments`:
  70. void AddSegmentId(proto::SegmentId segment_id);
  71. void AddSegmentId(proto::SegmentId segment_id,
  72. std::unique_ptr<ModelProvider> default_provider);
  73. // Returns the filter name that will be shown in the metrics for this
  74. // segmentation config.
  75. std::string GetSegmentationFilterName() const;
  76. // Returns the segment name for the `segment` used by the metrics.
  77. std::string GetSegmentUmaName(proto::SegmentId segment) const;
  78. };
  79. } // namespace segmentation_platform
  80. #endif // COMPONENTS_SEGMENTATION_PLATFORM_PUBLIC_CONFIG_H_