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" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 void ShutdownOnUIThread() override; | 122 void ShutdownOnUIThread() override; |
122 | 123 |
123 // Returns true if the custom JumpList is enabled. | 124 // Returns true if the custom JumpList is enabled. |
124 static bool Enabled(); | 125 static bool Enabled(); |
125 | 126 |
126 private: | 127 private: |
127 friend JumpListFactory; | 128 friend JumpListFactory; |
128 explicit JumpList(Profile* profile); // Use JumpListFactory instead | 129 explicit JumpList(Profile* profile); // Use JumpListFactory instead |
129 ~JumpList() override; | 130 ~JumpList() override; |
130 | 131 |
132 enum class JumpListCategory { kMostVisited = 0, kRecentlyClosed }; | |
grt (UTC plus 2)
2017/05/15 11:28:19
nit: omit " = 0"
chengx
2017/05/17 21:59:36
Done.
| |
133 | |
131 // Adds a new ShellLinkItem for |tab| to |data| provided that doing so will | 134 // Adds a new ShellLinkItem for |tab| to |data| provided that doing so will |
132 // not exceed |max_items|. | 135 // not exceed |max_items|. |
133 bool AddTab(const sessions::TabRestoreService::Tab& tab, | 136 bool AddTab(const sessions::TabRestoreService::Tab& tab, |
134 size_t max_items, | 137 size_t max_items, |
135 JumpListData* data); | 138 JumpListData* data); |
136 | 139 |
137 // Adds a new ShellLinkItem for each tab in |window| to |data| provided that | 140 // Adds a new ShellLinkItem for each tab in |window| to |data| provided that |
138 // doing so will not exceed |max_items|. | 141 // doing so will not exceed |max_items|. |
139 void AddWindow(const sessions::TabRestoreService::Window& window, | 142 void AddWindow(const sessions::TabRestoreService::Window& window, |
140 size_t max_items, | 143 size_t max_items, |
(...skipping 31 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. | |
grt (UTC plus 2)
2017/05/15 11:28:19
nit: mention |category| somehow here and in commen
chengx
2017/05/17 21:59:36
Done.
| |
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 | |
grt (UTC plus 2)
2017/05/15 11:28:19
please document which task runner(s) may access th
chengx
2017/05/17 21:59:36
Documentation added. Yes, only update_jumplist_tas
| |
249 // "Most visited" and "Recently closed" categories, respectively. | |
250 base::flat_map<std::string, base::FilePath> most_visited_map_; | |
grt (UTC plus 2)
2017/05/15 11:28:19
based on how this is used, i think an accurate des
chengx
2017/05/17 21:59:36
Done. Thanks for the suggestion!
| |
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 |