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

Side by Side Diff: chrome/browser/sync/glue/preference_model_associator.cc

Issue 3051001: Adjust preference sync code to only sync user modifiable preferences. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: separate out the download_manager_unittest.cc fixes Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/sync/glue/preference_model_associator.h" 5 #include "chrome/browser/sync/glue/preference_model_associator.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 base::JSONReader reader; 66 base::JSONReader reader;
67 for (std::set<std::wstring>::iterator it = synced_preferences_.begin(); 67 for (std::set<std::wstring>::iterator it = synced_preferences_.begin();
68 it != synced_preferences_.end(); ++it) { 68 it != synced_preferences_.end(); ++it) {
69 std::string tag = WideToUTF8(*it); 69 std::string tag = WideToUTF8(*it);
70 const PrefService::Preference* pref = 70 const PrefService::Preference* pref =
71 pref_service->FindPreference((*it).c_str()); 71 pref_service->FindPreference((*it).c_str());
72 DCHECK(pref); 72 DCHECK(pref);
73 73
74 sync_api::WriteNode node(&trans); 74 sync_api::WriteNode node(&trans);
75 if (node.InitByClientTagLookup(syncable::PREFERENCES, tag)) { 75 if (node.InitByClientTagLookup(syncable::PREFERENCES, tag)) {
76 // The server has a value for the preference.
76 const sync_pb::PreferenceSpecifics& preference( 77 const sync_pb::PreferenceSpecifics& preference(
77 node.GetPreferenceSpecifics()); 78 node.GetPreferenceSpecifics());
78 DCHECK_EQ(tag, preference.name()); 79 DCHECK_EQ(tag, preference.name());
79 80
80 if (!pref->IsManaged()) { 81 if (pref->IsUserModifiable()) {
81 scoped_ptr<Value> value( 82 scoped_ptr<Value> value(
82 reader.JsonToValue(preference.value(), false, false)); 83 reader.JsonToValue(preference.value(), false, false));
83 std::wstring pref_name = UTF8ToWide(preference.name()); 84 std::wstring pref_name = UTF8ToWide(preference.name());
84 if (!value.get()) { 85 if (!value.get()) {
85 LOG(ERROR) << "Failed to deserialize preference value: " 86 LOG(ERROR) << "Failed to deserialize preference value: "
86 << reader.GetErrorMessage(); 87 << reader.GetErrorMessage();
87 return false; 88 return false;
88 } 89 }
89 90
90 // Merge the server value of this preference with the local value. 91 // Merge the server value of this preference with the local value.
91 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); 92 scoped_ptr<Value> new_value(MergePreference(*pref, *value));
92 93
93 // Update the local preference based on what we got from the 94 // Update the local preference based on what we got from the
94 // sync server. 95 // sync server.
95 if (!pref->GetValue()->Equals(new_value.get())) 96 if (!pref->GetValue()->Equals(new_value.get()))
96 pref_service->Set(pref_name.c_str(), *new_value); 97 pref_service->Set(pref_name.c_str(), *new_value);
97 98
98 AfterUpdateOperations(pref_name); 99 AfterUpdateOperations(pref_name);
99 100
100 // If the merge resulted in an updated value, write it back to 101 // If the merge resulted in an updated value, write it back to
101 // the sync node. 102 // the sync node.
102 if (!value->Equals(new_value.get()) && 103 if (!value->Equals(new_value.get()) &&
103 !WritePreferenceToNode(pref->name(), *new_value, &node)) 104 !WritePreferenceToNode(pref->name(), *new_value, &node))
104 return false; 105 return false;
105 } 106 }
106 Associate(pref, node.GetId()); 107 Associate(pref, node.GetId());
107 } else if (!pref->IsManaged()) { 108 } else if (pref->IsUserControlled()) {
108 // If there is no server value for this preference and it is 109 // The server doesn't have a value, but we have a user-controlled value,
109 // currently its default value, don't create a new server node. 110 // so we push it to the server.
110 if (pref->IsDefaultValue())
111 continue;
112
113 sync_api::WriteNode write_node(&trans); 111 sync_api::WriteNode write_node(&trans);
114 if (!write_node.InitUniqueByCreation(syncable::PREFERENCES, root, tag)) { 112 if (!write_node.InitUniqueByCreation(syncable::PREFERENCES, root, tag)) {
115 LOG(ERROR) << "Failed to create preference sync node."; 113 LOG(ERROR) << "Failed to create preference sync node.";
116 return false; 114 return false;
117 } 115 }
118 116
119 // Update the sync node with the local value for this preference. 117 // Update the sync node with the local value for this preference.
120 if (!WritePreferenceToNode(pref->name(), *pref->GetValue(), &write_node)) 118 if (!WritePreferenceToNode(pref->name(), *pref->GetValue(), &write_node))
121 return false; 119 return false;
122 120
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // notification to update the UI. 295 // notification to update the UI.
298 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { 296 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) {
299 NotificationService::current()->Notify( 297 NotificationService::current()->Notify(
300 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 298 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
301 Source<PreferenceModelAssociator>(this), 299 Source<PreferenceModelAssociator>(this),
302 NotificationService::NoDetails()); 300 NotificationService::NoDetails());
303 } 301 }
304 } 302 }
305 303
306 } // namespace browser_sync 304 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698