Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 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. | |
|
MAD
2011/08/16 17:02:31
Maybe augment the comment to specify that this mus
| |
| 136 void Terminate(); | |
| 137 | |
| 125 // Returns true if the custom JumpList is enabled. | 138 // Returns true if the custom JumpList is enabled. |
| 126 // We use the custom JumpList when we satisfy the following conditions: | 139 // We use the custom JumpList when we satisfy the following conditions: |
| 127 // * Chromium is running on Windows 7 and; | 140 // * Chromium is running on Windows 7 and; |
| 128 // * Chromium is lauched without a "--disable-custom-jumplist" option. | 141 // * Chromium is lauched without a "--disable-custom-jumplist" option. |
| 129 // TODO(hbono): to be enabled by default when we finalize the categories and | 142 // TODO(hbono): to be enabled by default when we finalize the categories and |
| 130 // items of our JumpList. | 143 // items of our JumpList. |
| 131 static bool Enabled(); | 144 static bool Enabled(); |
| 132 | 145 |
| 133 protected: | 146 protected: |
| 134 // Creates a ShellLinkItem object from a tab (or a window) and add it to the | 147 // Creates a ShellLinkItem object from a tab (or a window) and add it to the |
| 135 // given list. | 148 // given list. |
| 136 // These functions are copied from the RecentlyClosedTabsHandler class for | 149 // These functions are copied from the RecentlyClosedTabsHandler class for |
| 137 // compatibility with the new-tab page. | 150 // compatibility with the new-tab page. |
| 138 bool AddTab(const TabRestoreService::Tab* tab, | 151 bool AddTab(const TabRestoreService::Tab* tab, ShellLinkItemList* list, |
| 139 ShellLinkItemList* list, | |
| 140 size_t max_items); | 152 size_t max_items); |
| 141 bool AddWindow(const TabRestoreService::Window* window, | 153 bool AddWindow(const TabRestoreService::Window* window, |
| 142 ShellLinkItemList* list, | 154 ShellLinkItemList* list, size_t max_items); |
| 143 size_t max_items); | |
| 144 | 155 |
| 145 // Starts loading a favicon for each URL in |icon_urls_|. | 156 // Starts loading a favicon for each URL in |icon_urls_|. |
| 146 // This function just sends a query to HistoryService. | 157 // This function just sends a query to HistoryService. |
| 147 bool StartLoadingFavicon(); | 158 bool StartLoadingFavicon(); |
| 148 | 159 |
| 149 // A callback function for HistoryService that notify when the "Most Visited" | 160 // A callback function for HistoryService that notify when the "Most Visited" |
| 150 // list is available. | 161 // list is available. |
| 151 // This function updates the ShellLinkItemList objects and send another query | 162 // This function updates the ShellLinkItemList objects and send another query |
| 152 // that retrieves a favicon for each URL in the list. | 163 // that retrieves a favicon for each URL in the list. |
| 153 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, | 164 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, |
| 154 std::vector<PageUsageData*>* data); | 165 std::vector<PageUsageData*>* data); |
| 155 | 166 |
| 156 // A callback function for HistoryService that notify when a requested favicon | 167 // A callback function for HistoryService that notify when a requested favicon |
| 157 // is available. | 168 // is available. |
| 158 // To avoid file operations, this function just attaches the given data to | 169 // To avoid file operations, this function just attaches the given data to |
| 159 // a ShellLinkItem object. | 170 // a ShellLinkItem object. |
| 160 // When finishing loading all favicons, this function posts a task that | 171 // When finishing loading all favicons, this function posts a task that |
| 161 // decompresses collected favicons and updates a JumpList. | 172 // decompresses collected favicons and updates a JumpList. |
| 162 void OnFaviconDataAvailable(HistoryService::Handle handle, | 173 void OnFaviconDataAvailable(HistoryService::Handle handle, |
| 163 history::FaviconData favicon); | 174 history::FaviconData favicon); |
| 164 | 175 |
| 176 // Callback for TopSites that notifies when the "Most | |
| 177 // Visited" list is available. This function updates the ShellLinkItemList | |
| 178 // objects and send another query that retrieves a favicon for each URL in | |
| 179 // the list. | |
| 180 void OnMostVisitedURLsAvailable( | |
| 181 const history::MostVisitedURLList& data); | |
|
MAD
2011/08/16 17:02:31
Should only 4 chars indent from where void starts.
| |
| 182 | |
| 183 // Runnable method that updates the jumplist, once have all the data | |
| 184 // has been fetched. | |
| 185 void JumpList::RunUpdate(); | |
|
MAD
2011/08/16 17:02:31
No need for JumpList::
| |
| 186 | |
| 187 // Helper method for RunUpdate to decode the data about the asynchrounously | |
| 188 // loaded icons | |
|
MAD
2011/08/16 17:02:31
missing a '.' at the end...
| |
| 189 void DecodeIconData(const ShellLinkItemList& item_list); | |
| 190 | |
| 165 private: | 191 private: |
| 192 friend class base::RefCountedThreadSafe<JumpList>; | |
| 193 ~JumpList(); | |
| 194 | |
| 166 // Our consumers for HistoryService. | 195 // Our consumers for HistoryService. |
| 167 CancelableRequestConsumer most_visited_consumer_; | 196 CancelableRequestConsumer most_visited_consumer_; |
| 168 CancelableRequestConsumer favicon_consumer_; | 197 CancelableRequestConsumer favicon_consumer_; |
| 198 CancelableRequestConsumer topsites_consumer_; | |
| 169 | 199 |
| 170 // The Profile object used for listening its events. | |
| 171 Profile* profile_; | 200 Profile* profile_; |
| 172 | 201 |
| 202 NotificationRegistrar registrar_; | |
| 203 | |
| 173 // App id to associate with the jump list. | 204 // App id to associate with the jump list. |
| 174 std::wstring app_id_; | 205 std::wstring app_id_; |
| 175 | 206 |
| 176 // The directory which contains JumpList icons. | 207 // The directory which contains JumpList icons. |
| 177 FilePath icon_dir_; | 208 FilePath icon_dir_; |
| 178 | 209 |
| 179 // Items in the "Most Visited" category of the application JumpList. | 210 // Items in the "Most Visited" category of the application JumpList. |
| 211 // Since the data members most_visited_pages_ and recently_closed_pages_ | |
| 212 // are updated in one thread and used in another (when the runnable method | |
| 213 // is called), they are and must remain, protected by the list_lock_. | |
|
MAD
2011/08/16 17:02:31
You could simply add "Protected by list_lock_" on
| |
| 180 ShellLinkItemList most_visited_pages_; | 214 ShellLinkItemList most_visited_pages_; |
| 181 | 215 |
| 182 // Items in the "Recently Closed" category of the application JumpList. | 216 // Items in the "Recently Closed" category of the application JumpList. |
| 183 ShellLinkItemList recently_closed_pages_; | 217 ShellLinkItemList recently_closed_pages_; |
| 184 | 218 |
| 185 // A list of URLs we need to retrieve their favicons. | 219 // A list of URLs we need to retrieve their favicons. |
| 186 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 220 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
| 187 std::list<URLPair> icon_urls_; | 221 std::list<URLPair> icon_urls_; |
| 222 | |
| 223 // Handle of last favicon request used to cancel if a new request | |
| 224 // comes in before the current one returns. | |
| 225 FaviconService::Handle handle_; | |
| 226 | |
| 227 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | |
| 228 // as they may be used by up to 3 threads. | |
| 229 base::Lock list_lock_; | |
| 188 }; | 230 }; |
| 189 | 231 |
| 190 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 232 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
| OLD | NEW |