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

Side by Side Diff: chrome/browser/extensions/chrome_app_icon_service.h

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: nits Created 3 years, 7 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
(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_CHROME_APP_ICON_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_SERVICE_H_
7
8 #include <map>
9 #include <memory>
10 #include <set>
11
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_observer.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "extensions/browser/extension_registry_observer.h"
17
18 namespace content {
19 class BrowserContext;
20 }
21
22 namespace extensions {
23
24 class ChromeAppIcon;
25 class ChromeAppIconDelegate;
26
27 // Factory for ChromeAppIcon. Each created icon is tracked by this service.
28 // Once some condition that affects how extension app icon should look is
29 // changed then corresponded app icons are automatically updated. This service
30 // is bound to content::BrowserContext.
31 // Usage: ChromeAppIconService::Get(context)->CreateIcon().
32 class ChromeAppIconService : public KeyedService,
33 public ExtensionRegistryObserver {
34 public:
35 explicit ChromeAppIconService(content::BrowserContext* context);
36
37 ~ChromeAppIconService() override;
38
39 // Convenience function to get the ChromeAppIconService for a
40 // BrowserContext.
41 static ChromeAppIconService* Get(content::BrowserContext* context);
42
43 // Creates extension app icon for requested app and size. Icon updates are
44 // dispatched via |delegate|.
45 std::unique_ptr<ChromeAppIcon> CreateIcon(ChromeAppIconDelegate* delegate,
46 const std::string& app_id,
47 int resource_size_in_dip);
48
49 // KeyedService:
50 void Shutdown() override;
51
52 private:
53 class Updater;
54
55 // System may have multiple icons for the same app id with the same of
msw 2017/05/10 19:05:21 nit: "same or" and "dimensions". (or just "multipl
khmel 2017/05/11 02:13:48 Thanks for nice wording.
khmel 2017/05/11 02:13:48 Thanks for nice wording.
56 // different dimension. For example icon in shelf and app launcher.
57 using IconMap = std::map<std::string, std::set<ChromeAppIcon*>>;
58
59 // Called from ChromeAppIcon DTOR.
60 void OnIconDestroyed(ChromeAppIcon* icon);
61
62 // Called from Updater when corresponded app icons need to be updated.
63 void OnAppUpdated(const std::string& app_id);
64
65 // ExtensionRegistryObserver:
66 void OnExtensionLoaded(content::BrowserContext* browser_context,
67 const Extension* extension) override;
68 void OnExtensionUnloaded(content::BrowserContext* browser_context,
69 const Extension* extension,
70 UnloadedExtensionReason reason) override;
71
72 // Unowned pointer.
73 content::BrowserContext* context_;
74
75 #if defined(OS_CHROMEOS)
76 // On Chrome OS this handles Chrome app life-cycle events that may change how
77 // extension based app icon looks like.
78 std::unique_ptr<Updater> app_updater_;
79 #endif
80
81 IconMap icon_map_;
82
83 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_;
84
85 base::WeakPtrFactory<ChromeAppIconService> weak_ptr_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(ChromeAppIconService);
88 };
89
90 } // namespace extensions
91
92 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698