| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; | 71 using UrlAndLinkItem = std::pair<std::string, scoped_refptr<ShellLinkItem>>; |
| 72 using URLIconCache = base::flat_map<std::string, base::FilePath>; | 72 using URLIconCache = base::flat_map<std::string, base::FilePath>; |
| 73 | 73 |
| 74 // Holds results of the RunUpdateJumpList run. | 74 // Holds results of a RunUpdateJumpList run. |
| 75 struct UpdateResults { | 75 // In-out params: |
| 76 UpdateResults(); | 76 // |most_visited_icons|, |recently_closed_icons| |
| 77 ~UpdateResults(); | 77 // Out params: |
| 78 // |update_success|, |update_timeout| |
| 79 struct UpdateTransaction { |
| 80 UpdateTransaction(); |
| 81 ~UpdateTransaction(); |
| 78 | 82 |
| 79 // Icon file paths of the most visited links, indexed by tab url. | 83 // 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 | 84 // Holding a copy of most_visited_icons_ initially, it's updated by the |
| 81 // JumpList update run. If the update run succeeds, it overwrites | 85 // JumpList update run. If the update run succeeds, it overwrites |
| 82 // most_visited_icons_. | 86 // most_visited_icons_. |
| 83 URLIconCache most_visited_icons_in_update; | 87 URLIconCache most_visited_icons; |
| 84 | 88 |
| 85 // icon file paths of the recently closed links, indexed by tab url. | 89 // 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 | 90 // Holding a copy of recently_closed_icons_ initially, it's updated by the |
| 87 // JumpList update run. If the update run succeeds, it overwrites | 91 // JumpList update run. If the update run succeeds, it overwrites |
| 88 // recently_closed_icons_. | 92 // recently_closed_icons_. |
| 89 URLIconCache recently_closed_icons_in_update; | 93 URLIconCache recently_closed_icons; |
| 90 | 94 |
| 91 // A flag indicating if a JumpList update run is successful. | 95 // A flag indicating if a JumpList update run is successful. |
| 92 bool update_success = false; | 96 bool update_success = false; |
| 93 | 97 |
| 94 // A flag indicating if there is a timeout in notifying the JumpList update | 98 // 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. | 99 // to shell. Note that this variable is independent of update_success. |
| 96 bool update_timeout = false; | 100 bool update_timeout = false; |
| 97 }; | 101 }; |
| 98 | 102 |
| 99 friend JumpListFactory; | 103 friend JumpListFactory; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // Callback for HistoryService that notifies when a requested favicon is | 158 // Callback for HistoryService that notifies when a requested favicon is |
| 155 // available. To avoid file operations, this function just attaches the given | 159 // available. To avoid file operations, this function just attaches the given |
| 156 // |image_result| to a ShellLinkItem object. | 160 // |image_result| to a ShellLinkItem object. |
| 157 void OnFaviconDataAvailable( | 161 void OnFaviconDataAvailable( |
| 158 const favicon_base::FaviconImageResult& image_result); | 162 const favicon_base::FaviconImageResult& image_result); |
| 159 | 163 |
| 160 // Posts tasks to update the JumpList and delete any obsolete JumpList related | 164 // Posts tasks to update the JumpList and delete any obsolete JumpList related |
| 161 // folders. | 165 // folders. |
| 162 void PostRunUpdate(); | 166 void PostRunUpdate(); |
| 163 | 167 |
| 164 // Callback for RunUpdateJumpList that notifies when it finishes running. | 168 // Handles the completion of an update by incorporating its results in |
| 165 // Updates certain JumpList member variables and/or triggers a new JumpList | 169 // |update_transaction| back into this instance. Additionally, a new update is |
| 166 // update based on |update_results|. | 170 // triggered as needed to process notifications that arrived while the |
| 167 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results); | 171 // now-completed update was running. |
| 172 void OnRunUpdateCompletion( |
| 173 std::unique_ptr<UpdateTransaction> update_transaction); |
| 168 | 174 |
| 169 // Cancels a pending JumpList update. | 175 // Cancels a pending JumpList update. |
| 170 void CancelPendingUpdate(); | 176 void CancelPendingUpdate(); |
| 171 | 177 |
| 172 // Terminates the JumpList, which includes cancelling any pending updates and | 178 // Terminates the JumpList, which includes cancelling any pending updates and |
| 173 // stopping observing the Profile and its services. This must be called before | 179 // stopping observing the Profile and its services. This must be called before |
| 174 // the |profile_| is destroyed. | 180 // the |profile_| is destroyed. |
| 175 void Terminate(); | 181 void Terminate(); |
| 176 | 182 |
| 177 // Updates the application JumpList, which consists of 1) create new icon | 183 // Updates the application JumpList, which consists of 1) create a new |
| 178 // files; 2) delete obsolete icon files; 3) notify the OS. | 184 // JumpList along with any icons that are not in the cache; 2) notify the OS; |
| 179 // Note that any timeout error along the way results in the old JumpList being | 185 // 3) delete obsolete icon files. Any error along the way results in the old |
| 180 // left as-is, while any non-timeout error results in the old JumpList being | 186 // JumpList being left as-is. |
| 181 // left as-is, but without icon files. | |
| 182 static void RunUpdateJumpList( | 187 static void RunUpdateJumpList( |
| 183 const base::string16& app_id, | 188 const base::string16& app_id, |
| 184 const base::FilePath& profile_dir, | 189 const base::FilePath& profile_dir, |
| 185 const ShellLinkItemList& most_visited_pages, | 190 const ShellLinkItemList& most_visited_pages, |
| 186 const ShellLinkItemList& recently_closed_pages, | 191 const ShellLinkItemList& recently_closed_pages, |
| 187 bool most_visited_pages_have_updates, | 192 bool most_visited_should_update, |
| 188 bool recently_closed_pages_have_updates, | 193 bool recently_closed_should_update, |
| 189 IncognitoModePrefs::Availability incognito_availability, | 194 IncognitoModePrefs::Availability incognito_availability, |
| 190 UpdateResults* update_results); | 195 UpdateTransaction* update_transaction); |
| 191 | 196 |
| 192 // Updates icon files for |page_list| in |icon_dir|, which consists of | 197 // Creates a new JumpList along with any icons that are not in the cache, |
| 193 // 1) creating at most |slot_limit| new icons which are not in |icon_cache|; | 198 // and notifies the OS. |
| 194 // 2) deleting old icons which are not in |icon_cache|. | 199 static void CreateNewJumpListAndNotifyOS( |
| 195 // Returns the number of new icon files created. | 200 const base::string16& app_id, |
| 201 const base::FilePath& most_visited_icon_dir, |
| 202 const base::FilePath& recently_closed_icon_dir, |
| 203 const ShellLinkItemList& most_visited_pages, |
| 204 const ShellLinkItemList& recently_closed_pages, |
| 205 bool most_visited_should_update, |
| 206 bool recently_closed_should_update, |
| 207 IncognitoModePrefs::Availability incognito_availability, |
| 208 UpdateTransaction* update_transaction); |
| 209 |
| 210 // Updates icon files for |item_list| in |icon_dir|, which consists of |
| 211 // 1) If certain safe conditions are not met, clean the folder at |icon_dir|. |
| 212 // If folder cleaning fails, skip step 2. Besides, clear |icon_cur| and |
| 213 // |icon_next|. |
| 214 // 2) Create at most |max_items| icon files which are not in |icon_cur| for |
| 215 // the asynchrounously loaded icons stored in |item_list|. |
| 196 static int UpdateIconFiles(const base::FilePath& icon_dir, | 216 static int UpdateIconFiles(const base::FilePath& icon_dir, |
| 197 const ShellLinkItemList& page_list, | 217 const ShellLinkItemList& item_list, |
| 198 size_t slot_limit, | 218 size_t max_items, |
| 199 URLIconCache* icon_cache); | 219 URLIconCache* icon_cur, |
| 220 URLIconCache* icon_next); |
| 200 | 221 |
| 201 // In |icon_dir|, creates at most |max_items| icon files which are not in | 222 // 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|. | 223 // |icon_cur| for the asynchrounously loaded icons stored in |item_list|. |
| 203 // |icon_cache| is also updated for newly created icons. | 224 // |icon_next| is updated based on the reusable icons and the newly created |
| 204 // Returns the number of new icon files created. | 225 // icons. Returns the number of new icon files created. |
| 205 static int CreateIconFiles(const base::FilePath& icon_dir, | 226 static int CreateIconFiles(const base::FilePath& icon_dir, |
| 206 const ShellLinkItemList& item_list, | 227 const ShellLinkItemList& item_list, |
| 207 size_t max_items, | 228 size_t max_items, |
| 208 URLIconCache* icon_cache); | 229 const URLIconCache& icon_cur, |
| 230 URLIconCache* icon_next); |
| 209 | 231 |
| 210 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. | 232 // Deletes icon files in |icon_dir| which are not in |icon_cache|. |
| 211 static void DeleteIconFiles(const base::FilePath& icon_dir, | 233 static void DeleteIconFiles(const base::FilePath& icon_dir, |
| 212 URLIconCache* icon_cache); | 234 const URLIconCache& icons_cache); |
| 213 | 235 |
| 214 // Tracks FaviconService tasks. | 236 // Tracks FaviconService tasks. |
| 215 base::CancelableTaskTracker cancelable_task_tracker_; | 237 base::CancelableTaskTracker cancelable_task_tracker_; |
| 216 | 238 |
| 217 // The Profile object is used to listen for events. | 239 // The Profile object is used to listen for events. |
| 218 Profile* profile_; | 240 Profile* profile_; |
| 219 | 241 |
| 220 // Manages the registration of pref change observers. | 242 // Manages the registration of pref change observers. |
| 221 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 243 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 222 | 244 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 300 |
| 279 SEQUENCE_CHECKER(sequence_checker_); | 301 SEQUENCE_CHECKER(sequence_checker_); |
| 280 | 302 |
| 281 // For callbacks may run after destruction. | 303 // For callbacks may run after destruction. |
| 282 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 304 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
| 283 | 305 |
| 284 DISALLOW_COPY_AND_ASSIGN(JumpList); | 306 DISALLOW_COPY_AND_ASSIGN(JumpList); |
| 285 }; | 307 }; |
| 286 | 308 |
| 287 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 309 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
| OLD | NEW |