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

Unified Diff: chrome/browser/prefs/pref_model_associator.cc

Issue 12033093: sync: Implementation of Priority Preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempting to parametrize the PSS pref test fixture to also test priority prefs. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_model_associator.cc
diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc
index 09e98d50d72db01bd53dc7fcec06863c716b2112..4fe518f76fca029cd64e9947592d0912af268ad0 100644
--- a/chrome/browser/prefs/pref_model_associator.cc
+++ b/chrome/browser/prefs/pref_model_associator.cc
@@ -21,12 +21,40 @@
#include "sync/protocol/sync.pb.h"
using syncer::PREFERENCES;
+using syncer::PRIORITY_PREFERENCES;
-PrefModelAssociator::PrefModelAssociator()
+namespace {
+
+const sync_pb::PreferenceSpecifics& GetSpecifics(const syncer::ModelType& type,
Nicolas Zea 2013/03/05 01:15:44 |type| isn't needed in either of these methods (yo
albertb 2013/03/15 21:08:45 Done for the first one. But the second one needs t
+ const syncer::SyncData& pref) {
+ DCHECK(type == PREFERENCES || type == PRIORITY_PREFERENCES);
+ if (type == syncer::PREFERENCES) {
+ return pref.GetSpecifics().preference();
+ } else {
+ return pref.GetSpecifics().priority_preference().preference();
+ }
+}
+
+sync_pb::PreferenceSpecifics* GetMutableSpecifics(
+ const syncer::ModelType& type,
+ sync_pb::EntitySpecifics* specifics) {
+ DCHECK(type == PREFERENCES || type == PRIORITY_PREFERENCES);
+ if (type == syncer::PREFERENCES) {
+ return specifics->mutable_preference();
+ } else {
+ return specifics->mutable_priority_preference()->mutable_preference();
+ }
+}
+
+} // namespace
+
+PrefModelAssociator::PrefModelAssociator(syncer::ModelType type)
: models_associated_(false),
processing_syncer_changes_(false),
- pref_service_(NULL) {
+ pref_service_(NULL),
+ type_(type) {
DCHECK(CalledOnValidThread());
+ DCHECK(type_ == PREFERENCES || type_ == PRIORITY_PREFERENCES);
}
PrefModelAssociator::~PrefModelAssociator() {
@@ -44,7 +72,7 @@ void PrefModelAssociator::InitPrefAndAssociate(
if (sync_pref.IsValid()) {
const sync_pb::PreferenceSpecifics& preference =
- sync_pref.GetSpecifics().preference();
+ GetSpecifics(type_, sync_pref);
DCHECK_EQ(pref_name, preference.name());
base::JSONReader reader;
@@ -124,7 +152,7 @@ syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
const syncer::SyncDataList& initial_sync_data,
scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
- DCHECK_EQ(type, PREFERENCES);
+ DCHECK_EQ(type_, type);
DCHECK(CalledOnValidThread());
DCHECK(pref_service_);
DCHECK(!sync_processor_.get());
@@ -143,8 +171,12 @@ syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
initial_sync_data.begin();
sync_iter != initial_sync_data.end();
++sync_iter) {
- DCHECK_EQ(PREFERENCES, sync_iter->GetDataType());
- std::string sync_pref_name = sync_iter->GetSpecifics().preference().name();
+ DCHECK_EQ(type_, sync_iter->GetDataType());
+
+ const sync_pb::PreferenceSpecifics& preference =
+ GetSpecifics(type_, *sync_iter);
+ const std::string& sync_pref_name = preference.name();
+
if (remaining_preferences.count(sync_pref_name) == 0) {
// We're not syncing this preference locally, ignore the sync data.
// TODO(zea): Eventually we want to be able to have the syncable service
@@ -178,7 +210,7 @@ syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
}
void PrefModelAssociator::StopSyncing(syncer::ModelType type) {
- DCHECK_EQ(type, PREFERENCES);
+ DCHECK_EQ(type_, type);
models_associated_ = false;
sync_processor_.reset();
sync_error_factory_.reset();
@@ -205,7 +237,7 @@ scoped_ptr<Value> PrefModelAssociator::MergePreference(
bool PrefModelAssociator::CreatePrefSyncData(
const std::string& name,
const Value& value,
- syncer::SyncData* sync_data) {
+ syncer::SyncData* sync_data) const {
if (value.IsType(Value::TYPE_NULL)) {
LOG(ERROR) << "Attempting to sync a null pref value for " << name;
return false;
@@ -221,9 +253,12 @@ bool PrefModelAssociator::CreatePrefSyncData(
}
sync_pb::EntitySpecifics specifics;
- sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
+ sync_pb::PreferenceSpecifics* pref_specifics =
+ GetMutableSpecifics(type_, &specifics);
+
pref_specifics->set_name(name);
pref_specifics->set_value(serialized);
+
*sync_data = syncer::SyncData::CreateLocalData(name, name, specifics);
return true;
}
@@ -290,7 +325,7 @@ Value* PrefModelAssociator::MergeDictionaryValues(
syncer::SyncDataList PrefModelAssociator::GetAllSyncData(
syncer::ModelType type)
const {
- DCHECK_EQ(PREFERENCES, type);
+ DCHECK_EQ(type_, type);
syncer::SyncDataList current_data;
for (PreferenceSet::const_iterator iter = synced_preferences_.begin();
iter != synced_preferences_.end();
@@ -322,11 +357,12 @@ syncer::SyncError PrefModelAssociator::ProcessSyncChanges(
base::AutoReset<bool> processing_changes(&processing_syncer_changes_, true);
syncer::SyncChangeList::const_iterator iter;
for (iter = change_list.begin(); iter != change_list.end(); ++iter) {
- DCHECK_EQ(PREFERENCES, iter->sync_data().GetDataType());
+ DCHECK_EQ(type_, iter->sync_data().GetDataType());
std::string name;
- sync_pb::PreferenceSpecifics pref_specifics =
- iter->sync_data().GetSpecifics().preference();
+ const sync_pb::PreferenceSpecifics& pref_specifics =
+ GetSpecifics(type_, iter->sync_data());
+
scoped_ptr<Value> value(ReadPreferenceSpecifics(pref_specifics,
&name));

Powered by Google App Engine
This is Rietveld 408576698