Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/sync_setup_flow.h" | 5 #include "chrome/browser/sync/sync_setup_flow.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 L"//iframe[@id='passphrase']"; | 38 L"//iframe[@id='passphrase']"; |
| 39 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; | 39 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; |
| 40 | 40 |
| 41 void FlowHandler::RegisterMessages() { | 41 void FlowHandler::RegisterMessages() { |
| 42 dom_ui_->RegisterMessageCallback("SubmitAuth", | 42 dom_ui_->RegisterMessageCallback("SubmitAuth", |
| 43 NewCallback(this, &FlowHandler::HandleSubmitAuth)); | 43 NewCallback(this, &FlowHandler::HandleSubmitAuth)); |
| 44 dom_ui_->RegisterMessageCallback("Configure", | 44 dom_ui_->RegisterMessageCallback("Configure", |
| 45 NewCallback(this, &FlowHandler::HandleConfigure)); | 45 NewCallback(this, &FlowHandler::HandleConfigure)); |
| 46 dom_ui_->RegisterMessageCallback("Passphrase", | 46 dom_ui_->RegisterMessageCallback("Passphrase", |
| 47 NewCallback(this, &FlowHandler::HandlePassphraseEntry)); | 47 NewCallback(this, &FlowHandler::HandlePassphraseEntry)); |
| 48 dom_ui_->RegisterMessageCallback("PassphraseCancel", | |
| 49 NewCallback(this, &FlowHandler::HandlePassphraseCancel)); | |
| 48 dom_ui_->RegisterMessageCallback("FirstPassphrase", | 50 dom_ui_->RegisterMessageCallback("FirstPassphrase", |
| 49 NewCallback(this, &FlowHandler::HandleFirstPassphrase)); | 51 NewCallback(this, &FlowHandler::HandleFirstPassphrase)); |
| 50 dom_ui_->RegisterMessageCallback("GoToDashboard", | 52 dom_ui_->RegisterMessageCallback("GoToDashboard", |
| 51 NewCallback(this, &FlowHandler::HandleGoToDashboard)); | 53 NewCallback(this, &FlowHandler::HandleGoToDashboard)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 static bool GetAuthData(const std::string& json, | 56 static bool GetAuthData(const std::string& json, |
| 55 std::string* username, | 57 std::string* username, |
| 56 std::string* password, | 58 std::string* password, |
| 57 std::string* captcha, | 59 std::string* captcha, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 // Encyption settings. | 162 // Encyption settings. |
| 161 if (!result->GetBoolean("usePassphrase", &config->use_secondary_passphrase)) | 163 if (!result->GetBoolean("usePassphrase", &config->use_secondary_passphrase)) |
| 162 return false; | 164 return false; |
| 163 if (config->use_secondary_passphrase && | 165 if (config->use_secondary_passphrase && |
| 164 !result->GetString("passphrase", &config->secondary_passphrase)) | 166 !result->GetString("passphrase", &config->secondary_passphrase)) |
| 165 return false; | 167 return false; |
| 166 | 168 |
| 167 return true; | 169 return true; |
| 168 } | 170 } |
| 169 | 171 |
| 172 static void DisablePasswordSync(ProfileSyncService* service) { | |
|
tim (not reviewing)
2011/01/26 18:41:31
at first I didn't like this, then I spent 10 minut
| |
| 173 syncable::ModelTypeSet types; | |
| 174 service->GetPreferredDataTypes(&types); | |
| 175 types.erase(syncable::PASSWORDS); | |
| 176 service->OnUserChoseDatatypes(false, types); | |
| 177 } | |
| 178 | |
| 170 void FlowHandler::HandleSubmitAuth(const ListValue* args) { | 179 void FlowHandler::HandleSubmitAuth(const ListValue* args) { |
| 171 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); | 180 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
| 172 std::string username, password, captcha, access_code; | 181 std::string username, password, captcha, access_code; |
| 173 if (json.empty()) | 182 if (json.empty()) |
| 174 return; | 183 return; |
| 175 | 184 |
| 176 if (!GetAuthData(json, &username, &password, &captcha, &access_code)) { | 185 if (!GetAuthData(json, &username, &password, &captcha, &access_code)) { |
| 177 // The page sent us something that we didn't understand. | 186 // The page sent us something that we didn't understand. |
| 178 // This probably indicates a programming error. | 187 // This probably indicates a programming error. |
| 179 NOTREACHED(); | 188 NOTREACHED(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 if (!GetPassphrase(json, &passphrase)) { | 223 if (!GetPassphrase(json, &passphrase)) { |
| 215 // Couldn't understand what the page sent. Indicates a programming error. | 224 // Couldn't understand what the page sent. Indicates a programming error. |
| 216 NOTREACHED(); | 225 NOTREACHED(); |
| 217 return; | 226 return; |
| 218 } | 227 } |
| 219 | 228 |
| 220 DCHECK(flow_); | 229 DCHECK(flow_); |
| 221 flow_->OnPassphraseEntry(passphrase); | 230 flow_->OnPassphraseEntry(passphrase); |
| 222 } | 231 } |
| 223 | 232 |
| 233 void FlowHandler::HandlePassphraseCancel(const ListValue* args) { | |
| 234 DCHECK(flow_); | |
| 235 flow_->OnPassphraseCancel(); | |
| 236 } | |
| 237 | |
| 224 void FlowHandler::HandleFirstPassphrase(const ListValue* args) { | 238 void FlowHandler::HandleFirstPassphrase(const ListValue* args) { |
| 225 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); | 239 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
| 226 | 240 |
| 227 if (json.empty()) | 241 if (json.empty()) |
| 228 return; | 242 return; |
| 229 | 243 |
| 230 std::string option; | 244 std::string option; |
| 231 std::string passphrase; | 245 std::string passphrase; |
| 232 if (!GetFirstPassphrase(json, &option, &passphrase)) { | 246 if (!GetFirstPassphrase(json, &option, &passphrase)) { |
| 233 // Page sent result which couldn't be parsed. Programming error. | 247 // Page sent result which couldn't be parsed. Programming error. |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 | 745 |
| 732 service_->OnUserChoseDatatypes(configuration.sync_everything, | 746 service_->OnUserChoseDatatypes(configuration.sync_everything, |
| 733 configuration.data_types); | 747 configuration.data_types); |
| 734 } | 748 } |
| 735 | 749 |
| 736 void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) { | 750 void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) { |
| 737 Advance(SyncSetupWizard::SETTING_UP); | 751 Advance(SyncSetupWizard::SETTING_UP); |
| 738 service_->SetPassphrase(passphrase, true, false); | 752 service_->SetPassphrase(passphrase, true, false); |
| 739 } | 753 } |
| 740 | 754 |
| 755 void SyncSetupFlow::OnPassphraseCancel() { | |
| 756 // If the user cancels when being asked for the passphrase, | |
| 757 // just disable encrypted sync and continue setting up. | |
| 758 if (current_state_ == SyncSetupWizard::ENTER_PASSPHRASE) | |
| 759 DisablePasswordSync(service_); | |
| 760 | |
| 761 Advance(SyncSetupWizard::SETTING_UP); | |
| 762 } | |
| 763 | |
| 741 void SyncSetupFlow::OnFirstPassphraseEntry(const std::string& option, | 764 void SyncSetupFlow::OnFirstPassphraseEntry(const std::string& option, |
| 742 const std::string& passphrase) { | 765 const std::string& passphrase) { |
| 743 Advance(SyncSetupWizard::SETTING_UP); | 766 Advance(SyncSetupWizard::SETTING_UP); |
| 744 | 767 |
| 745 if (option == "explicit") { | 768 if (option == "explicit") { |
| 746 service_->SetPassphrase(passphrase, true, true); | 769 service_->SetPassphrase(passphrase, true, true); |
| 747 } else if (option == "nothanks") { | 770 } else if (option == "nothanks") { |
| 748 // User opted out of encrypted sync, need to turn off encrypted | 771 // User opted out of encrypted sync, need to turn off encrypted |
| 749 // data types. | 772 // data types. |
| 750 syncable::ModelTypeSet registered_types; | 773 DisablePasswordSync(service_); |
| 751 service_->GetRegisteredDataTypes(®istered_types); | |
| 752 registered_types.erase(syncable::PASSWORDS); | |
| 753 service_->OnUserChoseDatatypes(false, registered_types); | |
| 754 } else if (option == "google") { | 774 } else if (option == "google") { |
| 755 // Implicit passphrase already set up. | 775 // Implicit passphrase already set up. |
| 756 Advance(SyncSetupWizard::DONE); | 776 Advance(SyncSetupWizard::DONE); |
| 757 } | 777 } |
| 758 } | 778 } |
| 759 | 779 |
| 760 void SyncSetupFlow::OnGoToDashboard() { | 780 void SyncSetupFlow::OnGoToDashboard() { |
| 761 BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate(); | 781 BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate(); |
| 762 } | 782 } |
| OLD | NEW |