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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 public history::TopSitesObserver, | 61 public history::TopSitesObserver, |
62 public KeyedService { | 62 public KeyedService { |
63 public: | 63 public: |
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 enum class JumpListVersion { kCurrent, kNext, kShared }; | |
72 | |
71 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; | 73 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; |
72 using URLIconCache = base::flat_map<std::string, base::FilePath>; | 74 using URLIconCache = base::flat_map<std::string, base::FilePath>; |
75 using IconAssociation = base::flat_map<base::FilePath, JumpListVersion>; | |
73 | 76 |
74 // Holds results of the RunUpdateJumpList run. | 77 // Holds results of the RunUpdateJumpList run. |
75 struct UpdateResults { | 78 struct UpdateResults { |
76 UpdateResults(); | 79 UpdateResults(); |
77 ~UpdateResults(); | 80 ~UpdateResults(); |
78 | 81 |
79 // Icon file paths of the most visited links, indexed by tab url. | 82 // 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 | 83 // Holding a copy of most_visited_icons_ initially, it's updated by the |
81 // JumpList update run. If the update run succeeds, it overwrites | 84 // JumpList update run. If the update run succeeds, it overwrites |
82 // most_visited_icons_. | 85 // most_visited_icons_. |
83 URLIconCache most_visited_icons_in_update; | 86 URLIconCache most_visited_icons; |
84 | 87 |
85 // icon file paths of the recently closed links, indexed by tab url. | 88 // 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 | 89 // Holding a copy of recent_closed_icons_ initially, it's updated by the |
87 // JumpList update run. If the update run succeeds, it overwrites | 90 // JumpList update run. If the update run succeeds, it overwrites |
88 // recently_closed_icons_. | 91 // recent_closed_icons_. |
89 URLIconCache recently_closed_icons_in_update; | 92 URLIconCache recent_closed_icons; |
grt (UTC plus 2)
2017/06/20 10:29:18
i prefer "recently" over "recent" since these are
chengx
2017/06/20 19:33:59
Done.
| |
93 | |
94 // The association of icon files in most visited category with the JumpList | |
95 // versions, defined in enum JumpListVersion. Holding a copy of | |
96 // most_visited_icon_assoc_ initially, it's updated by the JumpList update | |
97 // run. If the update run succeeds, it overwrites most_visited_icon_assoc_. | |
98 IconAssociation most_visited_icon_assoc; | |
99 | |
100 // The association of icon files in recently closed category with the | |
101 // JumpList versions, defined in enum JumpListVersion. Holding a copy of | |
102 // recent_closed_icon_assoc_ initially, it's updated by the JumpList | |
103 // update run. If the update run succeeds, it overwrites | |
104 // recent_closed_icon_assoc_. | |
105 IconAssociation recent_closed_icon_assoc; | |
106 | |
107 // A flag indicating if "Most Visited" category should be updated. | |
108 bool most_visited_should_update = false; | |
109 | |
110 // A flag indicating if "Recently Closed" category should be updated. | |
111 bool recent_closed_should_update = false; | |
90 | 112 |
91 // A flag indicating if a JumpList update run is successful. | 113 // A flag indicating if a JumpList update run is successful. |
92 bool update_success = false; | 114 bool update_success = false; |
93 | 115 |
94 // A flag indicating if there is a timeout in notifying the JumpList update | 116 // 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. | 117 // to shell. Note that this variable is independent of update_success. |
96 bool update_timeout = false; | 118 bool update_timeout = false; |
97 }; | 119 }; |
98 | 120 |
99 friend JumpListFactory; | 121 friend JumpListFactory; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 | 190 |
169 // Cancels a pending JumpList update. | 191 // Cancels a pending JumpList update. |
170 void CancelPendingUpdate(); | 192 void CancelPendingUpdate(); |
171 | 193 |
172 // Terminates the JumpList, which includes cancelling any pending updates and | 194 // Terminates the JumpList, which includes cancelling any pending updates and |
173 // stopping observing the Profile and its services. This must be called before | 195 // stopping observing the Profile and its services. This must be called before |
174 // the |profile_| is destroyed. | 196 // the |profile_| is destroyed. |
175 void Terminate(); | 197 void Terminate(); |
176 | 198 |
177 // Updates the application JumpList, which consists of 1) create new icon | 199 // Updates the application JumpList, which consists of 1) create new icon |
178 // files; 2) delete obsolete icon files; 3) notify the OS. | 200 // files; 2) notify the OS; 2) delete obsolete icon files. |
179 // Note that any timeout error along the way results in the old JumpList being | 201 // Note that any timeout error along the way results in the old JumpList being |
180 // left as-is, while any non-timeout error results in the old JumpList being | 202 // left as-is, while any non-timeout error results in the old JumpList being |
181 // left as-is, but without icon files. | 203 // left as-is, but without icon files. |
182 static void RunUpdateJumpList( | 204 static void RunUpdateJumpList( |
183 const base::string16& app_id, | 205 const base::string16& app_id, |
184 const base::FilePath& profile_dir, | 206 const base::FilePath& profile_dir, |
185 const ShellLinkItemList& most_visited_pages, | 207 const ShellLinkItemList& most_visited_pages, |
186 const ShellLinkItemList& recently_closed_pages, | 208 const ShellLinkItemList& recent_closed_pages, |
187 bool most_visited_pages_have_updates, | |
188 bool recently_closed_pages_have_updates, | |
189 IncognitoModePrefs::Availability incognito_availability, | 209 IncognitoModePrefs::Availability incognito_availability, |
190 UpdateResults* update_results); | 210 UpdateResults* update_results); |
191 | 211 |
192 // Updates icon files for |page_list| in |icon_dir|, which consists of | 212 // Updates icon files for |page_list| in |icon_dir|, which consists of |
193 // 1) creating at most |slot_limit| new icons which are not in |icon_cache|; | 213 // 1) If certain safe conditions are not met, clean the folder at |icon_dir|. |
194 // 2) deleting old icons which are not in |icon_cache|. | 214 // If folder cleaning fails, skip step 2. Besides, clear |icon_assoc|, |
195 // Returns the number of new icon files created. | 215 // |icon_cur| and |icon_next|. |
196 static int UpdateIconFiles(const base::FilePath& icon_dir, | 216 // 2) Create at most |max_items| icon files which are not in |icon_cur| for |
197 const ShellLinkItemList& page_list, | 217 // the asynchrounously loaded icons stored in |item_list|. |icon_assoc| and |
198 size_t slot_limit, | 218 // |icon_next| are updated based on the reusable icons in |icon_cur| and the |
199 URLIconCache* icon_cache); | 219 // newly created icons. Returns the number of new icon files created. |
220 static int SafeCreateIconFiles(const base::FilePath& icon_dir, | |
221 const ShellLinkItemList& page_list, | |
222 size_t slot_limit, | |
223 IconAssociation* icon_assoc, | |
224 URLIconCache* icon_cur, | |
225 URLIconCache* icon_next); | |
200 | 226 |
201 // In |icon_dir|, creates at most |max_items| icon files which are not in | 227 // 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|. | 228 // |icon_cur| for the asynchrounously loaded icons stored in |item_list|. |
203 // |icon_cache| is also updated for newly created icons. | 229 // |icon_assoc| and |icon_next| are updated based on the reusable icons in |
204 // Returns the number of new icon files created. | 230 // |icon_cur| and the newly created icons. Returns the number of new icon |
231 // files created. | |
205 static int CreateIconFiles(const base::FilePath& icon_dir, | 232 static int CreateIconFiles(const base::FilePath& icon_dir, |
206 const ShellLinkItemList& item_list, | 233 const ShellLinkItemList& item_list, |
207 size_t max_items, | 234 size_t max_items, |
208 URLIconCache* icon_cache); | 235 IconAssociation* icon_assoc, |
236 URLIconCache* icon_cur, | |
237 URLIconCache* icon_next); | |
209 | 238 |
210 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. | 239 // Deletes icon files which are associated with JumpList |version|, based on |
240 // the JumpList version and icon association information stored in | |
241 // |update_results|. Icons in both |most_visited_icon_dir| and | |
242 // |recent_closed_should_update| are attempted to process. | |
243 static void DeleteIconFilesUnified( | |
244 const base::FilePath& most_visited_icon_dir, | |
245 const base::FilePath& recent_closed_icon_dir, | |
246 UpdateResults* update_results, | |
247 JumpListVersion version); | |
248 | |
249 // Deletes icon files in |icon_dir| which are associated with JumpList | |
250 // |version|, based on the |icon_assoc| which records the association of | |
251 // icons and JumpList versions. | |
211 static void DeleteIconFiles(const base::FilePath& icon_dir, | 252 static void DeleteIconFiles(const base::FilePath& icon_dir, |
212 URLIconCache* icon_cache); | 253 IconAssociation* icon_assoc, |
254 JumpListVersion version); | |
213 | 255 |
214 // Tracks FaviconService tasks. | 256 // Tracks FaviconService tasks. |
215 base::CancelableTaskTracker cancelable_task_tracker_; | 257 base::CancelableTaskTracker cancelable_task_tracker_; |
216 | 258 |
217 // The Profile object is used to listen for events. | 259 // The Profile object is used to listen for events. |
218 Profile* profile_; | 260 Profile* profile_; |
219 | 261 |
220 // Manages the registration of pref change observers. | 262 // Manages the registration of pref change observers. |
221 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 263 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
222 | 264 |
223 // App id to associate with the JumpList. | 265 // App id to associate with the JumpList. |
224 base::string16 app_id_; | 266 base::string16 app_id_; |
225 | 267 |
226 // Timer for requesting delayed JumpList updates. | 268 // Timer for requesting delayed JumpList updates. |
227 base::OneShotTimer timer_; | 269 base::OneShotTimer timer_; |
228 | 270 |
229 // A list of URLs we need to retrieve their favicons, | 271 // A list of URLs we need to retrieve their favicons, |
230 std::list<UrlAndLinkItem> icon_urls_; | 272 std::list<UrlAndLinkItem> icon_urls_; |
231 | 273 |
232 // Items in the "Most Visited" category of the JumpList. | 274 // Items in the "Most Visited" category of the JumpList. |
233 ShellLinkItemList most_visited_pages_; | 275 ShellLinkItemList most_visited_pages_; |
234 | 276 |
235 // Items in the "Recently Closed" category of the JumpList. | 277 // Items in the "Recently Closed" category of the JumpList. |
236 ShellLinkItemList recently_closed_pages_; | 278 ShellLinkItemList recent_closed_pages_; |
237 | 279 |
238 // The icon file paths of the most visited links, indexed by tab url. | 280 // The icon file paths of the most visited links, indexed by tab url. |
239 URLIconCache most_visited_icons_; | 281 URLIconCache most_visited_icons_; |
240 | 282 |
241 // The icon file paths of the recently closed links, indexed by tab url. | 283 // The icon file paths of the recently closed links, indexed by tab url. |
242 URLIconCache recently_closed_icons_; | 284 URLIconCache recent_closed_icons_; |
285 | |
286 // The association of icon files in most visited category with the JumpList | |
287 // versions, defined in enum JumpListVersion. | |
288 IconAssociation most_visited_icon_assoc_; | |
289 | |
290 // The association of icon files in recently closed category with the JumpList | |
291 // versions, defined in enum JumpListVersion. | |
292 IconAssociation recent_closed_icon_assoc_; | |
243 | 293 |
244 // A flag indicating if TopSites service has notifications. | 294 // A flag indicating if TopSites service has notifications. |
245 bool top_sites_has_pending_notification_ = false; | 295 bool top_sites_has_pending_notification_ = false; |
246 | 296 |
247 // A flag indicating if TabRestore service has notifications. | 297 // A flag indicating if TabRestore service has notifications. |
248 bool tab_restore_has_pending_notification_ = false; | 298 bool tab_restore_has_pending_notification_ = false; |
249 | 299 |
250 // A flag indicating if "Most Visited" category should be updated. | 300 // A flag indicating if "Most Visited" category should be updated. |
251 bool most_visited_should_update_ = false; | 301 bool most_visited_should_update_ = false; |
252 | 302 |
253 // A flag indicating if "Recently Closed" category should be updated. | 303 // A flag indicating if "Recently Closed" category should be updated. |
254 bool recently_closed_should_update_ = false; | 304 bool recent_closed_should_update_ = false; |
255 | 305 |
256 // A flag indicating if there's a JumpList update task already posted or | 306 // A flag indicating if there's a JumpList update task already posted or |
257 // currently running. | 307 // currently running. |
258 bool update_in_progress_ = false; | 308 bool update_in_progress_ = false; |
259 | 309 |
260 // A flag indicating if a session has at least one tab closed. | 310 // A flag indicating if a session has at least one tab closed. |
261 bool has_tab_closed_ = false; | 311 bool has_tab_closed_ = false; |
262 | 312 |
263 // Number of updates to skip to alleviate the machine when a previous update | 313 // Number of updates to skip to alleviate the machine when a previous update |
264 // was too slow. Updates will be resumed when this reaches 0 again. | 314 // was too slow. Updates will be resumed when this reaches 0 again. |
(...skipping 13 matching lines...) Expand all Loading... | |
278 | 328 |
279 SEQUENCE_CHECKER(sequence_checker_); | 329 SEQUENCE_CHECKER(sequence_checker_); |
280 | 330 |
281 // For callbacks may run after destruction. | 331 // For callbacks may run after destruction. |
282 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 332 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
283 | 333 |
284 DISALLOW_COPY_AND_ASSIGN(JumpList); | 334 DISALLOW_COPY_AND_ASSIGN(JumpList); |
285 }; | 335 }; |
286 | 336 |
287 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 337 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |