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_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 using IconMap = std::map<std::string, std::set<ChromeAppIcon*>>; |
| 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 |
| 66 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 67 const Extension* extension, |
| 68 UnloadedExtensionInfo::Reason reason) override; |
| 69 |
| 70 // Unowned pointer. |
| 71 content::BrowserContext* context_; |
| 72 |
| 73 #if defined(OS_CHROMEOS) |
| 74 std::unique_ptr<Updater> app_updater_; |
| 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_ |
OLD | NEW |