| 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" |
| 20 #include "chrome/browser/sessions/tab_restore_service.h" | 22 #include "chrome/browser/sessions/tab_restore_service.h" |
| 21 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 23 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 22 #include "components/history/core/browser/history_types.h" | 24 #include "components/history/core/browser/history_types.h" |
| 23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 24 | 26 |
| 25 namespace chrome { | 27 namespace chrome { |
| 26 struct FaviconImageResult; | 28 struct FaviconImageResult; |
| 27 } | 29 } |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 // the JumpList whenever a change is detected. | 48 // the JumpList whenever a change is detected. |
| 47 // | 49 // |
| 48 // Updating a JumpList requires some file operations and it is not good to | 50 // Updating a JumpList requires some file operations and it is not good to |
| 49 // update it in a UI thread. To solve this problem, this class posts to a | 51 // update it in a UI thread. To solve this problem, this class posts to a |
| 50 // runnable method when it actually updates a JumpList. | 52 // runnable method when it actually updates a JumpList. |
| 51 // | 53 // |
| 52 // Note. base::CancelableTaskTracker is not thread safe, so we | 54 // Note. base::CancelableTaskTracker is not thread safe, so we |
| 53 // always delete JumpList on UI thread (the same thread it got constructed on). | 55 // always delete JumpList on UI thread (the same thread it got constructed on). |
| 54 class JumpList : public TabRestoreServiceObserver, | 56 class JumpList : public TabRestoreServiceObserver, |
| 55 public content::NotificationObserver, | 57 public content::NotificationObserver, |
| 58 public AvatarMenuObserver, |
| 56 public base::RefCountedThreadSafe< | 59 public base::RefCountedThreadSafe< |
| 57 JumpList, content::BrowserThread::DeleteOnUIThread> { | 60 JumpList, content::BrowserThread::DeleteOnUIThread> { |
| 58 public: | 61 public: |
| 59 explicit JumpList(Profile* profile); | 62 explicit JumpList(Profile* profile); |
| 60 | 63 |
| 61 // NotificationObserver implementation. | 64 // NotificationObserver implementation. |
| 62 virtual void Observe(int type, | 65 void Observe(int type, |
| 63 const content::NotificationSource& source, | 66 const content::NotificationSource& source, |
| 64 const content::NotificationDetails& details); | 67 const content::NotificationDetails& details) override; |
| 65 | 68 |
| 66 // Observer callback for TabRestoreService::Observer to notify when a tab is | 69 // Observer callback for TabRestoreService::Observer to notify when a tab is |
| 67 // added or removed. | 70 // added or removed. |
| 68 virtual void TabRestoreServiceChanged(TabRestoreService* service); | 71 void TabRestoreServiceChanged(TabRestoreService* service) override; |
| 69 | 72 |
| 70 // Observer callback to notice when our associated TabRestoreService | 73 // Observer callback to notice when our associated TabRestoreService |
| 71 // is destroyed. | 74 // is destroyed. |
| 72 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); | 75 void TabRestoreServiceDestroyed(TabRestoreService* service) override; |
| 76 |
| 77 // Overridden from AvatarMenuObserver: |
| 78 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override; |
| 73 | 79 |
| 74 // Cancel a pending jumplist update. | 80 // Cancel a pending jumplist update. |
| 75 void CancelPendingUpdate(); | 81 void CancelPendingUpdate(); |
| 76 | 82 |
| 77 // Terminate the jumplist: cancel any pending updates and stop observing | 83 // Terminate the jumplist: cancel any pending updates and stop observing |
| 78 // the Profile and its services. This must be called before the |profile_| | 84 // the Profile and its services. This must be called before the |profile_| |
| 79 // is destroyed. | 85 // is destroyed. |
| 80 void Terminate(); | 86 void Terminate(); |
| 81 | 87 |
| 82 // Returns true if the custom JumpList is enabled. | 88 // Returns true if the custom JumpList is enabled. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 const history::MostVisitedURLList& data); | 127 const history::MostVisitedURLList& data); |
| 122 | 128 |
| 123 // Callback for changes to the incognito mode availability pref. | 129 // Callback for changes to the incognito mode availability pref. |
| 124 void OnIncognitoAvailabilityChanged(); | 130 void OnIncognitoAvailabilityChanged(); |
| 125 | 131 |
| 126 // Helper for RunUpdate() that determines its parameters. | 132 // Helper for RunUpdate() that determines its parameters. |
| 127 void PostRunUpdate(); | 133 void PostRunUpdate(); |
| 128 | 134 |
| 129 // Runnable method that updates the jumplist, once all the data | 135 // Runnable method that updates the jumplist, once all the data |
| 130 // has been fetched. | 136 // has been fetched. |
| 131 void RunUpdate(IncognitoModePrefs::Availability incognito_availability); | 137 void RunUpdateOnFileThread( |
| 138 IncognitoModePrefs::Availability incognito_availability); |
| 132 | 139 |
| 133 // Helper method for RunUpdate to create icon files for the asynchrounously | 140 // Helper method for RunUpdate to create icon files for the asynchrounously |
| 134 // loaded icons. | 141 // loaded icons. |
| 135 void CreateIconFiles(const ShellLinkItemList& item_list); | 142 void CreateIconFiles(const ShellLinkItemList& item_list); |
| 136 | 143 |
| 144 // Called when the list of Profiles has changed. This function updates the |
| 145 // |profile_switcher_| ShellLinkItemList. |
| 146 void UpdateProfileSwitcher(); |
| 147 |
| 137 // Tracks FaviconService tasks. | 148 // Tracks FaviconService tasks. |
| 138 base::CancelableTaskTracker cancelable_task_tracker_; | 149 base::CancelableTaskTracker cancelable_task_tracker_; |
| 139 | 150 |
| 140 // The Profile object is used to listen for events | 151 // The Profile object is used to listen for events |
| 141 Profile* profile_; | 152 Profile* profile_; |
| 142 | 153 |
| 143 // Lives on the UI thread. | 154 // Lives on the UI thread. |
| 144 scoped_ptr<content::NotificationRegistrar> registrar_; | 155 scoped_ptr<content::NotificationRegistrar> registrar_; |
| 145 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 156 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 146 | 157 |
| 147 // App id to associate with the jump list. | 158 // App id to associate with the jump list. |
| 148 std::wstring app_id_; | 159 std::wstring app_id_; |
| 149 | 160 |
| 150 // The directory which contains JumpList icons. | 161 // The directory which contains JumpList icons. |
| 151 base::FilePath icon_dir_; | 162 base::FilePath icon_dir_; |
| 152 | 163 |
| 153 // Items in the "Most Visited" category of the application JumpList, | 164 // Items in the "Most Visited" category of the application JumpList, |
| 154 // protected by the list_lock_. | 165 // protected by the list_lock_. |
| 155 ShellLinkItemList most_visited_pages_; | 166 ShellLinkItemList most_visited_pages_; |
| 156 | 167 |
| 157 // Items in the "Recently Closed" category of the application JumpList, | 168 // Items in the "Recently Closed" category of the application JumpList, |
| 158 // protected by the list_lock_. | 169 // protected by the list_lock_. |
| 159 ShellLinkItemList recently_closed_pages_; | 170 ShellLinkItemList recently_closed_pages_; |
| 160 | 171 |
| 172 // Items in the "Profiles" category of the application JumpList, protected |
| 173 // by the list_lock_. |
| 174 ShellLinkItemList profile_switcher_; |
| 175 |
| 161 // A list of URLs we need to retrieve their favicons, | 176 // A list of URLs we need to retrieve their favicons, |
| 162 // protected by the list_lock_. | 177 // protected by the list_lock_. |
| 163 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 178 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
| 164 std::list<URLPair> icon_urls_; | 179 std::list<URLPair> icon_urls_; |
| 165 | 180 |
| 166 // Id of last favicon task. It's used to cancel current task if a new one | 181 // Id of last favicon task. It's used to cancel current task if a new one |
| 167 // comes in before it finishes. | 182 // comes in before it finishes. |
| 168 base::CancelableTaskTracker::TaskId task_id_; | 183 base::CancelableTaskTracker::TaskId task_id_; |
| 169 | 184 |
| 170 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | 185 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ |
| 171 // as they may be used by up to 3 threads. | 186 // as they may be used by up to 3 threads. |
| 172 base::Lock list_lock_; | 187 base::Lock list_lock_; |
| 173 | 188 |
| 174 // For callbacks may be run after destruction. | 189 // For callbacks may be run after destruction. |
| 175 base::WeakPtrFactory<JumpList> weak_ptr_factory_; | 190 base::WeakPtrFactory<JumpList> weak_ptr_factory_; |
| 176 | 191 |
| 192 // Contains data about existing Profiles. |
| 193 scoped_ptr<AvatarMenu> avatar_menu_; |
| 194 |
| 177 DISALLOW_COPY_AND_ASSIGN(JumpList); | 195 DISALLOW_COPY_AND_ASSIGN(JumpList); |
| 178 }; | 196 }; |
| 179 | 197 |
| 180 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 198 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
| OLD | NEW |