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

Side by Side Diff: chrome/browser/protector/protected_prefs_watcher.cc

Issue 10824344: Renamed ExtensionIdSet to ExtensionIds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undid files where I went too far Created 8 years, 4 months 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
« no previous file with comments | « chrome/browser/protector/protected_prefs_watcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/protector/protected_prefs_watcher.h" 5 #include "chrome/browser/protector/protected_prefs_watcher.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 bool ProtectedPrefsWatcher::UpdateCachedPrefs() { 202 bool ProtectedPrefsWatcher::UpdateCachedPrefs() {
203 // Direct access to the extensions prefs is required becase ExtensionService 203 // Direct access to the extensions prefs is required becase ExtensionService
204 // may not yet have been initialized. 204 // may not yet have been initialized.
205 const base::DictionaryValue* extension_prefs; 205 const base::DictionaryValue* extension_prefs;
206 const base::Value* extension_prefs_value = 206 const base::Value* extension_prefs_value =
207 profile_->GetPrefs()->GetUserPrefValue(ExtensionPrefs::kExtensionsPref); 207 profile_->GetPrefs()->GetUserPrefValue(ExtensionPrefs::kExtensionsPref);
208 if (!extension_prefs_value || 208 if (!extension_prefs_value ||
209 !extension_prefs_value->GetAsDictionary(&extension_prefs)) { 209 !extension_prefs_value->GetAsDictionary(&extension_prefs)) {
210 return false; 210 return false;
211 } 211 }
212 ExtensionPrefs::ExtensionIdSet extension_ids = 212 ExtensionPrefs::ExtensionIds extension_ids =
213 ExtensionPrefs::GetExtensionsFrom(extension_prefs); 213 ExtensionPrefs::GetExtensionsFrom(extension_prefs);
214 if (extension_ids == cached_extension_ids_) 214 if (extension_ids == cached_extension_ids_)
215 return false; 215 return false;
216 cached_extension_ids_.swap(extension_ids); 216 cached_extension_ids_.swap(extension_ids);
217 return true; 217 return true;
218 } 218 }
219 219
220 bool ProtectedPrefsWatcher::HasBackup() const { 220 bool ProtectedPrefsWatcher::HasBackup() const {
221 // TODO(ivankr): as soon as some irreversible change to Preferences happens, 221 // TODO(ivankr): as soon as some irreversible change to Preferences happens,
222 // add a condition that this change has occured as well (otherwise it's 222 // add a condition that this change has occured as well (otherwise it's
223 // possible to simply clear the "backup" dictionary to make settings 223 // possible to simply clear the "backup" dictionary to make settings
224 // unprotected). 224 // unprotected).
225 return profile_->GetPrefs()->HasPrefPath(kBackupSignature); 225 return profile_->GetPrefs()->HasPrefPath(kBackupSignature);
226 } 226 }
227 227
228 void ProtectedPrefsWatcher::InitBackup() { 228 void ProtectedPrefsWatcher::InitBackup() {
229 PrefService* prefs = profile_->GetPrefs(); 229 PrefService* prefs = profile_->GetPrefs();
230 for (size_t i = 0; i < arraysize(kProtectedPrefNames); ++i) { 230 for (size_t i = 0; i < arraysize(kProtectedPrefNames); ++i) {
231 const base::Value* user_value = 231 const base::Value* user_value =
232 prefs->GetUserPrefValue(kProtectedPrefNames[i]); 232 prefs->GetUserPrefValue(kProtectedPrefNames[i]);
233 if (user_value) 233 if (user_value)
234 prefs->Set(GetBackupNameFor(kProtectedPrefNames[i]).c_str(), *user_value); 234 prefs->Set(GetBackupNameFor(kProtectedPrefNames[i]).c_str(), *user_value);
235 } 235 }
236 ListPrefUpdate extension_ids_update(prefs, kBackupExtensionsIDs); 236 ListPrefUpdate extension_ids_update(prefs, kBackupExtensionsIDs);
237 base::ListValue* extension_ids = extension_ids_update.Get(); 237 base::ListValue* extension_ids = extension_ids_update.Get();
238 extension_ids->Clear(); 238 extension_ids->Clear();
239 for (ExtensionPrefs::ExtensionIdSet::const_iterator it = 239 for (ExtensionPrefs::ExtensionIds::const_iterator it =
240 cached_extension_ids_.begin(); 240 cached_extension_ids_.begin();
241 it != cached_extension_ids_.end(); ++it) { 241 it != cached_extension_ids_.end(); ++it) {
242 extension_ids->Append(base::Value::CreateStringValue(*it)); 242 extension_ids->Append(base::Value::CreateStringValue(*it));
243 } 243 }
244 prefs->SetInteger(kBackupVersion, kCurrentVersionNumber); 244 prefs->SetInteger(kBackupVersion, kCurrentVersionNumber);
245 UpdateBackupSignature(); 245 UpdateBackupSignature();
246 } 246 }
247 247
248 void ProtectedPrefsWatcher::MigrateOldBackupIfNeeded() { 248 void ProtectedPrefsWatcher::MigrateOldBackupIfNeeded() {
249 PrefService* prefs = profile_->GetPrefs(); 249 PrefService* prefs = profile_->GetPrefs();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 PrefService* prefs = profile_->GetPrefs(); 290 PrefService* prefs = profile_->GetPrefs();
291 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); 291 const PrefService::Preference* pref = prefs->FindPreference(path.c_str());
292 if (path == ExtensionPrefs::kExtensionsPref) { 292 if (path == ExtensionPrefs::kExtensionsPref) {
293 // For changes in extension dictionary, do nothing if the IDs list remained 293 // For changes in extension dictionary, do nothing if the IDs list remained
294 // the same. 294 // the same.
295 if (!UpdateCachedPrefs()) 295 if (!UpdateCachedPrefs())
296 return false; 296 return false;
297 ListPrefUpdate extension_ids_update(prefs, kBackupExtensionsIDs); 297 ListPrefUpdate extension_ids_update(prefs, kBackupExtensionsIDs);
298 base::ListValue* extension_ids = extension_ids_update.Get(); 298 base::ListValue* extension_ids = extension_ids_update.Get();
299 extension_ids->Clear(); 299 extension_ids->Clear();
300 for (ExtensionPrefs::ExtensionIdSet::const_iterator it = 300 for (ExtensionPrefs::ExtensionIds::const_iterator it =
301 cached_extension_ids_.begin(); 301 cached_extension_ids_.begin();
302 it != cached_extension_ids_.end(); ++it) { 302 it != cached_extension_ids_.end(); ++it) {
303 extension_ids->Append(base::Value::CreateStringValue(*it)); 303 extension_ids->Append(base::Value::CreateStringValue(*it));
304 } 304 }
305 } else if (!prefs->HasPrefPath(path.c_str())) { 305 } else if (!prefs->HasPrefPath(path.c_str())) {
306 // Preference has been removed, remove the backup as well. 306 // Preference has been removed, remove the backup as well.
307 prefs->ClearPref(backup_path.c_str()); 307 prefs->ClearPref(backup_path.c_str());
308 } else if (!pref->IsUserControlled()) { 308 } else if (!pref->IsUserControlled()) {
309 return false; 309 return false;
310 } else { 310 } else {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 NOTREACHED(); 388 NOTREACHED();
389 continue; 389 continue;
390 } 390 }
391 StringAppendStringDictionary(tab, &data); 391 StringAppendStringDictionary(tab, &data);
392 } 392 }
393 } 393 }
394 return data; 394 return data;
395 } 395 }
396 396
397 } // namespace protector 397 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/protected_prefs_watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698