| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/people_handler.h" | 5 #include "chrome/browser/ui/webui/settings/people_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 configuring_sync_ = true; | 317 configuring_sync_ = true; |
| 318 | 318 |
| 319 const int kTimeoutSec = 30; | 319 const int kTimeoutSec = 30; |
| 320 DCHECK(!engine_start_timer_); | 320 DCHECK(!engine_start_timer_); |
| 321 engine_start_timer_.reset(new base::OneShotTimer()); | 321 engine_start_timer_.reset(new base::OneShotTimer()); |
| 322 engine_start_timer_->Start(FROM_HERE, | 322 engine_start_timer_->Start(FROM_HERE, |
| 323 base::TimeDelta::FromSeconds(kTimeoutSec), this, | 323 base::TimeDelta::FromSeconds(kTimeoutSec), this, |
| 324 &PeopleHandler::DisplayTimeout); | 324 &PeopleHandler::DisplayTimeout); |
| 325 | 325 |
| 326 CallJavascriptFunction("cr.webUIListenerCallback", | 326 CallJavascriptFunction("cr.webUIListenerCallback", |
| 327 base::StringValue("page-status-changed"), | 327 base::Value("page-status-changed"), |
| 328 base::StringValue(kSpinnerPageStatus)); | 328 base::Value(kSpinnerPageStatus)); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void PeopleHandler::DisplayTimeout() { | 331 void PeopleHandler::DisplayTimeout() { |
| 332 // Stop a timer to handle timeout in waiting for checking network connection. | 332 // Stop a timer to handle timeout in waiting for checking network connection. |
| 333 engine_start_timer_.reset(); | 333 engine_start_timer_.reset(); |
| 334 | 334 |
| 335 // Do not listen to sync startup events. | 335 // Do not listen to sync startup events. |
| 336 sync_startup_tracker_.reset(); | 336 sync_startup_tracker_.reset(); |
| 337 | 337 |
| 338 CallJavascriptFunction("cr.webUIListenerCallback", | 338 CallJavascriptFunction("cr.webUIListenerCallback", |
| 339 base::StringValue("page-status-changed"), | 339 base::Value("page-status-changed"), |
| 340 base::StringValue(kTimeoutPageStatus)); | 340 base::Value(kTimeoutPageStatus)); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void PeopleHandler::OnDidClosePage(const base::ListValue* args) { | 343 void PeopleHandler::OnDidClosePage(const base::ListValue* args) { |
| 344 MarkFirstSetupComplete(); | 344 MarkFirstSetupComplete(); |
| 345 CloseSyncSetup(); | 345 CloseSyncSetup(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void PeopleHandler::SyncStartupFailed() { | 348 void PeopleHandler::SyncStartupFailed() { |
| 349 // Stop a timer to handle timeout in waiting for checking network connection. | 349 // Stop a timer to handle timeout in waiting for checking network connection. |
| 350 engine_start_timer_.reset(); | 350 engine_start_timer_.reset(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 configuration.payments_integration_enabled); | 384 configuration.payments_integration_enabled); |
| 385 | 385 |
| 386 // Start configuring the ProfileSyncService using the configuration passed | 386 // Start configuring the ProfileSyncService using the configuration passed |
| 387 // to us from the JS layer. | 387 // to us from the JS layer. |
| 388 ProfileSyncService* service = GetSyncService(); | 388 ProfileSyncService* service = GetSyncService(); |
| 389 | 389 |
| 390 // If the sync engine has shutdown for some reason, just close the sync | 390 // If the sync engine has shutdown for some reason, just close the sync |
| 391 // dialog. | 391 // dialog. |
| 392 if (!service || !service->IsEngineInitialized()) { | 392 if (!service || !service->IsEngineInitialized()) { |
| 393 CloseSyncSetup(); | 393 CloseSyncSetup(); |
| 394 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); | 394 ResolveJavascriptCallback(*callback_id, base::Value(kDonePageStatus)); |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 | 397 |
| 398 service->OnUserChoseDatatypes(configuration.sync_everything, | 398 service->OnUserChoseDatatypes(configuration.sync_everything, |
| 399 configuration.data_types); | 399 configuration.data_types); |
| 400 | 400 |
| 401 // Choosing data types to sync never fails. | 401 // Choosing data types to sync never fails. |
| 402 ResolveJavascriptCallback(*callback_id, | 402 ResolveJavascriptCallback(*callback_id, base::Value(kConfigurePageStatus)); |
| 403 base::StringValue(kConfigurePageStatus)); | |
| 404 | 403 |
| 405 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); | 404 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); |
| 406 if (!configuration.sync_everything) | 405 if (!configuration.sync_everything) |
| 407 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); | 406 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); |
| 408 } | 407 } |
| 409 | 408 |
| 410 void PeopleHandler::HandleSetEncryption(const base::ListValue* args) { | 409 void PeopleHandler::HandleSetEncryption(const base::ListValue* args) { |
| 411 DCHECK(!sync_startup_tracker_); | 410 DCHECK(!sync_startup_tracker_); |
| 412 | 411 |
| 413 SyncConfigInfo configuration; | 412 SyncConfigInfo configuration; |
| 414 const base::Value* callback_id = nullptr; | 413 const base::Value* callback_id = nullptr; |
| 415 ParseConfigurationArguments(args, &configuration, &callback_id); | 414 ParseConfigurationArguments(args, &configuration, &callback_id); |
| 416 | 415 |
| 417 // Start configuring the ProfileSyncService using the configuration passed | 416 // Start configuring the ProfileSyncService using the configuration passed |
| 418 // to us from the JS layer. | 417 // to us from the JS layer. |
| 419 ProfileSyncService* service = GetSyncService(); | 418 ProfileSyncService* service = GetSyncService(); |
| 420 | 419 |
| 421 // If the sync engine has shutdown for some reason, just close the sync | 420 // If the sync engine has shutdown for some reason, just close the sync |
| 422 // dialog. | 421 // dialog. |
| 423 if (!service || !service->IsEngineInitialized()) { | 422 if (!service || !service->IsEngineInitialized()) { |
| 424 CloseSyncSetup(); | 423 CloseSyncSetup(); |
| 425 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); | 424 ResolveJavascriptCallback(*callback_id, base::Value(kDonePageStatus)); |
| 426 return; | 425 return; |
| 427 } | 426 } |
| 428 | 427 |
| 429 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it. | 428 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it. |
| 430 // The UI is hidden, but the user may have enabled it e.g. by fiddling with | 429 // The UI is hidden, but the user may have enabled it e.g. by fiddling with |
| 431 // the web inspector. | 430 // the web inspector. |
| 432 if (!service->IsEncryptEverythingAllowed()) | 431 if (!service->IsEncryptEverythingAllowed()) |
| 433 configuration.encrypt_all = false; | 432 configuration.encrypt_all = false; |
| 434 | 433 |
| 435 // Note: Data encryption will not occur until configuration is complete | 434 // Note: Data encryption will not occur until configuration is complete |
| (...skipping 30 matching lines...) Expand all Loading... |
| 466 | 465 |
| 467 if (passphrase_failed || service->IsPassphraseRequiredForDecryption()) { | 466 if (passphrase_failed || service->IsPassphraseRequiredForDecryption()) { |
| 468 // If the user doesn't enter any passphrase, we won't call | 467 // If the user doesn't enter any passphrase, we won't call |
| 469 // SetDecryptionPassphrase() (passphrase_failed == false), but we still | 468 // SetDecryptionPassphrase() (passphrase_failed == false), but we still |
| 470 // want to display an error message to let the user know that their blank | 469 // want to display an error message to let the user know that their blank |
| 471 // passphrase entry is not acceptable. | 470 // passphrase entry is not acceptable. |
| 472 | 471 |
| 473 // TODO(tommycli): Switch this to RejectJavascriptCallback once the | 472 // TODO(tommycli): Switch this to RejectJavascriptCallback once the |
| 474 // Sync page JavaScript has been further refactored. | 473 // Sync page JavaScript has been further refactored. |
| 475 ResolveJavascriptCallback(*callback_id, | 474 ResolveJavascriptCallback(*callback_id, |
| 476 base::StringValue(kPassphraseFailedPageStatus)); | 475 base::Value(kPassphraseFailedPageStatus)); |
| 477 } else { | 476 } else { |
| 478 ResolveJavascriptCallback(*callback_id, | 477 ResolveJavascriptCallback(*callback_id, base::Value(kConfigurePageStatus)); |
| 479 base::StringValue(kConfigurePageStatus)); | |
| 480 } | 478 } |
| 481 | 479 |
| 482 if (configuration.encrypt_all) | 480 if (configuration.encrypt_all) |
| 483 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); | 481 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); |
| 484 if (!configuration.set_new_passphrase && !configuration.passphrase.empty()) | 482 if (!configuration.set_new_passphrase && !configuration.passphrase.empty()) |
| 485 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); | 483 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); |
| 486 } | 484 } |
| 487 | 485 |
| 488 void PeopleHandler::HandleShowSetupUI(const base::ListValue* args) { | 486 void PeopleHandler::HandleShowSetupUI(const base::ListValue* args) { |
| 489 AllowJavascript(); | 487 AllowJavascript(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 } | 689 } |
| 692 | 690 |
| 693 void PeopleHandler::FocusUI() { | 691 void PeopleHandler::FocusUI() { |
| 694 WebContents* web_contents = web_ui()->GetWebContents(); | 692 WebContents* web_contents = web_ui()->GetWebContents(); |
| 695 web_contents->GetDelegate()->ActivateContents(web_contents); | 693 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 696 } | 694 } |
| 697 | 695 |
| 698 void PeopleHandler::CloseUI() { | 696 void PeopleHandler::CloseUI() { |
| 699 CloseSyncSetup(); | 697 CloseSyncSetup(); |
| 700 CallJavascriptFunction("cr.webUIListenerCallback", | 698 CallJavascriptFunction("cr.webUIListenerCallback", |
| 701 base::StringValue("page-status-changed"), | 699 base::Value("page-status-changed"), |
| 702 base::StringValue(kDonePageStatus)); | 700 base::Value(kDonePageStatus)); |
| 703 } | 701 } |
| 704 | 702 |
| 705 void PeopleHandler::GoogleSigninSucceeded(const std::string& /* account_id */, | 703 void PeopleHandler::GoogleSigninSucceeded(const std::string& /* account_id */, |
| 706 const std::string& /* username */, | 704 const std::string& /* username */, |
| 707 const std::string& /* password */) { | 705 const std::string& /* password */) { |
| 708 UpdateSyncStatus(); | 706 UpdateSyncStatus(); |
| 709 } | 707 } |
| 710 | 708 |
| 711 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */, | 709 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */, |
| 712 const std::string& /* username */) { | 710 const std::string& /* username */) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 args.SetString("fullEncryptionBody", | 879 args.SetString("fullEncryptionBody", |
| 882 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM)); | 880 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM)); |
| 883 break; | 881 break; |
| 884 } | 882 } |
| 885 } else if (passphrase_type == syncer::PassphraseType::CUSTOM_PASSPHRASE) { | 883 } else if (passphrase_type == syncer::PassphraseType::CUSTOM_PASSPHRASE) { |
| 886 args.SetString("fullEncryptionBody", | 884 args.SetString("fullEncryptionBody", |
| 887 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM)); | 885 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM)); |
| 888 } | 886 } |
| 889 | 887 |
| 890 CallJavascriptFunction("cr.webUIListenerCallback", | 888 CallJavascriptFunction("cr.webUIListenerCallback", |
| 891 base::StringValue("sync-prefs-changed"), args); | 889 base::Value("sync-prefs-changed"), args); |
| 892 } | 890 } |
| 893 | 891 |
| 894 LoginUIService* PeopleHandler::GetLoginUIService() const { | 892 LoginUIService* PeopleHandler::GetLoginUIService() const { |
| 895 return LoginUIServiceFactory::GetForProfile(profile_); | 893 return LoginUIServiceFactory::GetForProfile(profile_); |
| 896 } | 894 } |
| 897 | 895 |
| 898 void PeopleHandler::UpdateSyncStatus() { | 896 void PeopleHandler::UpdateSyncStatus() { |
| 899 CallJavascriptFunction("cr.webUIListenerCallback", | 897 CallJavascriptFunction("cr.webUIListenerCallback", |
| 900 base::StringValue("sync-status-changed"), | 898 base::Value("sync-status-changed"), |
| 901 *GetSyncStatusDictionary()); | 899 *GetSyncStatusDictionary()); |
| 902 } | 900 } |
| 903 | 901 |
| 904 void PeopleHandler::MarkFirstSetupComplete() { | 902 void PeopleHandler::MarkFirstSetupComplete() { |
| 905 // Suppress the sign in promo once the user starts sync. This way the user | 903 // Suppress the sign in promo once the user starts sync. This way the user |
| 906 // doesn't see the sign in promo even if they sign out later on. | 904 // doesn't see the sign in promo even if they sign out later on. |
| 907 signin::SetUserSkippedPromo(profile_); | 905 signin::SetUserSkippedPromo(profile_); |
| 908 | 906 |
| 909 ProfileSyncService* service = GetSyncService(); | 907 ProfileSyncService* service = GetSyncService(); |
| 910 // The sync service may be nullptr if it has been just disabled by policy. | 908 // The sync service may be nullptr if it has been just disabled by policy. |
| 911 if (!service || service->IsFirstSetupComplete()) | 909 if (!service || service->IsFirstSetupComplete()) |
| 912 return; | 910 return; |
| 913 | 911 |
| 914 // This is the first time configuring sync, so log it. | 912 // This is the first time configuring sync, so log it. |
| 915 base::FilePath profile_file_path = profile_->GetPath(); | 913 base::FilePath profile_file_path = profile_->GetPath(); |
| 916 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 914 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 917 | 915 |
| 918 // We're done configuring, so notify ProfileSyncService that it is OK to | 916 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 919 // start syncing. | 917 // start syncing. |
| 920 sync_blocker_.reset(); | 918 sync_blocker_.reset(); |
| 921 service->SetFirstSetupComplete(); | 919 service->SetFirstSetupComplete(); |
| 922 } | 920 } |
| 923 | 921 |
| 924 } // namespace settings | 922 } // namespace settings |
| OLD | NEW |