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

Side by Side 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 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/extension_disabled_ui.h" 5 #include "chrome/browser/extensions/extension_disabled_ui.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/scoped_observer.h" 18 #include "base/scoped_observer.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
22 #include "chrome/app/chrome_command_ids.h" 23 #include "chrome/app/chrome_command_ids.h"
23 #include "chrome/browser/extensions/extension_install_error_menu_item_id_provide r.h" 24 #include "chrome/browser/extensions/extension_install_error_menu_item_id_provide r.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 using extensions::PermissionMessages; 61 using extensions::PermissionMessages;
61 62
62 namespace { 63 namespace {
63 64
64 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL; 65 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL;
65 66
66 } // namespace 67 } // namespace
67 68
68 // ExtensionDisabledDialogDelegate -------------------------------------------- 69 // ExtensionDisabledDialogDelegate --------------------------------------------
69 70
70 class ExtensionDisabledDialogDelegate 71 class ExtensionDisabledDialogDelegate {
71 : public ExtensionInstallPrompt::Delegate,
72 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> {
73 public: 72 public:
74 ExtensionDisabledDialogDelegate(ExtensionService* service, 73 ExtensionDisabledDialogDelegate(ExtensionService* service,
75 scoped_ptr<ExtensionInstallPrompt> install_ui, 74 scoped_ptr<ExtensionInstallPrompt> install_ui,
76 const Extension* extension); 75 const Extension* extension);
77 76
78 private: 77 private:
79 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; 78 ~ExtensionDisabledDialogDelegate();
80 79
81 ~ExtensionDisabledDialogDelegate() override; 80 void InstallPromptDone(ExtensionInstallPrompt::Result result);
82
83 // ExtensionInstallPrompt::Delegate:
84 void InstallUIProceed() override;
85 void InstallUIAbort(bool user_initiated) override;
86 81
87 // The UI for showing the install dialog when enabling. 82 // The UI for showing the install dialog when enabling.
88 scoped_ptr<ExtensionInstallPrompt> install_ui_; 83 scoped_ptr<ExtensionInstallPrompt> install_ui_;
89 84
90 ExtensionService* service_; 85 ExtensionService* service_;
91 const Extension* extension_; 86 const Extension* extension_;
87
88 DISALLOW_COPY_AND_ASSIGN(ExtensionDisabledDialogDelegate);
92 }; 89 };
93 90
94 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( 91 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
95 ExtensionService* service, 92 ExtensionService* service,
96 scoped_ptr<ExtensionInstallPrompt> install_ui, 93 scoped_ptr<ExtensionInstallPrompt> install_ui,
97 const Extension* extension) 94 const Extension* extension)
98 : install_ui_(std::move(install_ui)), 95 : install_ui_(std::move(install_ui)),
99 service_(service), 96 service_(service),
100 extension_(extension) { 97 extension_(extension) {
101 AddRef(); // Balanced in Proceed or Abort.
102 ExtensionInstallPrompt::PromptType type = 98 ExtensionInstallPrompt::PromptType type =
103 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( 99 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
104 service_->profile(), extension); 100 service_->profile(), extension);
101 // Unretained() is safe since this object manages its own lifetime and deletes
102 // itself only once the prompt finishes.
105 install_ui_->ShowDialog( 103 install_ui_->ShowDialog(
106 this, extension_, nullptr, 104 base::Bind(&ExtensionDisabledDialogDelegate::InstallPromptDone,
105 base::Unretained(this)),
106 extension_, nullptr,
107 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), 107 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)),
108 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 108 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
109 } 109 }
110 110
111 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { 111 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() {
112 } 112 }
113 113
114 void ExtensionDisabledDialogDelegate::InstallUIProceed() { 114 void ExtensionDisabledDialogDelegate::InstallPromptDone(
115 service_->GrantPermissionsAndEnableExtension(extension_); 115 ExtensionInstallPrompt::Result result) {
116 Release(); 116 if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
117 } 117 service_->GrantPermissionsAndEnableExtension(extension_);
118 } else {
119 const char* histogram_name =
120 result == ExtensionInstallPrompt::Result::USER_CANCELED
121 ? "ReEnableCancel"
122 : "ReEnableAbort";
123 ExtensionService::RecordPermissionMessagesHistogram(extension_,
124 histogram_name);
125 // Do nothing. The extension will remain disabled.
126 }
118 127
119 void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) { 128 delete this;
120 std::string histogram_name = user_initiated ? "ReEnableCancel"
121 : "ReEnableAbort";
122 ExtensionService::RecordPermissionMessagesHistogram(
123 extension_, histogram_name.c_str());
124
125 // Do nothing. The extension will remain disabled.
126 Release();
127 } 129 }
128 130
129 // ExtensionDisabledGlobalError ----------------------------------------------- 131 // ExtensionDisabledGlobalError -----------------------------------------------
130 132
131 class ExtensionDisabledGlobalError 133 class ExtensionDisabledGlobalError
132 : public GlobalErrorWithStandardBubble, 134 : public GlobalErrorWithStandardBubble,
133 public content::NotificationObserver, 135 public content::NotificationObserver,
134 public extensions::ExtensionUninstallDialog::Delegate, 136 public extensions::ExtensionUninstallDialog::Delegate,
135 public extensions::ExtensionRegistryObserver { 137 public extensions::ExtensionRegistryObserver {
136 public: 138 public:
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 content::WebContents* web_contents, 485 content::WebContents* web_contents,
484 const Extension* extension) { 486 const Extension* extension) {
485 scoped_ptr<ExtensionInstallPrompt> install_ui( 487 scoped_ptr<ExtensionInstallPrompt> install_ui(
486 new ExtensionInstallPrompt(web_contents)); 488 new ExtensionInstallPrompt(web_contents));
487 // This object manages its own lifetime. 489 // This object manages its own lifetime.
488 new ExtensionDisabledDialogDelegate(service, std::move(install_ui), 490 new ExtensionDisabledDialogDelegate(service, std::move(install_ui),
489 extension); 491 extension);
490 } 492 }
491 493
492 } // namespace extensions 494 } // namespace extensions
OLDNEW
« 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