Chromium Code Reviews| 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_CHROMEOS_APP_MODE_KIOSK_APP_ICON_LOADER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_ICON_LOADER_H_ | |
| 7 | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/memory/ref_counted_memory.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/sequenced_task_runner.h" | |
| 12 #include "chrome/browser/image_decoder.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 // Loads locally stored icon data and decodes it. | |
| 18 class KioskAppIconLoader { | |
| 19 public: | |
| 20 enum LoadResult { | |
| 21 SUCCESS, | |
| 22 FAILED_TO_LOAD, | |
| 23 FAILED_TO_DECODE, | |
| 24 }; | |
| 25 | |
| 26 class Delegate { | |
| 27 public: | |
| 28 Delegate() = default; | |
| 29 | |
| 30 virtual void OnIconLoadSuccess(const gfx::ImageSkia& icon) = 0; | |
| 31 virtual void OnIconLoadFailure() = 0; | |
| 32 | |
| 33 protected: | |
| 34 virtual ~Delegate() = default; | |
| 35 | |
| 36 private: | |
| 37 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 38 }; | |
| 39 | |
| 40 KioskAppIconLoader(const base::WeakPtr<Delegate>& client, | |
| 41 const base::FilePath& icon_path); | |
| 42 | |
| 43 void Start(); | |
| 44 | |
| 45 private: | |
| 46 friend class base::RefCountedThreadSafe<KioskAppIconLoader>; | |
| 47 | |
| 48 ~KioskAppIconLoader(); | |
| 49 | |
| 50 class IconImageRequest : public ImageDecoder::ImageRequest { | |
|
khmel
2017/03/27 22:56:34
nit: Move to cc file and use here only forward dec
Sergey Poromov
2017/03/28 15:25:55
Done. Thanks, missed the opportunity.
| |
| 51 public: | |
| 52 IconImageRequest( | |
| 53 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 54 KioskAppIconLoader* icon_loader); | |
| 55 | |
| 56 void OnImageDecoded(const SkBitmap& decoded_image) override; | |
| 57 | |
| 58 void OnDecodeImageFailed() override; | |
| 59 | |
| 60 private: | |
| 61 ~IconImageRequest() override = default; | |
| 62 KioskAppIconLoader* icon_loader_; | |
| 63 }; | |
| 64 | |
| 65 // Loads the icon from locally stored |icon_path_| on the blocking pool | |
| 66 void LoadOnBlockingPool(); | |
| 67 void ReportResultOnBlockingPool(LoadResult result); | |
| 68 void NotifyClient(); | |
| 69 void ReportResultOnUIThread(); | |
| 70 | |
| 71 base::WeakPtr<Delegate> client_; | |
| 72 base::FilePath icon_path_; | |
| 73 | |
| 74 LoadResult load_result_; | |
| 75 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 76 | |
| 77 gfx::ImageSkia icon_; | |
| 78 scoped_refptr<base::RefCountedString> raw_icon_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(KioskAppIconLoader); | |
| 81 }; | |
| 82 | |
| 83 } // namespace chromeos | |
| 84 | |
| 85 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_ICON_LOADER_H_ | |
| OLD | NEW |