Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 // the JumpList whenever a change is detected. | 55 // the JumpList whenever a change is detected. |
| 56 // | 56 // |
| 57 // Updating a JumpList requires some file operations and it is not good to | 57 // Updating a JumpList requires some file operations and it is not good to |
| 58 // update it in a UI thread. To solve this problem, this class posts to a | 58 // update it in a UI thread. To solve this problem, this class posts to a |
| 59 // runnable method when it actually updates a JumpList. | 59 // runnable method when it actually updates a JumpList. |
| 60 class JumpList : public sessions::TabRestoreServiceObserver, | 60 class JumpList : public sessions::TabRestoreServiceObserver, |
| 61 public history::TopSitesObserver, | 61 public history::TopSitesObserver, |
| 62 public KeyedService { | 62 public KeyedService { |
| 63 public: | 63 public: |
| 64 // KeyedService: | 64 // KeyedService: |
| 65 void Shutdown() override; | 65 void Shutdown() override; |
|
grt (UTC plus 2)
2017/06/14 20:50:38
nit: this method is less interesting to the reader
chengx
2017/06/16 18:10:41
Done.
| |
| 66 | 66 |
| 67 // Returns true if the custom JumpList is enabled. | 67 // Returns true if the custom JumpList is enabled. |
| 68 static bool Enabled(); | 68 static bool Enabled(); |
| 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 the RunUpdateJumpList run. |
| 75 struct UpdateResults { | 75 struct UpdateResults { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 94 // A flag indicating if there is a timeout in notifying the JumpList update | 94 // 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. | 95 // to shell. Note that this variable is independent of update_success. |
| 96 bool update_timeout = false; | 96 bool update_timeout = false; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 friend JumpListFactory; | 99 friend JumpListFactory; |
| 100 explicit JumpList(Profile* profile); // Use JumpListFactory instead | 100 explicit JumpList(Profile* profile); // Use JumpListFactory instead |
| 101 | 101 |
| 102 ~JumpList() override; | 102 ~JumpList() override; |
| 103 | 103 |
| 104 // history::TopSitesObserver: | |
| 105 void TopSitesLoaded(history::TopSites* top_sites) override; | |
| 106 void TopSitesChanged(history::TopSites* top_sites, | |
| 107 ChangeReason change_reason) override; | |
| 108 | |
| 109 // sessions::TabRestoreServiceObserver: | |
| 110 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; | |
| 111 void TabRestoreServiceDestroyed( | |
| 112 sessions::TabRestoreService* service) override; | |
| 113 | |
| 114 // Initializes the one-shot timer to update the JumpList in a while. If there | |
| 115 // is already a request queued then cancel it and post the new request. This | |
| 116 // ensures that JumpList update won't happen until there has been a brief | |
| 117 // quiet period, thus avoiding update storms. | |
| 118 void InitializeTimerForUpdate(); | |
| 119 | |
| 120 // Called on a timer after requests storms have subsided. Calls APIs | |
| 121 // ProcessTopSitesNotification and ProcessTabRestoreNotification on | |
| 122 // demand to do the actual work. | |
| 123 void OnDelayTimer(); | |
| 124 | |
| 125 // Processes notifications from TopSites service. | |
| 126 void ProcessTopSitesNotification(); | |
| 127 | |
| 128 // Processes notifications from TabRestore service. | |
| 129 void ProcessTabRestoreServiceNotification(); | |
| 130 | |
| 131 // Callback for TopSites that notifies when |data|, the "Most Visited" list, | |
| 132 // is available. This function updates the ShellLinkItemList objects and | |
| 133 // begins the process of fetching favicons for the URLs. | |
| 134 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data); | |
| 135 | |
| 104 // Adds a new ShellLinkItem for |tab| to the JumpList data provided that doing | 136 // Adds a new ShellLinkItem for |tab| to the JumpList data provided that doing |
| 105 // so will not exceed |max_items|. | 137 // so will not exceed |max_items|. |
| 106 bool AddTab(const sessions::TabRestoreService::Tab& tab, size_t max_items); | 138 bool AddTab(const sessions::TabRestoreService::Tab& tab, size_t max_items); |
| 107 | 139 |
| 108 // Adds a new ShellLinkItem for each tab in |window| to the JumpList data | 140 // Adds a new ShellLinkItem for each tab in |window| to the JumpList data |
| 109 // provided that doing so will not exceed |max_items|. | 141 // provided that doing so will not exceed |max_items|. |
| 110 void AddWindow(const sessions::TabRestoreService::Window& window, | 142 void AddWindow(const sessions::TabRestoreService::Window& window, |
| 111 size_t max_items); | 143 size_t max_items); |
| 112 | 144 |
| 113 // Starts loading a favicon for each URL in |icon_urls_|. | 145 // Starts loading a favicon for each URL in |icon_urls_|. |
| 114 // This function sends a query to HistoryService. | 146 // This function sends a query to HistoryService. |
| 115 // When finishing loading all favicons, this function posts a task that | 147 // When finishing loading all favicons, this function posts a task that |
| 116 // decompresses collected favicons and updates a JumpList. | 148 // decompresses collected favicons and updates a JumpList. |
| 117 void StartLoadingFavicon(); | 149 void StartLoadingFavicon(); |
| 118 | 150 |
| 119 // Callback for HistoryService that notifies when a requested favicon is | 151 // Callback for HistoryService that notifies when a requested favicon is |
| 120 // available. To avoid file operations, this function just attaches the given | 152 // available. To avoid file operations, this function just attaches the given |
| 121 // |image_result| to a ShellLinkItem object. | 153 // |image_result| to a ShellLinkItem object. |
| 122 void OnFaviconDataAvailable( | 154 void OnFaviconDataAvailable( |
| 123 const favicon_base::FaviconImageResult& image_result); | 155 const favicon_base::FaviconImageResult& image_result); |
| 124 | 156 |
| 125 // Callback for TopSites that notifies when |data|, the "Most Visited" list, | |
| 126 // is available. This function updates the ShellLinkItemList objects and | |
| 127 // begins the process of fetching favicons for the URLs. | |
| 128 void OnMostVisitedURLsAvailable( | |
| 129 const history::MostVisitedURLList& data); | |
| 130 | |
| 131 // Callback for changes to the incognito mode availability pref. | 157 // Callback for changes to the incognito mode availability pref. |
| 132 void OnIncognitoAvailabilityChanged(); | 158 void OnIncognitoAvailabilityChanged(); |
|
grt (UTC plus 2)
2017/06/14 20:50:38
nit: this is more similar to the overrides above,
chengx
2017/06/16 18:10:41
Done.
| |
| 133 | 159 |
| 134 // sessions::TabRestoreServiceObserver: | |
| 135 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; | |
| 136 void TabRestoreServiceDestroyed( | |
| 137 sessions::TabRestoreService* service) override; | |
| 138 | |
| 139 // history::TopSitesObserver: | |
| 140 void TopSitesLoaded(history::TopSites* top_sites) override; | |
| 141 void TopSitesChanged(history::TopSites* top_sites, | |
| 142 ChangeReason change_reason) override; | |
| 143 | |
| 144 // Initializes the one-shot timer to update the JumpList in a while. If there | |
| 145 // is already a request queued then cancel it and post the new request. This | |
| 146 // ensures that JumpList update won't happen until there has been a brief | |
| 147 // quiet period, thus avoiding update storms. | |
| 148 void InitializeTimerForUpdate(); | |
| 149 | |
| 150 // Called on a timer after requests storms have subsided. Calls APIs | |
| 151 // ProcessTopSitesNotification and ProcessTabRestoreNotification on | |
| 152 // demand to do the actual work. | |
| 153 void OnDelayTimer(); | |
| 154 | |
| 155 // Processes notifications from TopSites service. | |
| 156 void ProcessTopSitesNotification(); | |
| 157 | |
| 158 // Processes notifications from TabRestore service. | |
| 159 void ProcessTabRestoreServiceNotification(); | |
| 160 | |
| 161 // Posts tasks to update the JumpList and delete any obsolete JumpList related | 160 // Posts tasks to update the JumpList and delete any obsolete JumpList related |
| 162 // folders. | 161 // folders. |
| 163 void PostRunUpdate(); | 162 void PostRunUpdate(); |
| 164 | 163 |
| 165 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. | 164 // Callback for RunUpdateJumpList that notifies when it finishes running. |
| 166 static void DeleteIconFiles(const base::FilePath& icon_dir, | 165 // Updates certain JumpList member variables and/or triggers a new JumpList |
| 167 URLIconCache* icon_cache); | 166 // update based on |update_results|. |
| 167 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results); | |
| 168 | 168 |
| 169 // In |icon_dir|, creates at most |max_items| icon files which are not in | 169 // Cancels a pending JumpList update. |
| 170 // |icon_cache| for the asynchrounously loaded icons stored in |item_list|. | 170 void CancelPendingUpdate(); |
| 171 // |icon_cache| is also updated for newly created icons. | |
| 172 // Returns the number of new icon files created. | |
| 173 static int CreateIconFiles(const base::FilePath& icon_dir, | |
| 174 const ShellLinkItemList& item_list, | |
| 175 size_t max_items, | |
| 176 URLIconCache* icon_cache); | |
| 177 | 171 |
| 178 // Updates icon files for |page_list| in |icon_dir|, which consists of | 172 // Terminates the JumpList, which includes cancelling any pending updates and |
| 179 // 1) creating at most |slot_limit| new icons which are not in |icon_cache|; | 173 // stopping observing the Profile and its services. This must be called before |
| 180 // 2) deleting old icons which are not in |icon_cache|. | 174 // the |profile_| is destroyed. |
| 181 // Returns the number of new icon files created. | 175 void Terminate(); |
| 182 static int UpdateIconFiles(const base::FilePath& icon_dir, | |
| 183 const ShellLinkItemList& page_list, | |
| 184 size_t slot_limit, | |
| 185 URLIconCache* icon_cache); | |
| 186 | 176 |
| 187 // Updates the application JumpList, which consists of 1) create new icon | 177 // Updates the application JumpList, which consists of 1) create new icon |
| 188 // files; 2) delete obsolete icon files; 3) notify the OS. | 178 // files; 2) delete obsolete icon files; 3) notify the OS. |
| 189 // Note that any timeout error along the way results in the old JumpList being | 179 // Note that any timeout error along the way results in the old JumpList being |
| 190 // left as-is, while any non-timeout error results in the old JumpList being | 180 // left as-is, while any non-timeout error results in the old JumpList being |
| 191 // left as-is, but without icon files. | 181 // left as-is, but without icon files. |
| 192 static void RunUpdateJumpList( | 182 static void RunUpdateJumpList( |
| 193 const base::string16& app_id, | 183 const base::string16& app_id, |
| 194 const base::FilePath& profile_dir, | 184 const base::FilePath& profile_dir, |
| 195 const ShellLinkItemList& most_visited_pages, | 185 const ShellLinkItemList& most_visited_pages, |
| 196 const ShellLinkItemList& recently_closed_pages, | 186 const ShellLinkItemList& recently_closed_pages, |
| 197 bool most_visited_pages_have_updates, | 187 bool most_visited_pages_have_updates, |
| 198 bool recently_closed_pages_have_updates, | 188 bool recently_closed_pages_have_updates, |
| 199 IncognitoModePrefs::Availability incognito_availability, | 189 IncognitoModePrefs::Availability incognito_availability, |
| 200 UpdateResults* update_results); | 190 UpdateResults* update_results); |
| 201 | 191 |
| 202 // Callback for RunUpdateJumpList that notifies when it finishes running. | 192 // Updates icon files for |page_list| in |icon_dir|, which consists of |
| 203 // Updates certain JumpList member variables and/or triggers a new JumpList | 193 // 1) creating at most |slot_limit| new icons which are not in |icon_cache|; |
| 204 // update based on |update_results|. | 194 // 2) deleting old icons which are not in |icon_cache|. |
| 205 void OnRunUpdateCompletion(std::unique_ptr<UpdateResults> update_results); | 195 // Returns the number of new icon files created. |
| 196 static int UpdateIconFiles(const base::FilePath& icon_dir, | |
| 197 const ShellLinkItemList& page_list, | |
| 198 size_t slot_limit, | |
| 199 URLIconCache* icon_cache); | |
| 206 | 200 |
| 207 // Cancels a pending JumpList update. | 201 // In |icon_dir|, creates at most |max_items| icon files which are not in |
| 208 void CancelPendingUpdate(); | 202 // |icon_cache| for the asynchrounously loaded icons stored in |item_list|. |
| 203 // |icon_cache| is also updated for newly created icons. | |
| 204 // Returns the number of new icon files created. | |
| 205 static int CreateIconFiles(const base::FilePath& icon_dir, | |
| 206 const ShellLinkItemList& item_list, | |
| 207 size_t max_items, | |
| 208 URLIconCache* icon_cache); | |
| 209 | 209 |
| 210 // Terminates the JumpList, which includes cancelling any pending updates and | 210 // Deletes icon files in |icon_dir| which are not in |icon_cache| anymore. |
| 211 // stopping observing the Profile and its services. This must be called before | 211 static void DeleteIconFiles(const base::FilePath& icon_dir, |
| 212 // the |profile_| is destroyed. | 212 URLIconCache* icon_cache); |
| 213 void Terminate(); | |
| 214 | 213 |
| 215 // Tracks FaviconService tasks. | 214 // Tracks FaviconService tasks. |
| 216 base::CancelableTaskTracker cancelable_task_tracker_; | 215 base::CancelableTaskTracker cancelable_task_tracker_; |
| 217 | 216 |
| 218 // The Profile object is used to listen for events. | 217 // The Profile object is used to listen for events. |
| 219 Profile* profile_; | 218 Profile* profile_; |
| 220 | 219 |
| 221 // Manages the registration of pref change observers. | 220 // Manages the registration of pref change observers. |
| 222 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 221 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 223 | 222 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 | 278 |
| 280 SEQUENCE_CHECKER(sequence_checker_); | 279 SEQUENCE_CHECKER(sequence_checker_); |
| 281 | 280 |
| 282 // For callbacks may run after destruction. | 281 // For callbacks may run after destruction. |
| 283 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 282 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
| 284 | 283 |
| 285 DISALLOW_COPY_AND_ASSIGN(JumpList); | 284 DISALLOW_COPY_AND_ASSIGN(JumpList); |
| 286 }; | 285 }; |
| 287 | 286 |
| 288 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 287 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
| OLD | NEW |