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 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 a |
|
MAD
2011/08/19 14:46:03
posts TO a runnable...
| |
| 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 |
| 135 // given list. | 150 // given list. |
| 136 // These functions are copied from the RecentlyClosedTabsHandler class for | 151 // These functions are copied from the RecentlyClosedTabsHandler class for |
| 137 // compatibility with the new-tab page. | 152 // compatibility with the new-tab page. |
| 138 bool AddTab(const TabRestoreService::Tab* tab, | 153 bool AddTab(const TabRestoreService::Tab* tab, ShellLinkItemList* list, |
|
MAD
2011/08/19 14:46:03
Maybe we could bring those back to 3 lines to mini
| |
| 139 ShellLinkItemList* list, | |
| 140 size_t max_items); | 154 size_t max_items); |
| 141 bool AddWindow(const TabRestoreService::Window* window, | 155 bool AddWindow(const TabRestoreService::Window* window, |
| 142 ShellLinkItemList* list, | 156 ShellLinkItemList* list, size_t max_items); |
| 143 size_t max_items); | |
| 144 | 157 |
| 145 // Starts loading a favicon for each URL in |icon_urls_|. | 158 // Starts loading a favicon for each URL in |icon_urls_|. |
| 146 // This function just sends a query to HistoryService. | 159 // This function just sends a query to HistoryService. |
| 147 bool StartLoadingFavicon(); | 160 bool StartLoadingFavicon(); |
| 148 | 161 |
| 149 // A callback function for HistoryService that notify when the "Most Visited" | 162 // A callback function for HistoryService that notify when the "Most Visited" |
| 150 // list is available. | 163 // list is available. |
| 151 // This function updates the ShellLinkItemList objects and send another query | 164 // This function updates the ShellLinkItemList objects and send another query |
| 152 // that retrieves a favicon for each URL in the list. | 165 // that retrieves a favicon for each URL in the list. |
| 153 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, | 166 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, |
| 154 std::vector<PageUsageData*>* data); | 167 std::vector<PageUsageData*>* data); |
| 155 | 168 |
| 156 // A callback function for HistoryService that notify when a requested favicon | 169 // A callback function for HistoryService that notify when a requested favicon |
| 157 // is available. | 170 // is available. |
| 158 // To avoid file operations, this function just attaches the given data to | 171 // To avoid file operations, this function just attaches the given data to |
| 159 // a ShellLinkItem object. | 172 // a ShellLinkItem object. |
| 160 // When finishing loading all favicons, this function posts a task that | 173 // When finishing loading all favicons, this function posts a task that |
| 161 // decompresses collected favicons and updates a JumpList. | 174 // decompresses collected favicons and updates a JumpList. |
| 162 void OnFaviconDataAvailable(HistoryService::Handle handle, | 175 void OnFaviconDataAvailable(HistoryService::Handle handle, |
| 163 history::FaviconData favicon); | 176 history::FaviconData favicon); |
| 164 | 177 |
| 178 // Callback for TopSites that notifies when the "Most | |
| 179 // Visited" list is available. This function updates the ShellLinkItemList | |
| 180 // objects and send another query that retrieves a favicon for each URL in | |
| 181 // the list. | |
| 182 void OnMostVisitedURLsAvailable( | |
| 183 const history::MostVisitedURLList& data); | |
|
MAD
2011/08/19 14:46:03
Bad alignment, should only be 4 more indent space
| |
| 184 | |
| 185 // Runnable method that updates the jumplist, once have all the data | |
|
MAD
2011/08/19 14:46:03
once all the data... (remove the word have)
| |
| 186 // has been fetched. | |
| 187 void RunUpdate(); | |
| 188 | |
| 189 // Helper method for RunUpdate to decode the data about the asynchrounously | |
| 190 // loaded icons. | |
| 191 void DecodeIconData(const ShellLinkItemList& item_list); | |
| 192 | |
| 165 private: | 193 private: |
| 194 friend class base::RefCountedThreadSafe<JumpList>; | |
| 195 ~JumpList(); | |
| 196 | |
| 166 // Our consumers for HistoryService. | 197 // Our consumers for HistoryService. |
| 167 CancelableRequestConsumer most_visited_consumer_; | 198 CancelableRequestConsumer most_visited_consumer_; |
| 168 CancelableRequestConsumer favicon_consumer_; | 199 CancelableRequestConsumer favicon_consumer_; |
| 200 CancelableRequestConsumer topsites_consumer_; | |
| 169 | 201 |
| 170 // The Profile object used for listening its events. | |
|
MAD
2011/08/19 14:46:03
Bring back this comment.
| |
| 171 Profile* profile_; | 202 Profile* profile_; |
| 172 | 203 |
| 204 NotificationRegistrar registrar_; | |
| 205 | |
| 173 // App id to associate with the jump list. | 206 // App id to associate with the jump list. |
| 174 std::wstring app_id_; | 207 std::wstring app_id_; |
| 175 | 208 |
| 176 // The directory which contains JumpList icons. | 209 // The directory which contains JumpList icons. |
| 177 FilePath icon_dir_; | 210 FilePath icon_dir_; |
| 178 | 211 |
| 179 // Items in the "Most Visited" category of the application JumpList. | 212 // Items in the "Most Visited" category of the application JumpList, |
| 213 // protected by the list_lock_. | |
| 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, |
| 217 // protected by the list_lock_. | |
| 183 ShellLinkItemList recently_closed_pages_; | 218 ShellLinkItemList recently_closed_pages_; |
| 184 | 219 |
| 185 // A list of URLs we need to retrieve their favicons. | 220 // A list of URLs we need to retrieve their favicons, |
| 221 // protected by the list_lock_. | |
| 186 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; | 222 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
| 187 std::list<URLPair> icon_urls_; | 223 std::list<URLPair> icon_urls_; |
| 224 | |
| 225 // Handle of last favicon request used to cancel if a new request | |
| 226 // comes in before the current one returns. | |
| 227 FaviconService::Handle handle_; | |
| 228 | |
| 229 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ | |
| 230 // as they may be used by up to 3 threads. | |
| 231 base::Lock list_lock_; | |
| 188 }; | 232 }; |
| 189 | 233 |
| 190 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ | 234 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ |
| OLD | NEW |