| OLD | NEW |
| 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/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 SyncConfigInfo::SyncConfigInfo() | 85 SyncConfigInfo::SyncConfigInfo() |
| 86 : encrypt_all(false), | 86 : encrypt_all(false), |
| 87 sync_everything(false), | 87 sync_everything(false), |
| 88 sync_nothing(false), | 88 sync_nothing(false), |
| 89 passphrase_is_gaia(false) { | 89 passphrase_is_gaia(false) { |
| 90 } | 90 } |
| 91 | 91 |
| 92 SyncConfigInfo::~SyncConfigInfo() {} | 92 SyncConfigInfo::~SyncConfigInfo() {} |
| 93 | 93 |
| 94 // Note: The order of these types must match the ordering of | |
| 95 // the respective types in ModelType | |
| 96 const char* kDataTypeNames[] = { | |
| 97 "bookmarks", | |
| 98 "preferences", | |
| 99 "passwords", | |
| 100 "autofill", | |
| 101 "themes", | |
| 102 "typedUrls", | |
| 103 "extensions", | |
| 104 "apps", | |
| 105 "tabs" | |
| 106 }; | |
| 107 | |
| 108 COMPILE_ASSERT(32 == syncer::MODEL_TYPE_COUNT, | |
| 109 update_kDataTypeNames_to_match_UserSelectableTypes); | |
| 110 | |
| 111 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap; | |
| 112 | |
| 113 ModelTypeNameMap GetSelectableTypeNameMap() { | |
| 114 ModelTypeNameMap type_names; | |
| 115 syncer::ModelTypeSet type_set = syncer::UserSelectableTypes(); | |
| 116 syncer::ModelTypeSet::Iterator it = type_set.First(); | |
| 117 DCHECK_EQ(arraysize(kDataTypeNames), type_set.Size()); | |
| 118 for (size_t i = 0; i < arraysize(kDataTypeNames) && it.Good(); | |
| 119 ++i, it.Inc()) { | |
| 120 type_names[it.Get()] = kDataTypeNames[i]; | |
| 121 } | |
| 122 return type_names; | |
| 123 } | |
| 124 | |
| 125 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { | 94 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { |
| 126 scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(json)); | 95 scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(json)); |
| 127 base::DictionaryValue* result; | 96 base::DictionaryValue* result; |
| 128 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { | 97 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { |
| 129 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; | 98 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; |
| 130 return false; | 99 return false; |
| 131 } | 100 } |
| 132 | 101 |
| 133 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { | 102 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { |
| 134 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; | 103 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; |
| 135 return false; | 104 return false; |
| 136 } | 105 } |
| 137 | 106 |
| 138 if (!result->GetBoolean("syncNothing", &config->sync_nothing)) { | 107 if (!result->GetBoolean("syncNothing", &config->sync_nothing)) { |
| 139 DLOG(ERROR) << "GetConfiguration() not passed a syncNothing value"; | 108 DLOG(ERROR) << "GetConfiguration() not passed a syncNothing value"; |
| 140 return false; | 109 return false; |
| 141 } | 110 } |
| 142 | 111 |
| 143 DCHECK(!(config->sync_everything && config->sync_nothing)) | 112 DCHECK(!(config->sync_everything && config->sync_nothing)) |
| 144 << "syncAllDataTypes and syncNothing cannot both be true"; | 113 << "syncAllDataTypes and syncNothing cannot both be true"; |
| 145 | 114 |
| 146 ModelTypeNameMap type_names = GetSelectableTypeNameMap(); | 115 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 147 | 116 |
| 148 for (ModelTypeNameMap::const_iterator it = type_names.begin(); | 117 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 149 it != type_names.end(); ++it) { | 118 it != type_names.end(); ++it) { |
| 150 std::string key_name = it->second + std::string("Synced"); | 119 std::string key_name = it->second + std::string("Synced"); |
| 151 bool sync_value; | 120 bool sync_value; |
| 152 if (!result->GetBoolean(key_name, &sync_value)) { | 121 if (!result->GetBoolean(key_name, &sync_value)) { |
| 153 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; | 122 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; |
| 154 return false; | 123 return false; |
| 155 } | 124 } |
| 156 if (sync_value) | 125 if (sync_value) |
| 157 config->data_types.Put(it->first); | 126 config->data_types.Put(it->first); |
| 158 } | 127 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES }, | 233 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES }, |
| 265 { "syncNothing", IDS_SYNC_NOTHING }, | 234 { "syncNothing", IDS_SYNC_NOTHING }, |
| 266 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, | 235 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, |
| 267 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, | 236 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, |
| 268 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, | 237 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, |
| 269 { "themes", IDS_SYNC_DATATYPE_THEMES }, | 238 { "themes", IDS_SYNC_DATATYPE_THEMES }, |
| 270 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, | 239 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, |
| 271 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, | 240 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, |
| 272 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, | 241 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, |
| 273 { "apps", IDS_SYNC_DATATYPE_APPS }, | 242 { "apps", IDS_SYNC_DATATYPE_APPS }, |
| 243 { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS }, |
| 274 { "openTabs", IDS_SYNC_DATATYPE_TABS }, | 244 { "openTabs", IDS_SYNC_DATATYPE_TABS }, |
| 275 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR }, | 245 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR }, |
| 276 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL }, | 246 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL }, |
| 277 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR }, | 247 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR }, |
| 278 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR }, | 248 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR }, |
| 279 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL }, | 249 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL }, |
| 280 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES }, | 250 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES }, |
| 281 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING }, | 251 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING }, |
| 282 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS }, | 252 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS }, |
| 283 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY }, | 253 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY }, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // passwords) | 320 // passwords) |
| 351 // usePassphrase: true if the data is encrypted with a secondary passphrase | 321 // usePassphrase: true if the data is encrypted with a secondary passphrase |
| 352 // show_passphrase: true if a passphrase is needed to decrypt the sync data | 322 // show_passphrase: true if a passphrase is needed to decrypt the sync data |
| 353 base::DictionaryValue args; | 323 base::DictionaryValue args; |
| 354 | 324 |
| 355 // Tell the UI layer which data types are registered/enabled by the user. | 325 // Tell the UI layer which data types are registered/enabled by the user. |
| 356 const syncer::ModelTypeSet registered_types = | 326 const syncer::ModelTypeSet registered_types = |
| 357 service->GetRegisteredDataTypes(); | 327 service->GetRegisteredDataTypes(); |
| 358 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); | 328 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); |
| 359 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); | 329 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); |
| 360 ModelTypeNameMap type_names = GetSelectableTypeNameMap(); | 330 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 361 for (ModelTypeNameMap::const_iterator it = type_names.begin(); | 331 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 362 it != type_names.end(); ++it) { | 332 it != type_names.end(); ++it) { |
| 363 syncer::ModelType sync_type = it->first; | 333 syncer::ModelType sync_type = it->first; |
| 364 const std::string key_name = it->second; | 334 const std::string key_name = it->second; |
| 365 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); | 335 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); |
| 366 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); | 336 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); |
| 367 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); | 337 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); |
| 368 // TODO(treib): How do we want to handle pref groups, i.e. when only some of | 338 // TODO(treib): How do we want to handle pref groups, i.e. when only some of |
| 369 // the sync types behind a checkbox are force-enabled? crbug.com/403326 | 339 // the sync types behind a checkbox are force-enabled? crbug.com/403326 |
| 370 } | 340 } |
| 371 sync_driver::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | 341 sync_driver::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 | 928 |
| 959 LoginUIService* service = GetLoginUIService(); | 929 LoginUIService* service = GetLoginUIService(); |
| 960 DCHECK(service); | 930 DCHECK(service); |
| 961 service->current_login_ui()->FocusUI(); | 931 service->current_login_ui()->FocusUI(); |
| 962 return true; | 932 return true; |
| 963 } | 933 } |
| 964 | 934 |
| 965 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 935 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
| 966 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 936 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 967 } | 937 } |
| OLD | NEW |