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 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| 20 #endif |
| 21 |
| 22 namespace content { |
| 23 class BrowserContext; |
| 24 } |
| 25 |
| 26 namespace extensions { |
| 27 |
| 28 class ChromeAppIcon; |
| 29 class ChromeAppIconDelegate; |
| 30 |
| 31 // Factory for ChromeAppIcon. Each created icon is tracked by this service. |
| 32 // Once some condition that affects how extension app icon should look is |
| 33 // changed then corresponded app icons are automatically updated. This service |
| 34 // is bound to content::BrowserContext. |
| 35 // Usage: ChromeAppIconService::Get(context)->CreateIcon(). |
| 36 class ChromeAppIconService : public KeyedService, |
| 37 #if defined(OS_CHROMEOS) |
| 38 public LauncherAppUpdater::Delegate, |
| 39 #endif |
| 40 public ExtensionRegistryObserver { |
| 41 public: |
| 42 explicit ChromeAppIconService(content::BrowserContext* context); |
| 43 |
| 44 ~ChromeAppIconService() override; |
| 45 |
| 46 // Convenience function to get the ChromeAppIconService for a |
| 47 // BrowserContext. |
| 48 static ChromeAppIconService* Get(content::BrowserContext* context); |
| 49 |
| 50 // Creates extension app icon for requested app and size. Icon updates are |
| 51 // dispatched via |delegate|. |
| 52 std::unique_ptr<ChromeAppIcon> CreateIcon(ChromeAppIconDelegate* delegate, |
| 53 const std::string& app_id, |
| 54 int resource_size_in_dip); |
| 55 |
| 56 // KeyedService: |
| 57 void Shutdown() override; |
| 58 |
| 59 private: |
| 60 class Updater; |
| 61 |
| 62 // System may have multiple icons for the same app id with different |
| 63 // dimensions. For example icon in shelf and app launcher. |
| 64 using IconMap = std::map<std::string, std::set<ChromeAppIcon*>>; |
| 65 |
| 66 // Called from ChromeAppIcon DTOR. |
| 67 void OnIconDestroyed(ChromeAppIcon* icon); |
| 68 |
| 69 // Called from Updater when corresponded app icons need to be updated. |
| 70 void OnAppUpdated(const std::string& app_id); |
| 71 |
| 72 // ExtensionRegistryObserver: |
| 73 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 74 const Extension* extension) override; |
| 75 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 76 const Extension* extension, |
| 77 UnloadedExtensionReason reason) override; |
| 78 |
| 79 #if defined(OS_CHROMEOS) |
| 80 // LauncherAppUpdater::Delegate: |
| 81 void OnAppUpdated(content::BrowserContext* browser_context, |
| 82 const std::string& app_id) override; |
| 83 #endif |
| 84 |
| 85 // Unowned pointer. |
| 86 content::BrowserContext* context_; |
| 87 |
| 88 #if defined(OS_CHROMEOS) |
| 89 // On Chrome OS this handles Chrome app life-cycle events that may change how |
| 90 // extension based app icon looks like. |
| 91 std::unique_ptr<LauncherExtensionAppUpdater> app_updater_; |
| 92 #endif |
| 93 |
| 94 IconMap icon_map_; |
| 95 |
| 96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_; |
| 97 |
| 98 base::WeakPtrFactory<ChromeAppIconService> weak_ptr_factory_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(ChromeAppIconService); |
| 101 }; |
| 102 |
| 103 } // namespace extensions |
| 104 |
| 105 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_SERVICE_H_ |
OLD | NEW |