OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_WIN_JUMPLIST_H_ | 5 #ifndef CHROME_BROWSER_WIN_JUMPLIST_H_ |
6 #define CHROME_BROWSER_WIN_JUMPLIST_H_ | 6 #define CHROME_BROWSER_WIN_JUMPLIST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // Returns true if the custom JumpList is enabled. | 64 // Returns true if the custom JumpList is enabled. |
65 static bool Enabled(); | 65 static bool Enabled(); |
66 | 66 |
67 // KeyedService: | 67 // KeyedService: |
68 void Shutdown() override; | 68 void Shutdown() override; |
69 | 69 |
70 private: | 70 private: |
71 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; | 71 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; |
72 using URLIconCache = base::flat_map<std::string, base::FilePath>; | 72 using URLIconCache = base::flat_map<std::string, base::FilePath>; |
73 | 73 |
74 // Holds results of the RunUpdateJumpList run. | 74 // Holds results of a RunUpdateJumpList run. |
75 struct UpdateResults { | 75 // In-out params: |
76 UpdateResults(); | 76 // |most_visited_icons|, |recently_closed_icons| |
77 ~UpdateResults(); | 77 // Out params: |
78 // |update_success|, |update_timeout| | |
79 struct UpdateTransaction { | |
80 UpdateTransaction(); | |
81 ~UpdateTransaction(); | |
78 | 82 |
79 // Icon file paths of the most visited links, indexed by tab url. | 83 // Icon file paths of the most visited links, indexed by tab url. |
80 // Holding a copy of most_visited_icons_ initially, it's updated by the | 84 // Holding a copy of most_visited_icons_ initially, it's updated by the |
81 // JumpList update run. If the update run succeeds, it overwrites | 85 // JumpList update run. If the update run succeeds, it overwrites |
82 // most_visited_icons_. | 86 // most_visited_icons_. |
83 URLIconCache most_visited_icons_in_update; | 87 URLIconCache most_visited_icons; |
84 | 88 |
85 // icon file paths of the recently closed links, indexed by tab url. | 89 // Icon file paths of the recently closed links, indexed by tab url. |
86 // Holding a copy of recently_closed_icons_ initially, it's updated by the | 90 // Holding a copy of recently_closed_icons_ initially, it's updated by the |
87 // JumpList update run. If the update run succeeds, it overwrites | 91 // JumpList update run. If the update run succeeds, it overwrites |
88 // recently_closed_icons_. | 92 // recently_closed_icons_. |
89 URLIconCache recently_closed_icons_in_update; | 93 URLIconCache recently_closed_icons; |
90 | 94 |
91 // A flag indicating if a JumpList update run is successful. | 95 // A flag indicating if a JumpList update run is successful. |
92 bool update_success = false; | 96 bool update_success = false; |
93 | 97 |
94 // A flag indicating if there is a timeout in notifying the JumpList update | 98 // A flag indicating if there is a timeout in notifying the JumpList update |
95 // to shell. Note that this variable is independent of update_success. | 99 // to shell. Note that this variable is independent of update_success. |
96 bool update_timeout = false; | 100 bool update_timeout = false; |
97 }; | 101 }; |
98 | 102 |
99 friend JumpListFactory; | 103 friend JumpListFactory; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 // available. To avoid file operations, this function just attaches the given | 159 // available. To avoid file operations, this function just attaches the given |
156 // |image_result| to a ShellLinkItem object. | 160 // |image_result| to a ShellLinkItem object. |
157 void OnFaviconDataAvailable( | 161 void OnFaviconDataAvailable( |
158 const favicon_base::FaviconImageResult& image_result); | 162 const favicon_base::FaviconImageResult& image_result); |
159 | 163 |
160 // Posts tasks to update the JumpList and delete any obsolete JumpList related | 164 // Posts tasks to update the JumpList and delete any obsolete JumpList related |
161 // folders. | 165 // folders. |
162 void PostRunUpdate(); | 166 void PostRunUpdate(); |
163 | 167 |
164 // Callback for RunUpdateJumpList that notifies when it finishes running. | 168 // Callback for RunUpdateJumpList that notifies when it finishes running. |
165 // Updates certain JumpList member variables and/or triggers a new JumpList | 169 // Updates certain JumpList member variables and/or triggers a new JumpList |
grt (UTC plus 2)
2017/06/27 07:45:29
this comment is a little misleading since triggeri
chengx
2017/06/29 17:46:05
I'll happily accept this suggestion! Thanks!
| |
166 // update based on |update_results|. | 170 // update based on |update_transaction|. |
167 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results); | 171 void OnRunUpdateCompletion( |
172 std::unique_ptr<UpdateTransaction> update_transaction); | |
168 | 173 |
169 // Cancels a pending JumpList update. | 174 // Cancels a pending JumpList update. |
170 void CancelPendingUpdate(); | 175 void CancelPendingUpdate(); |
171 | 176 |
172 // Terminates the JumpList, which includes cancelling any pending updates and | 177 // Terminates the JumpList, which includes cancelling any pending updates and |
173 // stopping observing the Profile and its services. This must be called before | 178 // stopping observing the Profile and its services. This must be called before |
174 // the |profile_| is destroyed. | 179 // the |profile_| is destroyed. |
175 void Terminate(); | 180 void Terminate(); |
176 | 181 |
177 // Updates the application JumpList, which consists of 1) create new icon | 182 // Updates the application JumpList, which consists of 1) create a new |
178 // files; 2) delete obsolete icon files; 3) notify the OS. | 183 // JumpList along with any icons that are not in the cache; 2) notify the OS; |
179 // Note that any timeout error along the way results in the old JumpList being | 184 // 3) delete obsolete icon files. Any error along the way results in the old |
180 // left as-is, while any non-timeout error results in the old JumpList being | 185 // JumpList being left as-is. |
181 // left as-is, but without icon files. | |
182 static void RunUpdateJumpList( | 186 static void RunUpdateJumpList( |
183 const base::string16& app_id, | 187 const base::string16& app_id, |
184 const base::FilePath& profile_dir, | 188 const base::FilePath& profile_dir, |
185 const ShellLinkItemList& most_visited_pages, | 189 const ShellLinkItemList& most_visited_pages, |
186 const ShellLinkItemList& recently_closed_pages, | 190 const ShellLinkItemList& recently_closed_pages, |
187 bool most_visited_pages_have_updates, | 191 bool most_visited_should_update, |
188 bool recently_closed_pages_have_updates, | 192 bool recently_closed_should_update, |
189 IncognitoModePrefs::Availability incognito_availability, | 193 IncognitoModePrefs::Availability incognito_availability, |
190 UpdateResults* update_results); | 194 UpdateTransaction* update_transaction); |
191 | 195 |
192 // Updates icon files for |page_list| in |icon_dir|, which consists of | 196 // Creates a new JumpList along with any icons that are not in the cache, |
193 // 1) creating at most |slot_limit| new icons which are not in |icon_cache|; | 197 // and notifies the OS. |
194 // 2) deleting old icons which are not in |icon_cache|. | 198 static void CreateNewJumpListAndNotifyOS( |
195 // Returns the number of new icon files created. | 199 const base::string16& app_id, |
200 const base::FilePath& most_visited_icon_dir, | |
201 const base::FilePath& recently_closed_icon_dir, | |
202 const ShellLinkItemList& most_visited_pages, | |
203 const ShellLinkItemList& recently_closed_pages, | |
204 bool most_visited_should_update, | |
205 bool recently_closed_should_update, | |
206 IncognitoModePrefs::Availability incognito_availability, | |
207 UpdateTransaction* update_transaction); | |
208 | |
209 // Updates icon files for |item_list| in |icon_dir|, which consists of | |
210 // 1) If certain safe conditions are not met, clean the folder at |icon_dir|. | |
211 // If folder cleaning fails, skip step 2. Besides, clear |icon_cur| and | |
212 // |icon_next|. | |
213 // 2) Create at most |max_items| icon files which are not in |icon_cur| for | |
214 // the asynchrounously loaded icons stored in |item_list|. | |
196 static int UpdateIconFiles(const base::FilePath& icon_dir, | 215 static int UpdateIconFiles(const base::FilePath& icon_dir, |
197 const ShellLinkItemList& page_list, | 216 const ShellLinkItemList& item_list, |
198 size_t slot_limit, | 217 size_t max_items, |
199 URLIconCache* icon_cache); | 218 URLIconCache* icon_cur, |
219 URLIconCache* icon_next); | |
200 | 220 |
201 // In |icon_dir|, creates at most |max_items| icon files which are not in | 221 // In |icon_dir|, creates at most |max_items| icon files which are not in |
202 // |icon_cache| for the asynchrounously loaded icons stored in |item_list|. | 222 // |icon_cur| for the asynchrounously loaded icons stored in |item_list|. |
203 // |icon_cache| is also updated for newly created icons. | 223 // |icon_next| is updated based on the reusable icons and the newly created |
204 // Returns the number of new icon files created. | 224 // icons. Returns the number of new icon files created. |
205 static int CreateIconFiles(const base::FilePath& icon_dir, | 225 static int CreateIconFiles(const base::FilePath& icon_dir, |
206 const ShellLinkItemList& item_list, | 226 const ShellLinkItemList& item_list, |
207 size_t max_items, | 227 size_t max_items, |
208 URLIconCache* icon_cache); | 228 const URLIconCache& icon_cur, |
229 URLIconCache* icon_next); | |
209 | 230 |
210 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. | 231 // Deletes icon files in |icon_dir| which are not in |icon_cache|. |
211 static void DeleteIconFiles(const base::FilePath& icon_dir, | 232 static void DeleteIconFiles(const base::FilePath& icon_dir, |
212 URLIconCache* icon_cache); | 233 const URLIconCache& icons_cache); |
213 | 234 |
214 // Tracks FaviconService tasks. | 235 // Tracks FaviconService tasks. |
215 base::CancelableTaskTracker cancelable_task_tracker_; | 236 base::CancelableTaskTracker cancelable_task_tracker_; |
216 | 237 |
217 // The Profile object is used to listen for events. | 238 // The Profile object is used to listen for events. |
218 Profile* profile_; | 239 Profile* profile_; |
219 | 240 |
220 // Manages the registration of pref change observers. | 241 // Manages the registration of pref change observers. |
221 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 242 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
222 | 243 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 | 299 |
279 SEQUENCE_CHECKER(sequence_checker_); | 300 SEQUENCE_CHECKER(sequence_checker_); |
280 | 301 |
281 // For callbacks may run after destruction. | 302 // For callbacks may run after destruction. |
282 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 303 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
283 | 304 |
284 DISALLOW_COPY_AND_ASSIGN(JumpList); | 305 DISALLOW_COPY_AND_ASSIGN(JumpList); |
285 }; | 306 }; |
286 | 307 |
287 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 308 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |