app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / webstore_reinstaller.cc
blob340fc2df684560b1e8f2746070c4dbdc11ec066a
1 // Copyright 2014 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.
5 #include "chrome/browser/extensions/webstore_reinstaller.h"
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/web_contents.h"
12 #include "extensions/browser/extension_system.h"
14 namespace extensions {
16 namespace {
17 const char kCouldNotUninstallExtension[] = "Failed to uninstall the extension.";
18 const char kTabClosed[] = "Tab was closed.";
21 WebstoreReinstaller::WebstoreReinstaller(
22 content::WebContents* web_contents,
23 const std::string& extension_id,
24 const WebstoreStandaloneInstaller::Callback& callback)
25 : WebstoreStandaloneInstaller(
26 extension_id,
27 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
28 callback),
29 content::WebContentsObserver(web_contents) {
32 WebstoreReinstaller::~WebstoreReinstaller() {
35 void WebstoreReinstaller::BeginReinstall() {
36 WebstoreStandaloneInstaller::BeginInstall();
39 bool WebstoreReinstaller::CheckRequestorAlive() const {
40 return web_contents() != NULL;
43 const GURL& WebstoreReinstaller::GetRequestorURL() const {
44 return GURL::EmptyGURL();
47 scoped_refptr<ExtensionInstallPrompt::Prompt>
48 WebstoreReinstaller::CreateInstallPrompt() const {
49 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt(
50 new ExtensionInstallPrompt::Prompt(
51 ExtensionInstallPrompt::REPAIR_PROMPT));
52 prompt->SetWebstoreData(localized_user_count(),
53 show_user_count(),
54 average_rating(),
55 rating_count());
56 return prompt;
59 bool WebstoreReinstaller::ShouldShowPostInstallUI() const {
60 return false;
63 bool WebstoreReinstaller::ShouldShowAppInstalledBubble() const {
64 return false;
67 content::WebContents* WebstoreReinstaller::GetWebContents() const {
68 return web_contents();
71 bool WebstoreReinstaller::CheckInlineInstallPermitted(
72 const base::DictionaryValue& webstore_data,
73 std::string* error) const {
74 return true;
77 bool WebstoreReinstaller::CheckRequestorPermitted(
78 const base::DictionaryValue& webstore_data,
79 std::string* error) const {
80 return true;
83 void WebstoreReinstaller::WebContentsDestroyed() {
84 // Run the callback now, because AbortInstall() doesn't do it.
85 RunCallback(false, kTabClosed, webstore_install::ABORTED);
86 AbortInstall();
89 void WebstoreReinstaller::InstallUIProceed() {
90 if (!ExtensionSystem::Get(profile())->extension_service()->UninstallExtension(
91 id(),
92 UNINSTALL_REASON_REINSTALL,
93 base::Bind(&WebstoreReinstaller::OnDeletionDone, this),
94 NULL)) {
95 // Run the callback now, because AbortInstall() doesn't do it.
96 RunCallback(
97 false, kCouldNotUninstallExtension, webstore_install::OTHER_ERROR);
98 AbortInstall();
102 void WebstoreReinstaller::OnDeletionDone() {
103 WebstoreStandaloneInstaller::InstallUIProceed();
106 } // namespace extensions