Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / extensions / external_install_error.h
blobaa53afccb0bd7cfef7b6bcd669968dc757971bf6
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 ExtensionInstallUI;
17 class GlobalError;
18 class GlobalErrorService;
20 namespace content {
21 class BrowserContext;
24 namespace extensions {
25 class Extension;
26 class ExternalInstallManager;
27 class WebstoreDataFetcher;
29 // An error to show the user an extension has been externally installed. The
30 // error will automatically fetch data about the extension from the webstore (if
31 // possible) and will handle adding itself to the GlobalErrorService when
32 // initialized and removing itself from the GlobalErrorService upon
33 // destruction.
34 class ExternalInstallError : public ExtensionInstallPrompt::Delegate,
35 public WebstoreDataFetcherDelegate {
36 public:
37 // The possible types of errors to show. A menu alert adds a menu item to the
38 // wrench, which spawns an extension install dialog when clicked. The bubble
39 // alert also adds an item, but spawns a bubble instead (less invasive and
40 // easier to dismiss).
41 enum AlertType {
42 BUBBLE_ALERT,
43 MENU_ALERT
46 ExternalInstallError(content::BrowserContext* browser_context,
47 const std::string& extension_id,
48 AlertType error_type,
49 ExternalInstallManager* manager);
50 virtual ~ExternalInstallError();
52 // ExtensionInstallPrompt::Delegate implementation.
53 virtual void InstallUIProceed() OVERRIDE;
54 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
56 // Acknowledge the associated external extension.
57 void AcknowledgeExtension();
59 // Show the associated dialog. This should only be called once the dialog is
60 // ready.
61 void ShowDialog();
63 // Return the associated extension, or NULL.
64 const Extension* GetExtension() const;
66 const std::string& extension_id() const { return extension_id_; }
67 AlertType alert_type() const { return alert_type_; }
69 private:
70 // WebstoreDataFetcherDelegate implementation.
71 virtual void OnWebstoreRequestFailure() OVERRIDE;
72 virtual void OnWebstoreResponseParseSuccess(
73 scoped_ptr<base::DictionaryValue> webstore_data) OVERRIDE;
74 virtual void OnWebstoreResponseParseFailure(
75 const std::string& error) OVERRIDE;
77 // Called when data fetching has completed (either successfully or not).
78 void OnFetchComplete();
80 // Called when the dialog has been successfully populated, and is ready to be
81 // shown.
82 void OnDialogReady(const ExtensionInstallPrompt::ShowParams& show_params,
83 ExtensionInstallPrompt::Delegate* prompt_delegate,
84 const ExtensionInstallPrompt::Prompt& prompt);
86 // The associated BrowserContext.
87 content::BrowserContext* browser_context_;
89 // The id of the external extension.
90 std::string extension_id_;
92 // The type of alert to show the user.
93 AlertType alert_type_;
95 // The owning ExternalInstallManager.
96 ExternalInstallManager* manager_;
98 // The associated GlobalErrorService.
99 GlobalErrorService* error_service_;
101 // The UI for showing the error.
102 scoped_ptr<ExtensionInstallPrompt> install_ui_;
103 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt_;
104 scoped_ptr<ExtensionInstallPrompt::ShowParams> show_params_;
106 // The UI for the given error, which will take the form of either a menu
107 // alert or a bubble alert (depending on the |alert_type_|.
108 scoped_ptr<GlobalError> global_error_;
110 // The associated browser. Can be NULL.
111 Browser* browser_;
113 // The WebstoreDataFetcher to use in order to populate the error with webstore
114 // information of the extension.
115 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
117 base::WeakPtrFactory<ExternalInstallError> weak_factory_;
119 DISALLOW_COPY_AND_ASSIGN(ExternalInstallError);
122 } // namespace extensions
124 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_