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

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

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: rebase 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,
msw 2017/05/08 19:59:53 It would be very nice if this functionality (updat
khmel 2017/05/09 00:05:04 I described in another comments. ChromeAppIconLoad
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 using IconMap = std::map<std::string, std::set<ChromeAppIcon*>>;
msw 2017/05/08 19:59:53 nit: comment on why each app would have a set of i
khmel 2017/05/09 00:05:05 Done.
55
56 // Called from ChromeAppIcon DTOR.
57 void OnIconDestroyed(ChromeAppIcon* icon);
58
59 // Called from Updater when corresponded app icons need to be updated.
60 void OnAppUpdated(const std::string& app_id);
61
62 // ExtensionRegistryObserver:
63 void OnExtensionLoaded(content::BrowserContext* browser_context,
64 const Extension* extension) override;
65
msw 2017/05/08 19:59:54 nit: remove blank line
khmel 2017/05/09 00:05:05 Done.
66 void OnExtensionUnloaded(content::BrowserContext* browser_context,
67 const Extension* extension,
68 UnloadedExtensionReason reason) override;
69
70 // Unowned pointer.
71 content::BrowserContext* context_;
72
73 #if defined(OS_CHROMEOS)
74 std::unique_ptr<Updater> app_updater_;
msw 2017/05/08 19:59:53 nit: add a comment
khmel 2017/05/09 00:05:05 Done.
75 #endif
76
77 IconMap icon_map_;
78
79 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_;
80
81 base::WeakPtrFactory<ChromeAppIconService> weak_ptr_factory_;
82
83 DISALLOW_COPY_AND_ASSIGN(ChromeAppIconService);
84 };
85
86 } // namespace extensions
87
88 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698