Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 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_UI_APP_ICON_LOADER_H_ |
| 6 | #define CHROME_BROWSER_UI_APP_ICON_LOADER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 10 | #include "base/memory/raw_ptr.h" |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 11 | #include "chrome/browser/ui/app_icon_loader_delegate.h" |
| 12 | |
| 13 | class Profile; |
| 14 | |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 15 | // Base class that loads and updates Chrome app's icons. |
khmel | 8c1f662 | 2017-05-11 19:14:50 | [diff] [blame] | 16 | // TODO(khmel): Switch to using ChromeAppIconService instead ChromeAppIconLoader |
| 17 | // and ArcAppIconLoader. |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 18 | class AppIconLoader { |
| 19 | public: |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 20 | AppIconLoader(const AppIconLoader&) = delete; |
| 21 | AppIconLoader& operator=(const AppIconLoader&) = delete; |
| 22 | |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 23 | virtual ~AppIconLoader(); |
| 24 | |
| 25 | // Returns true is this AppIconLoader is able to load an image for the |
| 26 | // requested app. |
| 27 | virtual bool CanLoadImageForApp(const std::string& app_id) = 0; |
| 28 | |
| 29 | // Fetches the image for the specified id. When done (which may be |
| 30 | // synchronous), this should invoke SetAppImage() on the delegate. |
| 31 | virtual void FetchImage(const std::string& app_id) = 0; |
| 32 | |
| 33 | // Clears the image for the specified id. |
| 34 | virtual void ClearImage(const std::string& app_id) = 0; |
| 35 | |
| 36 | // Updates the image for the specified id. This is called to re-create |
| 37 | // the app icon with latest app state (enabled or disabled/terminiated). |
| 38 | // SetAppImage() is called when done. |
| 39 | virtual void UpdateImage(const std::string& app_id) = 0; |
| 40 | |
| 41 | protected: |
| 42 | AppIconLoader(); |
| 43 | AppIconLoader(Profile* profile, |
Nigel Tao | 7cc6f7a | 2019-03-14 09:13:38 | [diff] [blame] | 44 | int icon_size_in_dip, |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 45 | AppIconLoaderDelegate* delegate); |
| 46 | |
| 47 | Profile* profile() { return profile_; } |
Nigel Tao | 7cc6f7a | 2019-03-14 09:13:38 | [diff] [blame] | 48 | int icon_size_in_dip() const { return icon_size_in_dip_; } |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 49 | AppIconLoaderDelegate* delegate() { return delegate_; } |
| 50 | |
| 51 | private: |
Ali Hijazi | 9594a64 | 2022-12-01 14:30:56 | [diff] [blame] | 52 | const raw_ptr<Profile, DanglingUntriaged> profile_ = nullptr; |
Nigel Tao | 7cc6f7a | 2019-03-14 09:13:38 | [diff] [blame] | 53 | const int icon_size_in_dip_ = 0; |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 54 | |
| 55 | // The delegate object which receives the icon images. No ownership. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 56 | const raw_ptr<AppIconLoaderDelegate> delegate_ = nullptr; |
khmel | 6f0c8b4b | 2016-02-19 02:09:06 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #endif // CHROME_BROWSER_UI_APP_ICON_LOADER_H_ |