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, kRecentlyClosed }; | |
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 |
182 // Creates at most |max_items| icon files in |icon_dir| for the | 185 // Deletes icon files of |category| in |icon_dir| which are not in the cache |
186 // anymore. | |
187 void DeleteIconFiles(const base::FilePath& icon_dir, | |
188 JumpListCategory category); | |
189 | |
190 // Creates at most |max_items| icon files of |category| in |icon_dir| for the | |
183 // asynchrounously loaded icons stored in |item_list|. | 191 // asynchrounously loaded icons stored in |item_list|. |
184 void CreateIconFiles(const base::FilePath& icon_dir, | 192 void CreateIconFiles(const base::FilePath& icon_dir, |
185 const ShellLinkItemList& item_list, | 193 const ShellLinkItemList& item_list, |
186 size_t max_items); | 194 size_t max_items, |
195 JumpListCategory category); | |
187 | 196 |
188 // Updates icon files in |icon_dir|, which includes deleting old icons and | 197 // Updates icon files in |icon_dir|, which includes deleting old icons and |
189 // creating at most |slot_limit| new icons for |page_list|. | 198 // creating at most |slot_limit| new icons for |page_list|. |
190 void UpdateIconFiles(const base::FilePath& icon_dir, | 199 void UpdateIconFiles(const base::FilePath& icon_dir, |
191 const ShellLinkItemList& page_list, | 200 const ShellLinkItemList& page_list, |
192 size_t slot_limit); | 201 size_t slot_limit, |
202 JumpListCategory category); | |
193 | 203 |
194 // Updates the jumplist, once all the data has been fetched. This method calls | 204 // Updates the jumplist, once all the data has been fetched. This method calls |
195 // UpdateJumpList() to do most of the work. | 205 // UpdateJumpList() to do most of the work. |
196 void RunUpdateJumpList( | 206 void RunUpdateJumpList( |
197 IncognitoModePrefs::Availability incognito_availability, | 207 IncognitoModePrefs::Availability incognito_availability, |
198 const base::string16& app_id, | 208 const base::string16& app_id, |
199 const base::FilePath& profile_dir, | 209 const base::FilePath& profile_dir, |
200 base::RefCountedData<JumpListData>* ref_counted_data); | 210 base::RefCountedData<JumpListData>* ref_counted_data); |
201 | 211 |
202 // Updates the application JumpList, which consists of 1) delete old icon | 212 // 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 | 213 // files; 2) create new icon files; 3) notify the OS. This method is called |
204 // from RunUpdateJumpList(). | 214 // from RunUpdateJumpList(). |
205 // Note that any timeout error along the way results in the old jumplist being | 215 // 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 | 216 // left as-is, while any non-timeout error results in the old jumplist being |
207 // left as-is, but without icon files. | 217 // left as-is, but without icon files. |
208 bool UpdateJumpList(const base::string16& app_id, | 218 bool UpdateJumpList(const base::string16& app_id, |
209 const base::FilePath& profile_dir, | 219 const base::FilePath& profile_dir, |
210 const ShellLinkItemList& most_visited_pages, | 220 const ShellLinkItemList& most_visited_pages, |
211 const ShellLinkItemList& recently_closed_pages, | 221 const ShellLinkItemList& recently_closed_pages, |
212 bool most_visited_pages_have_updates, | 222 bool most_visited_pages_have_updates, |
213 bool recently_closed_pages_have_updates, | 223 bool recently_closed_pages_have_updates, |
214 IncognitoModePrefs::Availability incognito_availability); | 224 IncognitoModePrefs::Availability incognito_availability); |
215 | 225 |
216 // Tracks FaviconService tasks. | 226 // Tracks FaviconService tasks. |
217 base::CancelableTaskTracker cancelable_task_tracker_; | 227 base::CancelableTaskTracker cancelable_task_tracker_; |
218 | 228 |
219 // The Profile object is used to listen for events | 229 // The Profile object is used to listen for events. |
220 Profile* profile_; | 230 Profile* profile_; |
221 | 231 |
222 // Lives on the UI thread. | 232 // Lives on the UI thread. |
223 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 233 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
224 | 234 |
225 // App id to associate with the jump list. | 235 // App id to associate with the jump list. |
226 base::string16 app_id_; | 236 base::string16 app_id_; |
227 | 237 |
228 // Timer for requesting delayed updates of the "Most Visited" category of | 238 // Timer for requesting delayed updates of the "Most Visited" category of |
229 // jumplist. | 239 // jumplist. |
230 base::OneShotTimer timer_most_visited_; | 240 base::OneShotTimer timer_most_visited_; |
231 | 241 |
232 // Timer for requesting delayed updates of the "Recently Closed" category of | 242 // Timer for requesting delayed updates of the "Recently Closed" category of |
233 // jumplist. | 243 // jumplist. |
234 base::OneShotTimer timer_recently_closed_; | 244 base::OneShotTimer timer_recently_closed_; |
235 | 245 |
236 // Number of updates to skip to alleviate the machine when a previous update | 246 // Number of updates to skip to alleviate the machine when a previous update |
237 // was too slow. Updates will be resumed when this reaches 0 again. | 247 // was too slow. Updates will be resumed when this reaches 0 again. |
238 int updates_to_skip_ = 0; | 248 int updates_to_skip_ = 0; |
239 | 249 |
240 // Holds data that can be accessed from multiple threads. | 250 // Holds data that can be accessed from multiple threads. |
241 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; | 251 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; |
242 | 252 |
253 // The icon file paths of the most visited links and the recently closed links | |
254 // in the current jumplist, indexed by tab url, respectively. | |
255 // They should be only accessed by update_jumplist_task_runner_. | |
grt (UTC plus 2)
2017/05/18 08:59:59
nit: "They may only be accessed on update_jumplist
chengx
2017/05/18 17:21:55
Done.
| |
256 base::flat_map<std::string, base::FilePath> most_visited_icons_; | |
257 base::flat_map<std::string, base::FilePath> recently_closed_icons_; | |
258 | |
243 // Id of last favicon task. It's used to cancel current task if a new one | 259 // Id of last favicon task. It's used to cancel current task if a new one |
244 // comes in before it finishes. | 260 // comes in before it finishes. |
245 base::CancelableTaskTracker::TaskId task_id_; | 261 base::CancelableTaskTracker::TaskId task_id_; |
246 | 262 |
247 // A task runner running tasks to update the JumpList. | 263 // A task runner running tasks to update the JumpList. |
248 scoped_refptr<base::SingleThreadTaskRunner> update_jumplist_task_runner_; | 264 scoped_refptr<base::SingleThreadTaskRunner> update_jumplist_task_runner_; |
249 | 265 |
250 // A task runner running tasks to delete JumpListIcons directory and | 266 // A task runner running tasks to delete JumpListIcons directory and |
251 // JumpListIconsOld directory. | 267 // JumpListIconsOld directory. |
252 scoped_refptr<base::SequencedTaskRunner> delete_jumplisticons_task_runner_; | 268 scoped_refptr<base::SequencedTaskRunner> delete_jumplisticons_task_runner_; |
253 | 269 |
254 // For callbacks may be run after destruction. | 270 // For callbacks may be run after destruction. |
255 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 271 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
256 | 272 |
257 DISALLOW_COPY_AND_ASSIGN(JumpList); | 273 DISALLOW_COPY_AND_ASSIGN(JumpList); |
258 }; | 274 }; |
259 | 275 |
260 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 276 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |