feature_provider.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2018 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 MEDIA_LEARNING_IMPL_FEATURE_PROVIDER_H_
  5. #define MEDIA_LEARNING_IMPL_FEATURE_PROVIDER_H_
  6. #include "base/callback.h"
  7. #include "base/component_export.h"
  8. #include "base/threading/sequence_bound.h"
  9. #include "media/learning/common/labelled_example.h"
  10. #include "media/learning/common/learning_task.h"
  11. namespace media {
  12. namespace learning {
  13. // Add features to a training example. If the LearningTask's feature
  14. // description includes feature names that a FeatureProvider knows about, then
  15. // it will replace their value in the examples with whatever value that feature
  16. // should have. For example, "NetworkType" might be replaced by a value that
  17. // indicates the type of network connection.
  18. class COMPONENT_EXPORT(LEARNING_IMPL) FeatureProvider {
  19. public:
  20. using FeatureVectorCB = base::OnceCallback<void(FeatureVector)>;
  21. FeatureProvider();
  22. FeatureProvider(const FeatureProvider&) = delete;
  23. FeatureProvider& operator=(const FeatureProvider&) = delete;
  24. virtual ~FeatureProvider();
  25. // Update |features| to include whatever features are specified by |task_|,
  26. // and call |cb| once they're filled in.
  27. virtual void AddFeatures(FeatureVector features, FeatureVectorCB cb) = 0;
  28. };
  29. // Since FeatureProviders are often going to thread-hop, provide this typedef.
  30. using SequenceBoundFeatureProvider = base::SequenceBound<FeatureProvider>;
  31. // Factory callback, since things that create implementations will likely be
  32. // elsewhere (e.g., content/) from the things which use them (e.g., here). May
  33. // return an empty provider if the task doesn't require one.
  34. using FeatureProviderFactoryCB =
  35. base::RepeatingCallback<SequenceBoundFeatureProvider(const LearningTask&)>;
  36. } // namespace learning
  37. } // namespace media
  38. #endif // MEDIA_LEARNING_IMPL_FEATURE_PROVIDER_H_