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

Unified Diff: chrome/browser/extensions/extension_disabled_ui.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/crx_installer.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_disabled_ui.cc
diff --git a/chrome/browser/extensions/extension_disabled_ui.cc b/chrome/browser/extensions/extension_disabled_ui.cc
index 80fdb73d1e7b2d044511f0e59f11c1842dc2fc51..4b9795ae7918f9261d02c9ec59f6f2d8a01a2d1f 100644
--- a/chrome/browser/extensions/extension_disabled_ui.cc
+++ b/chrome/browser/extensions/extension_disabled_ui.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
+#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
@@ -67,28 +68,24 @@ static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL;
// ExtensionDisabledDialogDelegate --------------------------------------------
-class ExtensionDisabledDialogDelegate
- : public ExtensionInstallPrompt::Delegate,
- public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> {
+class ExtensionDisabledDialogDelegate {
public:
ExtensionDisabledDialogDelegate(ExtensionService* service,
scoped_ptr<ExtensionInstallPrompt> install_ui,
const Extension* extension);
private:
- friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>;
+ ~ExtensionDisabledDialogDelegate();
- ~ExtensionDisabledDialogDelegate() override;
-
- // ExtensionInstallPrompt::Delegate:
- void InstallUIProceed() override;
- void InstallUIAbort(bool user_initiated) override;
+ void InstallPromptDone(ExtensionInstallPrompt::Result result);
// The UI for showing the install dialog when enabling.
scoped_ptr<ExtensionInstallPrompt> install_ui_;
ExtensionService* service_;
const Extension* extension_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionDisabledDialogDelegate);
};
ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
@@ -98,12 +95,15 @@ ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
: install_ui_(std::move(install_ui)),
service_(service),
extension_(extension) {
- AddRef(); // Balanced in Proceed or Abort.
ExtensionInstallPrompt::PromptType type =
ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
service_->profile(), extension);
+ // Unretained() is safe since this object manages its own lifetime and deletes
+ // itself only once the prompt finishes.
install_ui_->ShowDialog(
- this, extension_, nullptr,
+ base::Bind(&ExtensionDisabledDialogDelegate::InstallPromptDone,
+ base::Unretained(this)),
+ extension_, nullptr,
make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)),
ExtensionInstallPrompt::GetDefaultShowDialogCallback());
}
@@ -111,19 +111,21 @@ ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() {
}
-void ExtensionDisabledDialogDelegate::InstallUIProceed() {
- service_->GrantPermissionsAndEnableExtension(extension_);
- Release();
-}
-
-void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) {
- std::string histogram_name = user_initiated ? "ReEnableCancel"
- : "ReEnableAbort";
- ExtensionService::RecordPermissionMessagesHistogram(
- extension_, histogram_name.c_str());
+void ExtensionDisabledDialogDelegate::InstallPromptDone(
+ ExtensionInstallPrompt::Result result) {
+ if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
+ service_->GrantPermissionsAndEnableExtension(extension_);
+ } else {
+ const char* histogram_name =
+ result == ExtensionInstallPrompt::Result::USER_CANCELED
+ ? "ReEnableCancel"
+ : "ReEnableAbort";
+ ExtensionService::RecordPermissionMessagesHistogram(extension_,
+ histogram_name);
+ // Do nothing. The extension will remain disabled.
+ }
- // Do nothing. The extension will remain disabled.
- Release();
+ delete this;
}
// ExtensionDisabledGlobalError -----------------------------------------------
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698