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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.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 "chrome/browser/history/history_service.h" | 17 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/browser/history/history_types.h" | 18 #include "chrome/browser/history/history_types.h" |
18 #include "chrome/browser/sessions/tab_restore_service.h" | 19 #include "chrome/browser/sessions/tab_restore_service.h" |
19 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 20 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
20 #include "chrome/common/cancelable_task_tracker.h" | |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class FilePath; | 25 class FilePath; |
26 } | 26 } |
27 | 27 |
28 namespace chrome { | 28 namespace chrome { |
29 struct FaviconImageResult; | 29 struct FaviconImageResult; |
30 } | 30 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // * Adding COM objects to JumpList, etc. | 108 // * Adding COM objects to JumpList, etc. |
109 // | 109 // |
110 // This class also implements TabRestoreServiceObserver. So, once we call | 110 // This class also implements TabRestoreServiceObserver. So, once we call |
111 // AddObserver() and register this class as an observer, it automatically | 111 // AddObserver() and register this class as an observer, it automatically |
112 // updates a JumpList when a tab is added or removed. | 112 // updates a JumpList when a tab is added or removed. |
113 // | 113 // |
114 // Updating a JumpList requires some file operations and it is not good to | 114 // Updating a JumpList requires some file operations and it is not good to |
115 // update it in a UI thread. To solve this problem, this class posts to a | 115 // update it in a UI thread. To solve this problem, this class posts to a |
116 // runnable method when it actually updates a JumpList. | 116 // runnable method when it actually updates a JumpList. |
117 // | 117 // |
118 // Note. CancelableTaskTracker is not thread safe, so we always delete JumpList | 118 // Note. base::CancelableTaskTracker is not thread safe, so we |
119 // on UI thread (the same thread it got constructed on). | 119 // always delete JumpList on UI thread (the same thread it got constructed on). |
120 class JumpList : public TabRestoreServiceObserver, | 120 class JumpList : public TabRestoreServiceObserver, |
121 public content::NotificationObserver, | 121 public content::NotificationObserver, |
122 public base::RefCountedThreadSafe< | 122 public base::RefCountedThreadSafe< |
123 JumpList, content::BrowserThread::DeleteOnUIThread> { | 123 JumpList, content::BrowserThread::DeleteOnUIThread> { |
124 public: | 124 public: |
125 JumpList(); | 125 JumpList(); |
126 | 126 |
127 // NotificationObserver implementation. | 127 // NotificationObserver implementation. |
128 virtual void Observe(int type, | 128 virtual void Observe(int type, |
129 const content::NotificationSource& source, | 129 const content::NotificationSource& source, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 private: | 211 private: |
212 friend struct content::BrowserThread::DeleteOnThread< | 212 friend struct content::BrowserThread::DeleteOnThread< |
213 content::BrowserThread::UI>; | 213 content::BrowserThread::UI>; |
214 friend class base::DeleteHelper<JumpList>; | 214 friend class base::DeleteHelper<JumpList>; |
215 ~JumpList(); | 215 ~JumpList(); |
216 | 216 |
217 // For callbacks may be run after destruction. | 217 // For callbacks may be run after destruction. |
218 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 218 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
219 | 219 |
220 // Tracks FaviconService tasks. | 220 // Tracks FaviconService tasks. |
221 CancelableTaskTracker cancelable_task_tracker_; | 221 base::CancelableTaskTracker cancelable_task_tracker_; |
222 | 222 |
223 // The Profile object is used to listen for events | 223 // The Profile object is used to listen for events |
224 Profile* profile_; | 224 Profile* profile_; |
225 | 225 |
226 // Lives on the UI thread. | 226 // Lives on the UI thread. |
227 scoped_ptr<content::NotificationRegistrar> registrar_; | 227 scoped_ptr<content::NotificationRegistrar> registrar_; |
228 | 228 |
229 // App id to associate with the jump list. | 229 // App id to associate with the jump list. |
230 std::wstring app_id_; | 230 std::wstring app_id_; |
231 | 231 |
232 // The directory which contains JumpList icons. | 232 // The directory which contains JumpList icons. |
233 base::FilePath icon_dir_; | 233 base::FilePath icon_dir_; |
234 | 234 |
235 // Items in the "Most Visited" category of the application JumpList, | 235 // Items in the "Most Visited" category of the application JumpList, |
236 // protected by the list_lock_. | 236 // protected by the list_lock_. |
237 ShellLinkItemList most_visited_pages_; | 237 ShellLinkItemList most_visited_pages_; |
238 | 238 |
239 // Items in the "Recently Closed" category of the application JumpList, | 239 // Items in the "Recently Closed" category of the application JumpList, |
240 // protected by the list_lock_. | 240 // protected by the list_lock_. |
241 ShellLinkItemList recently_closed_pages_; | 241 ShellLinkItemList recently_closed_pages_; |
242 | 242 |
243 // A list of URLs we need to retrieve their favicons, | 243 // A list of URLs we need to retrieve their favicons, |
244 // protected by the list_lock_. | 244 // protected by the list_lock_. |
245 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 245 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
246 std::list<URLPair> icon_urls_; | 246 std::list<URLPair> icon_urls_; |
247 | 247 |
248 // Id of last favicon task. It's used to cancel current task if a new one | 248 // Id of last favicon task. It's used to cancel current task if a new one |
249 // comes in before it finishes. | 249 // comes in before it finishes. |
250 CancelableTaskTracker::TaskId task_id_; | 250 base::CancelableTaskTracker::TaskId task_id_; |
251 | 251 |
252 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | 252 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ |
253 // as they may be used by up to 3 threads. | 253 // as they may be used by up to 3 threads. |
254 base::Lock list_lock_; | 254 base::Lock list_lock_; |
255 | 255 |
256 DISALLOW_COPY_AND_ASSIGN(JumpList); | 256 DISALLOW_COPY_AND_ASSIGN(JumpList); |
257 }; | 257 }; |
258 | 258 |
259 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 259 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
OLD | NEW |