Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_icon.h

Issue 2864243006: [Merge M59] arc: Prevent overwriting of the Chrome Play Store icon. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_ 5 #ifndef CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_
6 #define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_ 6 #define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 27 matching lines...) Expand all
38 virtual ~Observer() {} 38 virtual ~Observer() {}
39 }; 39 };
40 40
41 ArcAppIcon(content::BrowserContext* context, 41 ArcAppIcon(content::BrowserContext* context,
42 const std::string& app_id, 42 const std::string& app_id,
43 int resource_size_in_dip, 43 int resource_size_in_dip,
44 Observer* observer); 44 Observer* observer);
45 ~ArcAppIcon(); 45 ~ArcAppIcon();
46 46
47 const std::string& app_id() const { return app_id_; } 47 const std::string& app_id() const { return app_id_; }
48 gfx::Image image() const { return image_; }
49 const gfx::ImageSkia& image_skia() const { return image_skia_; } 48 const gfx::ImageSkia& image_skia() const { return image_skia_; }
50 49
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 // Disables async safe decoding requests when unit tests are executed. This is 50 // Disables async safe decoding requests when unit tests are executed. This is
69 // done to avoid two problems. Problems come because icons are decoded at a 51 // done to avoid two problems. Problems come because icons are decoded at a
70 // separate process created by ImageDecoder. ImageDecoder has 5 seconds delay 52 // separate process created by ImageDecoder. ImageDecoder has 5 seconds delay
71 // to stop since the last request (see its kBatchModeTimeoutSeconds for more 53 // to stop since the last request (see its kBatchModeTimeoutSeconds for more
72 // details). This is unacceptably long for unit tests because the test 54 // details). This is unacceptably long for unit tests because the test
73 // framework waits until external process is finished. Another problem happens 55 // framework waits until external process is finished. Another problem happens
74 // when we issue a decoding request, but the process has not started its 56 // when we issue a decoding request, but the process has not started its
75 // processing yet by the time when a test exits. This might cause situation 57 // processing yet by the time when a test exits. This might cause situation
76 // when g_one_utility_thread_lock from in_process_utility_thread.cc gets 58 // when g_one_utility_thread_lock from in_process_utility_thread.cc gets
77 // released in an acquired state which is crash condition in debug builds. 59 // released in an acquired state which is crash condition in debug builds.
78 static void DisableSafeDecodingForTesting(); 60 static void DisableSafeDecodingForTesting();
79 61
80 private: 62 private:
63 friend class ArcAppIconLoader;
64 friend class ArcAppModelBuilder;
65
81 class Source; 66 class Source;
82 class DecodeRequest; 67 class DecodeRequest;
83 struct ReadResult; 68 struct ReadResult;
84 69
70 // Icon loading is performed in several steps. It is initiated by
71 // LoadImageForScaleFactor request that specifies a required scale factor.
72 // ArcAppListPrefs is used to resolve a path to resource. Content of file is
73 // asynchronously read in context of browser file thread. On successful read,
74 // an icon data is decoded to an image in the special utility process.
75 // DecodeRequest is used to interact with the utility process, and each
76 // active request is stored at |decode_requests_| vector. When decoding is
77 // complete, results are returned in context of UI thread, and corresponding
78 // request is removed from |decode_requests_|. In case of some requests are
79 // not completed by the time of deleting this icon, they are automatically
80 // canceled.
81 // In case of the icon file is not available this requests ArcAppListPrefs to
82 // install required resource from ARC side. ArcAppListPrefs notifies UI items
83 // that new icon is available and corresponding item should invoke
84 // LoadImageForScaleFactor again.
85 void LoadForScaleFactor(ui::ScaleFactor scale_factor);
86
85 void MaybeRequestIcon(ui::ScaleFactor scale_factor); 87 void MaybeRequestIcon(ui::ScaleFactor scale_factor);
86 static std::unique_ptr<ArcAppIcon::ReadResult> ReadOnFileThread( 88 static std::unique_ptr<ArcAppIcon::ReadResult> ReadOnFileThread(
87 ui::ScaleFactor scale_factor, 89 ui::ScaleFactor scale_factor,
88 const base::FilePath& path, 90 const base::FilePath& path,
89 const base::FilePath& default_app_path); 91 const base::FilePath& default_app_path);
90 void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result); 92 void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result);
91 void Update(const gfx::ImageSkia* image); 93 void Update(const gfx::ImageSkia* image);
92 void DiscardDecodeRequest(DecodeRequest* request); 94 void DiscardDecodeRequest(DecodeRequest* request);
93 95
94 content::BrowserContext* context_; 96 content::BrowserContext* context_;
95 std::string app_id_; 97 std::string app_id_;
96 const int resource_size_in_dip_; 98 const int resource_size_in_dip_;
97 Observer* observer_; 99 Observer* observer_;
98 100
99 Source* source_ = nullptr; // Owned by ImageSkia storage. 101 Source* source_ = nullptr; // Owned by ImageSkia storage.
100 gfx::ImageSkia image_skia_; 102 gfx::ImageSkia image_skia_;
101 103
102 // The image wrapper around |image_skia_|.
103 // Note: this is reset each time a new representation is loaded.
104 gfx::Image image_;
105
106 // Contains pending image decode requests. 104 // Contains pending image decode requests.
107 std::vector<std::unique_ptr<DecodeRequest>> decode_requests_; 105 std::vector<std::unique_ptr<DecodeRequest>> decode_requests_;
108 106
109 base::WeakPtrFactory<ArcAppIcon> weak_ptr_factory_; 107 base::WeakPtrFactory<ArcAppIcon> weak_ptr_factory_;
110 108
111 DISALLOW_COPY_AND_ASSIGN(ArcAppIcon); 109 DISALLOW_COPY_AND_ASSIGN(ArcAppIcon);
112 }; 110 };
113 111
114 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_ 112 #endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698