Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / developer_private / extension_info_generator.h
blob51d8c91a4c55147bd19a0a93a2eb10050869c111
1 // Copyright 2015 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_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR_H_
8 #include "base/callback.h"
9 #include "base/memory/linked_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/common/extensions/api/developer_private.h"
13 namespace content {
14 class BrowserContext;
17 namespace gfx {
18 class Image;
21 namespace extensions {
22 class CommandService;
23 class ErrorConsole;
24 class Extension;
25 class ExtensionActionAPI;
26 class ExtensionPrefs;
27 class ExtensionSystem;
28 class ImageLoader;
29 class WarningService;
31 // Generates the developerPrivate api's specification for ExtensionInfo.
32 // This class is designed to only have one generation running at a time!
33 class ExtensionInfoGenerator {
34 public:
35 using ExtensionInfoList =
36 std::vector<linked_ptr<api::developer_private::ExtensionInfo>>;
38 using ExtensionInfosCallback = base::Callback<void(const ExtensionInfoList&)>;
40 explicit ExtensionInfoGenerator(content::BrowserContext* context);
41 ~ExtensionInfoGenerator();
43 // Creates and asynchronously returns an ExtensionInfo for the given
44 // |extension_id|, if the extension can be found.
45 // If the extension cannot be found, an empty vector is passed to |callback|.
46 void CreateExtensionInfo(const std::string& id,
47 const ExtensionInfosCallback& callback);
49 // Creates and asynchronously returns a collection of ExtensionInfos,
50 // optionally including disabled and terminated.
51 void CreateExtensionsInfo(bool include_disabled,
52 bool include_terminated,
53 const ExtensionInfosCallback& callback);
55 private:
56 // Creates an ExtensionInfo for the given |extension| and |state|, and
57 // asynchronously adds it to the |list|.
58 void CreateExtensionInfoHelper(const Extension& extension,
59 api::developer_private::ExtensionState state);
61 // Callback for the asynchronous image loading.
62 void OnImageLoaded(scoped_ptr<api::developer_private::ExtensionInfo> info,
63 const gfx::Image& image);
65 // Returns the icon url for the default icon to use.
66 const std::string& GetDefaultIconUrl(bool is_app, bool is_disabled);
68 // Returns an icon url from the given image, optionally applying a greyscale.
69 std::string GetIconUrlFromImage(const gfx::Image& image,
70 bool should_greyscale);
72 // Various systems, cached for convenience.
73 content::BrowserContext* browser_context_;
74 CommandService* command_service_;
75 ExtensionSystem* extension_system_;
76 ExtensionPrefs* extension_prefs_;
77 ExtensionActionAPI* extension_action_api_;
78 WarningService* warning_service_;
79 ErrorConsole* error_console_;
80 ImageLoader* image_loader_;
82 // The number of pending image loads.
83 size_t pending_image_loads_;
85 // Default icons, cached and lazily initialized.
86 std::string default_app_icon_url_;
87 std::string default_extension_icon_url_;
88 std::string default_disabled_app_icon_url_;
89 std::string default_disabled_extension_icon_url_;
91 // The list of extension infos that have been generated.
92 ExtensionInfoList list_;
94 // The callback to run once all infos have been created.
95 ExtensionInfosCallback callback_;
97 base::WeakPtrFactory<ExtensionInfoGenerator> weak_factory_;
99 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGenerator);
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR_H_