Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: chrome/browser/extensions/api/developer_private/extension_info_generator.h

Issue 1092953004: [Extensions] Update developerPrivate API to use base-64 data urls for icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR _H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR _H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR _H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERATOR _H_
7 7
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
8 #include "chrome/common/extensions/api/developer_private.h" 10 #include "chrome/common/extensions/api/developer_private.h"
9 11
10 namespace content { 12 namespace content {
11 class BrowserContext; 13 class BrowserContext;
12 } 14 }
13 15
16 namespace gfx {
17 class Image;
18 }
19
14 namespace extensions { 20 namespace extensions {
15 class ErrorConsole; 21 class ErrorConsole;
16 class Extension; 22 class Extension;
17 class ExtensionActionAPI; 23 class ExtensionActionAPI;
18 class ExtensionPrefs; 24 class ExtensionPrefs;
19 class ExtensionSystem; 25 class ExtensionSystem;
26 class ImageLoader;
20 class WarningService; 27 class WarningService;
21 28
22 // Generates the developerPrivate api's specification for ExtensionInfo. 29 // Generates the developerPrivate api's specification for ExtensionInfo.
30 // This class is designed to only have one generation running at a time!
23 class ExtensionInfoGenerator { 31 class ExtensionInfoGenerator {
24 public: 32 public:
25 using ExtensionInfoList = 33 using ExtensionInfoList =
26 std::vector<linked_ptr<api::developer_private::ExtensionInfo>>; 34 std::vector<linked_ptr<api::developer_private::ExtensionInfo>>;
27 35
36 using ExtensionInfosCallback = base::Callback<void(const ExtensionInfoList&)>;
37
28 explicit ExtensionInfoGenerator(content::BrowserContext* context); 38 explicit ExtensionInfoGenerator(content::BrowserContext* context);
29 ~ExtensionInfoGenerator(); 39 ~ExtensionInfoGenerator();
30 40
31 // Returns the ExtensionInfo for a given |extension| and |state|. 41 // Creates and asynchronously returns an ExtensionInfo for the given
32 scoped_ptr<api::developer_private::ExtensionInfo> CreateExtensionInfo( 42 // |extension_id|, if the extension can be found.
33 const Extension& extension, 43 // If the extension cannot be found, an empty vector is passed to |callback|.
34 api::developer_private::ExtensionState state); 44 void CreateExtensionInfo(const std::string& id,
35 // Returns an ExtensionInfo for the given |extension_id|, if the extension 45 const ExtensionInfosCallback& callback);
36 // can be found.
37 scoped_ptr<api::developer_private::ExtensionInfo> CreateExtensionInfo(
38 const std::string& id);
39 46
40 // Returns a collection of ExtensionInfos, optionally including disabled and 47 // Creates and asynchronously returns a collection of ExtensionInfos,
41 // terminated. 48 // optionally including disabled and terminated.
42 ExtensionInfoList CreateExtensionsInfo(bool include_disabled, 49 void CreateExtensionsInfo(bool include_disabled,
43 bool include_terminated); 50 bool include_terminated,
51 const ExtensionInfosCallback& callback);
44 52
45 private: 53 private:
54 // Creates an ExtensionInfo for the given |extension| and |state|, and
55 // asynchronously adds it to the |list|.
56 void CreateExtensionInfoHelper(const Extension& extension,
57 api::developer_private::ExtensionState state);
58
59 // Callback for the asynchronous image loading.
60 void OnImageLoaded(scoped_ptr<api::developer_private::ExtensionInfo> info,
61 const gfx::Image& image);
62
63 // Returns the icon url for the default icon to use.
64 const std::string& GetDefaultIconUrl(bool is_app, bool is_disabled);
65
66 // Returns an icon url from the given image, optionally applying a greyscale.
67 std::string GetIconUrlFromImage(const gfx::Image& image,
68 bool should_greyscale);
69
46 // Various systems, cached for convenience. 70 // Various systems, cached for convenience.
47 content::BrowserContext* browser_context_; 71 content::BrowserContext* browser_context_;
48 ExtensionSystem* extension_system_; 72 ExtensionSystem* extension_system_;
49 ExtensionPrefs* extension_prefs_; 73 ExtensionPrefs* extension_prefs_;
50 ExtensionActionAPI* extension_action_api_; 74 ExtensionActionAPI* extension_action_api_;
51 WarningService* warning_service_; 75 WarningService* warning_service_;
52 ErrorConsole* error_console_; 76 ErrorConsole* error_console_;
77 ImageLoader* image_loader_;
78
79 // The number of pending image loads.
80 size_t pending_image_loads_;
81
82 // Default icons, cached and lazily initialized.
83 std::string default_app_icon_url_;
84 std::string default_extension_icon_url_;
85 std::string default_disabled_app_icon_url_;
86 std::string default_disabled_extension_icon_url_;
87
88 // The list of extension infos that have been generated.
89 ExtensionInfoList list_;
90
91 // The callback to run once all infos have been created.
92 ExtensionInfosCallback callback_;
93
94 base::WeakPtrFactory<ExtensionInfoGenerator> weak_factory_;
53 95
54 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGenerator); 96 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGenerator);
55 }; 97 };
56 98
57 } // namespace extensions 99 } // namespace extensions
58 100
59 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERA TOR_H_ 101 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERA TOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698