hints_processing_util.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_HINTS_PROCESSING_UTIL_H_
  5. #define COMPONENTS_OPTIMIZATION_GUIDE_CORE_HINTS_PROCESSING_UTIL_H_
  6. #include <string>
  7. #include "components/optimization_guide/proto/hints.pb.h"
  8. #include "net/nqe/effective_connection_type.h"
  9. class GURL;
  10. namespace optimization_guide {
  11. // Returns the string representation of the optimization type.
  12. std::string GetStringNameForOptimizationType(
  13. proto::OptimizationType optimization_type);
  14. // Returns the matching PageHint for |gurl| if found in |hint|.
  15. const proto::PageHint* FindPageHintForURL(const GURL& gurl,
  16. const proto::Hint* hint);
  17. // The host is hashed and returned as a string because
  18. // base::Value(base::Value::Type::DICTIONARY) only accepts strings as keys.
  19. // Note, some hash collisions could occur on hosts. For querying the blocklist,
  20. // collisions are acceptable as they would only block additional hosts. For
  21. // updating the blocklist, a collision would enable a site that should remain on
  22. // the blocklist. However, the likelihood of a collision for the number of hosts
  23. // allowed in the blocklist is practically zero.
  24. std::string HashHostForDictionary(const std::string& host);
  25. // Converts |proto_ect| into a net::EffectiveConnectionType.
  26. net::EffectiveConnectionType ConvertProtoEffectiveConnectionType(
  27. proto::EffectiveConnectionType proto_ect);
  28. // Validates a URL used for URL-keyed hints.
  29. bool IsValidURLForURLKeyedHint(const GURL& url);
  30. } // namespace optimization_guide
  31. #endif // COMPONENTS_OPTIMIZATION_GUIDE_CORE_HINTS_PROCESSING_UTIL_H_