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

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: 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.
23 class ExtensionInfoGenerator { 30 class ExtensionInfoGenerator {
24 public: 31 public:
25 using ExtensionInfoList = 32 using ExtensionInfoList =
26 std::vector<linked_ptr<api::developer_private::ExtensionInfo>>; 33 std::vector<linked_ptr<api::developer_private::ExtensionInfo>>;
27 34
35 using ExtensionInfosCallback = base::Callback<void(const ExtensionInfoList&)>;
36
28 explicit ExtensionInfoGenerator(content::BrowserContext* context); 37 explicit ExtensionInfoGenerator(content::BrowserContext* context);
29 ~ExtensionInfoGenerator(); 38 ~ExtensionInfoGenerator();
30 39
31 // Returns the ExtensionInfo for a given |extension| and |state|. 40 // Creates and asynchronously returns an ExtensionInfo for the given
32 scoped_ptr<api::developer_private::ExtensionInfo> CreateExtensionInfo( 41 // |extension_id|, if the extension can be found.
33 const Extension& extension, 42 // If the extension cannot be found, an empty vector is passed to |callback|.
34 api::developer_private::ExtensionState state); 43 void CreateExtensionInfo(const std::string& id,
35 // Returns an ExtensionInfo for the given |extension_id|, if the extension 44 const ExtensionInfosCallback& callback);
36 // can be found.
37 scoped_ptr<api::developer_private::ExtensionInfo> CreateExtensionInfo(
38 const std::string& id);
39 45
40 // Returns a collection of ExtensionInfos, optionally including disabled and 46 // Creates and asynchronously returns a collection of ExtensionInfos,
41 // terminated. 47 // optionally including disabled and terminated.
42 ExtensionInfoList CreateExtensionsInfo(bool include_disabled, 48 void CreateExtensionsInfo(bool include_disabled,
43 bool include_terminated); 49 bool include_terminated,
50 const ExtensionInfosCallback& callback);
44 51
45 private: 52 private:
53 // Creates an ExtensionInfo for the given |extension| and |state|, and
54 // asynchronously adds it to the |list|.
55 void CreateExtensionInfoHelper(const Extension& extension,
56 api::developer_private::ExtensionState state);
57
58 // Callback for the asynchronous image loading.
59 void OnImageLoaded(scoped_ptr<api::developer_private::ExtensionInfo> info,
60 const gfx::Image& image);
61
62 // Returns the icon url for the default icon to use.
63 const std::string& GetDefaultIconUrl(bool is_app, bool is_disabled);
64
65 // Returns an icon url from the given image, optionally applying a greyscale.
66 std::string GetIconUrlFromImage(const gfx::Image& image,
67 bool should_greyscale);
68
46 // Various systems, cached for convenience. 69 // Various systems, cached for convenience.
47 content::BrowserContext* browser_context_; 70 content::BrowserContext* browser_context_;
48 ExtensionSystem* extension_system_; 71 ExtensionSystem* extension_system_;
49 ExtensionPrefs* extension_prefs_; 72 ExtensionPrefs* extension_prefs_;
50 ExtensionActionAPI* extension_action_api_; 73 ExtensionActionAPI* extension_action_api_;
51 WarningService* warning_service_; 74 WarningService* warning_service_;
52 ErrorConsole* error_console_; 75 ErrorConsole* error_console_;
76 ImageLoader* image_loader_;
77
78 // The number of pending image loads.
79 size_t pending_image_loads_;
80
81 // Default icons, cached and lazily initialized.
82 std::string default_app_icon_url_;
83 std::string default_extension_icon_url_;
84 std::string default_disabled_app_icon_url_;
85 std::string default_disabled_extension_icon_url_;
86
87 // The list of extension infos that have been generated.
88 ExtensionInfoList list_;
89
90 // The callback to run once all infos have been created.
91 ExtensionInfosCallback callback_;
not at google - send to devlin 2015/04/22 21:38:37 |callback_| and |list_| mean that there can be onl
Devlin 2015/04/23 19:17:21 Yeah, always meant this to be a one-time-use thing
not at google - send to devlin 2015/04/23 22:25:21 Doesn't look like it'd be that bad to me, you coul
Devlin 2015/04/27 17:06:30 But it's not easy to pass them around, even in a s
92
93 base::WeakPtrFactory<ExtensionInfoGenerator> weak_factory_;
53 94
54 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGenerator); 95 DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGenerator);
55 }; 96 };
56 97
57 } // namespace extensions 98 } // namespace extensions
58 99
59 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERA TOR_H_ 100 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_EXTENSION_INFO_GENERA TOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698