blob: e05f42d7dde5d6ee4b67137819a6eb217fd71d0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/prefs/persistent_pref_store.h"
#include "base/values.h"
#include "components/pref_registry/pref_registry_syncable.h"
namespace {
const char kPreferenceMACs[] = "protection.macs";
const char kSuperMACPref[] = "protection.super_mac";
class MutablePreferenceMacDictionary
: public HashStoreContents::MutableDictionary {
public:
explicit MutablePreferenceMacDictionary(base::DictionaryValue* storage);
// MutableDictionary implementation
virtual base::DictionaryValue* operator->() OVERRIDE;
private:
base::DictionaryValue* storage_;
DISALLOW_COPY_AND_ASSIGN(MutablePreferenceMacDictionary);
};
MutablePreferenceMacDictionary::MutablePreferenceMacDictionary(
base::DictionaryValue* storage)
: storage_(storage) {
}
base::DictionaryValue* MutablePreferenceMacDictionary::operator->() {
base::DictionaryValue* mac_dictionary = NULL;
if (!storage_->GetDictionary(kPreferenceMACs, &mac_dictionary)) {
mac_dictionary = new base::DictionaryValue;
storage_->Set(kPreferenceMACs, mac_dictionary);
}
return mac_dictionary;
}
} // namespace
DictionaryHashStoreContents::DictionaryHashStoreContents(
base::DictionaryValue* storage)
: storage_(storage) {
}
// static
void DictionaryHashStoreContents::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterDictionaryPref(
kPreferenceMACs,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterStringPref(
kSuperMACPref,
std::string(),
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
std::string DictionaryHashStoreContents::hash_store_id() const {
return "";
}
void DictionaryHashStoreContents::Reset() {
storage_->Remove(kPreferenceMACs, NULL);
}
bool DictionaryHashStoreContents::IsInitialized() const {
return storage_->GetDictionary(kPreferenceMACs, NULL);
}
const base::DictionaryValue* DictionaryHashStoreContents::GetContents() const {
const base::DictionaryValue* mac_dictionary = NULL;
storage_->GetDictionary(kPreferenceMACs, &mac_dictionary);
return mac_dictionary;
}
scoped_ptr<HashStoreContents::MutableDictionary>
DictionaryHashStoreContents::GetMutableContents() {
return scoped_ptr<MutableDictionary>(
new MutablePreferenceMacDictionary(storage_));
}
std::string DictionaryHashStoreContents::GetSuperMac() const {
std::string super_mac_string;
storage_->GetString(kSuperMACPref, &super_mac_string);
return super_mac_string;
}
void DictionaryHashStoreContents::SetSuperMac(const std::string& super_mac) {
storage_->SetString(kSuperMACPref, super_mac);
}
|