tracked_preference_helper.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2014 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 SERVICES_PREFERENCES_TRACKED_TRACKED_PREFERENCE_HELPER_H_
  5. #define SERVICES_PREFERENCES_TRACKED_TRACKED_PREFERENCE_HELPER_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include "services/preferences/tracked/pref_hash_filter.h"
  9. #include "services/preferences/tracked/pref_hash_store_transaction.h"
  10. // A TrackedPreferenceHelper is a helper class for TrackedPreference which
  11. // handles decision making and reporting for TrackedPreference's
  12. // implementations.
  13. class TrackedPreferenceHelper {
  14. public:
  15. enum ResetAction {
  16. DONT_RESET,
  17. // WANTED_RESET is reported when DO_RESET would have been reported but the
  18. // current |enforcement_level| doesn't allow a reset for the detected state.
  19. WANTED_RESET,
  20. DO_RESET,
  21. };
  22. TrackedPreferenceHelper(
  23. const std::string& pref_path,
  24. size_t reporting_id,
  25. size_t reporting_ids_count,
  26. prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel
  27. enforcement_level,
  28. prefs::mojom::TrackedPreferenceMetadata::ValueType value_type);
  29. TrackedPreferenceHelper(const TrackedPreferenceHelper&) = delete;
  30. TrackedPreferenceHelper& operator=(const TrackedPreferenceHelper&) = delete;
  31. // Returns a ResetAction stating whether a reset is desired (DO_RESET) or not
  32. // (DONT_RESET) based on observing |value_state|. Can also return WANTED_RESET
  33. // if a reset would have been desired but the current |enforcement_level|
  34. // doesn't allow it.
  35. ResetAction GetAction(
  36. prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state)
  37. const;
  38. // Returns true if the preference value may contain personal information.
  39. bool IsPersonal() const;
  40. // Reports |value_state| via UMA under |reporting_id_|.
  41. // |validation_type_suffix| is appended to the reported histogram's name.
  42. void ReportValidationResult(
  43. prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state,
  44. base::StringPiece validation_type_suffix) const;
  45. // Reports |reset_action| via UMA under |reporting_id_|.
  46. void ReportAction(ResetAction reset_action) const;
  47. private:
  48. const std::string pref_path_;
  49. const size_t reporting_id_;
  50. const size_t reporting_ids_count_;
  51. // Deny setting changes and hash seeding/migration.
  52. const bool enforce_;
  53. const bool personal_;
  54. };
  55. #endif // SERVICES_PREFERENCES_TRACKED_TRACKED_PREFERENCE_HELPER_H_