Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/win/jumplist.h

Issue 2940743002: Reorder the methods in JumpList class according to the update workflow (Closed)
Patch Set: More reordering Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/win/jumplist.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // This class observes the tabs and policies of the given Profile and updates 54 // This class observes the tabs and policies of the given Profile and updates
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 // Returns true if the custom JumpList is enabled.
65 static bool Enabled();
66
64 // KeyedService: 67 // KeyedService:
65 void Shutdown() override; 68 void Shutdown() override;
66 69
67 // Returns true if the custom JumpList is enabled.
68 static bool Enabled();
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 {
76 UpdateResults(); 76 UpdateResults();
77 ~UpdateResults(); 77 ~UpdateResults();
78 78
79 // Icon file paths of the most visited links, indexed by tab url. 79 // Icon file paths of the most visited links, indexed by tab url.
(...skipping 14 matching lines...) Expand all
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 // Adds a new ShellLinkItem for |tab| to the JumpList data provided that doing 104 // history::TopSitesObserver:
105 // so will not exceed |max_items|. 105 void TopSitesLoaded(history::TopSites* top_sites) override;
106 bool AddTab(const sessions::TabRestoreService::Tab& tab, size_t max_items); 106 void TopSitesChanged(history::TopSites* top_sites,
107 107 ChangeReason change_reason) override;
108 // Adds a new ShellLinkItem for each tab in |window| to the JumpList data
109 // provided that doing so will not exceed |max_items|.
110 void AddWindow(const sessions::TabRestoreService::Window& window,
111 size_t max_items);
112
113 // Starts loading a favicon for each URL in |icon_urls_|.
114 // This function sends a query to HistoryService.
115 // When finishing loading all favicons, this function posts a task that
116 // decompresses collected favicons and updates a JumpList.
117 void StartLoadingFavicon();
118
119 // Callback for HistoryService that notifies when a requested favicon is
120 // available. To avoid file operations, this function just attaches the given
121 // |image_result| to a ShellLinkItem object.
122 void OnFaviconDataAvailable(
123 const favicon_base::FaviconImageResult& image_result);
124
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.
132 void OnIncognitoAvailabilityChanged();
133 108
134 // sessions::TabRestoreServiceObserver: 109 // sessions::TabRestoreServiceObserver:
135 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; 110 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override;
136 void TabRestoreServiceDestroyed( 111 void TabRestoreServiceDestroyed(
137 sessions::TabRestoreService* service) override; 112 sessions::TabRestoreService* service) override;
138 113
139 // history::TopSitesObserver: 114 // Callback for changes to the incognito mode availability pref.
140 void TopSitesLoaded(history::TopSites* top_sites) override; 115 void OnIncognitoAvailabilityChanged();
141 void TopSitesChanged(history::TopSites* top_sites,
142 ChangeReason change_reason) override;
143 116
144 // Initializes the one-shot timer to update the JumpList in a while. If there 117 // 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 118 // 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 119 // ensures that JumpList update won't happen until there has been a brief
147 // quiet period, thus avoiding update storms. 120 // quiet period, thus avoiding update storms.
148 void InitializeTimerForUpdate(); 121 void InitializeTimerForUpdate();
149 122
150 // Called on a timer after requests storms have subsided. Calls APIs 123 // Called on a timer after requests storms have subsided. Calls APIs
151 // ProcessTopSitesNotification and ProcessTabRestoreNotification on 124 // ProcessTopSitesNotification and ProcessTabRestoreNotification on
152 // demand to do the actual work. 125 // demand to do the actual work.
153 void OnDelayTimer(); 126 void OnDelayTimer();
154 127
155 // Processes notifications from TopSites service. 128 // Processes notifications from TopSites service.
156 void ProcessTopSitesNotification(); 129 void ProcessTopSitesNotification();
157 130
158 // Processes notifications from TabRestore service. 131 // Processes notifications from TabRestore service.
159 void ProcessTabRestoreServiceNotification(); 132 void ProcessTabRestoreServiceNotification();
160 133
134 // Callback for TopSites that notifies when |data|, the "Most Visited" list,
135 // is available. This function updates the ShellLinkItemList objects and
136 // begins the process of fetching favicons for the URLs.
137 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data);
138
139 // Adds a new ShellLinkItem for |tab| to the JumpList data provided that doing
140 // so will not exceed |max_items|.
141 bool AddTab(const sessions::TabRestoreService::Tab& tab, size_t max_items);
142
143 // Adds a new ShellLinkItem for each tab in |window| to the JumpList data
144 // provided that doing so will not exceed |max_items|.
145 void AddWindow(const sessions::TabRestoreService::Window& window,
146 size_t max_items);
147
148 // Starts loading a favicon for each URL in |icon_urls_|.
149 // This function sends a query to HistoryService.
150 // When finishing loading all favicons, this function posts a task that
151 // decompresses collected favicons and updates a JumpList.
152 void StartLoadingFavicon();
153
154 // Callback for HistoryService that notifies when a requested favicon is
155 // available. To avoid file operations, this function just attaches the given
156 // |image_result| to a ShellLinkItem object.
157 void OnFaviconDataAvailable(
158 const favicon_base::FaviconImageResult& image_result);
159
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
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_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/win/jumplist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698