Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_UI_APP_LIST_ARC_APP_ICON_H_ | |
| 6 #define CHROME_BROWSER_UI_APP_LIST_ARC_APP_ICON_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_vector.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "ui/base/layout.h" | |
| 14 #include "ui/gfx/image/image.h" | |
| 15 #include "ui/gfx/image/image_skia.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class FilePath; | |
| 19 } | |
| 20 | |
| 21 namespace content { | |
| 22 class BrowserContext; | |
| 23 } | |
| 24 | |
| 25 // A class that provides an ImageSkia for UI code to use. It handles ARC app | |
| 26 // icon resource loading, screen scale factor change etc. UI code that uses | |
| 27 // ARC app icon should host this class. | |
| 28 class ArcAppIcon { | |
| 29 public: | |
| 30 struct ReadResult; | |
|
xiyuan
2015/11/18 17:41:15
nit: Think this can be private now.
khmel1
2015/11/19 02:56:13
Yes, is works update recent updates.
| |
| 31 | |
| 32 class Observer { | |
| 33 public: | |
| 34 // Invoked when a new image rep for an additional scale factor | |
| 35 // is loaded and added to |image|. | |
| 36 virtual void OnIconUpdated() = 0; | |
| 37 | |
| 38 protected: | |
| 39 virtual ~Observer() {} | |
| 40 }; | |
| 41 | |
| 42 ArcAppIcon(content::BrowserContext* context, | |
| 43 const std::string& app_id, | |
| 44 int resource_size_in_dip, | |
| 45 Observer* observer); | |
| 46 ~ArcAppIcon(); | |
| 47 | |
| 48 gfx::Image image() const { return image_; } | |
| 49 const gfx::ImageSkia& image_skia() const { return image_skia_; } | |
| 50 | |
| 51 // Icon loading is performed in several steps. It is initiated by | |
| 52 // LoadImageForScaleFactor request that specifies a required scale factor. | |
| 53 // ArcAppListPrefs is used to resolve a path to resource. Content of file is | |
| 54 // asynchronously read in context of browser file thread. On successful read, | |
| 55 // an icon data is decoded to an image in the special utility process. | |
| 56 // DecodeRequest is used to interact with the utility process, and each | |
| 57 // active request is stored at |decode_requests_| vector. When decoding is | |
| 58 // complete, results are returned in context of UI thread, and corresponding | |
| 59 // request is removed from |decode_requests_|. In case of some requests are | |
| 60 // not completed by the time of deleting this icon, they are automatically | |
| 61 // canceled. | |
| 62 // In case of the icon file is not available this requests ArcAppListPrefs to | |
| 63 // install required resource from ARC side. ArcAppListPrefs notifies UI items | |
| 64 // that new icon is available and corresponding item should invoke | |
| 65 // LoadImageForScaleFactor again. | |
| 66 void LoadForScaleFactor(ui::ScaleFactor scale_factor); | |
| 67 | |
| 68 private: | |
| 69 class Source; | |
| 70 class DecodeRequest; | |
| 71 | |
| 72 void RequestIcon(ui::ScaleFactor scale_factor); | |
| 73 static scoped_ptr<ArcAppIcon::ReadResult> ReadOnFileThread( | |
| 74 ui::ScaleFactor scale_factor, | |
| 75 const base::FilePath& path); | |
| 76 void OnIconRead(scoped_ptr<ArcAppIcon::ReadResult> read_result); | |
| 77 void Update(const gfx::ImageSkia* image); | |
| 78 void DiscardDecodeRequest(DecodeRequest* request); | |
| 79 | |
| 80 content::BrowserContext* context_; | |
| 81 std::string app_id_; | |
| 82 const int resource_size_in_dip_; | |
| 83 Observer* observer_; | |
| 84 | |
| 85 Source* source_ = nullptr; // Owned by ImageSkia storage. | |
| 86 gfx::ImageSkia image_skia_; | |
| 87 | |
| 88 // The image wrapper around |image_skia_|. | |
| 89 // Note: this is reset each time a new representation is loaded. | |
| 90 gfx::Image image_; | |
| 91 | |
| 92 // Contains pending image decode requests. | |
| 93 ScopedVector<DecodeRequest> decode_requests_; | |
| 94 | |
| 95 base::WeakPtrFactory<ArcAppIcon> weak_ptr_factory_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(ArcAppIcon); | |
| 98 }; | |
| 99 | |
| 100 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_ICON_H_ | |
| OLD | NEW |