| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/font_util.h" | 7 #include "app/gfx/font_util.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/renderer_host/render_view_host.h" | 25 #include "chrome/browser/renderer_host/render_view_host.h" |
| 26 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 27 #include "chrome/browser/sync/syncable/model_type.h" | 27 #include "chrome/browser/sync/syncable/model_type.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents.h" | 28 #include "chrome/browser/tab_contents/tab_contents.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "gfx/font.h" | 30 #include "gfx/font.h" |
| 31 #include "grit/locale_settings.h" | 31 #include "grit/locale_settings.h" |
| 32 | 32 |
| 33 // XPath expression for finding specific iframes. | 33 // XPath expression for finding specific iframes. |
| 34 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']"; | 34 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']"; |
| 35 static const wchar_t* kChooseDataTypesIFrameXPath = | |
| 36 L"//iframe[@id='choose_data_types']"; | |
| 37 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; | 35 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; |
| 38 | 36 |
| 39 void FlowHandler::RegisterMessages() { | 37 void FlowHandler::RegisterMessages() { |
| 40 dom_ui_->RegisterMessageCallback("ShowCustomize", | 38 dom_ui_->RegisterMessageCallback("ShowCustomize", |
| 41 NewCallback(this, &FlowHandler::HandleUserClickedCustomize)); | 39 NewCallback(this, &FlowHandler::HandleUserClickedCustomize)); |
| 42 // On OS X, the customize dialog is modal to the HTML window so we | 40 // On OS X, the customize dialog is modal to the HTML window so we |
| 43 // don't need to hook up the two functions below. | 41 // don't need to hook up the two functions below. |
| 44 #if defined(OS_WIN) || defined(OS_LINUX) | 42 #if defined(OS_WIN) || defined(OS_LINUX) |
| 45 dom_ui_->RegisterMessageCallback("ClickCustomizeOk", | 43 dom_ui_->RegisterMessageCallback("ClickCustomizeOk", |
| 46 NewCallback(this, &FlowHandler::ClickCustomizeOk)); | 44 NewCallback(this, &FlowHandler::ClickCustomizeOk)); |
| 47 dom_ui_->RegisterMessageCallback("ClickCustomizeCancel", | 45 dom_ui_->RegisterMessageCallback("ClickCustomizeCancel", |
| 48 NewCallback(this, &FlowHandler::ClickCustomizeCancel)); | 46 NewCallback(this, &FlowHandler::ClickCustomizeCancel)); |
| 49 #endif | 47 #endif |
| 50 dom_ui_->RegisterMessageCallback("SubmitAuth", | 48 dom_ui_->RegisterMessageCallback("SubmitAuth", |
| 51 NewCallback(this, &FlowHandler::HandleSubmitAuth)); | 49 NewCallback(this, &FlowHandler::HandleSubmitAuth)); |
| 52 dom_ui_->RegisterMessageCallback("ChooseDataTypes", | |
| 53 NewCallback(this, &FlowHandler::HandleChooseDataTypes)); | |
| 54 } | 50 } |
| 55 | 51 |
| 56 static bool GetAuthData(const std::string& json, | 52 static bool GetAuthData(const std::string& json, |
| 57 std::string* username, std::string* password, std::string* captcha) { | 53 std::string* username, std::string* password, std::string* captcha) { |
| 58 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 54 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 59 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 55 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 60 return false; | 56 return false; |
| 61 | 57 |
| 62 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 58 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
| 63 if (!result->GetString(L"user", username) || | 59 if (!result->GetString(L"user", username) || |
| 64 !result->GetString(L"pass", password) || | 60 !result->GetString(L"pass", password) || |
| 65 !result->GetString(L"captcha", captcha)) { | 61 !result->GetString(L"captcha", captcha)) { |
| 66 return false; | 62 return false; |
| 67 } | 63 } |
| 68 return true; | 64 return true; |
| 69 } | 65 } |
| 70 | 66 |
| 71 static bool GetDataTypeChoiceData(const std::string& json, | |
| 72 bool* sync_everything, syncable::ModelTypeSet* data_types) { | |
| 73 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | |
| 74 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | |
| 75 return false; | |
| 76 | |
| 77 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | |
| 78 if (!result->GetBoolean(L"keepEverythingSynced", sync_everything)) | |
| 79 return false; | |
| 80 | |
| 81 // These values need to be kept in sync with where they are written in | |
| 82 // choose_datatypes.html. | |
| 83 bool sync_bookmarks; | |
| 84 if (!result->GetBoolean(L"syncBookmarks", &sync_bookmarks)) | |
| 85 return false; | |
| 86 if (sync_bookmarks) | |
| 87 data_types->insert(syncable::BOOKMARKS); | |
| 88 | |
| 89 bool sync_preferences; | |
| 90 if (!result->GetBoolean(L"syncPreferences", &sync_preferences)) | |
| 91 return false; | |
| 92 if (sync_preferences) | |
| 93 data_types->insert(syncable::PREFERENCES); | |
| 94 | |
| 95 bool sync_themes; | |
| 96 if (!result->GetBoolean(L"syncThemes", &sync_themes)) | |
| 97 return false; | |
| 98 if (sync_themes) | |
| 99 data_types->insert(syncable::THEMES); | |
| 100 | |
| 101 bool sync_passwords; | |
| 102 if (!result->GetBoolean(L"syncPasswords", &sync_passwords)) | |
| 103 return false; | |
| 104 if (sync_passwords) | |
| 105 data_types->insert(syncable::PASSWORDS); | |
| 106 | |
| 107 bool sync_autofill; | |
| 108 if (!result->GetBoolean(L"syncAutofill", &sync_autofill)) | |
| 109 return false; | |
| 110 if (sync_autofill) | |
| 111 data_types->insert(syncable::AUTOFILL); | |
| 112 | |
| 113 bool sync_extensions; | |
| 114 if (!result->GetBoolean(L"syncExtensions", &sync_extensions)) | |
| 115 return false; | |
| 116 if (sync_extensions) | |
| 117 data_types->insert(syncable::EXTENSIONS); | |
| 118 | |
| 119 bool sync_typed_urls; | |
| 120 if (!result->GetBoolean(L"syncTypedUrls", &sync_typed_urls)) | |
| 121 return false; | |
| 122 if (sync_typed_urls) | |
| 123 data_types->insert(syncable::TYPED_URLS); | |
| 124 | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 void FlowHandler::HandleUserClickedCustomize(const Value* value) { | 67 void FlowHandler::HandleUserClickedCustomize(const Value* value) { |
| 129 if (flow_) | 68 if (flow_) |
| 130 flow_->OnUserClickedCustomize(); | 69 flow_->OnUserClickedCustomize(); |
| 131 } | 70 } |
| 132 | 71 |
| 133 // To simulate the user clicking "OK" or "Cancel" on the Customize Sync dialog | 72 // To simulate the user clicking "OK" or "Cancel" on the Customize Sync dialog |
| 134 void FlowHandler::ClickCustomizeOk(const Value* value) { | 73 void FlowHandler::ClickCustomizeOk(const Value* value) { |
| 135 if (flow_) | 74 if (flow_) |
| 136 flow_->ClickCustomizeOk(); | 75 flow_->ClickCustomizeOk(); |
| 137 } | 76 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 165 // The page sent us something that we didn't understand. | 104 // The page sent us something that we didn't understand. |
| 166 // This probably indicates a programming error. | 105 // This probably indicates a programming error. |
| 167 NOTREACHED(); | 106 NOTREACHED(); |
| 168 return; | 107 return; |
| 169 } | 108 } |
| 170 | 109 |
| 171 if (flow_) | 110 if (flow_) |
| 172 flow_->OnUserSubmittedAuth(username, password, captcha); | 111 flow_->OnUserSubmittedAuth(username, password, captcha); |
| 173 } | 112 } |
| 174 | 113 |
| 175 | |
| 176 void FlowHandler::HandleChooseDataTypes(const Value* value) { | |
| 177 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(value)); | |
| 178 bool sync_everything; | |
| 179 syncable::ModelTypeSet chosen_types; | |
| 180 if (json.empty()) | |
| 181 return; | |
| 182 | |
| 183 if (!GetDataTypeChoiceData(json, &sync_everything, &chosen_types)) { | |
| 184 // The page sent us something that we didn't understand. | |
| 185 // This probably indicates a programming error. | |
| 186 NOTREACHED(); | |
| 187 return; | |
| 188 } | |
| 189 | |
| 190 DCHECK(flow_); | |
| 191 flow_->OnUserChoseDataTypes(sync_everything, chosen_types); | |
| 192 | |
| 193 return; | |
| 194 } | |
| 195 | |
| 196 // Called by SyncSetupFlow::Advance. | 114 // Called by SyncSetupFlow::Advance. |
| 197 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { | 115 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { |
| 198 // Whenever you start a wizard, you pass in an arg so it starts on the right | |
| 199 // iframe (see setup_flow.html's showTheRightIframe() method). But when you | |
| 200 // transition from one flow to another, you have to explicitly call the JS | |
| 201 // function to show the next iframe. | |
| 202 // So if you ever made a wizard that involved a gaia login as not the first | |
| 203 // frame, this call would be necessary to ensure that this method actually | |
| 204 // shows the gaia login. | |
| 205 if (dom_ui_) | |
| 206 dom_ui_->CallJavascriptFunction(L"showGaiaLoginIframe"); | |
| 207 | |
| 208 std::string json; | 116 std::string json; |
| 209 base::JSONWriter::Write(&args, false, &json); | 117 base::JSONWriter::Write(&args, false, &json); |
| 210 std::wstring javascript = std::wstring(L"showGaiaLogin") + | 118 std::wstring javascript = std::wstring(L"showGaiaLogin") + |
| 211 L"(" + UTF8ToWide(json) + L");"; | 119 L"(" + UTF8ToWide(json) + L");"; |
| 212 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); | 120 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); |
| 213 } | 121 } |
| 214 | 122 |
| 215 void FlowHandler::ShowGaiaSuccessAndClose() { | 123 void FlowHandler::ShowGaiaSuccessAndClose() { |
| 216 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); | 124 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); |
| 217 } | 125 } |
| 218 | 126 |
| 219 void FlowHandler::ShowGaiaSuccessAndSettingUp() { | 127 void FlowHandler::ShowGaiaSuccessAndSettingUp() { |
| 220 ExecuteJavascriptInIFrame(kLoginIFrameXPath, | 128 ExecuteJavascriptInIFrame(kLoginIFrameXPath, |
| 221 L"showGaiaSuccessAndSettingUp();"); | 129 L"showGaiaSuccessAndSettingUp();"); |
| 222 } | 130 } |
| 223 | 131 |
| 224 // Called by SyncSetupFlow::Advance. | |
| 225 void FlowHandler::ShowChooseDataTypes(const DictionaryValue& args) { | |
| 226 | |
| 227 // If you're starting the wizard at the Choose Data Types screen (i.e. from | |
| 228 // "Customize Sync"), this will be redundant. However, if you're coming from | |
| 229 // another wizard state, this will make sure Choose Data Types is on top. | |
| 230 if (dom_ui_) | |
| 231 dom_ui_->CallJavascriptFunction(L"showChooseDataTypes"); | |
| 232 | |
| 233 std::string json; | |
| 234 base::JSONWriter::Write(&args, false, &json); | |
| 235 std::wstring javascript = std::wstring(L"setChooseDataTypesCheckboxes") + | |
| 236 L"(" + UTF8ToWide(json) + L");"; | |
| 237 ExecuteJavascriptInIFrame(kChooseDataTypesIFrameXPath, javascript); | |
| 238 } | |
| 239 | |
| 240 void FlowHandler::ShowSetupDone(const std::wstring& user) { | 132 void FlowHandler::ShowSetupDone(const std::wstring& user) { |
| 241 StringValue synced_to_string(WideToUTF8(l10n_util::GetStringF( | 133 StringValue synced_to_string(WideToUTF8(l10n_util::GetStringF( |
| 242 IDS_SYNC_NTP_SYNCED_TO, user))); | 134 IDS_SYNC_NTP_SYNCED_TO, user))); |
| 243 std::string json; | 135 std::string json; |
| 244 base::JSONWriter::Write(&synced_to_string, false, &json); | 136 base::JSONWriter::Write(&synced_to_string, false, &json); |
| 245 std::wstring javascript = std::wstring(L"setSyncedToUser") + | 137 std::wstring javascript = std::wstring(L"setSyncedToUser") + |
| 246 L"(" + UTF8ToWide(json) + L");"; | 138 L"(" + UTF8ToWide(json) + L");"; |
| 247 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); | 139 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); |
| 248 | 140 |
| 249 if (dom_ui_) | 141 if (dom_ui_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 // Record the state at which the user cancelled the signon dialog. | 222 // Record the state at which the user cancelled the signon dialog. |
| 331 switch (current_state_) { | 223 switch (current_state_) { |
| 332 case SyncSetupWizard::GAIA_LOGIN: | 224 case SyncSetupWizard::GAIA_LOGIN: |
| 333 ProfileSyncService::SyncEvent( | 225 ProfileSyncService::SyncEvent( |
| 334 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 226 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
| 335 break; | 227 break; |
| 336 case SyncSetupWizard::GAIA_SUCCESS: | 228 case SyncSetupWizard::GAIA_SUCCESS: |
| 337 ProfileSyncService::SyncEvent( | 229 ProfileSyncService::SyncEvent( |
| 338 ProfileSyncService::CANCEL_DURING_SIGNON); | 230 ProfileSyncService::CANCEL_DURING_SIGNON); |
| 339 break; | 231 break; |
| 340 case SyncSetupWizard::CHOOSE_DATA_TYPES: | |
| 341 ProfileSyncService::SyncEvent( | |
| 342 ProfileSyncService::CANCEL_FROM_CHOOSE_DATA_TYPES); | |
| 343 case SyncSetupWizard::DONE_FIRST_TIME: | 232 case SyncSetupWizard::DONE_FIRST_TIME: |
| 344 case SyncSetupWizard::DONE: | 233 case SyncSetupWizard::DONE: |
| 345 // TODO(sync): rename this histogram; it's tracking authorization AND | |
| 346 // initial sync download time. | |
| 347 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", | 234 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", |
| 348 base::TimeTicks::Now() - login_start_time_); | 235 base::TimeTicks::Now() - login_start_time_); |
| 349 break; | 236 break; |
| 350 default: | 237 default: |
| 351 break; | 238 break; |
| 352 } | 239 } |
| 353 | 240 |
| 354 service_->OnUserCancelledDialog(); | 241 service_->OnUserCancelledDialog(); |
| 355 delete this; | 242 delete this; |
| 356 } | 243 } |
| 357 | 244 |
| 358 // static | 245 // static |
| 359 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, | 246 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, |
| 360 DictionaryValue* args) { | 247 DictionaryValue* args) { |
| 361 args->SetString(L"iframeToShow", "login"); | |
| 362 const GoogleServiceAuthError& error = service->GetAuthError(); | 248 const GoogleServiceAuthError& error = service->GetAuthError(); |
| 363 if (!service->last_attempted_user_email().empty()) { | 249 if (!service->last_attempted_user_email().empty()) { |
| 364 args->SetString(L"user", service->last_attempted_user_email()); | 250 args->SetString(L"user", service->last_attempted_user_email()); |
| 365 args->SetInteger(L"error", error.state()); | 251 args->SetInteger(L"error", error.state()); |
| 366 } else { | 252 } else { |
| 367 std::wstring user(UTF16ToWide(service->GetAuthenticatedUsername())); | 253 std::wstring user(UTF16ToWide(service->GetAuthenticatedUsername())); |
| 368 args->SetString(L"user", user); | 254 args->SetString(L"user", user); |
| 369 args->SetInteger(L"error", user.empty() ? 0 : error.state()); | 255 args->SetInteger(L"error", user.empty() ? 0 : error.state()); |
| 370 } | 256 } |
| 371 | 257 |
| 372 args->SetString(L"captchaUrl", error.captcha().image_url.spec()); | 258 args->SetString(L"captchaUrl", error.captcha().image_url.spec()); |
| 373 | 259 |
| 374 args->SetBoolean(L"showCustomize", true); | 260 args->SetBoolean(L"showCustomize", true); |
| 375 } | 261 } |
| 376 | 262 |
| 377 // static | |
| 378 void SyncSetupFlow::GetArgsForChooseDataTypes(ProfileSyncService* service, | |
| 379 DictionaryValue* args) { | |
| 380 args->SetString(L"iframeToShow", "choose_data_types"); | |
| 381 args->SetBoolean(L"keepEverythingSynced", | |
| 382 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); | |
| 383 | |
| 384 // Bookmarks, Preferences, and Themes are launched for good, there's no | |
| 385 // going back now. Check if the other data types are registered though. | |
| 386 syncable::ModelTypeSet registered_types; | |
| 387 service->GetRegisteredDataTypes(®istered_types); | |
| 388 args->SetBoolean(L"passwordsRegistered", | |
| 389 registered_types.count(syncable::PASSWORDS) > 0); | |
| 390 args->SetBoolean(L"autofillRegistered", | |
| 391 registered_types.count(syncable::AUTOFILL) > 0); | |
| 392 args->SetBoolean(L"extensionsRegistered", | |
| 393 registered_types.count(syncable::EXTENSIONS) > 0); | |
| 394 args->SetBoolean(L"typedUrlsRegistered", | |
| 395 registered_types.count(syncable::TYPED_URLS) > 0); | |
| 396 | |
| 397 args->SetBoolean(L"syncBookmarks", | |
| 398 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncBookmarks)); | |
| 399 args->SetBoolean(L"syncPreferences", | |
| 400 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPreferences)); | |
| 401 args->SetBoolean(L"syncThemes", | |
| 402 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncThemes)); | |
| 403 args->SetBoolean(L"syncPasswords", | |
| 404 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPasswords)); | |
| 405 args->SetBoolean(L"syncAutofill", | |
| 406 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); | |
| 407 args->SetBoolean(L"syncExtensions", | |
| 408 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); | |
| 409 args->SetBoolean(L"syncTypedUrls", | |
| 410 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); | |
| 411 } | |
| 412 | |
| 413 void SyncSetupFlow::GetDOMMessageHandlers( | 263 void SyncSetupFlow::GetDOMMessageHandlers( |
| 414 std::vector<DOMMessageHandler*>* handlers) const { | 264 std::vector<DOMMessageHandler*>* handlers) const { |
| 415 handlers->push_back(flow_handler_); | 265 handlers->push_back(flow_handler_); |
| 416 // We don't own flow_handler_ anymore, but it sticks around until at least | 266 // We don't own flow_handler_ anymore, but it sticks around until at least |
| 417 // right after OnDialogClosed() is called (and this object is destroyed). | 267 // right after OnDialogClosed() is called (and this object is destroyed). |
| 418 owns_flow_handler_ = false; | 268 owns_flow_handler_ = false; |
| 419 } | 269 } |
| 420 | 270 |
| 421 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { | 271 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { |
| 422 switch (state) { | 272 switch (state) { |
| 423 case SyncSetupWizard::GAIA_LOGIN: | 273 case SyncSetupWizard::GAIA_LOGIN: |
| 424 return current_state_ == SyncSetupWizard::FATAL_ERROR || | 274 return current_state_ == SyncSetupWizard::GAIA_LOGIN; |
| 425 current_state_ == SyncSetupWizard::GAIA_LOGIN; | |
| 426 case SyncSetupWizard::GAIA_SUCCESS: | 275 case SyncSetupWizard::GAIA_SUCCESS: |
| 427 return current_state_ == SyncSetupWizard::GAIA_LOGIN; | 276 return current_state_ == SyncSetupWizard::GAIA_LOGIN; |
| 428 case SyncSetupWizard::CHOOSE_DATA_TYPES: | |
| 429 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; | |
| 430 case SyncSetupWizard::FATAL_ERROR: | 277 case SyncSetupWizard::FATAL_ERROR: |
| 431 return true; // You can always hit the panic button. | 278 return true; // You can always hit the panic button. |
| 432 case SyncSetupWizard::DONE_FIRST_TIME: | 279 case SyncSetupWizard::DONE_FIRST_TIME: |
| 433 case SyncSetupWizard::DONE: | 280 case SyncSetupWizard::DONE: |
| 434 return current_state_ == SyncSetupWizard::CHOOSE_DATA_TYPES; | 281 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; |
| 435 default: | 282 default: |
| 436 NOTREACHED() << "Unhandled State: " << state; | 283 NOTREACHED() << "Unhandled State: " << state; |
| 437 return false; | 284 return false; |
| 438 } | 285 } |
| 439 } | 286 } |
| 440 | 287 |
| 441 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { | 288 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { |
| 442 if (!ShouldAdvance(advance_state)) | 289 if (!ShouldAdvance(advance_state)) |
| 443 return; | 290 return; |
| 444 | |
| 445 switch (advance_state) { | 291 switch (advance_state) { |
| 446 case SyncSetupWizard::GAIA_LOGIN: { | 292 case SyncSetupWizard::GAIA_LOGIN: { |
| 447 DictionaryValue args; | 293 DictionaryValue args; |
| 448 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 294 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
| 449 flow_handler_->ShowGaiaLogin(args); | 295 flow_handler_->ShowGaiaLogin(args); |
| 450 break; | 296 break; |
| 451 } | 297 } |
| 452 case SyncSetupWizard::GAIA_SUCCESS: | 298 case SyncSetupWizard::GAIA_SUCCESS: |
| 453 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { | 299 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) |
| 454 flow_handler_->ShowGaiaSuccessAndClose(); | 300 flow_handler_->ShowGaiaSuccessAndClose(); |
| 455 break; | 301 else |
| 456 } | 302 flow_handler_->ShowGaiaSuccessAndSettingUp(); |
| 457 advance_state = SyncSetupWizard::CHOOSE_DATA_TYPES; | |
| 458 // Fall through. | |
| 459 case SyncSetupWizard::CHOOSE_DATA_TYPES: { | |
| 460 DictionaryValue args; | |
| 461 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); | |
| 462 flow_handler_->ShowChooseDataTypes(args); | |
| 463 break; | 303 break; |
| 464 } | |
| 465 case SyncSetupWizard::FATAL_ERROR: { | 304 case SyncSetupWizard::FATAL_ERROR: { |
| 466 // This shows the user the "Could not connect to server" error. | 305 // This shows the user the "Could not connect to server" error. |
| 467 // TODO(sync): Update this error messaging. | 306 // TODO(sync): Update this error messaging. |
| 468 DictionaryValue args; | 307 DictionaryValue args; |
| 469 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 308 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
| 470 args.SetInteger(L"error", GoogleServiceAuthError::CONNECTION_FAILED); | 309 args.SetInteger(L"error", GoogleServiceAuthError::CONNECTION_FAILED); |
| 471 flow_handler_->ShowGaiaLogin(args); | 310 flow_handler_->ShowGaiaLogin(args); |
| 472 break; | 311 break; |
| 473 } | 312 } |
| 474 case SyncSetupWizard::DONE_FIRST_TIME: | 313 case SyncSetupWizard::DONE_FIRST_TIME: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 499 } | 338 } |
| 500 | 339 |
| 501 // static | 340 // static |
| 502 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, | 341 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, |
| 503 SyncSetupFlowContainer* container, | 342 SyncSetupFlowContainer* container, |
| 504 SyncSetupWizard::State start, | 343 SyncSetupWizard::State start, |
| 505 SyncSetupWizard::State end) { | 344 SyncSetupWizard::State end) { |
| 506 DictionaryValue args; | 345 DictionaryValue args; |
| 507 if (start == SyncSetupWizard::GAIA_LOGIN) | 346 if (start == SyncSetupWizard::GAIA_LOGIN) |
| 508 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 347 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
| 509 else if (start == SyncSetupWizard::CHOOSE_DATA_TYPES) | |
| 510 SyncSetupFlow::GetArgsForChooseDataTypes(service, &args); | |
| 511 std::string json_args; | 348 std::string json_args; |
| 512 base::JSONWriter::Write(&args, false, &json_args); | 349 base::JSONWriter::Write(&args, false, &json_args); |
| 513 | 350 |
| 514 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, | 351 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, |
| 515 container, service); | 352 container, service); |
| 516 #if defined(OS_MACOSX) | 353 #if defined(OS_MACOSX) |
| 517 // TODO(akalin): Figure out a cleaner way to do this than to have this | 354 // TODO(akalin): Figure out a cleaner way to do this than to have this |
| 518 // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() | 355 // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() |
| 519 // function that is not tied to a browser instance. Note that if we do | 356 // function that is not tied to a browser instance. Note that if we do |
| 520 // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on | 357 // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on |
| 521 // being able to intercept ShowHtmlDialog() calls. | 358 // being able to intercept ShowHtmlDialog() calls. |
| 522 flow->html_dialog_window_ = | 359 flow->html_dialog_window_ = |
| 523 html_dialog_window_controller::ShowHtmlDialog( | 360 html_dialog_window_controller::ShowHtmlDialog( |
| 524 flow, service->profile()); | 361 flow, service->profile()); |
| 525 #else | 362 #else |
| 526 Browser* b = BrowserList::GetLastActive(); | 363 Browser* b = BrowserList::GetLastActive(); |
| 527 if (b) { | 364 if (b) { |
| 528 b->BrowserShowHtmlDialog(flow, NULL); | 365 b->BrowserShowHtmlDialog(flow, NULL); |
| 529 } else { | 366 } else { |
| 530 delete flow; | 367 delete flow; |
| 531 return NULL; | 368 return NULL; |
| 532 } | 369 } |
| 533 #endif // defined(OS_MACOSX) | 370 #endif // defined(OS_MACOSX) |
| 534 return flow; | 371 return flow; |
| 535 } | 372 } |
| OLD | NEW |