prediction_service_base.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2020 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_PERMISSIONS_PREDICTION_SERVICE_PREDICTION_SERVICE_BASE_H_
  5. #define COMPONENTS_PERMISSIONS_PREDICTION_SERVICE_PREDICTION_SERVICE_BASE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "components/keyed_service/core/keyed_service.h"
  10. #include "components/permissions/permission_request_enums.h"
  11. #include "components/permissions/prediction_service/prediction_request_features.h"
  12. #include "components/permissions/prediction_service/prediction_service_messages.pb.h"
  13. namespace permissions {
  14. // TODO(crbug.com/1138595, andypaicu): Refactor this class and
  15. // RealTimeUrlLookupServiceBase to derive from the same base class instead of
  16. // doing a bunch of duplicate work. Design doc:
  17. // https://docs.google.com/document/d/11Gd4bMpuPiVOVNhgqkixZXfckFDzv921BHoZWTBIISc/edit#heading=h.lxxeltml3hwr
  18. class PredictionServiceBase : public KeyedService {
  19. public:
  20. // TODO(crbug.com/1138595, andypaicu): once the above TODO is done, refactor
  21. // to use a struct to make the call sites more readable (for both callbacks).
  22. using LookupRequestCallback =
  23. base::OnceCallback<void(std::unique_ptr<GeneratePredictionsRequest>,
  24. std::string)>; // Access token.
  25. using LookupResponseCallback = base::OnceCallback<void(
  26. bool, // Lookup successful.
  27. bool, // Response from cache.
  28. const absl::optional<GeneratePredictionsResponse>&)>;
  29. virtual void StartLookup(const PredictionRequestFeatures& entity,
  30. LookupRequestCallback request_callback,
  31. LookupResponseCallback response_callback) = 0;
  32. };
  33. } // namespace permissions
  34. #endif // COMPONENTS_PERMISSIONS_PREDICTION_SERVICE_PREDICTION_SERVICE_BASE_H_