Home | History | Annotate | Download | only in app_list
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/app_list/extension_uninstaller.h"
      6 
      7 #include "chrome/browser/extensions/extension_service.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
     10 #include "extensions/browser/extension_system.h"
     11 #include "extensions/browser/uninstall_reason.h"
     12 #include "extensions/common/extension.h"
     13 
     14 ExtensionUninstaller::ExtensionUninstaller(
     15     Profile* profile,
     16     const std::string& extension_id,
     17     AppListControllerDelegate* controller)
     18     : profile_(profile),
     19       app_id_(extension_id),
     20       controller_(controller) {
     21 }
     22 
     23 ExtensionUninstaller::~ExtensionUninstaller() {
     24 }
     25 
     26 void ExtensionUninstaller::Run() {
     27   const extensions::Extension* extension =
     28       extensions::ExtensionSystem::Get(profile_)->extension_service()->
     29           GetInstalledExtension(app_id_);
     30   if (!extension) {
     31     CleanUp();
     32     return;
     33   }
     34   controller_->OnShowChildDialog();
     35   dialog_.reset(extensions::ExtensionUninstallDialog::Create(
     36       profile_, controller_->GetAppListWindow(), this));
     37   dialog_->ConfirmUninstall(extension);
     38 }
     39 
     40 void ExtensionUninstaller::ExtensionUninstallAccepted() {
     41   ExtensionService* service =
     42       extensions::ExtensionSystem::Get(profile_)->extension_service();
     43   const extensions::Extension* extension =
     44       service->GetInstalledExtension(app_id_);
     45   if (extension) {
     46     service->UninstallExtension(app_id_,
     47                                 extensions::UNINSTALL_REASON_USER_INITIATED,
     48                                 base::Bind(&base::DoNothing),
     49                                 NULL);
     50   }
     51   controller_->OnCloseChildDialog();
     52   CleanUp();
     53 }
     54 
     55 void ExtensionUninstaller::ExtensionUninstallCanceled() {
     56   controller_->OnCloseChildDialog();
     57   CleanUp();
     58 }
     59 
     60 void ExtensionUninstaller::CleanUp() {
     61   delete this;
     62 }
     63