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_JUMPLIST_WIN_H_ | 5 #ifndef CHROME_BROWSER_JUMPLIST_WIN_H_ |
6 #define CHROME_BROWSER_JUMPLIST_WIN_H_ | 6 #define CHROME_BROWSER_JUMPLIST_WIN_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
17 #include "chrome/browser/history/history_service.h" | 17 #include "chrome/browser/history/history_service.h" |
18 #include "chrome/browser/jumplist_updater_win.h" | 18 #include "chrome/browser/jumplist_updater_win.h" |
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 19 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
20 #include "chrome/browser/profiles/avatar_menu.h" | |
21 #include "chrome/browser/profiles/avatar_menu_observer.h" | |
22 #include "chrome/browser/sessions/tab_restore_service.h" | 20 #include "chrome/browser/sessions/tab_restore_service.h" |
23 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 21 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
24 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
25 #include "components/history/core/browser/top_sites_observer.h" | 23 #include "components/history/core/browser/top_sites_observer.h" |
26 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/notification_observer.h" | |
26 #include "content/public/browser/notification_registrar.h" | |
tapted
2015/02/18 03:07:18
optinal-nit: The registrar can probably still be f
noms (inactive)
2015/02/19 15:41:34
Done.
| |
27 | 27 |
28 namespace chrome { | 28 namespace chrome { |
29 struct FaviconImageResult; | 29 struct FaviconImageResult; |
30 } | 30 } |
31 | 31 |
32 namespace content { | |
33 class NotificationRegistrar; | |
34 } | |
35 | |
36 class PrefChangeRegistrar; | 32 class PrefChangeRegistrar; |
37 class Profile; | 33 class Profile; |
38 | 34 |
39 // A class which implements an application JumpList. | 35 // A class which implements an application JumpList. |
40 // This class encapsulates operations required for updating an application | 36 // This class encapsulates operations required for updating an application |
41 // JumpList: | 37 // JumpList: |
42 // * Retrieving "Most Visited" pages from HistoryService; | 38 // * Retrieving "Most Visited" pages from HistoryService; |
43 // * Retrieving strings from the application resource; | 39 // * Retrieving strings from the application resource; |
44 // * Adding COM objects to JumpList, etc. | 40 // * Adding COM objects to JumpList, etc. |
45 // | 41 // |
46 // This class observes the tabs and policies of the given Profile and updates | 42 // This class observes the tabs and policies of the given Profile and updates |
47 // the JumpList whenever a change is detected. | 43 // the JumpList whenever a change is detected. |
48 // | 44 // |
49 // Updating a JumpList requires some file operations and it is not good to | 45 // Updating a JumpList requires some file operations and it is not good to |
50 // update it in a UI thread. To solve this problem, this class posts to a | 46 // update it in a UI thread. To solve this problem, this class posts to a |
51 // runnable method when it actually updates a JumpList. | 47 // runnable method when it actually updates a JumpList. |
52 // | 48 // |
53 // Note. base::CancelableTaskTracker is not thread safe, so we | 49 // Note. base::CancelableTaskTracker is not thread safe, so we |
54 // always delete JumpList on UI thread (the same thread it got constructed on). | 50 // always delete JumpList on UI thread (the same thread it got constructed on). |
55 class JumpList : public TabRestoreServiceObserver, | 51 class JumpList : public TabRestoreServiceObserver, |
56 public content::NotificationObserver, | 52 public content::NotificationObserver, |
57 public AvatarMenuObserver, | |
58 public history::TopSitesObserver, | 53 public history::TopSitesObserver, |
59 public base::RefCountedThreadSafe< | 54 public base::RefCountedThreadSafe< |
60 JumpList, | 55 JumpList, |
61 content::BrowserThread::DeleteOnUIThread> { | 56 content::BrowserThread::DeleteOnUIThread> { |
62 public: | 57 public: |
63 explicit JumpList(Profile* profile); | 58 explicit JumpList(Profile* profile); |
64 | 59 |
65 // NotificationObserver implementation. | 60 // NotificationObserver implementation. |
66 void Observe(int type, | 61 void Observe(int type, |
67 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
68 const content::NotificationDetails& details) override; | 63 const content::NotificationDetails& details) override; |
69 | 64 |
70 // Observer callback for TabRestoreService::Observer to notify when a tab is | 65 // Observer callback for TabRestoreService::Observer to notify when a tab is |
71 // added or removed. | 66 // added or removed. |
72 void TabRestoreServiceChanged(TabRestoreService* service) override; | 67 void TabRestoreServiceChanged(TabRestoreService* service) override; |
73 | 68 |
74 // Observer callback to notice when our associated TabRestoreService | 69 // Observer callback to notice when our associated TabRestoreService |
75 // is destroyed. | 70 // is destroyed. |
76 void TabRestoreServiceDestroyed(TabRestoreService* service) override; | 71 void TabRestoreServiceDestroyed(TabRestoreService* service) override; |
77 | 72 |
78 // Overridden from AvatarMenuObserver: | |
79 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override; | |
80 | |
81 // Cancel a pending jumplist update. | 73 // Cancel a pending jumplist update. |
82 void CancelPendingUpdate(); | 74 void CancelPendingUpdate(); |
83 | 75 |
84 // Terminate the jumplist: cancel any pending updates and stop observing | 76 // Terminate the jumplist: cancel any pending updates and stop observing |
85 // the Profile and its services. This must be called before the |profile_| | 77 // the Profile and its services. This must be called before the |profile_| |
86 // is destroyed. | 78 // is destroyed. |
87 void Terminate(); | 79 void Terminate(); |
88 | 80 |
89 // Returns true if the custom JumpList is enabled. | 81 // Returns true if the custom JumpList is enabled. |
90 // The custom jumplist works only on Windows 7 and above. | 82 // The custom jumplist works only on Windows 7 and above. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 127 |
136 // Runnable method that updates the jumplist, once all the data | 128 // Runnable method that updates the jumplist, once all the data |
137 // has been fetched. | 129 // has been fetched. |
138 void RunUpdateOnFileThread( | 130 void RunUpdateOnFileThread( |
139 IncognitoModePrefs::Availability incognito_availability); | 131 IncognitoModePrefs::Availability incognito_availability); |
140 | 132 |
141 // Helper method for RunUpdate to create icon files for the asynchrounously | 133 // Helper method for RunUpdate to create icon files for the asynchrounously |
142 // loaded icons. | 134 // loaded icons. |
143 void CreateIconFiles(const ShellLinkItemList& item_list); | 135 void CreateIconFiles(const ShellLinkItemList& item_list); |
144 | 136 |
145 // Called when the list of Profiles has changed. This function updates the | |
146 // |profile_switcher_| ShellLinkItemList. | |
147 void UpdateProfileSwitcher(); | |
148 | |
149 // history::TopSitesObserver implementation. | 137 // history::TopSitesObserver implementation. |
150 void TopSitesLoaded(history::TopSites* top_sites) override; | 138 void TopSitesLoaded(history::TopSites* top_sites) override; |
151 void TopSitesChanged(history::TopSites* top_sites) override; | 139 void TopSitesChanged(history::TopSites* top_sites) override; |
152 | 140 |
153 // Tracks FaviconService tasks. | 141 // Tracks FaviconService tasks. |
154 base::CancelableTaskTracker cancelable_task_tracker_; | 142 base::CancelableTaskTracker cancelable_task_tracker_; |
155 | 143 |
156 // The Profile object is used to listen for events | 144 // The Profile object is used to listen for events |
157 Profile* profile_; | 145 Profile* profile_; |
158 | 146 |
159 // Lives on the UI thread. | 147 // Lives on the UI thread. |
160 scoped_ptr<content::NotificationRegistrar> registrar_; | 148 scoped_ptr<content::NotificationRegistrar> registrar_; |
161 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 149 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
162 | 150 |
163 // App id to associate with the jump list. | 151 // App id to associate with the jump list. |
164 std::wstring app_id_; | 152 std::wstring app_id_; |
165 | 153 |
166 // The directory which contains JumpList icons. | 154 // The directory which contains JumpList icons. |
167 base::FilePath icon_dir_; | 155 base::FilePath icon_dir_; |
168 | 156 |
169 // Items in the "Most Visited" category of the application JumpList, | 157 // Items in the "Most Visited" category of the application JumpList, |
170 // protected by the list_lock_. | 158 // protected by the list_lock_. |
171 ShellLinkItemList most_visited_pages_; | 159 ShellLinkItemList most_visited_pages_; |
172 | 160 |
173 // Items in the "Recently Closed" category of the application JumpList, | 161 // Items in the "Recently Closed" category of the application JumpList, |
174 // protected by the list_lock_. | 162 // protected by the list_lock_. |
175 ShellLinkItemList recently_closed_pages_; | 163 ShellLinkItemList recently_closed_pages_; |
176 | 164 |
177 // Items in the "People" category of the application JumpList, protected | |
178 // by the list_lock_. | |
179 ShellLinkItemList profile_switcher_; | |
180 | |
181 // A list of URLs we need to retrieve their favicons, | 165 // A list of URLs we need to retrieve their favicons, |
182 // protected by the list_lock_. | 166 // protected by the list_lock_. |
183 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 167 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
184 std::list<URLPair> icon_urls_; | 168 std::list<URLPair> icon_urls_; |
185 | 169 |
186 // Id of last favicon task. It's used to cancel current task if a new one | 170 // Id of last favicon task. It's used to cancel current task if a new one |
187 // comes in before it finishes. | 171 // comes in before it finishes. |
188 base::CancelableTaskTracker::TaskId task_id_; | 172 base::CancelableTaskTracker::TaskId task_id_; |
189 | 173 |
190 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | 174 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ |
191 // as they may be used by up to 3 threads. | 175 // as they may be used by up to 3 threads. |
192 base::Lock list_lock_; | 176 base::Lock list_lock_; |
193 | 177 |
194 // For callbacks may be run after destruction. | 178 // For callbacks may be run after destruction. |
195 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 179 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
196 | 180 |
197 // Contains data about existing Profiles. | |
198 scoped_ptr<AvatarMenu> avatar_menu_; | |
199 | |
200 // Whether the experiment that is replacing "Most Visited" category with a | |
201 // "People" category is enabled. | |
202 bool use_profiles_category_; | |
203 | |
204 DISALLOW_COPY_AND_ASSIGN(JumpList); | 181 DISALLOW_COPY_AND_ASSIGN(JumpList); |
205 }; | 182 }; |
206 | 183 |
207 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 184 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
OLD | NEW |