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 SERVICES_PREFERENCES_TRACKED_TRACKED_SPLIT_PREFERENCE_H_
6 #define SERVICES_PREFERENCES_TRACKED_TRACKED_SPLIT_PREFERENCE_H_
7 
8 #include <stddef.h>
9 
10 #include <string>
11 
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "services/preferences/tracked/pref_hash_filter.h"
15 #include "services/preferences/tracked/tracked_preference.h"
16 #include "services/preferences/tracked/tracked_preference_helper.h"
17 
18 namespace prefs {
19 namespace mojom {
20 class TrackedPreferenceValidationDelegate;
21 }
22 }
23 
24 // A TrackedSplitPreference must be tracking a dictionary pref. Each top-level
25 // entry in its dictionary is tracked and enforced independently. An optional
26 // delegate is notified of the status of the preference during enforcement.
27 class TrackedSplitPreference : public TrackedPreference {
28  public:
29   // Constructs a TrackedSplitPreference. |pref_path| must be a dictionary pref.
30   TrackedSplitPreference(
31       const std::string& pref_path,
32       size_t reporting_id,
33       size_t reporting_ids_count,
34       prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel
35           enforcement_level,
36       prefs::mojom::TrackedPreferenceMetadata::ValueType value_type,
37       prefs::mojom::TrackedPreferenceValidationDelegate* delegate);
38 
39   // TrackedPreference implementation.
40   TrackedPreferenceType GetType() const override;
41   void OnNewValue(const base::Value* value,
42                   PrefHashStoreTransaction* transaction) const override;
43   bool EnforceAndReport(
44       base::DictionaryValue* pref_store_contents,
45       PrefHashStoreTransaction* transaction,
46       PrefHashStoreTransaction* external_validation_transaction) const override;
47 
48  private:
49   const std::string pref_path_;
50   const TrackedPreferenceHelper helper_;
51   prefs::mojom::TrackedPreferenceValidationDelegate* delegate_;
52 
53   DISALLOW_COPY_AND_ASSIGN(TrackedSplitPreference);
54 };
55 
56 #endif  // SERVICES_PREFERENCES_TRACKED_TRACKED_SPLIT_PREFERENCE_H_
57