Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / extensions / external_install_error.h
blobc26aa7303b47655685fd71f7cb127b43e052aa83
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
16 class Browser;
17 class ExtensionInstallPromptShowParams;
18 class ExtensionInstallUI;
19 class GlobalError;
20 class GlobalErrorService;
22 namespace content {
23 class BrowserContext;
26 namespace extensions {
27 class Extension;
28 class ExternalInstallManager;
29 class WebstoreDataFetcher;
31 // An error to show the user an extension has been externally installed. The
32 // error will automatically fetch data about the extension from the webstore (if
33 // possible) and will handle adding itself to the GlobalErrorService when
34 // initialized and removing itself from the GlobalErrorService upon
35 // destruction.
36 class ExternalInstallError : public ExtensionInstallPrompt::Delegate,
37 public WebstoreDataFetcherDelegate {
38 public:
39 // The possible types of errors to show. A menu alert adds a menu item to the
40 // wrench, which spawns an extension install dialog when clicked. The bubble
41 // alert also adds an item, but spawns a bubble instead (less invasive and
42 // easier to dismiss).
43 enum AlertType {
44 BUBBLE_ALERT,
45 MENU_ALERT
48 ExternalInstallError(content::BrowserContext* browser_context,
49 const std::string& extension_id,
50 AlertType error_type,
51 ExternalInstallManager* manager);
52 ~ExternalInstallError() override;
54 // ExtensionInstallPrompt::Delegate implementation.
55 void InstallUIProceed() override;
56 void InstallUIAbort(bool user_initiated) override;
58 // Show the associated dialog. This should only be called once the dialog is
59 // ready.
60 void ShowDialog(Browser* browser);
62 // Return the associated extension, or NULL.
63 const Extension* GetExtension() const;
65 const std::string& extension_id() const { return extension_id_; }
66 AlertType alert_type() const { return alert_type_; }
68 private:
69 // WebstoreDataFetcherDelegate implementation.
70 void OnWebstoreRequestFailure() override;
71 void OnWebstoreResponseParseSuccess(
72 scoped_ptr<base::DictionaryValue> webstore_data) override;
73 void OnWebstoreResponseParseFailure(const std::string& error) override;
75 // Called when data fetching has completed (either successfully or not).
76 void OnFetchComplete();
78 // Called when the dialog has been successfully populated, and is ready to be
79 // shown.
80 void OnDialogReady(ExtensionInstallPromptShowParams* show_params,
81 ExtensionInstallPrompt::Delegate* prompt_delegate,
82 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
84 // The associated BrowserContext.
85 content::BrowserContext* browser_context_;
87 // The id of the external extension.
88 std::string extension_id_;
90 // The type of alert to show the user.
91 AlertType alert_type_;
93 // The owning ExternalInstallManager.
94 ExternalInstallManager* manager_;
96 // The associated GlobalErrorService.
97 GlobalErrorService* error_service_;
99 // The UI for showing the error.
100 scoped_ptr<ExtensionInstallPrompt> install_ui_;
101 scoped_ptr<ExtensionInstallPromptShowParams> install_ui_show_params_;
102 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
104 // The UI for the given error, which will take the form of either a menu
105 // alert or a bubble alert (depending on the |alert_type_|.
106 scoped_ptr<GlobalError> global_error_;
108 // The WebstoreDataFetcher to use in order to populate the error with webstore
109 // information of the extension.
110 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
112 base::WeakPtrFactory<ExternalInstallError> weak_factory_;
114 DISALLOW_COPY_AND_ASSIGN(ExternalInstallError);
117 } // namespace extensions
119 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_