| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync_prefs.h" | 5 #include "chrome/browser/sync/sync_prefs.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const syncable::ModelTypeSet& registered_types) const { | 127 const syncable::ModelTypeSet& registered_types) const { |
| 128 DCHECK(non_thread_safe_.CalledOnValidThread()); | 128 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 129 if (!pref_service_) { | 129 if (!pref_service_) { |
| 130 return syncable::ModelTypeSet(); | 130 return syncable::ModelTypeSet(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) { | 133 if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) { |
| 134 return registered_types; | 134 return registered_types; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Remove autofill_profile since it's controlled by autofill (see | 137 // Remove autofill_profile since it's controlled by autofill, and |
| 138 // code below). | 138 // search_engines since it's controlled by preferences (see code below). |
| 139 syncable::ModelTypeSet user_selectable_types(registered_types); | 139 syncable::ModelTypeSet user_selectable_types(registered_types); |
| 140 DCHECK_EQ(user_selectable_types.count(syncable::NIGORI), 0u); | 140 DCHECK_EQ(user_selectable_types.count(syncable::NIGORI), 0u); |
| 141 user_selectable_types.erase(syncable::AUTOFILL_PROFILE); | 141 user_selectable_types.erase(syncable::AUTOFILL_PROFILE); |
| 142 user_selectable_types.erase(syncable::SEARCH_ENGINES); |
| 142 | 143 |
| 143 // Remove app_notifications since it's controlled by apps (see | 144 // Remove app_notifications since it's controlled by apps (see |
| 144 // code below). | 145 // code below). |
| 145 // TODO(akalin): Centralize notion of all user selectable data types. | 146 // TODO(akalin): Centralize notion of all user selectable data types. |
| 146 user_selectable_types.erase(syncable::APP_NOTIFICATIONS); | 147 user_selectable_types.erase(syncable::APP_NOTIFICATIONS); |
| 147 | 148 |
| 148 syncable::ModelTypeSet preferred_types; | 149 syncable::ModelTypeSet preferred_types; |
| 149 | 150 |
| 150 for (syncable::ModelTypeSet::const_iterator it = | 151 for (syncable::ModelTypeSet::const_iterator it = |
| 151 user_selectable_types.begin(); | 152 user_selectable_types.begin(); |
| 152 it != user_selectable_types.end(); ++it) { | 153 it != user_selectable_types.end(); ++it) { |
| 153 if (GetDataTypePreferred(*it)) { | 154 if (GetDataTypePreferred(*it)) { |
| 154 preferred_types.insert(*it); | 155 preferred_types.insert(*it); |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 // Set autofill_profile to the same enabled/disabled state as | 159 // Group the enabled/disabled state of autofill_profile with autofill, and |
| 159 // autofill (since only autofill is shown on the UI). | 160 // search_engines with preferences (since only autofill and preferences are |
| 161 // shown on the UI). |
| 160 if (registered_types.count(syncable::AUTOFILL) && | 162 if (registered_types.count(syncable::AUTOFILL) && |
| 161 registered_types.count(syncable::AUTOFILL_PROFILE) && | 163 registered_types.count(syncable::AUTOFILL_PROFILE) && |
| 162 GetDataTypePreferred(syncable::AUTOFILL)) { | 164 GetDataTypePreferred(syncable::AUTOFILL)) { |
| 163 preferred_types.insert(syncable::AUTOFILL_PROFILE); | 165 preferred_types.insert(syncable::AUTOFILL_PROFILE); |
| 164 } | 166 } |
| 167 if (registered_types.count(syncable::PREFERENCES) && |
| 168 registered_types.count(syncable::SEARCH_ENGINES) && |
| 169 GetDataTypePreferred(syncable::PREFERENCES)) { |
| 170 preferred_types.insert(syncable::SEARCH_ENGINES); |
| 171 } |
| 165 | 172 |
| 166 // Set app_notifications to the same enabled/disabled state as | 173 // Set app_notifications to the same enabled/disabled state as |
| 167 // apps (since only apps is shown on the UI). | 174 // apps (since only apps is shown on the UI). |
| 168 if (registered_types.count(syncable::APPS) && | 175 if (registered_types.count(syncable::APPS) && |
| 169 registered_types.count(syncable::APP_NOTIFICATIONS) && | 176 registered_types.count(syncable::APP_NOTIFICATIONS) && |
| 170 GetDataTypePreferred(syncable::APPS)) { | 177 GetDataTypePreferred(syncable::APPS)) { |
| 171 preferred_types.insert(syncable::APP_NOTIFICATIONS); | 178 preferred_types.insert(syncable::APP_NOTIFICATIONS); |
| 172 } | 179 } |
| 173 | 180 |
| 174 return preferred_types; | 181 return preferred_types; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 195 // Set app_notifications to the same enabled/disabled state as | 202 // Set app_notifications to the same enabled/disabled state as |
| 196 // apps (since only apps is shown in the UI). | 203 // apps (since only apps is shown in the UI). |
| 197 if (registered_types.count(syncable::APPS) && | 204 if (registered_types.count(syncable::APPS) && |
| 198 registered_types.count(syncable::APP_NOTIFICATIONS)) { | 205 registered_types.count(syncable::APP_NOTIFICATIONS)) { |
| 199 if (preferred_types_with_dependents.count(syncable::APPS)) { | 206 if (preferred_types_with_dependents.count(syncable::APPS)) { |
| 200 preferred_types_with_dependents.insert(syncable::APP_NOTIFICATIONS); | 207 preferred_types_with_dependents.insert(syncable::APP_NOTIFICATIONS); |
| 201 } else { | 208 } else { |
| 202 preferred_types_with_dependents.erase(syncable::APP_NOTIFICATIONS); | 209 preferred_types_with_dependents.erase(syncable::APP_NOTIFICATIONS); |
| 203 } | 210 } |
| 204 } | 211 } |
| 212 // Set search_engines to the same enabled/disabled state as |
| 213 // preferences (since only preferences is shown in the UI). |
| 214 if (registered_types.count(syncable::PREFERENCES) && |
| 215 registered_types.count(syncable::SEARCH_ENGINES)) { |
| 216 if (preferred_types_with_dependents.count(syncable::PREFERENCES)) { |
| 217 preferred_types_with_dependents.insert(syncable::SEARCH_ENGINES); |
| 218 } else { |
| 219 preferred_types_with_dependents.erase(syncable::SEARCH_ENGINES); |
| 220 } |
| 221 } |
| 205 | 222 |
| 206 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); | 223 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); |
| 207 it != registered_types.end(); ++it) { | 224 it != registered_types.end(); ++it) { |
| 208 SetDataTypePreferred(*it, preferred_types_with_dependents.count(*it) > 0); | 225 SetDataTypePreferred(*it, preferred_types_with_dependents.count(*it) > 0); |
| 209 } | 226 } |
| 210 } | 227 } |
| 211 | 228 |
| 212 bool SyncPrefs::IsManaged() const { | 229 bool SyncPrefs::IsManaged() const { |
| 213 DCHECK(non_thread_safe_.CalledOnValidThread()); | 230 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 214 return pref_service_ && pref_service_->GetBoolean(prefs::kSyncManaged); | 231 return pref_service_ && pref_service_->GetBoolean(prefs::kSyncManaged); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 const char* pref_name = GetPrefNameForDataType(type); | 523 const char* pref_name = GetPrefNameForDataType(type); |
| 507 if (!pref_name) { | 524 if (!pref_name) { |
| 508 NOTREACHED(); | 525 NOTREACHED(); |
| 509 return; | 526 return; |
| 510 } | 527 } |
| 511 pref_service_->SetBoolean(pref_name, is_preferred); | 528 pref_service_->SetBoolean(pref_name, is_preferred); |
| 512 pref_service_->ScheduleSavePersistentPrefs(); | 529 pref_service_->ScheduleSavePersistentPrefs(); |
| 513 } | 530 } |
| 514 | 531 |
| 515 } // namespace browser_sync | 532 } // namespace browser_sync |
| OLD | NEW |