prediction_common.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_COMMON_H_
  5. #define COMPONENTS_PERMISSIONS_PREDICTION_SERVICE_PREDICTION_COMMON_H_
  6. #include "components/permissions/prediction_service/prediction_request_features.h"
  7. #include "components/permissions/prediction_service/prediction_service_messages.pb.h"
  8. namespace permissions {
  9. constexpr char kDefaultPredictionServiceUrl[] =
  10. "https://webpermissionpredictions.googleapis.com/v1:generatePredictions";
  11. // A command line switch to override the default service url.
  12. constexpr char kDefaultPredictionServiceUrlSwitchKey[] =
  13. "permission-predictions-service-url";
  14. constexpr float kRoundToMultiplesOf = 0.1f;
  15. constexpr int kCountBuckets[] = {20, 15, 12, 10, 9, 8, 7, 6, 5, 4};
  16. // Thresholds of the likelihood that triggers the CPSS prompts.
  17. constexpr float kNotificationPredictionsThreshold = 0.81;
  18. constexpr float kGeolocationPredictionsThreshold = 0.87;
  19. // Returns the ratio rounded to the nearest 10%. It returns a value between 0
  20. // and 1 in steps of 0.1
  21. float GetRoundedRatio(int numerator, int denominator);
  22. // This method normalises the value returned by GetRoundedRatio(int, int) for
  23. // sending it to ukm. It returns a value between 0 and 100 in steps of 10.
  24. int GetRoundedRatioForUkm(int numerator, int denominator);
  25. // Returns the appropriate bucket for `count`.
  26. int BucketizeValue(int count);
  27. // Get the current platform for proto message purposes.
  28. ClientFeatures_Platform GetCurrentPlatformProto();
  29. // Get the current platform for proto message purposes.
  30. ClientFeatures_PlatformEnum GetCurrentPlatformEnumProto();
  31. // Convert PermissionRequestGestureType to ClientFeatures_Gesture.
  32. ClientFeatures_Gesture ConvertToProtoGesture(
  33. const permissions::PermissionRequestGestureType type);
  34. // Convert PermissionRequestGestureType to ClientFeatures_GestureEnum.
  35. ClientFeatures_GestureEnum ConvertToProtoGestureEnum(
  36. const permissions::PermissionRequestGestureType type);
  37. // Fill in the values in StatsFeature using the values in
  38. // PredictionRequestFeatures::ActionCounts
  39. void FillInStatsFeatures(const PredictionRequestFeatures::ActionCounts& counts,
  40. StatsFeatures* features);
  41. std::unique_ptr<GeneratePredictionsRequest> GetPredictionRequestProto(
  42. const PredictionRequestFeatures& entity);
  43. } // namespace permissions
  44. #endif // COMPONENTS_PERMISSIONS_PREDICTION_SERVICE_PREDICTION_COMMON_H_