11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/app_list/extension_uninstaller.h"
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/extension_service.h"
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_system.h"
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/browser/uninstall_reason.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)ExtensionUninstaller::ExtensionUninstaller(
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    Profile* profile,
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::string& extension_id,
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    AppListControllerDelegate* controller)
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    : profile_(profile),
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      app_id_(extension_id),
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      controller_(controller) {
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)ExtensionUninstaller::~ExtensionUninstaller() {
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ExtensionUninstaller::Run() {
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const extensions::Extension* extension =
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      extensions::ExtensionSystem::Get(profile_)->extension_service()->
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          GetInstalledExtension(app_id_);
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (!extension) {
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    CleanUp();
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return;
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  controller_->OnShowChildDialog();
355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  dialog_.reset(extensions::ExtensionUninstallDialog::Create(
365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      profile_, controller_->GetAppListWindow(), this));
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  dialog_->ConfirmUninstall(extension);
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ExtensionUninstaller::ExtensionUninstallAccepted() {
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ExtensionService* service =
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      extensions::ExtensionSystem::Get(profile_)->extension_service();
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const extensions::Extension* extension =
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      service->GetInstalledExtension(app_id_);
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (extension) {
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    service->UninstallExtension(app_id_,
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                extensions::UNINSTALL_REASON_USER_INITIATED,
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                base::Bind(&base::DoNothing),
495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                NULL);
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  controller_->OnCloseChildDialog();
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  CleanUp();
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ExtensionUninstaller::ExtensionUninstallCanceled() {
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  controller_->OnCloseChildDialog();
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  CleanUp();
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ExtensionUninstaller::CleanUp() {
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  delete this;
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
63