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

Side by Side Diff: chrome/browser/extensions/webstore_standalone_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, 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/webstore_standalone_installer.h" 5 #include "chrome/browser/extensions/webstore_standalone_installer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/version.h" 10 #include "base/version.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 scoped_active_install_.reset(); 128 scoped_active_install_.reset();
129 if (!callback_.is_null()) 129 if (!callback_.is_null())
130 callback_.Run(result == webstore_install::SUCCESS, error, result); 130 callback_.Run(result == webstore_install::SUCCESS, error, result);
131 Release(); // Matches the AddRef in BeginInstall. 131 Release(); // Matches the AddRef in BeginInstall.
132 } 132 }
133 133
134 void WebstoreStandaloneInstaller::ProceedWithInstallPrompt() { 134 void WebstoreStandaloneInstaller::ProceedWithInstallPrompt() {
135 install_prompt_ = CreateInstallPrompt(); 135 install_prompt_ = CreateInstallPrompt();
136 if (install_prompt_.get()) { 136 if (install_prompt_.get()) {
137 ShowInstallUI(); 137 ShowInstallUI();
138 // Control flow finishes up in InstallUIProceed or InstallUIAbort. 138 // Control flow finishes up in OnInstallPromptDone().
139 } else { 139 } else {
140 InstallUIProceed(); 140 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED);
141 } 141 }
142 } 142 }
143 143
144 scoped_refptr<const Extension> 144 scoped_refptr<const Extension>
145 WebstoreStandaloneInstaller::GetLocalizedExtensionForDisplay() { 145 WebstoreStandaloneInstaller::GetLocalizedExtensionForDisplay() {
146 if (!localized_extension_for_display_.get()) { 146 if (!localized_extension_for_display_.get()) {
147 DCHECK(manifest_.get()); 147 DCHECK(manifest_.get());
148 if (!manifest_.get()) 148 if (!manifest_.get())
149 return NULL; 149 return NULL;
150 150
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 profile_, 182 profile_,
183 id_, 183 id_,
184 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()), 184 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()),
185 true)); 185 true));
186 approval->skip_post_install_ui = !ShouldShowPostInstallUI(); 186 approval->skip_post_install_ui = !ShouldShowPostInstallUI();
187 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble(); 187 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble();
188 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); 188 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_);
189 return approval; 189 return approval;
190 } 190 }
191 191
192 void WebstoreStandaloneInstaller::InstallUIProceed() { 192 void WebstoreStandaloneInstaller::OnInstallPromptDone(
193 if (!CheckRequestorAlive()) { 193 ExtensionInstallPrompt::Result result) {
194 if (result == ExtensionInstallPrompt::Result::USER_CANCELED) {
195 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
196 return;
197 }
198
199 if (result == ExtensionInstallPrompt::Result::ABORTED ||
200 !CheckRequestorAlive()) {
194 CompleteInstall(webstore_install::ABORTED, std::string()); 201 CompleteInstall(webstore_install::ABORTED, std::string());
195 return; 202 return;
196 } 203 }
197 204
205 DCHECK(result == ExtensionInstallPrompt::Result::ACCEPTED);
206
198 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); 207 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval();
199 208
200 ExtensionService* extension_service = 209 ExtensionService* extension_service =
201 ExtensionSystem::Get(profile_)->extension_service(); 210 ExtensionSystem::Get(profile_)->extension_service();
202 const Extension* installed_extension = 211 const Extension* installed_extension =
203 extension_service->GetExtensionById(id_, true /* include disabled */); 212 extension_service->GetExtensionById(id_, true /* include disabled */);
204 if (installed_extension) { 213 if (installed_extension) {
205 std::string install_message; 214 std::string install_message;
206 webstore_install::Result install_result = webstore_install::SUCCESS; 215 webstore_install::Result install_result = webstore_install::SUCCESS;
207 bool done = true; 216 bool done = true;
(...skipping 13 matching lines...) Expand all
221 return; 230 return;
222 } 231 }
223 } 232 }
224 233
225 scoped_refptr<WebstoreInstaller> installer = 234 scoped_refptr<WebstoreInstaller> installer =
226 new WebstoreInstaller(profile_, this, GetWebContents(), id_, 235 new WebstoreInstaller(profile_, this, GetWebContents(), id_,
227 std::move(approval), install_source_); 236 std::move(approval), install_source_);
228 installer->Start(); 237 installer->Start();
229 } 238 }
230 239
231 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) {
232 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
233 }
234
235 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() { 240 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() {
236 OnWebStoreDataFetcherDone(); 241 OnWebStoreDataFetcherDone();
237 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR, 242 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR,
238 kWebstoreRequestError); 243 kWebstoreRequestError);
239 } 244 }
240 245
241 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess( 246 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess(
242 scoped_ptr<base::DictionaryValue> webstore_data) { 247 scoped_ptr<base::DictionaryValue> webstore_data) {
243 OnWebStoreDataFetcherDone(); 248 OnWebStoreDataFetcherDone();
244 249
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 void WebstoreStandaloneInstaller::ShowInstallUI() { 402 void WebstoreStandaloneInstaller::ShowInstallUI() {
398 scoped_refptr<const Extension> localized_extension = 403 scoped_refptr<const Extension> localized_extension =
399 GetLocalizedExtensionForDisplay(); 404 GetLocalizedExtensionForDisplay();
400 if (!localized_extension.get()) { 405 if (!localized_extension.get()) {
401 CompleteInstall(webstore_install::INVALID_MANIFEST, kInvalidManifestError); 406 CompleteInstall(webstore_install::INVALID_MANIFEST, kInvalidManifestError);
402 return; 407 return;
403 } 408 }
404 409
405 install_ui_ = CreateInstallUI(); 410 install_ui_ = CreateInstallUI();
406 install_ui_->ShowDialog( 411 install_ui_->ShowDialog(
407 this, localized_extension.get(), &icon_, std::move(install_prompt_), 412 base::Bind(&WebstoreStandaloneInstaller::OnInstallPromptDone, this),
413 localized_extension.get(), &icon_, std::move(install_prompt_),
408 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 414 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
409 } 415 }
410 416
411 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { 417 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() {
412 // An instance of this class is passed in as a delegate for the 418 // An instance of this class is passed in as a delegate for the
413 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and 419 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and
414 // therefore needs to remain alive until they are done. Clear the webstore 420 // therefore needs to remain alive until they are done. Clear the webstore
415 // data fetcher to avoid calling Release in AbortInstall while any of these 421 // data fetcher to avoid calling Release in AbortInstall while any of these
416 // operations are in progress. 422 // operations are in progress.
417 webstore_data_fetcher_.reset(); 423 webstore_data_fetcher_.reset();
418 } 424 }
419 425
420 } // namespace extensions 426 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698