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 }; | |
grt (UTC plus 2)
2017/06/21 10:57:29
// Indicates whether a JumpList icon file is used
chengx
2017/06/22 22:45:06
I've removed this enum class as it's no longer nee
| |
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>; |
grt (UTC plus 2)
2017/06/21 10:57:29
rather than introducing another container to hold
chengx
2017/06/22 22:45:06
Done. After a second thought, I think using the or
| |
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 recently_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 // recently_closed_icons_. |
89 URLIconCache recently_closed_icons_in_update; | 92 URLIconCache recently_closed_icons; |
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 // recently_closed_icon_assoc_ initially, it's updated by the JumpList | |
103 // update run. If the update run succeeds, it overwrites | |
104 // recently_closed_icon_assoc_. | |
105 IconAssociation recently_closed_icon_assoc; | |
90 | 106 |
91 // A flag indicating if a JumpList update run is successful. | 107 // A flag indicating if a JumpList update run is successful. |
92 bool update_success = false; | 108 bool update_success = false; |
93 | 109 |
94 // A flag indicating if there is a timeout in notifying the JumpList update | 110 // 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. | 111 // to shell. Note that this variable is independent of update_success. |
96 bool update_timeout = false; | 112 bool update_timeout = false; |
97 }; | 113 }; |
98 | 114 |
99 friend JumpListFactory; | 115 friend JumpListFactory; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 // |image_result| to a ShellLinkItem object. | 172 // |image_result| to a ShellLinkItem object. |
157 void OnFaviconDataAvailable( | 173 void OnFaviconDataAvailable( |
158 const favicon_base::FaviconImageResult& image_result); | 174 const favicon_base::FaviconImageResult& image_result); |
159 | 175 |
160 // Posts tasks to update the JumpList and delete any obsolete JumpList related | 176 // Posts tasks to update the JumpList and delete any obsolete JumpList related |
161 // folders. | 177 // folders. |
162 void PostRunUpdate(); | 178 void PostRunUpdate(); |
163 | 179 |
164 // Callback for RunUpdateJumpList that notifies when it finishes running. | 180 // Callback for RunUpdateJumpList that notifies when it finishes running. |
165 // Updates certain JumpList member variables and/or triggers a new JumpList | 181 // Updates certain JumpList member variables and/or triggers a new JumpList |
166 // update based on |update_results|. | 182 // update based on |update_results|, the flags |most_visited_should_update| |
167 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results); | 183 // and |recently_closed_should_update|. |
184 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results, | |
185 bool most_visited_should_update, | |
186 bool recently_closed_should_update); | |
168 | 187 |
169 // Cancels a pending JumpList update. | 188 // Cancels a pending JumpList update. |
170 void CancelPendingUpdate(); | 189 void CancelPendingUpdate(); |
171 | 190 |
172 // Terminates the JumpList, which includes cancelling any pending updates and | 191 // Terminates the JumpList, which includes cancelling any pending updates and |
173 // stopping observing the Profile and its services. This must be called before | 192 // stopping observing the Profile and its services. This must be called before |
174 // the |profile_| is destroyed. | 193 // the |profile_| is destroyed. |
175 void Terminate(); | 194 void Terminate(); |
176 | 195 |
177 // Updates the application JumpList, which consists of 1) create new icon | 196 // Updates the application JumpList, which consists of 1) create new icon |
178 // files; 2) delete obsolete icon files; 3) notify the OS. | 197 // 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 | 198 // 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 | 199 // left as-is, while any non-timeout error results in the old JumpList being |
181 // left as-is, but without icon files. | 200 // left as-is, but without icon files. |
182 static void RunUpdateJumpList( | 201 static void RunUpdateJumpList( |
183 const base::string16& app_id, | 202 const base::string16& app_id, |
184 const base::FilePath& profile_dir, | 203 const base::FilePath& profile_dir, |
185 const ShellLinkItemList& most_visited_pages, | 204 const ShellLinkItemList& most_visited_pages, |
186 const ShellLinkItemList& recently_closed_pages, | 205 const ShellLinkItemList& recently_closed_pages, |
187 bool most_visited_pages_have_updates, | 206 bool most_visited_should_update, |
188 bool recently_closed_pages_have_updates, | 207 bool recently_closed_should_update, |
189 IncognitoModePrefs::Availability incognito_availability, | 208 IncognitoModePrefs::Availability incognito_availability, |
190 UpdateResults* update_results); | 209 UpdateResults* update_results); |
191 | 210 |
192 // Updates icon files for |page_list| in |icon_dir|, which consists of | 211 // 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|; | 212 // 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|. | 213 // If folder cleaning fails, skip step 2. Besides, clear |icon_assoc|, |
195 // Returns the number of new icon files created. | 214 // |icon_cur| and |icon_next|. |
196 static int UpdateIconFiles(const base::FilePath& icon_dir, | 215 // 2) Create at most |max_items| icon files which are not in |icon_cur| for |
197 const ShellLinkItemList& page_list, | 216 // the asynchrounously loaded icons stored in |item_list|. |icon_assoc| and |
198 size_t slot_limit, | 217 // |icon_next| are updated based on the reusable icons in |icon_cur| and the |
199 URLIconCache* icon_cache); | 218 // newly created icons. Returns the number of new icon files created. |
219 static int SafeCreateIconFiles(const base::FilePath& icon_dir, | |
220 const ShellLinkItemList& page_list, | |
221 size_t slot_limit, | |
222 IconAssociation* icon_assoc, | |
223 URLIconCache* icon_cur, | |
224 URLIconCache* icon_next); | |
200 | 225 |
201 // In |icon_dir|, creates at most |max_items| icon files which are not in | 226 // 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|. | 227 // |icon_cur| for the asynchrounously loaded icons stored in |item_list|. |
203 // |icon_cache| is also updated for newly created icons. | 228 // |icon_assoc| and |icon_next| are updated based on the reusable icons in |
204 // Returns the number of new icon files created. | 229 // |icon_cur| and the newly created icons. Returns the number of new icon |
230 // files created. | |
205 static int CreateIconFiles(const base::FilePath& icon_dir, | 231 static int CreateIconFiles(const base::FilePath& icon_dir, |
206 const ShellLinkItemList& item_list, | 232 const ShellLinkItemList& item_list, |
207 size_t max_items, | 233 size_t max_items, |
208 URLIconCache* icon_cache); | 234 IconAssociation* icon_assoc, |
235 URLIconCache* icon_cur, | |
236 URLIconCache* icon_next); | |
209 | 237 |
210 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. | 238 // Deletes icon files which are associated with JumpList |version|, based on |
239 // the JumpList version and icon association information stored in | |
240 // |update_results|. Icons in |most_visited_icon_dir| are processed if | |
241 // |most_visited_should_update| is true. Icons in |recently_closed_icon_dir| | |
242 // are processed if |recently_closed_should_update| is true. | |
243 static void DeleteIconFilesUnified( | |
244 bool most_visited_should_update, | |
245 bool recently_closed_should_update, | |
246 const base::FilePath& most_visited_icon_dir, | |
247 const base::FilePath& recently_closed_icon_dir, | |
248 UpdateResults* update_results, | |
249 JumpListVersion version); | |
250 | |
251 // Deletes icon files in |icon_dir| which are associated with JumpList | |
252 // |version|, based on the |icon_assoc| which records the association of | |
253 // icons and JumpList versions. | |
211 static void DeleteIconFiles(const base::FilePath& icon_dir, | 254 static void DeleteIconFiles(const base::FilePath& icon_dir, |
212 URLIconCache* icon_cache); | 255 IconAssociation* icon_assoc, |
256 JumpListVersion version); | |
213 | 257 |
214 // Tracks FaviconService tasks. | 258 // Tracks FaviconService tasks. |
215 base::CancelableTaskTracker cancelable_task_tracker_; | 259 base::CancelableTaskTracker cancelable_task_tracker_; |
216 | 260 |
217 // The Profile object is used to listen for events. | 261 // The Profile object is used to listen for events. |
218 Profile* profile_; | 262 Profile* profile_; |
219 | 263 |
220 // Manages the registration of pref change observers. | 264 // Manages the registration of pref change observers. |
221 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 265 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
222 | 266 |
(...skipping 11 matching lines...) Expand all Loading... | |
234 | 278 |
235 // Items in the "Recently Closed" category of the JumpList. | 279 // Items in the "Recently Closed" category of the JumpList. |
236 ShellLinkItemList recently_closed_pages_; | 280 ShellLinkItemList recently_closed_pages_; |
237 | 281 |
238 // The icon file paths of the most visited links, indexed by tab url. | 282 // The icon file paths of the most visited links, indexed by tab url. |
239 URLIconCache most_visited_icons_; | 283 URLIconCache most_visited_icons_; |
240 | 284 |
241 // The icon file paths of the recently closed links, indexed by tab url. | 285 // The icon file paths of the recently closed links, indexed by tab url. |
242 URLIconCache recently_closed_icons_; | 286 URLIconCache recently_closed_icons_; |
243 | 287 |
288 // The association of icon files in most visited category with the JumpList | |
289 // versions, defined in enum JumpListVersion. | |
290 IconAssociation most_visited_icon_assoc_; | |
291 | |
292 // The association of icon files in recently closed category with the JumpList | |
293 // versions, defined in enum JumpListVersion. | |
294 IconAssociation recently_closed_icon_assoc_; | |
295 | |
244 // A flag indicating if TopSites service has notifications. | 296 // A flag indicating if TopSites service has notifications. |
245 bool top_sites_has_pending_notification_ = false; | 297 bool top_sites_has_pending_notification_ = false; |
246 | 298 |
247 // A flag indicating if TabRestore service has notifications. | 299 // A flag indicating if TabRestore service has notifications. |
248 bool tab_restore_has_pending_notification_ = false; | 300 bool tab_restore_has_pending_notification_ = false; |
249 | 301 |
250 // A flag indicating if "Most Visited" category should be updated. | 302 // A flag indicating if "Most Visited" category should be updated. |
251 bool most_visited_should_update_ = false; | 303 bool most_visited_should_update_ = false; |
252 | 304 |
253 // A flag indicating if "Recently Closed" category should be updated. | 305 // A flag indicating if "Recently Closed" category should be updated. |
(...skipping 24 matching lines...) Expand all Loading... | |
278 | 330 |
279 SEQUENCE_CHECKER(sequence_checker_); | 331 SEQUENCE_CHECKER(sequence_checker_); |
280 | 332 |
281 // For callbacks may run after destruction. | 333 // For callbacks may run after destruction. |
282 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 334 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
283 | 335 |
284 DISALLOW_COPY_AND_ASSIGN(JumpList); | 336 DISALLOW_COPY_AND_ASSIGN(JumpList); |
285 }; | 337 }; |
286 | 338 |
287 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 339 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |