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

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, 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/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
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 // Make a menu ID available when it is no longer used. 86 // Make a menu ID available when it is no longer used.
87 void ReleaseMenuCommandID(int id) { 87 void ReleaseMenuCommandID(int id) {
88 menu_command_ids.Get().reset(id - IDC_EXTENSION_DISABLED_FIRST); 88 menu_command_ids.Get().reset(id - IDC_EXTENSION_DISABLED_FIRST);
89 } 89 }
90 90
91 } // namespace 91 } // namespace
92 92
93 // ExtensionDisabledDialogDelegate -------------------------------------------- 93 // ExtensionDisabledDialogDelegate --------------------------------------------
94 94
95 class ExtensionDisabledDialogDelegate 95 class ExtensionDisabledDialogDelegate {
96 : public ExtensionInstallPrompt::Delegate,
97 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> {
98 public: 96 public:
99 ExtensionDisabledDialogDelegate(ExtensionService* service, 97 ExtensionDisabledDialogDelegate(ExtensionService* service,
100 scoped_ptr<ExtensionInstallPrompt> install_ui, 98 scoped_ptr<ExtensionInstallPrompt> install_ui,
101 const Extension* extension); 99 const Extension* extension);
102 100
103 private: 101 private:
104 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; 102 ~ExtensionDisabledDialogDelegate();
105 103
106 ~ExtensionDisabledDialogDelegate() override; 104 void InstallPromptDone(ExtensionInstallPrompt::Result result);
107
108 // ExtensionInstallPrompt::Delegate:
109 void InstallUIProceed() override;
110 void InstallUIAbort(bool user_initiated) override;
111 105
112 // The UI for showing the install dialog when enabling. 106 // The UI for showing the install dialog when enabling.
113 scoped_ptr<ExtensionInstallPrompt> install_ui_; 107 scoped_ptr<ExtensionInstallPrompt> install_ui_;
114 108
115 ExtensionService* service_; 109 ExtensionService* service_;
116 const Extension* extension_; 110 const Extension* extension_;
111
112 DISALLOW_COPY_AND_ASSIGN(ExtensionDisabledDialogDelegate);
Avi (use Gerrit) 2015/12/29 03:10:45 base/macros.h
Devlin 2016/01/04 22:59:23 Done.
117 }; 113 };
118 114
119 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( 115 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
120 ExtensionService* service, 116 ExtensionService* service,
121 scoped_ptr<ExtensionInstallPrompt> install_ui, 117 scoped_ptr<ExtensionInstallPrompt> install_ui,
122 const Extension* extension) 118 const Extension* extension)
123 : install_ui_(std::move(install_ui)), 119 : install_ui_(std::move(install_ui)),
124 service_(service), 120 service_(service),
125 extension_(extension) { 121 extension_(extension) {
126 AddRef(); // Balanced in Proceed or Abort.
127 ExtensionInstallPrompt::PromptType type = 122 ExtensionInstallPrompt::PromptType type =
128 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( 123 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
129 service_->profile(), extension); 124 service_->profile(), extension);
125 // Unretained() is safe since this object manages its own lifetime and deletes
126 // itself only once the prompt finishes.
asargent_no_longer_on_chrome 2015/12/31 00:45:56 also because it owns install_ui_ (not sure if wort
Devlin 2016/01/04 22:59:23 See other comment.
130 install_ui_->ShowDialog( 127 install_ui_->ShowDialog(
131 this, extension_, nullptr, 128 base::Bind(&ExtensionDisabledDialogDelegate::InstallPromptDone,
129 base::Unretained(this)),
130 extension_, nullptr,
132 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), 131 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)),
133 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 132 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
134 } 133 }
135 134
136 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { 135 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() {
137 } 136 }
138 137
139 void ExtensionDisabledDialogDelegate::InstallUIProceed() { 138 void ExtensionDisabledDialogDelegate::InstallPromptDone(
140 service_->GrantPermissionsAndEnableExtension(extension_); 139 ExtensionInstallPrompt::Result result) {
141 Release(); 140 if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
142 } 141 service_->GrantPermissionsAndEnableExtension(extension_);
142 } else {
143 const char* histogram_name =
144 result == ExtensionInstallPrompt::Result::USER_CANCELED
145 ? "ReEnableCancel"
146 : "ReEnableAbort";
147 ExtensionService::RecordPermissionMessagesHistogram(extension_,
148 histogram_name);
149 // Do nothing. The extension will remain disabled.
150 }
143 151
144 void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) { 152 delete this;
145 std::string histogram_name = user_initiated ? "ReEnableCancel"
146 : "ReEnableAbort";
147 ExtensionService::RecordPermissionMessagesHistogram(
148 extension_, histogram_name.c_str());
149
150 // Do nothing. The extension will remain disabled.
151 Release();
152 } 153 }
153 154
154 // ExtensionDisabledGlobalError ----------------------------------------------- 155 // ExtensionDisabledGlobalError -----------------------------------------------
155 156
156 class ExtensionDisabledGlobalError 157 class ExtensionDisabledGlobalError
157 : public GlobalErrorWithStandardBubble, 158 : public GlobalErrorWithStandardBubble,
158 public content::NotificationObserver, 159 public content::NotificationObserver,
159 public extensions::ExtensionUninstallDialog::Delegate, 160 public extensions::ExtensionUninstallDialog::Delegate,
160 public extensions::ExtensionRegistryObserver { 161 public extensions::ExtensionRegistryObserver {
161 public: 162 public:
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 content::WebContents* web_contents, 511 content::WebContents* web_contents,
511 const Extension* extension) { 512 const Extension* extension) {
512 scoped_ptr<ExtensionInstallPrompt> install_ui( 513 scoped_ptr<ExtensionInstallPrompt> install_ui(
513 new ExtensionInstallPrompt(web_contents)); 514 new ExtensionInstallPrompt(web_contents));
514 // This object manages its own lifetime. 515 // This object manages its own lifetime.
515 new ExtensionDisabledDialogDelegate(service, std::move(install_ui), 516 new ExtensionDisabledDialogDelegate(service, std::move(install_ui),
516 extension); 517 extension);
517 } 518 }
518 519
519 } // namespace extensions 520 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698