| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/synchronization/lock.h" |
| 15 #include "chrome/browser/history/history.h" | 16 #include "chrome/browser/history/history.h" |
| 17 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/sessions/tab_restore_service.h" | 18 #include "chrome/browser/sessions/tab_restore_service.h" |
| 17 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 19 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 18 #include "content/browser/cancelable_request.h" | 20 #include "content/browser/cancelable_request.h" |
| 19 | 21 |
| 20 class FilePath; | 22 class FilePath; |
| 21 class Profile; | 23 class Profile; |
| 22 class PageUsageData; | 24 class PageUsageData; |
| 23 | 25 |
| 24 // Represents a class used for creating an IShellLink object by the utility | 26 // Represents a class used for creating an IShellLink object by the utility |
| 25 // functions in this file. | 27 // functions in this file. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // * Retrieving "Most Visited" pages from HistoryService; | 92 // * Retrieving "Most Visited" pages from HistoryService; |
| 91 // * Retrieving strings from the application resource; | 93 // * Retrieving strings from the application resource; |
| 92 // * Creatng COM objects used by JumpList from PageUsageData objects; | 94 // * Creatng COM objects used by JumpList from PageUsageData objects; |
| 93 // * Adding COM objects to JumpList, etc. | 95 // * Adding COM objects to JumpList, etc. |
| 94 // | 96 // |
| 95 // This class also implements TabRestoreServiceObserver. So, once we call | 97 // This class also implements TabRestoreServiceObserver. So, once we call |
| 96 // AddObserver() and register this class as an observer, it automatically | 98 // AddObserver() and register this class as an observer, it automatically |
| 97 // updates a JumpList when a tab is added or removed. | 99 // updates a JumpList when a tab is added or removed. |
| 98 // | 100 // |
| 99 // Updating a JumpList requires some file operations and it is not good to | 101 // Updating a JumpList requires some file operations and it is not good to |
| 100 // update it in a UI thread. To solve this problem, this class posts a | 102 // update it in a UI thread. To solve this problem, this class posts to a |
| 101 // task when it actually updates a JumpList. (This task is implemented in an | 103 // runnable method when it actually updates a JumpList. |
| 102 // anomynous namespace in "jumplist_win.cc".) | 104 class JumpList : public TabRestoreServiceObserver, |
| 103 class JumpList : public TabRestoreServiceObserver { | 105 public NotificationObserver, |
| 106 public base::RefCountedThreadSafe<JumpList> { |
| 104 public: | 107 public: |
| 105 JumpList(); | 108 JumpList(); |
| 106 ~JumpList(); | 109 |
| 110 // NotificationObserver implementation. |
| 111 virtual void Observe(int type, |
| 112 const NotificationSource& source, |
| 113 const NotificationDetails& details); |
| 107 | 114 |
| 108 // Registers (or unregisters) this object as an observer. | 115 // Registers (or unregisters) this object as an observer. |
| 109 // When the TabRestoreService object notifies the tab status is changed, this | 116 // When the TabRestoreService object notifies the tab status is changed, this |
| 110 // class automatically updates an application JumpList. | 117 // class automatically updates an application JumpList. |
| 111 bool AddObserver(Profile* profile); | 118 bool AddObserver(Profile* profile); |
| 112 void RemoveObserver(); | 119 void RemoveObserver(); |
| 113 | 120 |
| 114 // Observer callback for TabRestoreService::Observer to notify when a tab is | 121 // Observer callback for TabRestoreService::Observer to notify when a tab is |
| 115 // added or removed. | 122 // added or removed. |
| 116 // This function sends a query that retrieves "Most Visited" pages to | 123 // This function sends a query that retrieves "Most Visited" pages to |
| 117 // HistoryService. When the query finishes successfully, HistoryService call | 124 // HistoryService. When the query finishes successfully, HistoryService call |
| 118 // OnSegmentUsageAvailable(). | 125 // OnSegmentUsageAvailable(). |
| 119 virtual void TabRestoreServiceChanged(TabRestoreService* service); | 126 virtual void TabRestoreServiceChanged(TabRestoreService* service); |
| 120 | 127 |
| 121 // Observer callback to notice when our associated TabRestoreService | 128 // Observer callback to notice when our associated TabRestoreService |
| 122 // is destroyed. | 129 // is destroyed. |
| 123 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); | 130 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); |
| 124 | 131 |
| 132 // Cancel a pending jumplist update. |
| 133 void CancelPendingUpdate(); |
| 134 |
| 135 // Terminate the jumplist: cancel any pending updates and remove observer |
| 136 // from TabRestoreService. This must be called before the profile provided |
| 137 // in the AddObserver method is destroyed. |
| 138 void Terminate(); |
| 139 |
| 125 // Returns true if the custom JumpList is enabled. | 140 // Returns true if the custom JumpList is enabled. |
| 126 // We use the custom JumpList when we satisfy the following conditions: | 141 // We use the custom JumpList when we satisfy the following conditions: |
| 127 // * Chromium is running on Windows 7 and; | 142 // * Chromium is running on Windows 7 and; |
| 128 // * Chromium is lauched without a "--disable-custom-jumplist" option. | 143 // * Chromium is lauched without a "--disable-custom-jumplist" option. |
| 129 // TODO(hbono): to be enabled by default when we finalize the categories and | 144 // TODO(hbono): to be enabled by default when we finalize the categories and |
| 130 // items of our JumpList. | 145 // items of our JumpList. |
| 131 static bool Enabled(); | 146 static bool Enabled(); |
| 132 | 147 |
| 133 protected: | 148 protected: |
| 134 // Creates a ShellLinkItem object from a tab (or a window) and add it to the | 149 // Creates a ShellLinkItem object from a tab (or a window) and add it to the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 | 170 |
| 156 // A callback function for HistoryService that notify when a requested favicon | 171 // A callback function for HistoryService that notify when a requested favicon |
| 157 // is available. | 172 // is available. |
| 158 // To avoid file operations, this function just attaches the given data to | 173 // To avoid file operations, this function just attaches the given data to |
| 159 // a ShellLinkItem object. | 174 // a ShellLinkItem object. |
| 160 // When finishing loading all favicons, this function posts a task that | 175 // When finishing loading all favicons, this function posts a task that |
| 161 // decompresses collected favicons and updates a JumpList. | 176 // decompresses collected favicons and updates a JumpList. |
| 162 void OnFaviconDataAvailable(HistoryService::Handle handle, | 177 void OnFaviconDataAvailable(HistoryService::Handle handle, |
| 163 history::FaviconData favicon); | 178 history::FaviconData favicon); |
| 164 | 179 |
| 180 // Callback for TopSites that notifies when the "Most |
| 181 // Visited" list is available. This function updates the ShellLinkItemList |
| 182 // objects and send another query that retrieves a favicon for each URL in |
| 183 // the list. |
| 184 void OnMostVisitedURLsAvailable( |
| 185 const history::MostVisitedURLList& data); |
| 186 |
| 187 // Runnable method that updates the jumplist, once all the data |
| 188 // has been fetched. |
| 189 void RunUpdate(); |
| 190 |
| 191 // Helper method for RunUpdate to decode the data about the asynchrounously |
| 192 // loaded icons. |
| 193 void DecodeIconData(const ShellLinkItemList& item_list); |
| 194 |
| 165 private: | 195 private: |
| 196 friend class base::RefCountedThreadSafe<JumpList>; |
| 197 ~JumpList(); |
| 198 |
| 166 // Our consumers for HistoryService. | 199 // Our consumers for HistoryService. |
| 167 CancelableRequestConsumer most_visited_consumer_; | 200 CancelableRequestConsumer most_visited_consumer_; |
| 168 CancelableRequestConsumer favicon_consumer_; | 201 CancelableRequestConsumer favicon_consumer_; |
| 202 CancelableRequestConsumer topsites_consumer_; |
| 169 | 203 |
| 170 // The Profile object used for listening its events. | 204 // The Profile object is used to listen for events |
| 171 Profile* profile_; | 205 Profile* profile_; |
| 172 | 206 |
| 207 NotificationRegistrar registrar_; |
| 208 |
| 173 // App id to associate with the jump list. | 209 // App id to associate with the jump list. |
| 174 std::wstring app_id_; | 210 std::wstring app_id_; |
| 175 | 211 |
| 176 // The directory which contains JumpList icons. | 212 // The directory which contains JumpList icons. |
| 177 FilePath icon_dir_; | 213 FilePath icon_dir_; |
| 178 | 214 |
| 179 // Items in the "Most Visited" category of the application JumpList. | 215 // Items in the "Most Visited" category of the application JumpList, |
| 216 // protected by the list_lock_. |
| 180 ShellLinkItemList most_visited_pages_; | 217 ShellLinkItemList most_visited_pages_; |
| 181 | 218 |
| 182 // Items in the "Recently Closed" category of the application JumpList. | 219 // Items in the "Recently Closed" category of the application JumpList, |
| 220 // protected by the list_lock_. |
| 183 ShellLinkItemList recently_closed_pages_; | 221 ShellLinkItemList recently_closed_pages_; |
| 184 | 222 |
| 185 // A list of URLs we need to retrieve their favicons. | 223 // A list of URLs we need to retrieve their favicons, |
| 224 // protected by the list_lock_. |
| 186 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 225 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
| 187 std::list<URLPair> icon_urls_; | 226 std::list<URLPair> icon_urls_; |
| 227 |
| 228 // Handle of last favicon request used to cancel if a new request |
| 229 // comes in before the current one returns. |
| 230 FaviconService::Handle handle_; |
| 231 |
| 232 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ |
| 233 // as they may be used by up to 3 threads. |
| 234 base::Lock list_lock_; |
| 188 }; | 235 }; |
| 189 | 236 |
| 190 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 237 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
| OLD | NEW |