url_param_classification_component_installer.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2022 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_COMPONENT_UPDATER_INSTALLER_POLICIES_URL_PARAM_CLASSIFICATION_COMPONENT_INSTALLER_H_
  5. #define COMPONENTS_COMPONENT_UPDATER_INSTALLER_POLICIES_URL_PARAM_CLASSIFICATION_COMPONENT_INSTALLER_H_
  6. #include "base/callback.h"
  7. #include "base/files/file_path.h"
  8. #include "base/values.h"
  9. #include "components/component_updater/component_installer.h"
  10. namespace component_updater {
  11. class ComponentUpdateService;
  12. using OnUrlParamClassificationComponentReady =
  13. base::RepeatingCallback<void(std::string)>;
  14. class UrlParamClassificationComponentInstallerPolicy
  15. : public ComponentInstallerPolicy {
  16. public:
  17. // The result of reading and validating the UrlParamFilterClassification list
  18. // from Component Updater.
  19. //
  20. // These values are persisted to logs. Entries should not be renumbered and
  21. // numeric values should never be reused.
  22. enum class ClassificationListValidationResult {
  23. // No invalid classifications were found in the list.
  24. kSuccessful = 0,
  25. // The file wasn't present.
  26. kMissingClassificationsFile = 1,
  27. // Reading from the classifications file failed.
  28. kReadingClassificationsFileFailed = 2,
  29. // The raw classifications string was unabled to be parsed into the proto.
  30. kParsingToProtoFailed = 3,
  31. // Classification was ignored due to missing required site name.
  32. kClassificationMissingSite = 4,
  33. // Classification was ignored due to missing required site role.
  34. kClassificationMissingSiteRole = 5,
  35. kMaxValue = kClassificationMissingSiteRole,
  36. };
  37. explicit UrlParamClassificationComponentInstallerPolicy(
  38. OnUrlParamClassificationComponentReady on_component_ready);
  39. ~UrlParamClassificationComponentInstallerPolicy() override;
  40. UrlParamClassificationComponentInstallerPolicy(
  41. const UrlParamClassificationComponentInstallerPolicy&) = delete;
  42. UrlParamClassificationComponentInstallerPolicy& operator=(
  43. const UrlParamClassificationComponentInstallerPolicy&) = delete;
  44. static void WriteComponentForTesting(const base::FilePath& install_dir,
  45. base::StringPiece contents);
  46. static void ResetForTesting();
  47. private:
  48. FRIEND_TEST_ALL_PREFIXES(UrlParamClassificationComponentInstallerTest,
  49. VerifyAttributes);
  50. // The following methods override ComponentInstallerPolicy.
  51. bool SupportsGroupPolicyEnabledComponentUpdates() const override;
  52. bool RequiresNetworkEncryption() const override;
  53. update_client::CrxInstaller::Result OnCustomInstall(
  54. const base::Value& manifest,
  55. const base::FilePath& install_dir) override;
  56. void OnCustomUninstall() override;
  57. bool VerifyInstallation(const base::Value& manifest,
  58. const base::FilePath& install_dir) const override;
  59. void ComponentReady(const base::Version& version,
  60. const base::FilePath& install_dir,
  61. base::Value manifest) override;
  62. base::FilePath GetRelativeInstallDir() const override;
  63. void GetHash(std::vector<uint8_t>* hash) const override;
  64. std::string GetName() const override;
  65. update_client::InstallerAttributes GetInstallerAttributes() const override;
  66. static base::FilePath GetInstalledPath(const base::FilePath& base);
  67. void MaybeFireCallback(
  68. const absl::optional<std::string>& maybe_classifications);
  69. OnUrlParamClassificationComponentReady on_component_ready_;
  70. };
  71. // Call once during startup to make the component update service aware of
  72. // the Url Param Classification component.
  73. void RegisterUrlParamClassificationComponent(ComponentUpdateService* cus);
  74. } // namespace component_updater
  75. #endif // COMPONENTS_COMPONENT_UPDATER_INSTALLER_POLICIES_URL_PARAM_CLASSIFICATION_COMPONENT_INSTALLER_H_