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

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

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: Devlin's comments 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_EXTENSION_APP_ICON_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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 ExtensionAppIcon;
25 class ExtensionAppIconDelegate;
26
27 // Factory for ExtensionAppIcon. 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: ExtensionAppIconService::Get(context)->CreateIcon().
32 class ExtensionAppIconService : public KeyedService,
33 public ExtensionRegistryObserver {
34 public:
35 // See the Create methods.
Devlin 2017/05/01 14:51:11 Obsolete?
khmel 2017/05/01 20:18:18 Done.
36 explicit ExtensionAppIconService(content::BrowserContext* context);
37
38 ~ExtensionAppIconService() override;
39
40 // Convenience function to get the ExtensionAppIconService for a
41 // BrowserContext.
42 static ExtensionAppIconService* Get(content::BrowserContext* context);
43
44 // Creates extension app icon for requested app and size. Icon updates are
45 // dispatched via |delegate|.
46 std::unique_ptr<ExtensionAppIcon> CreateIcon(
47 ExtensionAppIconDelegate* delegate,
48 const std::string& app_id,
49 int resource_size_in_dip);
50
51 // KeyedService:
52 void Shutdown() override;
53
54 private:
55 friend class ExtensionAppIcon;
Devlin 2017/05/01 14:51:11 Is this needed?
khmel 2017/05/01 20:18:18 Done.
56
57 class Updater;
58 using IconMap = std::map<std::string, std::set<ExtensionAppIcon*>>;
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 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_;
84
85 base::WeakPtrFactory<ExtensionAppIconService> weak_ptr_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(ExtensionAppIconService);
88 };
89
90 } // namespace extensions
91
92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_APP_ICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698