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

Unified Diff: chrome/browser/extensions/navigation_observer.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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/navigation_observer.h ('k') | chrome/browser/extensions/unpacked_installer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/navigation_observer.cc
diff --git a/chrome/browser/extensions/navigation_observer.cc b/chrome/browser/extensions/navigation_observer.cc
index a775583626b6b48e299bc86ff5cd1fcd9cd8aa2f..f865ece62d5805eb98a9f77b8afbb5b561af415d 100644
--- a/chrome/browser/extensions/navigation_observer.cc
+++ b/chrome/browser/extensions/navigation_observer.cc
@@ -19,7 +19,8 @@ using content::NavigationEntry;
namespace extensions {
-NavigationObserver::NavigationObserver(Profile* profile) : profile_(profile) {
+NavigationObserver::NavigationObserver(Profile* profile)
+ : profile_(profile), weak_factory_(this) {
RegisterForNotifications();
}
@@ -72,7 +73,7 @@ void NavigationObserver::PromptToEnableExtensionIfNecessary(
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
if (extension_prefs->DidExtensionEscalatePermissions(extension->id())) {
// Keep track of the extension id and nav controller we're prompting for.
- // These must be reset in InstallUIProceed and InstallUIAbort.
+ // These must be reset in OnInstallPromptDone.
in_progress_prompt_extension_id_ = extension->id();
in_progress_prompt_navigation_controller_ = nav_controller;
@@ -82,45 +83,42 @@ void NavigationObserver::PromptToEnableExtensionIfNecessary(
ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(profile_,
extension);
extension_install_prompt_->ShowDialog(
- this, extension, nullptr,
+ base::Bind(&NavigationObserver::OnInstallPromptDone,
+ weak_factory_.GetWeakPtr()),
+ extension, nullptr,
make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)),
ExtensionInstallPrompt::GetDefaultShowDialogCallback());
}
}
-void NavigationObserver::InstallUIProceed() {
+void NavigationObserver::OnInstallPromptDone(
+ ExtensionInstallPrompt::Result result) {
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
const Extension* extension = extension_service->GetExtensionById(
in_progress_prompt_extension_id_, true);
- NavigationController* nav_controller =
- in_progress_prompt_navigation_controller_;
- CHECK(extension);
- CHECK(nav_controller);
- in_progress_prompt_extension_id_ = "";
- in_progress_prompt_navigation_controller_ = NULL;
- extension_install_prompt_.reset();
-
- // Grant permissions, re-enable the extension, and then reload the tab.
- extension_service->GrantPermissionsAndEnableExtension(extension);
- nav_controller->Reload(true);
-}
-
-void NavigationObserver::InstallUIAbort(bool user_initiated) {
- ExtensionService* extension_service =
- extensions::ExtensionSystem::Get(profile_)->extension_service();
- const Extension* extension = extension_service->GetExtensionById(
- in_progress_prompt_extension_id_, true);
+ if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
+ NavigationController* nav_controller =
+ in_progress_prompt_navigation_controller_;
+ CHECK(extension);
+ CHECK(nav_controller);
+
+ // Grant permissions, re-enable the extension, and then reload the tab.
+ extension_service->GrantPermissionsAndEnableExtension(extension);
+ nav_controller->Reload(true);
+ } else {
+ std::string histogram_name =
+ result == ExtensionInstallPrompt::Result::USER_CANCELED
+ ? "ReEnableCancel"
+ : "ReEnableAbort";
+ ExtensionService::RecordPermissionMessagesHistogram(extension,
+ histogram_name.c_str());
+ }
- in_progress_prompt_extension_id_ = "";
- in_progress_prompt_navigation_controller_ = NULL;
+ in_progress_prompt_extension_id_ = std::string();
+ in_progress_prompt_navigation_controller_ = nullptr;
extension_install_prompt_.reset();
-
- std::string histogram_name = user_initiated ? "ReEnableCancel"
- : "ReEnableAbort";
- ExtensionService::RecordPermissionMessagesHistogram(
- extension, histogram_name.c_str());
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/navigation_observer.h ('k') | chrome/browser/extensions/unpacked_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698