OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_APP_ICON_SERVICE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_APP_ICON_SERVICE_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "components/keyed_service/core/keyed_service.h" | |
14 #include "extensions/browser/extension_registry_observer.h" | |
15 | |
16 namespace content { | |
17 class BrowserContext; | |
18 } | |
19 | |
20 namespace extensions { | |
21 | |
22 class ExtensionAppIcon; | |
23 class ExtensionAppIconDelegate; | |
24 | |
25 // Factory for ExtensionAppIcon. Each created icon is tracked by this service. | |
26 // Once some condition that affects how extension app icon should look is | |
27 // changed then corresponded app icons are automatically updated. This service | |
28 // is bound to content::BrowserContext. | |
29 // Usage: ExtensionAppIconService::Get(context)->CreateIcon(). | |
30 class ExtensionAppIconService : public KeyedService, | |
Devlin
2017/04/20 20:17:41
Do we even need this class? Is there a reason the
khmel
2017/04/20 20:21:53
This would requires tons on listeners and very ine
Devlin
2017/04/26 22:41:57
Ah, I missed that call to UpdateIcon (and only saw
khmel
2017/04/27 00:18:12
Acknowledged.
| |
31 public ExtensionRegistryObserver { | |
32 public: | |
33 static ExtensionAppIconService* Create(content::BrowserContext* context); | |
Devlin
2017/04/26 22:41:57
Why do we need a Create() rather than just using t
khmel
2017/04/27 00:18:12
This is common practice for services to have CTOR
Devlin
2017/05/01 14:51:10
We should only need a Create() method when there's
khmel
2017/05/01 20:18:18
Acknowledged.
| |
34 | |
35 // Convenience function to get the ExtensionAppIconService for a | |
36 // BrowserContext. | |
37 static ExtensionAppIconService* Get(content::BrowserContext* context); | |
38 | |
39 ~ExtensionAppIconService() override; | |
40 | |
41 // Creates extension app icon for requested app and size. Icon updates are | |
42 // dispatched via |delegate|. | |
43 std::unique_ptr<ExtensionAppIcon> CreateIcon( | |
44 ExtensionAppIconDelegate* delegate, | |
45 const std::string& app_id, | |
46 int resource_size_in_dip); | |
47 | |
48 // KeyedService: | |
49 void Shutdown() override; | |
50 | |
51 private: | |
52 friend class ExtensionAppIcon; | |
53 | |
54 class Updater; | |
55 using IconMap = std::multimap<std::string, ExtensionAppIcon*>; | |
Devlin
2017/04/26 22:41:57
Is there a reason to use a multimap instead of e.g
khmel
2017/04/27 00:18:12
Changed as you suggested.
| |
56 | |
57 // See the Create methods. | |
58 explicit ExtensionAppIconService(content::BrowserContext* context); | |
59 | |
60 // Called from ExtensionAppIcon DTOR. | |
61 void OnIconDestroyed(ExtensionAppIcon* icon); | |
62 | |
63 // Called from Updater when corresponded app icons need to be updated. | |
64 void OnAppUpdated(const std::string& app_id); | |
65 | |
66 // ExtensionRegistryObserver: | |
67 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
68 const Extension* extension) override; | |
69 | |
70 void OnExtensionUnloaded(content::BrowserContext* browser_context, | |
71 const Extension* extension, | |
72 UnloadedExtensionInfo::Reason reason) override; | |
73 | |
74 // Unowned pointer. | |
75 content::BrowserContext* context_; | |
76 | |
77 #if defined(OS_CHROMEOS) | |
78 std::unique_ptr<Updater> app_updater_; | |
79 #endif | |
80 | |
81 IconMap icon_map_; | |
82 | |
83 base::WeakPtrFactory<ExtensionAppIconService> weak_ptr_factory_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(ExtensionAppIconService); | |
86 }; | |
87 | |
88 } // namespace extensions | |
89 | |
90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_APP_ICON_SERVICE_H_ | |
OLD | NEW |