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> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/containers/flat_map.h" | |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/task/cancelable_task_tracker.h" | 22 #include "base/task/cancelable_task_tracker.h" |
22 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
23 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 24 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
24 #include "chrome/browser/win/jumplist_updater.h" | 25 #include "chrome/browser/win/jumplist_updater.h" |
25 #include "components/history/core/browser/history_service.h" | 26 #include "components/history/core/browser/history_service.h" |
26 #include "components/history/core/browser/history_types.h" | 27 #include "components/history/core/browser/history_types.h" |
27 #include "components/history/core/browser/top_sites_observer.h" | 28 #include "components/history/core/browser/top_sites_observer.h" |
28 #include "components/keyed_service/core/refcounted_keyed_service.h" | 29 #include "components/keyed_service/core/refcounted_keyed_service.h" |
29 #include "components/sessions/core/tab_restore_service.h" | 30 #include "components/sessions/core/tab_restore_service.h" |
30 #include "components/sessions/core/tab_restore_service_observer.h" | 31 #include "components/sessions/core/tab_restore_service_observer.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_observer.h" | 33 #include "content/public/browser/notification_observer.h" |
33 #include "content/public/browser/notification_registrar.h" | 34 #include "content/public/browser/notification_registrar.h" |
34 | 35 |
36 enum JumpListCategory { MOST_VISITED = 0, RECENTLY_CLOSED }; | |
grt (UTC plus 2)
2017/05/11 20:29:13
nit: Chromium no longer deviates from the Google s
grt (UTC plus 2)
2017/05/11 20:29:13
move this type into the "private:" section of the
grt (UTC plus 2)
2017/05/11 20:29:13
nit: "enum class"
chengx
2017/05/12 01:04:24
Done with moving to private section of the class.
chengx
2017/05/12 01:04:24
Done with changing names to kLikeAConstant alike.
chengx
2017/05/12 01:04:24
Done. Using "enum class" now.
| |
37 | |
35 namespace base { | 38 namespace base { |
36 class SingleThreadTaskRunner; | 39 class SingleThreadTaskRunner; |
37 class SequencedTaskRunner; | 40 class SequencedTaskRunner; |
38 } | 41 } |
39 | 42 |
40 namespace chrome { | 43 namespace chrome { |
41 struct FaviconImageResult; | 44 struct FaviconImageResult; |
42 } | 45 } |
43 | 46 |
44 class JumpListFactory; | 47 class JumpListFactory; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 ChangeReason change_reason) override; | 175 ChangeReason change_reason) override; |
173 | 176 |
174 // Called on a timer to update the most visited URLs after requests storms | 177 // Called on a timer to update the most visited URLs after requests storms |
175 // have subsided. | 178 // have subsided. |
176 void DeferredTopSitesChanged(); | 179 void DeferredTopSitesChanged(); |
177 | 180 |
178 // Called on a timer to update the "Recently Closed" category of JumpList | 181 // Called on a timer to update the "Recently Closed" category of JumpList |
179 // after requests storms have subsided. | 182 // after requests storms have subsided. |
180 void DeferredTabRestoreServiceChanged(); | 183 void DeferredTabRestoreServiceChanged(); |
181 | 184 |
185 // Deletes icon files in |icon_dir| which are not in the cache anymore. | |
186 void DeleteIconFiles(const base::FilePath& icon_dir, | |
187 JumpListCategory category); | |
188 | |
182 // Creates at most |max_items| icon files in |icon_dir| for the | 189 // Creates at most |max_items| icon files in |icon_dir| for the |
183 // asynchrounously loaded icons stored in |item_list|. | 190 // asynchrounously loaded icons stored in |item_list|. |
184 void CreateIconFiles(const base::FilePath& icon_dir, | 191 void CreateIconFiles(const base::FilePath& icon_dir, |
185 const ShellLinkItemList& item_list, | 192 const ShellLinkItemList& item_list, |
186 size_t max_items); | 193 size_t max_items, |
194 JumpListCategory category); | |
187 | 195 |
188 // Updates icon files in |icon_dir|, which includes deleting old icons and | 196 // Updates icon files in |icon_dir|, which includes deleting old icons and |
189 // creating at most |slot_limit| new icons for |page_list|. | 197 // creating at most |slot_limit| new icons for |page_list|. |
190 void UpdateIconFiles(const base::FilePath& icon_dir, | 198 void UpdateIconFiles(const base::FilePath& icon_dir, |
191 const ShellLinkItemList& page_list, | 199 const ShellLinkItemList& page_list, |
192 size_t slot_limit); | 200 size_t slot_limit, |
201 JumpListCategory category); | |
193 | 202 |
194 // Updates the jumplist, once all the data has been fetched. This method calls | 203 // Updates the jumplist, once all the data has been fetched. This method calls |
195 // UpdateJumpList() to do most of the work. | 204 // UpdateJumpList() to do most of the work. |
196 void RunUpdateJumpList( | 205 void RunUpdateJumpList( |
197 IncognitoModePrefs::Availability incognito_availability, | 206 IncognitoModePrefs::Availability incognito_availability, |
198 const base::string16& app_id, | 207 const base::string16& app_id, |
199 const base::FilePath& profile_dir, | 208 const base::FilePath& profile_dir, |
200 base::RefCountedData<JumpListData>* ref_counted_data); | 209 base::RefCountedData<JumpListData>* ref_counted_data); |
201 | 210 |
202 // Updates the application JumpList, which consists of 1) delete old icon | 211 // Updates the application JumpList, which consists of 1) delete old icon |
203 // files; 2) create new icon files; 3) notify the OS. This method is called | 212 // files; 2) create new icon files; 3) notify the OS. This method is called |
204 // from RunUpdateJumpList(). | 213 // from RunUpdateJumpList(). |
205 // Note that any timeout error along the way results in the old jumplist being | 214 // Note that any timeout error along the way results in the old jumplist being |
206 // left as-is, while any non-timeout error results in the old jumplist being | 215 // left as-is, while any non-timeout error results in the old jumplist being |
207 // left as-is, but without icon files. | 216 // left as-is, but without icon files. |
208 bool UpdateJumpList(const base::string16& app_id, | 217 bool UpdateJumpList(const base::string16& app_id, |
209 const base::FilePath& profile_dir, | 218 const base::FilePath& profile_dir, |
210 const ShellLinkItemList& most_visited_pages, | 219 const ShellLinkItemList& most_visited_pages, |
211 const ShellLinkItemList& recently_closed_pages, | 220 const ShellLinkItemList& recently_closed_pages, |
212 bool most_visited_pages_have_updates, | 221 bool most_visited_pages_have_updates, |
213 bool recently_closed_pages_have_updates, | 222 bool recently_closed_pages_have_updates, |
214 IncognitoModePrefs::Availability incognito_availability); | 223 IncognitoModePrefs::Availability incognito_availability); |
215 | 224 |
216 // Tracks FaviconService tasks. | 225 // Tracks FaviconService tasks. |
217 base::CancelableTaskTracker cancelable_task_tracker_; | 226 base::CancelableTaskTracker cancelable_task_tracker_; |
218 | 227 |
219 // The Profile object is used to listen for events | 228 // The Profile object is used to listen for events. |
220 Profile* profile_; | 229 Profile* profile_; |
221 | 230 |
222 // Lives on the UI thread. | 231 // Lives on the UI thread. |
223 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 232 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
224 | 233 |
225 // App id to associate with the jump list. | 234 // App id to associate with the jump list. |
226 base::string16 app_id_; | 235 base::string16 app_id_; |
227 | 236 |
228 // Timer for requesting delayed updates of the "Most Visited" category of | 237 // Timer for requesting delayed updates of the "Most Visited" category of |
229 // jumplist. | 238 // jumplist. |
230 base::OneShotTimer timer_most_visited_; | 239 base::OneShotTimer timer_most_visited_; |
231 | 240 |
232 // Timer for requesting delayed updates of the "Recently Closed" category of | 241 // Timer for requesting delayed updates of the "Recently Closed" category of |
233 // jumplist. | 242 // jumplist. |
234 base::OneShotTimer timer_recently_closed_; | 243 base::OneShotTimer timer_recently_closed_; |
235 | 244 |
236 // Holds data that can be accessed from multiple threads. | 245 // Holds data that can be accessed from multiple threads. |
237 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; | 246 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; |
238 | 247 |
248 // Cache of the mappings from JumpList items' URLs to icon file paths for | |
249 // "Most visited" and "Recently closed" categories, respectively. | |
250 base::flat_map<std::string, base::FilePath> most_visited_map_; | |
251 base::flat_map<std::string, base::FilePath> recently_closed_map_; | |
252 | |
239 // Id of last favicon task. It's used to cancel current task if a new one | 253 // Id of last favicon task. It's used to cancel current task if a new one |
240 // comes in before it finishes. | 254 // comes in before it finishes. |
241 base::CancelableTaskTracker::TaskId task_id_; | 255 base::CancelableTaskTracker::TaskId task_id_; |
242 | 256 |
243 // A task runner running tasks to update the JumpList. | 257 // A task runner running tasks to update the JumpList. |
244 scoped_refptr<base::SingleThreadTaskRunner> update_jumplist_task_runner_; | 258 scoped_refptr<base::SingleThreadTaskRunner> update_jumplist_task_runner_; |
245 | 259 |
246 // A task runner running tasks to delete JumpListIcons directory and | 260 // A task runner running tasks to delete JumpListIcons directory and |
247 // JumpListIconsOld directory. | 261 // JumpListIconsOld directory. |
248 scoped_refptr<base::SequencedTaskRunner> delete_jumplisticons_task_runner_; | 262 scoped_refptr<base::SequencedTaskRunner> delete_jumplisticons_task_runner_; |
249 | 263 |
250 // For callbacks may be run after destruction. | 264 // For callbacks may be run after destruction. |
251 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 265 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
252 | 266 |
253 DISALLOW_COPY_AND_ASSIGN(JumpList); | 267 DISALLOW_COPY_AND_ASSIGN(JumpList); |
254 }; | 268 }; |
255 | 269 |
256 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 270 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |