Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 base::UTF8ToUTF16(overlapping_extension->name())))); 620 base::UTF8ToUTF16(overlapping_extension->name()))));
621 return; 621 return;
622 } 622 }
623 623
624 current_version_ = base::Version(ExtensionPrefs::Get(service->profile()) 624 current_version_ = base::Version(ExtensionPrefs::Get(service->profile())
625 ->GetVersionString(extension()->id())); 625 ->GetVersionString(extension()->id()));
626 626
627 if (client_ && 627 if (client_ &&
628 (!allow_silent_install_ || !approved_) && 628 (!allow_silent_install_ || !approved_) &&
629 !update_from_settings_page_) { 629 !update_from_settings_page_) {
630 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). 630 AddRef(); // Balanced in OnInstallPromptDone().
631 client_->ShowDialog(this, extension(), nullptr, show_dialog_callback_); 631 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this),
632 extension(), nullptr, show_dialog_callback_);
632 } else { 633 } else {
633 if (!installer_task_runner_->PostTask( 634 if (!installer_task_runner_->PostTask(
634 FROM_HERE, 635 FROM_HERE,
635 base::Bind(&CrxInstaller::CompleteInstall, this))) 636 base::Bind(&CrxInstaller::CompleteInstall, this)))
636 NOTREACHED(); 637 NOTREACHED();
637 } 638 }
638 return; 639 return;
639 } 640 }
640 641
641 void CrxInstaller::InstallUIProceed() { 642 void CrxInstaller::OnInstallPromptDone(ExtensionInstallPrompt::Result result) {
642 DCHECK_CURRENTLY_ON(BrowserThread::UI); 643 DCHECK_CURRENTLY_ON(BrowserThread::UI);
643 644
644 ExtensionService* service = service_weak_.get();
645 if (!service || service->browser_terminating())
646 return;
647
648 // If update_from_settings_page_ boolean is true, this functions is 645 // If update_from_settings_page_ boolean is true, this functions is
649 // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() 646 // getting called in response to ExtensionInstallPrompt::ConfirmReEnable()
650 // and if it is false, this function is called in response to 647 // and if it is false, this function is called in response to
651 // ExtensionInstallPrompt::ShowDialog(). 648 // ExtensionInstallPrompt::ShowDialog().
652 if (update_from_settings_page_) { 649 if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
653 service->GrantPermissionsAndEnableExtension(extension()); 650 ExtensionService* service = service_weak_.get();
654 } else { 651 if (!service || service->browser_terminating())
655 if (!installer_task_runner_->PostTask( 652 return;
656 FROM_HERE, 653
657 base::Bind(&CrxInstaller::CompleteInstall, this))) 654 if (update_from_settings_page_) {
655 service->GrantPermissionsAndEnableExtension(extension());
656 } else if (!installer_task_runner_->PostTask(
657 FROM_HERE,
658 base::Bind(&CrxInstaller::CompleteInstall, this))) {
658 NOTREACHED(); 659 NOTREACHED();
659 } 660 }
660 661 } else if (!update_from_settings_page_) {
661 Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). 662 const char* histogram_name =
662 } 663 result == ExtensionInstallPrompt::Result::USER_CANCELED
663 664 ? "InstallCancel"
664 void CrxInstaller::InstallUIAbort(bool user_initiated) { 665 : "InstallAbort";
665 // If update_from_settings_page_ boolean is true, this functions is
666 // getting called in response to ExtensionInstallPrompt::ConfirmReEnable()
667 // and if it is false, this function is called in response to
668 // ExtensionInstallPrompt::ShowDialog().
669 if (!update_from_settings_page_) {
670 const char* histogram_name = user_initiated ? "InstallCancel"
671 : "InstallAbort";
672 ExtensionService::RecordPermissionMessagesHistogram( 666 ExtensionService::RecordPermissionMessagesHistogram(
673 extension(), histogram_name); 667 extension(), histogram_name);
674 668
675 NotifyCrxInstallComplete(false); 669 NotifyCrxInstallComplete(false);
676 } 670 }
677 671
678 Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). 672 Release(); // balanced in ConfirmInstall() or ConfirmReEnable().
679
680 // We're done. Since we don't post any more tasks to ourself, our ref count
681 // should go to zero and we die. The destructor will clean up the temp dir.
682 } 673 }
683 674
684 void CrxInstaller::CompleteInstall() { 675 void CrxInstaller::CompleteInstall() {
685 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); 676 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread());
686 677
687 if (current_version_.IsValid() && 678 if (current_version_.IsValid() &&
688 current_version_.CompareTo(*(extension()->version())) > 0) { 679 current_version_.CompareTo(*(extension()->version())) > 0) {
689 ReportFailureFromFileThread(CrxInstallError( 680 ReportFailureFromFileThread(CrxInstallError(
690 CrxInstallError::ERROR_DECLINED, 681 CrxInstallError::ERROR_DECLINED,
691 l10n_util::GetStringUTF16( 682 l10n_util::GetStringUTF16(
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 return; 896 return;
906 897
907 if (!update_from_settings_page_) 898 if (!update_from_settings_page_)
908 return; 899 return;
909 900
910 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); 901 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile());
911 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) 902 if (!prefs->DidExtensionEscalatePermissions(extension()->id()))
912 return; 903 return;
913 904
914 if (client_) { 905 if (client_) {
915 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). 906 AddRef(); // Balanced in OnInstallPromptDone().
916 ExtensionInstallPrompt::PromptType type = 907 ExtensionInstallPrompt::PromptType type =
917 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( 908 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
918 service->profile(), extension()); 909 service->profile(), extension());
919 client_->ShowDialog( 910 client_->ShowDialog(
920 this, extension(), nullptr, 911 base::Bind(&CrxInstaller::OnInstallPromptDone, this), extension(),
921 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), 912 nullptr, make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)),
922 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 913 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
923 } 914 }
924 } 915 }
925 916
926 } // namespace extensions 917 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698