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

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

Issue 444763005: Clear a preference when sync tries to delete a preference (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | « no previous file | 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/prefs/pref_model_associator.h" 5 #include "chrome/browser/prefs/pref_model_associator.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 for (iter = change_list.begin(); iter != change_list.end(); ++iter) { 471 for (iter = change_list.begin(); iter != change_list.end(); ++iter) {
472 DCHECK_EQ(type_, iter->sync_data().GetDataType()); 472 DCHECK_EQ(type_, iter->sync_data().GetDataType());
473 473
474 std::string name; 474 std::string name;
475 const sync_pb::PreferenceSpecifics& pref_specifics = 475 const sync_pb::PreferenceSpecifics& pref_specifics =
476 GetSpecifics(iter->sync_data()); 476 GetSpecifics(iter->sync_data());
477 477
478 scoped_ptr<base::Value> value(ReadPreferenceSpecifics(pref_specifics, 478 scoped_ptr<base::Value> value(ReadPreferenceSpecifics(pref_specifics,
479 &name)); 479 &name));
480 480
481 if (iter->change_type() == syncer::SyncChange::ACTION_DELETE) { 481 if (iter->change_type() != syncer::SyncChange::ACTION_DELETE &&
Nicolas Zea 2014/08/08 17:38:32 does the ACTION_DELETE condition still need to be
482 // We never delete preferences. 482 !value.get()) {
483 NOTREACHED() << "Attempted to process sync delete change for " << name 483 // Skip values we can't deserialize.
484 << ". Skipping."; 484 // TODO(zea): consider taking some further action such as erasing the bad
485 // data.
485 continue; 486 continue;
486 } 487 }
487 488
488 // Skip values we can't deserialize.
489 // TODO(zea): consider taking some further action such as erasing the bad
490 // data.
491 if (!value.get())
492 continue;
493
494 // It is possible that we may receive a change to a preference we do not 489 // It is possible that we may receive a change to a preference we do not
495 // want to sync. For example if the user is syncing a Mac client and a 490 // want to sync. For example if the user is syncing a Mac client and a
496 // Windows client, the Windows client does not support 491 // Windows client, the Windows client does not support
497 // kConfirmToQuitEnabled. Ignore updates from these preferences. 492 // kConfirmToQuitEnabled. Ignore updates from these preferences.
498 const char* pref_name = name.c_str(); 493 const char* pref_name = name.c_str();
499 std::string new_name; 494 std::string new_name;
500 // We migrated this preference name, so do as if the name had not changed. 495 // We migrated this preference name, so do as if the name had not changed.
501 if (IsOldMigratedPreference(pref_name)) { 496 if (IsOldMigratedPreference(pref_name)) {
502 new_name = GetNewMigratedPreferenceName(pref_name); 497 new_name = GetNewMigratedPreferenceName(pref_name);
503 pref_name = new_name.c_str(); 498 pref_name = new_name.c_str();
504 } 499 }
505 500
506 if (!IsPrefRegistered(pref_name)) 501 if (!IsPrefRegistered(pref_name))
507 continue; 502 continue;
508 503
509 const PrefService::Preference* pref = 504 const PrefService::Preference* pref =
510 pref_service_->FindPreference(pref_name); 505 pref_service_->FindPreference(pref_name);
511 DCHECK(pref); 506 DCHECK(pref);
512 507
513 // This will only modify the user controlled value store, which takes 508 // This will only modify the user controlled value store, which takes
514 // priority over the default value but is ignored if the preference is 509 // priority over the default value but is ignored if the preference is
515 // policy controlled. 510 // policy controlled.
516 pref_service_->Set(pref_name, *value); 511 if (iter->change_type() != syncer::SyncChange::ACTION_DELETE) {
512 pref_service_->Set(pref_name, *value);
513 } else {
514 pref_service_->Set(pref_name,
515 *pref_service_->GetDefaultPrefValue(pref_name));
gab 2014/08/08 12:55:43 You should just do pref_service_->ClearPref(pref_n
Nicolas Zea 2014/08/08 17:38:32 Agreed. This will actually sync the default value
516 }
517 517
518 NotifySyncedPrefObservers(name, true /*from_sync*/); 518 NotifySyncedPrefObservers(name, true /*from_sync*/);
519 519
520 // Keep track of any newly synced preferences. 520 // Keep track of any newly synced preferences.
521 if (iter->change_type() == syncer::SyncChange::ACTION_ADD) { 521 if (iter->change_type() == syncer::SyncChange::ACTION_ADD) {
522 synced_preferences_.insert(name); 522 synced_preferences_.insert(name);
523 } 523 }
524 } 524 }
525 return syncer::SyncError(); 525 return syncer::SyncError();
526 } 526 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, 655 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path,
656 bool from_sync) const { 656 bool from_sync) const {
657 SyncedPrefObserverMap::const_iterator observer_iter = 657 SyncedPrefObserverMap::const_iterator observer_iter =
658 synced_pref_observers_.find(path); 658 synced_pref_observers_.find(path);
659 if (observer_iter == synced_pref_observers_.end()) 659 if (observer_iter == synced_pref_observers_.end())
660 return; 660 return;
661 SyncedPrefObserverList* observers = observer_iter->second; 661 SyncedPrefObserverList* observers = observer_iter->second;
662 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, 662 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers,
663 OnSyncedPrefChanged(path, from_sync)); 663 OnSyncedPrefChanged(path, from_sync));
664 } 664 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698