model_util.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_OPTIMIZATION_GUIDE_CORE_MODEL_UTIL_H_
  5. #define COMPONENTS_OPTIMIZATION_GUIDE_CORE_MODEL_UTIL_H_
  6. #include <string>
  7. #include "base/files/file_path.h"
  8. #include "components/optimization_guide/proto/models.pb.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace optimization_guide {
  11. // Returns the string than can be used to record histograms for the optimization
  12. // target. If adding a histogram to use the string or adding an optimization
  13. // target, update the OptimizationGuide.OptimizationTargets histogram suffixes
  14. // in histograms.xml.
  15. std::string GetStringNameForOptimizationTarget(
  16. proto::OptimizationTarget optimization_target);
  17. // Returns the file path represented by the given string, handling platform
  18. // differences in the conversion. nullopt is only returned iff the passed string
  19. // is empty.
  20. absl::optional<base::FilePath> StringToFilePath(const std::string& str_path);
  21. // Returns a string representation of the given |file_path|, handling platform
  22. // differences in the conversion.
  23. std::string FilePathToString(const base::FilePath& file_path);
  24. // Returns the base file name to use for storing all prediction models.
  25. base::FilePath GetBaseFileNameForModels();
  26. // Returns the separator used in the model override switch below, which differs
  27. // between platforms.
  28. std::string ModelOverrideSeparator();
  29. // Returns the file path string and metadata for the model provided via
  30. // command-line for |optimization_target|, if applicable.
  31. absl::optional<
  32. std::pair<std::string, absl::optional<optimization_guide::proto::Any>>>
  33. GetModelOverrideForOptimizationTarget(
  34. optimization_guide::proto::OptimizationTarget optimization_target);
  35. } // namespace optimization_guide
  36. #endif // COMPONENTS_OPTIMIZATION_GUIDE_CORE_MODEL_UTIL_H_