| OLD | NEW |
| 1 // Copyright (c) 2006-2009 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_change_processor.h" | 5 #include "chrome/browser/sync/glue/preference_change_processor.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 41 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 41 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 42 DCHECK(running()); | 42 DCHECK(running()); |
| 43 DCHECK(NotificationType::PREF_CHANGED == type); | 43 DCHECK(NotificationType::PREF_CHANGED == type); |
| 44 DCHECK_EQ(pref_service_, Source<PrefService>(source).ptr()); | 44 DCHECK_EQ(pref_service_, Source<PrefService>(source).ptr()); |
| 45 | 45 |
| 46 std::wstring* name = Details<std::wstring>(details).ptr(); | 46 std::wstring* name = Details<std::wstring>(details).ptr(); |
| 47 const PrefService::Preference* preference = | 47 const PrefService::Preference* preference = |
| 48 pref_service_->FindPreference((*name).c_str()); | 48 pref_service_->FindPreference((*name).c_str()); |
| 49 DCHECK(preference); | 49 DCHECK(preference); |
| 50 | 50 |
| 51 // TODO(mnissler): Detect preference->IsManaged() state changes here and call | 51 // TODO(mnissler): Detect preference->IsUserControlled() state changes here |
| 52 // into PreferenceModelAssociator to associate/disassociate sync nodes when | 52 // and call into PreferenceModelAssociator to associate/disassociate sync |
| 53 // the state changes. | 53 // nodes when the state changes. |
| 54 | 54 |
| 55 // Do not pollute sync data with values coming from policy. | 55 // Do not pollute sync data with values coming from policy, extensions or the |
| 56 if (preference->IsManaged()) | 56 // commandline. |
| 57 if (!preference->IsUserModifiable()) |
| 57 return; | 58 return; |
| 58 | 59 |
| 59 sync_api::WriteTransaction trans(share_handle()); | 60 sync_api::WriteTransaction trans(share_handle()); |
| 60 sync_api::WriteNode node(&trans); | 61 sync_api::WriteNode node(&trans); |
| 61 | 62 |
| 62 // Since we don't create sync nodes for preferences that still have | 63 // Since we don't create sync nodes for preferences that still have |
| 63 // their default values, this changed preference may not have a sync | 64 // their default values, this changed preference may not have a sync |
| 64 // node yet. If not, create it. | 65 // node yet. If not, create it. |
| 65 int64 sync_id = model_associator_->GetSyncIdFromChromeId(*name); | 66 int64 sync_id = model_associator_->GetSyncIdFromChromeId(*name); |
| 66 if (sync_api::kInvalidId == sync_id) { | 67 if (sync_api::kInvalidId == sync_id) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 // It is possible that we may receive a change to a preference we | 136 // It is possible that we may receive a change to a preference we |
| 136 // do not want to sync. For example if the user is syncing a Mac | 137 // do not want to sync. For example if the user is syncing a Mac |
| 137 // client and a Windows client, the Windows client does not | 138 // client and a Windows client, the Windows client does not |
| 138 // support kShowPageOptionsButtons. Ignore updates from these | 139 // support kShowPageOptionsButtons. Ignore updates from these |
| 139 // preferences. | 140 // preferences. |
| 140 const wchar_t* pref_name = name.c_str(); | 141 const wchar_t* pref_name = name.c_str(); |
| 141 if (model_associator_->synced_preferences().count(pref_name) == 0) | 142 if (model_associator_->synced_preferences().count(pref_name) == 0) |
| 142 continue; | 143 continue; |
| 143 | 144 |
| 144 // Don't try to overwrite preferences controlled by policy. | 145 // Don't try to overwrite preferences not controllable by the user. |
| 145 const PrefService::Preference* pref = | 146 const PrefService::Preference* pref = |
| 146 pref_service_->FindPreference(pref_name); | 147 pref_service_->FindPreference(pref_name); |
| 147 DCHECK(pref); | 148 DCHECK(pref); |
| 148 if (pref->IsManaged()) | 149 if (!pref->IsUserModifiable()) |
| 149 continue; | 150 continue; |
| 150 | 151 |
| 151 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == | 152 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == |
| 152 changes[i].action) { | 153 changes[i].action) { |
| 153 pref_service_->ClearPref(pref_name); | 154 pref_service_->ClearPref(pref_name); |
| 154 } else { | 155 } else { |
| 155 pref_service_->Set(pref_name, *value); | 156 pref_service_->Set(pref_name, *value); |
| 156 | 157 |
| 157 // If this is a newly added node, associate. | 158 // If this is a newly added node, associate. |
| 158 if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == | 159 if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void PreferenceChangeProcessor::StopObserving() { | 211 void PreferenceChangeProcessor::StopObserving() { |
| 211 DCHECK(pref_service_); | 212 DCHECK(pref_service_); |
| 212 for (std::set<std::wstring>::const_iterator it = | 213 for (std::set<std::wstring>::const_iterator it = |
| 213 model_associator_->synced_preferences().begin(); | 214 model_associator_->synced_preferences().begin(); |
| 214 it != model_associator_->synced_preferences().end(); ++it) { | 215 it != model_associator_->synced_preferences().end(); ++it) { |
| 215 pref_service_->RemovePrefObserver((*it).c_str(), this); | 216 pref_service_->RemovePrefObserver((*it).c_str(), this); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace browser_sync | 220 } // namespace browser_sync |
| OLD | NEW |