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
5#ifndef CHROME_BROWSER_PREFS_TRACKED_TRACKED_PREFERENCE_HELPER_H_
6#define CHROME_BROWSER_PREFS_TRACKED_TRACKED_PREFERENCE_HELPER_H_
7
8#include <string>
9
10#include "base/macros.h"
11#include "chrome/browser/prefs/pref_hash_filter.h"
12#include "chrome/browser/prefs/pref_hash_store_transaction.h"
13
14// A TrackedPreferenceHelper is a helper class for TrackedPreference which
15// handles decision making and reporting for TrackedPreference's
16// implementations.
17class TrackedPreferenceHelper {
18 public:
19  enum ResetAction {
20    DONT_RESET,
21    // WANTED_RESET is reported when DO_RESET would have been reported but the
22    // current |enforcement_level| doesn't allow a reset for the detected state.
23    WANTED_RESET,
24    DO_RESET,
25  };
26
27  TrackedPreferenceHelper(const std::string& pref_path,
28                          size_t reporting_id,
29                          size_t reporting_ids_count,
30                          PrefHashFilter::EnforcementLevel enforcement_level);
31
32  // Returns a ResetAction stating whether a reset is desired (DO_RESET) or not
33  // (DONT_RESET) based on observing |value_state|. Can also return WANTED_RESET
34  // if a reset would have been desired but the current |enforcement_level|
35  // doesn't allow it.
36  ResetAction GetAction(
37      PrefHashStoreTransaction::ValueState value_state) const;
38
39  // Reports |value_state| via UMA under |reporting_id_|.
40  void ReportValidationResult(
41      PrefHashStoreTransaction::ValueState value_state) const;
42
43  // Reports |reset_action| via UMA under |reporting_id_|.
44  void ReportAction(ResetAction reset_action) const;
45
46  // Reports, via UMA, the |count| of split preference entries that were
47  // considered invalid in a CHANGED event.
48  void ReportSplitPreferenceChangedCount(size_t count) const;
49
50 private:
51  const std::string pref_path_;
52
53  const size_t reporting_id_;
54  const size_t reporting_ids_count_;
55
56  // Deny setting changes and hash seeding/migration.
57  const bool enforce_;
58
59  DISALLOW_COPY_AND_ASSIGN(TrackedPreferenceHelper);
60};
61
62#endif  // CHROME_BROWSER_PREFS_TRACKED_TRACKED_PREFERENCE_HELPER_H_
63