prediction_model_fetcher.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 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_OPTIMIZATION_GUIDE_CORE_PREDICTION_MODEL_FETCHER_H_
  5. #define COMPONENTS_OPTIMIZATION_GUIDE_CORE_PREDICTION_MODEL_FETCHER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "components/optimization_guide/proto/models.pb.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace optimization_guide {
  12. // Callback to inform the caller that the remote hints have been fetched and
  13. // to pass back the fetched hints response from the remote Optimization Guide
  14. // Service.
  15. using ModelsFetchedCallback = base::OnceCallback<void(
  16. absl::optional<
  17. std::unique_ptr<optimization_guide::proto::GetModelsResponse>>)>;
  18. // A class to handle requests for prediction models (and prediction data) from
  19. // a remote Optimization Guide Service.
  20. //
  21. // This class fetches new models from the remote Optimization Guide Service.
  22. class PredictionModelFetcher {
  23. public:
  24. PredictionModelFetcher() = default;
  25. PredictionModelFetcher(const PredictionModelFetcher&) = delete;
  26. PredictionModelFetcher& operator=(const PredictionModelFetcher&) = delete;
  27. virtual ~PredictionModelFetcher() = default;
  28. // Requests PredictionModels and HostModelFeatures from the Optimization Guide
  29. // Service if a request for them is not already in progress. Returns whether a
  30. // new request was issued. |models_fetched_callback| is called when the
  31. // request is complete providing the GetModelsResponse object if successful or
  32. // nullopt if the fetch failed or no fetch is needed. Virtualized for testing.
  33. virtual bool FetchOptimizationGuideServiceModels(
  34. const std::vector<proto::ModelInfo>& models_request_info,
  35. proto::RequestContext request_context,
  36. const std::string& locale,
  37. ModelsFetchedCallback models_fetched_callback) = 0;
  38. };
  39. } // namespace optimization_guide
  40. #endif // COMPONENTS_OPTIMIZATION_GUIDE_CORE_PREDICTION_MODEL_FETCHER_H_