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

Side by Side Diff: chrome/browser/extensions/bundle_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
« no previous file with comments | « chrome/browser/extensions/bundle_installer.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bundle_installer.h" 5 #include "chrome/browser/extensions/bundle_installer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const std::string& authuser, 106 const std::string& authuser,
107 const std::string& delegated_username, 107 const std::string& delegated_username,
108 const BundleInstaller::ItemList& items) 108 const BundleInstaller::ItemList& items)
109 : approved_(false), 109 : approved_(false),
110 browser_(browser), 110 browser_(browser),
111 name_(name), 111 name_(name),
112 icon_(icon), 112 icon_(icon),
113 authuser_(authuser), 113 authuser_(authuser),
114 delegated_username_(delegated_username), 114 delegated_username_(delegated_username),
115 host_desktop_type_(browser->host_desktop_type()), 115 host_desktop_type_(browser->host_desktop_type()),
116 profile_(browser->profile()) { 116 profile_(browser->profile()),
117 weak_factory_(this) {
117 BrowserList::AddObserver(this); 118 BrowserList::AddObserver(this);
118 for (size_t i = 0; i < items.size(); ++i) { 119 for (size_t i = 0; i < items.size(); ++i) {
119 items_[items[i].id] = items[i]; 120 items_[items[i].id] = items[i];
120 items_[items[i].id].state = Item::STATE_PENDING; 121 items_[items[i].id].state = Item::STATE_PENDING;
121 } 122 }
122 } 123 }
123 124
124 BundleInstaller::~BundleInstaller() { 125 BundleInstaller::~BundleInstaller() {
125 BrowserList::RemoveObserver(this); 126 BrowserList::RemoveObserver(this);
126 } 127 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 PermissionSet empty; 264 PermissionSet empty;
264 for (size_t i = 0; i < dummy_extensions_.size(); ++i) { 265 for (size_t i = 0; i < dummy_extensions_.size(); ++i) {
265 // Using "permissions ? *permissions : PermissionSet()" tries to do a copy, 266 // Using "permissions ? *permissions : PermissionSet()" tries to do a copy,
266 // and doesn't compile. Use a more verbose, but compilable, workaround. 267 // and doesn't compile. Use a more verbose, but compilable, workaround.
267 permissions = PermissionSet::CreateUnion( 268 permissions = PermissionSet::CreateUnion(
268 permissions ? *permissions : empty, 269 permissions ? *permissions : empty,
269 dummy_extensions_[i]->permissions_data()->active_permissions()); 270 dummy_extensions_[i]->permissions_data()->active_permissions());
270 } 271 }
271 272
272 if (g_auto_approve_for_test == PROCEED) { 273 if (g_auto_approve_for_test == PROCEED) {
273 InstallUIProceed(); 274 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED);
274 } else if (g_auto_approve_for_test == ABORT) { 275 } else if (g_auto_approve_for_test == ABORT) {
275 InstallUIAbort(true); 276 OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED);
276 } else { 277 } else {
277 Browser* browser = browser_; 278 Browser* browser = browser_;
278 if (!browser) { 279 if (!browser) {
279 // The browser that we got initially could have gone away during our 280 // The browser that we got initially could have gone away during our
280 // thread hopping. 281 // thread hopping.
281 browser = chrome::FindLastActiveWithProfile(profile_, host_desktop_type_); 282 browser = chrome::FindLastActiveWithProfile(profile_, host_desktop_type_);
282 } 283 }
283 content::WebContents* web_contents = NULL; 284 content::WebContents* web_contents = NULL;
284 if (browser) 285 if (browser)
285 web_contents = browser->tab_strip_model()->GetActiveWebContents(); 286 web_contents = browser->tab_strip_model()->GetActiveWebContents();
286 install_ui_.reset(new ExtensionInstallPrompt(web_contents)); 287 install_ui_.reset(new ExtensionInstallPrompt(web_contents));
287 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt; 288 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt;
288 if (delegated_username_.empty()) { 289 if (delegated_username_.empty()) {
289 prompt.reset(new ExtensionInstallPrompt::Prompt( 290 prompt.reset(new ExtensionInstallPrompt::Prompt(
290 ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT)); 291 ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT));
291 } else { 292 } else {
292 prompt.reset(new ExtensionInstallPrompt::Prompt( 293 prompt.reset(new ExtensionInstallPrompt::Prompt(
293 ExtensionInstallPrompt::DELEGATED_BUNDLE_PERMISSIONS_PROMPT)); 294 ExtensionInstallPrompt::DELEGATED_BUNDLE_PERMISSIONS_PROMPT));
294 prompt->set_delegated_username(delegated_username_); 295 prompt->set_delegated_username(delegated_username_);
295 } 296 }
296 prompt->set_bundle(this); 297 prompt->set_bundle(this);
297 install_ui_->ShowDialog( 298 install_ui_->ShowDialog(
298 this, nullptr, &icon_, std::move(prompt), std::move(permissions), 299 base::Bind(&BundleInstaller::OnInstallPromptDone,
300 weak_factory_.GetWeakPtr()),
301 nullptr, &icon_, std::move(prompt), std::move(permissions),
299 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 302 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
300 } 303 }
301 } 304 }
302 305
303 void BundleInstaller::ShowInstalledBubbleIfDone() { 306 void BundleInstaller::ShowInstalledBubbleIfDone() {
304 // We're ready to show the installed bubble when no items are pending. 307 // We're ready to show the installed bubble when no items are pending.
305 if (HasItemWithState(Item::STATE_PENDING)) 308 if (HasItemWithState(Item::STATE_PENDING))
306 return; 309 return;
307 310
308 if (browser_) 311 if (browser_)
(...skipping 16 matching lines...) Expand all
325 328
326 void BundleInstaller::OnWebstoreParseFailure( 329 void BundleInstaller::OnWebstoreParseFailure(
327 const std::string& id, 330 const std::string& id,
328 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, 331 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
329 const std::string& error_message) { 332 const std::string& error_message) {
330 items_[id].state = Item::STATE_FAILED; 333 items_[id].state = Item::STATE_FAILED;
331 334
332 ShowPromptIfDoneParsing(); 335 ShowPromptIfDoneParsing();
333 } 336 }
334 337
335 void BundleInstaller::InstallUIProceed() { 338 void BundleInstaller::OnInstallPromptDone(
336 approved_ = true; 339 ExtensionInstallPrompt::Result result) {
337 approval_callback_.Run(APPROVED); 340 ApprovalState state = APPROVED;
338 } 341 if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
342 approved_ = true;
343 state = APPROVED;
344 } else {
345 for (std::pair<const std::string, Item>& entry : items_)
346 entry.second.state = Item::STATE_FAILED;
339 347
340 void BundleInstaller::InstallUIAbort(bool user_initiated) { 348 state = result == ExtensionInstallPrompt::Result::USER_CANCELED
341 for (std::pair<const std::string, Item>& entry : items_) 349 ? USER_CANCELED
342 entry.second.state = Item::STATE_FAILED; 350 : APPROVAL_ERROR;
343 351 }
344 approval_callback_.Run(user_initiated ? USER_CANCELED : APPROVAL_ERROR); 352 approval_callback_.Run(state);
345 } 353 }
346 354
347 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) { 355 void BundleInstaller::OnExtensionInstallSuccess(const std::string& id) {
348 items_[id].state = Item::STATE_INSTALLED; 356 items_[id].state = Item::STATE_INSTALLED;
349 357
350 ShowInstalledBubbleIfDone(); 358 ShowInstalledBubbleIfDone();
351 } 359 }
352 360
353 void BundleInstaller::OnExtensionInstallFailure( 361 void BundleInstaller::OnExtensionInstallFailure(
354 const std::string& id, 362 const std::string& id,
(...skipping 11 matching lines...) Expand all
366 374
367 ShowInstalledBubbleIfDone(); 375 ShowInstalledBubbleIfDone();
368 } 376 }
369 377
370 void BundleInstaller::OnBrowserRemoved(Browser* browser) { 378 void BundleInstaller::OnBrowserRemoved(Browser* browser) {
371 if (browser_ == browser) 379 if (browser_ == browser)
372 browser_ = nullptr; 380 browser_ = nullptr;
373 } 381 }
374 382
375 } // namespace extensions 383 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/bundle_installer.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698