| 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/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 config->secondary_passphrase = passphrase; | 167 config->secondary_passphrase = passphrase; |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool HasConfigurationChanged(const SyncConfiguration& config, | 173 bool HasConfigurationChanged(const SyncConfiguration& config, |
| 174 Profile* profile) { | 174 Profile* profile) { |
| 175 CHECK(profile); | 175 CHECK(profile); |
| 176 | 176 |
| 177 // This function must be updated every time a new sync datatype is added to |
| 178 // the sync preferences page. |
| 179 COMPILE_ASSERT(17 == syncable::MODEL_TYPE_COUNT, |
| 180 UpdateCustomConfigHistogram); |
| 181 |
| 177 // If service is null or if this is a first time configuration, return true. | 182 // If service is null or if this is a first time configuration, return true. |
| 178 ProfileSyncService* service = profile->GetProfileSyncService(); | 183 ProfileSyncService* service = profile->GetProfileSyncService(); |
| 179 if (!service || !service->HasSyncSetupCompleted()) | 184 if (!service || !service->HasSyncSetupCompleted()) |
| 180 return true; | 185 return true; |
| 181 | 186 |
| 182 if ((config.set_secondary_passphrase || config.set_gaia_passphrase) && | 187 if ((config.set_secondary_passphrase || config.set_gaia_passphrase) && |
| 183 !service->IsUsingSecondaryPassphrase()) | 188 !service->IsUsingSecondaryPassphrase()) |
| 184 return true; | 189 return true; |
| 185 | 190 |
| 186 if (config.encrypt_all != service->EncryptEverythingEnabled()) | 191 if (config.encrypt_all != service->EncryptEverythingEnabled()) |
| 187 return true; | 192 return true; |
| 188 | 193 |
| 189 PrefService* pref_service = profile->GetPrefs(); | 194 PrefService* pref_service = profile->GetPrefs(); |
| 190 CHECK(pref_service); | 195 CHECK(pref_service); |
| 191 | 196 |
| 192 if (config.sync_everything != | 197 if (config.sync_everything != |
| 193 pref_service->GetBoolean(prefs::kSyncKeepEverythingSynced)) | 198 pref_service->GetBoolean(prefs::kSyncKeepEverythingSynced)) |
| 194 return true; | 199 return true; |
| 195 | 200 |
| 201 // Only check the data types that are explicitly listed on the sync |
| 202 // preferences page. |
| 196 const syncable::ModelTypeSet& types = config.data_types; | 203 const syncable::ModelTypeSet& types = config.data_types; |
| 197 if (((types.find(syncable::BOOKMARKS) != types.end()) != | 204 if (((types.find(syncable::BOOKMARKS) != types.end()) != |
| 198 pref_service->GetBoolean(prefs::kSyncBookmarks)) || | 205 pref_service->GetBoolean(prefs::kSyncBookmarks)) || |
| 199 ((types.find(syncable::PREFERENCES) != types.end()) != | 206 ((types.find(syncable::PREFERENCES) != types.end()) != |
| 200 pref_service->GetBoolean(prefs::kSyncPreferences)) || | 207 pref_service->GetBoolean(prefs::kSyncPreferences)) || |
| 201 ((types.find(syncable::THEMES) != types.end()) != | 208 ((types.find(syncable::THEMES) != types.end()) != |
| 202 pref_service->GetBoolean(prefs::kSyncThemes)) || | 209 pref_service->GetBoolean(prefs::kSyncThemes)) || |
| 203 ((types.find(syncable::PASSWORDS) != types.end()) != | 210 ((types.find(syncable::PASSWORDS) != types.end()) != |
| 204 pref_service->GetBoolean(prefs::kSyncPasswords)) || | 211 pref_service->GetBoolean(prefs::kSyncPasswords)) || |
| 205 ((types.find(syncable::AUTOFILL) != types.end()) != | 212 ((types.find(syncable::AUTOFILL) != types.end()) != |
| 206 pref_service->GetBoolean(prefs::kSyncAutofill)) || | 213 pref_service->GetBoolean(prefs::kSyncAutofill)) || |
| 207 ((types.find(syncable::EXTENSIONS) != types.end()) != | 214 ((types.find(syncable::EXTENSIONS) != types.end()) != |
| 208 pref_service->GetBoolean(prefs::kSyncExtensions)) || | 215 pref_service->GetBoolean(prefs::kSyncExtensions)) || |
| 209 ((types.find(syncable::EXTENSION_SETTINGS) != types.end()) != | |
| 210 pref_service->GetBoolean(prefs::kSyncExtensionSettings)) || | |
| 211 ((types.find(syncable::TYPED_URLS) != types.end()) != | 216 ((types.find(syncable::TYPED_URLS) != types.end()) != |
| 212 pref_service->GetBoolean(prefs::kSyncTypedUrls)) || | 217 pref_service->GetBoolean(prefs::kSyncTypedUrls)) || |
| 213 ((types.find(syncable::SESSIONS) != types.end()) != | 218 ((types.find(syncable::SESSIONS) != types.end()) != |
| 214 pref_service->GetBoolean(prefs::kSyncSessions)) || | 219 pref_service->GetBoolean(prefs::kSyncSessions)) || |
| 215 ((types.find(syncable::APPS) != types.end()) != | 220 ((types.find(syncable::APPS) != types.end()) != |
| 216 pref_service->GetBoolean(prefs::kSyncApps)) || | 221 pref_service->GetBoolean(prefs::kSyncApps))) |
| 217 ((types.find(syncable::APP_SETTINGS) != types.end()) != | |
| 218 pref_service->GetBoolean(prefs::kSyncAppSettings))) | |
| 219 return true; | 222 return true; |
| 220 | 223 |
| 221 return false; | 224 return false; |
| 222 } | 225 } |
| 223 | 226 |
| 224 bool GetPassphrase(const std::string& json, std::string* passphrase) { | 227 bool GetPassphrase(const std::string& json, std::string* passphrase) { |
| 225 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 228 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 226 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 229 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 227 return false; | 230 return false; |
| 228 | 231 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 551 } |
| 549 | 552 |
| 550 SyncConfiguration configuration; | 553 SyncConfiguration configuration; |
| 551 if (!GetConfiguration(json, &configuration)) { | 554 if (!GetConfiguration(json, &configuration)) { |
| 552 // The page sent us something that we didn't understand. | 555 // The page sent us something that we didn't understand. |
| 553 // This probably indicates a programming error. | 556 // This probably indicates a programming error. |
| 554 NOTREACHED(); | 557 NOTREACHED(); |
| 555 return; | 558 return; |
| 556 } | 559 } |
| 557 | 560 |
| 561 // We do not do UMA logging during unit tests. |
| 562 if (web_ui_) { |
| 563 Profile* profile = Profile::FromWebUI(web_ui_); |
| 564 if (HasConfigurationChanged(configuration, profile)) { |
| 565 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", |
| 566 configuration.sync_everything); |
| 567 if (!configuration.sync_everything) { |
| 568 // Only log the data types that are explicitly listed on the sync |
| 569 // preferences page. |
| 570 const syncable::ModelTypeSet& types = configuration.data_types; |
| 571 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncBookmarks", |
| 572 types.find(syncable::BOOKMARKS) != types.end()); |
| 573 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncPreferences", |
| 574 types.find(syncable::PREFERENCES) != types.end()); |
| 575 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncThemes", |
| 576 types.find(syncable::THEMES) != types.end()); |
| 577 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncPasswords", |
| 578 types.find(syncable::PASSWORDS) != types.end()); |
| 579 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncAutofill", |
| 580 types.find(syncable::AUTOFILL) != types.end()); |
| 581 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncExtensions", |
| 582 types.find(syncable::EXTENSIONS) != types.end()); |
| 583 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncTypedUrls", |
| 584 types.find(syncable::TYPED_URLS) != types.end()); |
| 585 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncSessions", |
| 586 types.find(syncable::SESSIONS) != types.end()); |
| 587 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncApps", |
| 588 types.find(syncable::APPS) != types.end()); |
| 589 COMPILE_ASSERT(17 == syncable::MODEL_TYPE_COUNT, |
| 590 UpdateCustomConfigHistogram); |
| 591 } |
| 592 UMA_HISTOGRAM_BOOLEAN("Sync.EncryptAllData", configuration.encrypt_all); |
| 593 UMA_HISTOGRAM_BOOLEAN("Sync.CustomPassphrase", |
| 594 configuration.set_gaia_passphrase || |
| 595 configuration.set_secondary_passphrase); |
| 596 } |
| 597 } |
| 598 |
| 558 DCHECK(flow_); | 599 DCHECK(flow_); |
| 559 flow_->OnUserConfigured(configuration); | 600 flow_->OnUserConfigured(configuration); |
| 560 | 601 |
| 561 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); | 602 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); |
| 562 if (configuration.encrypt_all) { | 603 if (configuration.encrypt_all) { |
| 563 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); | 604 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); |
| 564 } | 605 } |
| 565 if (configuration.set_secondary_passphrase) { | 606 if (configuration.set_secondary_passphrase) { |
| 566 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); | 607 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); |
| 567 } | 608 } |
| 568 if (!configuration.sync_everything) { | 609 if (!configuration.sync_everything) { |
| 569 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); | 610 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); |
| 570 } | 611 } |
| 571 | |
| 572 // Happens during unit tests. | |
| 573 if (!web_ui_) | |
| 574 return; | |
| 575 | |
| 576 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 577 if (HasConfigurationChanged(configuration, profile)) { | |
| 578 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", | |
| 579 configuration.sync_everything); | |
| 580 if (!configuration.sync_everything) { | |
| 581 const syncable::ModelTypeSet& types = configuration.data_types; | |
| 582 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncBookmarks", | |
| 583 types.find(syncable::BOOKMARKS) != types.end()); | |
| 584 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncPreferences", | |
| 585 types.find(syncable::PREFERENCES) != types.end()); | |
| 586 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncThemes", | |
| 587 types.find(syncable::THEMES) != types.end()); | |
| 588 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncPasswords", | |
| 589 types.find(syncable::PASSWORDS) != types.end()); | |
| 590 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncAutofill", | |
| 591 types.find(syncable::AUTOFILL) != types.end()); | |
| 592 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncExtensions", | |
| 593 types.find(syncable::EXTENSIONS) != types.end()); | |
| 594 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncExtensionSettings", | |
| 595 types.find(syncable::EXTENSION_SETTINGS) != types.end()); | |
| 596 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncTypedUrls", | |
| 597 types.find(syncable::TYPED_URLS) != types.end()); | |
| 598 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncSessions", | |
| 599 types.find(syncable::SESSIONS) != types.end()); | |
| 600 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncApps", | |
| 601 types.find(syncable::APPS) != types.end()); | |
| 602 UMA_HISTOGRAM_BOOLEAN("Sync.CustomSyncAppSettings", | |
| 603 types.find(syncable::APP_SETTINGS) != types.end()); | |
| 604 COMPILE_ASSERT(17 == syncable::MODEL_TYPE_COUNT, | |
| 605 UpdateCustomConfigHistogram); | |
| 606 } | |
| 607 UMA_HISTOGRAM_BOOLEAN("Sync.EncryptAllData", configuration.encrypt_all); | |
| 608 UMA_HISTOGRAM_BOOLEAN("Sync.CustomPassphrase", | |
| 609 configuration.set_gaia_passphrase || | |
| 610 configuration.set_secondary_passphrase); | |
| 611 } | |
| 612 } | 612 } |
| 613 | 613 |
| 614 void SyncSetupHandler::HandlePassphraseEntry(const ListValue* args) { | 614 void SyncSetupHandler::HandlePassphraseEntry(const ListValue* args) { |
| 615 std::string json; | 615 std::string json; |
| 616 if (!args->GetString(0, &json)) { | 616 if (!args->GetString(0, &json)) { |
| 617 NOTREACHED() << "Could not read JSON argument"; | 617 NOTREACHED() << "Could not read JSON argument"; |
| 618 return; | 618 return; |
| 619 } | 619 } |
| 620 | 620 |
| 621 if (json.empty()) | 621 if (json.empty()) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } | 744 } |
| 745 | 745 |
| 746 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { | 746 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { |
| 747 DictionaryValue args; | 747 DictionaryValue args; |
| 748 Profile* profile = Profile::FromWebUI(web_ui_); | 748 Profile* profile = Profile::FromWebUI(web_ui_); |
| 749 ProfileSyncService* service = profile->GetProfileSyncService(); | 749 ProfileSyncService* service = profile->GetProfileSyncService(); |
| 750 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 750 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
| 751 args.SetString("error_message", error_message); | 751 args.SetString("error_message", error_message); |
| 752 ShowGaiaLogin(args); | 752 ShowGaiaLogin(args); |
| 753 } | 753 } |
| OLD | NEW |