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 <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/task/cancelable_task_tracker.h" | 19 #include "base/task/cancelable_task_tracker.h" |
20 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
21 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
22 #include "chrome/browser/win/jumplist_updater.h" | 22 #include "chrome/browser/win/jumplist_updater.h" |
23 #include "components/history/core/browser/history_service.h" | 23 #include "components/history/core/browser/history_service.h" |
24 #include "components/history/core/browser/history_types.h" | 24 #include "components/history/core/browser/history_types.h" |
25 #include "components/history/core/browser/top_sites_observer.h" | 25 #include "components/history/core/browser/top_sites_observer.h" |
| 26 #include "components/keyed_service/core/refcounted_keyed_service.h" |
26 #include "components/sessions/core/tab_restore_service.h" | 27 #include "components/sessions/core/tab_restore_service.h" |
27 #include "components/sessions/core/tab_restore_service_observer.h" | 28 #include "components/sessions/core/tab_restore_service_observer.h" |
28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
30 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
31 | 32 |
32 namespace chrome { | 33 namespace chrome { |
33 struct FaviconImageResult; | 34 struct FaviconImageResult; |
34 } | 35 } |
35 | 36 |
| 37 class JumpListFactory; |
36 class PrefChangeRegistrar; | 38 class PrefChangeRegistrar; |
37 class Profile; | 39 class Profile; |
38 | 40 |
39 // A class which implements an application JumpList. | 41 // A class which implements an application JumpList. |
40 // This class encapsulates operations required for updating an application | 42 // This class encapsulates operations required for updating an application |
41 // JumpList: | 43 // JumpList: |
42 // * Retrieving "Most Visited" pages from HistoryService; | 44 // * Retrieving "Most Visited" pages from HistoryService; |
43 // * Retrieving strings from the application resource; | 45 // * Retrieving strings from the application resource; |
44 // * Adding COM objects to JumpList, etc. | 46 // * Adding COM objects to JumpList, etc. |
45 // | 47 // |
46 // This class observes the tabs and policies of the given Profile and updates | 48 // This class observes the tabs and policies of the given Profile and updates |
47 // the JumpList whenever a change is detected. | 49 // the JumpList whenever a change is detected. |
48 // | 50 // |
49 // Updating a JumpList requires some file operations and it is not good to | 51 // 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 | 52 // update it in a UI thread. To solve this problem, this class posts to a |
51 // runnable method when it actually updates a JumpList. | 53 // runnable method when it actually updates a JumpList. |
52 // | 54 // |
53 // Note. base::CancelableTaskTracker is not thread safe, so we | 55 // Note. base::CancelableTaskTracker is not thread safe, so we |
54 // always delete JumpList on UI thread (the same thread it got constructed on). | 56 // always delete JumpList on UI thread (the same thread it got constructed on). |
55 class JumpList : public sessions::TabRestoreServiceObserver, | 57 class JumpList : public sessions::TabRestoreServiceObserver, |
56 public content::NotificationObserver, | |
57 public history::TopSitesObserver, | 58 public history::TopSitesObserver, |
58 public base::NonThreadSafe, | 59 public RefcountedKeyedService, |
59 public base::RefCounted<JumpList> { | 60 public base::NonThreadSafe { |
60 public: | 61 public: |
61 struct JumpListData { | 62 struct JumpListData { |
62 JumpListData(); | 63 JumpListData(); |
63 ~JumpListData(); | 64 ~JumpListData(); |
64 | 65 |
65 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | 66 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ |
66 // as they may be used by up to 2 threads. | 67 // as they may be used by up to 2 threads. |
67 base::Lock list_lock_; | 68 base::Lock list_lock_; |
68 | 69 |
69 // A list of URLs we need to retrieve their favicons, | 70 // A list of URLs we need to retrieve their favicons, |
70 // protected by the list_lock_. | 71 // protected by the list_lock_. |
71 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 72 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
72 std::list<URLPair> icon_urls_; | 73 std::list<URLPair> icon_urls_; |
73 | 74 |
74 // Items in the "Most Visited" category of the application JumpList, | 75 // Items in the "Most Visited" category of the application JumpList, |
75 // protected by the list_lock_. | 76 // protected by the list_lock_. |
76 ShellLinkItemList most_visited_pages_; | 77 ShellLinkItemList most_visited_pages_; |
77 | 78 |
78 // Items in the "Recently Closed" category of the application JumpList, | 79 // Items in the "Recently Closed" category of the application JumpList, |
79 // protected by the list_lock_. | 80 // protected by the list_lock_. |
80 ShellLinkItemList recently_closed_pages_; | 81 ShellLinkItemList recently_closed_pages_; |
81 }; | 82 }; |
82 | 83 |
83 explicit JumpList(Profile* profile); | |
84 | |
85 // NotificationObserver implementation. | |
86 void Observe(int type, | |
87 const content::NotificationSource& source, | |
88 const content::NotificationDetails& details) override; | |
89 | |
90 // Observer callback for TabRestoreService::Observer to notify when a tab is | 84 // Observer callback for TabRestoreService::Observer to notify when a tab is |
91 // added or removed. | 85 // added or removed. |
92 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; | 86 void TabRestoreServiceChanged(sessions::TabRestoreService* service) override; |
93 | 87 |
94 // Observer callback to notice when our associated TabRestoreService | 88 // Observer callback to notice when our associated TabRestoreService |
95 // is destroyed. | 89 // is destroyed. |
96 void TabRestoreServiceDestroyed( | 90 void TabRestoreServiceDestroyed( |
97 sessions::TabRestoreService* service) override; | 91 sessions::TabRestoreService* service) override; |
98 | 92 |
99 // Cancel a pending jumplist update. | 93 // Cancel a pending jumplist update. |
100 void CancelPendingUpdate(); | 94 void CancelPendingUpdate(); |
101 | 95 |
102 // Terminate the jumplist: cancel any pending updates and stop observing | 96 // Terminate the jumplist: cancel any pending updates and stop observing |
103 // the Profile and its services. This must be called before the |profile_| | 97 // the Profile and its services. This must be called before the |profile_| |
104 // is destroyed. | 98 // is destroyed. |
105 void Terminate(); | 99 void Terminate(); |
106 | 100 |
| 101 // RefcountedKeyedService: |
| 102 void ShutdownOnUIThread() override; |
| 103 |
107 // Returns true if the custom JumpList is enabled. | 104 // Returns true if the custom JumpList is enabled. |
108 // The custom jumplist works only on Windows 7 and above. | 105 // The custom jumplist works only on Windows 7 and above. |
109 static bool Enabled(); | 106 static bool Enabled(); |
110 | 107 |
111 private: | 108 private: |
112 friend class base::RefCounted<JumpList>; | 109 friend JumpListFactory; |
| 110 explicit JumpList(Profile* profile); // Use JumpListFactory instead |
113 ~JumpList() override; | 111 ~JumpList() override; |
114 | 112 |
115 // Creates a ShellLinkItem object from a tab (or a window) and add it to the | 113 // Creates a ShellLinkItem object from a tab (or a window) and add it to the |
116 // given list. | 114 // given list. |
117 // These functions are copied from the RecentlyClosedTabsHandler class for | 115 // These functions are copied from the RecentlyClosedTabsHandler class for |
118 // compatibility with the new-tab page. | 116 // compatibility with the new-tab page. |
119 bool AddTab(const sessions::TabRestoreService::Tab& tab, | 117 bool AddTab(const sessions::TabRestoreService::Tab& tab, |
120 ShellLinkItemList* list, | 118 ShellLinkItemList* list, |
121 size_t max_items); | 119 size_t max_items); |
122 void AddWindow(const sessions::TabRestoreService::Window& window, | 120 void AddWindow(const sessions::TabRestoreService::Window& window, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void TopSitesChanged(history::TopSites* top_sites, | 156 void TopSitesChanged(history::TopSites* top_sites, |
159 ChangeReason change_reason) override; | 157 ChangeReason change_reason) override; |
160 | 158 |
161 // Tracks FaviconService tasks. | 159 // Tracks FaviconService tasks. |
162 base::CancelableTaskTracker cancelable_task_tracker_; | 160 base::CancelableTaskTracker cancelable_task_tracker_; |
163 | 161 |
164 // The Profile object is used to listen for events | 162 // The Profile object is used to listen for events |
165 Profile* profile_; | 163 Profile* profile_; |
166 | 164 |
167 // Lives on the UI thread. | 165 // Lives on the UI thread. |
168 std::unique_ptr<content::NotificationRegistrar> registrar_; | |
169 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 166 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
170 | 167 |
171 // App id to associate with the jump list. | 168 // App id to associate with the jump list. |
172 std::wstring app_id_; | 169 std::wstring app_id_; |
173 | 170 |
174 // The directory which contains JumpList icons. | 171 // The directory which contains JumpList icons. |
175 base::FilePath icon_dir_; | 172 base::FilePath icon_dir_; |
176 | 173 |
177 // Timer for requesting delayed updates of the jumplist. | 174 // Timer for requesting delayed updates of the jumplist. |
178 base::OneShotTimer timer_; | 175 base::OneShotTimer timer_; |
179 | 176 |
180 // Holds data that can be accessed from multiple threads. | 177 // Holds data that can be accessed from multiple threads. |
181 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; | 178 scoped_refptr<base::RefCountedData<JumpListData>> jumplist_data_; |
182 | 179 |
183 // Id of last favicon task. It's used to cancel current task if a new one | 180 // Id of last favicon task. It's used to cancel current task if a new one |
184 // comes in before it finishes. | 181 // comes in before it finishes. |
185 base::CancelableTaskTracker::TaskId task_id_; | 182 base::CancelableTaskTracker::TaskId task_id_; |
186 | 183 |
187 // For callbacks may be run after destruction. | 184 // For callbacks may be run after destruction. |
188 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 185 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
189 | 186 |
190 DISALLOW_COPY_AND_ASSIGN(JumpList); | 187 DISALLOW_COPY_AND_ASSIGN(JumpList); |
191 }; | 188 }; |
192 | 189 |
193 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ | 190 #endif // CHROME_BROWSER_WIN_JUMPLIST_H_ |
OLD | NEW |