Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1685)

Side by Side Diff: chrome/browser/prefs/pref_hash_store_impl.cc

Issue 114223002: Multi-strategy based tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review:asvitkine 2 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prefs/pref_hash_store_impl.h" 5 #include "chrome/browser/prefs/pref_hash_store_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // Get the dictionary corresponding to the profile name, which may have a '.' 61 // Get the dictionary corresponding to the profile name, which may have a '.'
62 if (!update->GetDictionaryWithoutPathExpansion(hash_store_id_, 62 if (!update->GetDictionaryWithoutPathExpansion(hash_store_id_,
63 &child_dictionary)) { 63 &child_dictionary)) {
64 child_dictionary = new DictionaryValue; 64 child_dictionary = new DictionaryValue;
65 update->SetWithoutPathExpansion(hash_store_id_, child_dictionary); 65 update->SetWithoutPathExpansion(hash_store_id_, child_dictionary);
66 } 66 }
67 67
68 child_dictionary->SetString( 68 child_dictionary->SetString(
69 path, pref_hash_calculator_.Calculate(path, new_value)); 69 path, pref_hash_calculator_.Calculate(path, new_value));
70 } 70 }
71
72 PrefHashStore::ValueState PrefHashStoreImpl::CheckSplitValue(
73 const std::string& path,
74 const base::DictionaryValue* initial_split_value,
75 std::vector<std::string>* invalid_keys) const {
76 DCHECK(invalid_keys && invalid_keys->empty());
77
78 bool has_hashes = HasPath(path);
Alexei Svitkine (slow) 2013/12/18 18:28:02 Nit: const.
gab 2013/12/18 18:48:03 Done.
79
80 // Treat NULL and empty the same; otherwise we would need to store a hash
Alexei Svitkine (slow) 2013/12/18 18:28:02 Can you document that in the header api for CheckS
gab 2013/12/18 18:48:03 Done.
81 // for the entire dictionary (or some other special beacon) to
82 // differentiate these two cases which are really the same for
83 // dictionaries.
84 if (!initial_split_value || initial_split_value->empty())
85 return has_hashes ? CLEARED : UNCHANGED;
86
87 if (!has_hashes)
88 return UNKNOWN_VALUE;
89
90 for (base::DictionaryValue::Iterator it(*initial_split_value); !it.IsAtEnd();
91 it.Advance()) {
92 ValueState value_state = CheckValue(path + "." + it.key(), &it.value());
93 switch (value_state) {
94 case CLEARED:
95 // CLEARED doesn't make sense as a NULL value would never be sampled
96 // by the DictionaryValue::Iterator; in fact it is a known weakness of
97 // this current algorithm to not detect the case where a single key is
98 // cleared entirely from the dictionary pref.
99 NOTREACHED();
100 break;
101 case MIGRATED:
102 // Split tracked preferences were introduced after the migration started
103 // so no migration is expected.
104 NOTREACHED();
105 break;
106 case UNCHANGED:
107 break;
108 case CHANGED: // Falls through.
109 case UNKNOWN_VALUE:
110 // Declare this value invalid, whether it was changed or never seen
111 // before.
112 invalid_keys->push_back(it.key());
113 break;
114 }
115 }
116 return invalid_keys->empty() ? UNCHANGED : CHANGED;
117 }
118
119 void PrefHashStoreImpl::StoreSplitHash(
120 const std::string& path,
121 const base::DictionaryValue* split_value) {
122 ClearPath(path);
123
124 if (split_value) {
125 for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd();
126 it.Advance()) {
127 StoreHash(path + "." + it.key(), &it.value());
128 }
129 }
130 }
131
132 void PrefHashStoreImpl::ClearPath(const std::string& path) {
133 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes);
134 DictionaryValue* child_dictionary = NULL;
135
136 if (update->GetDictionaryWithoutPathExpansion(hash_store_id_,
137 &child_dictionary)) {
138 child_dictionary->Remove(path, NULL);
139 }
140 }
141
142 bool PrefHashStoreImpl::HasPath(const std::string& path) const {
143 const base::DictionaryValue* pref_hash_dicts =
144 local_state_->GetDictionary(prefs::kProfilePreferenceHashes);
145 const base::DictionaryValue* hashed_prefs = NULL;
146 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_,
147 &hashed_prefs);
148 return hashed_prefs && hashed_prefs->Get(path, NULL);
149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698