| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_JUMPLIST_H_ |
| 6 #define CHROME_BROWSER_JUMPLIST_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/ref_counted.h" |
| 14 #include "chrome/browser/cancelable_request.h" |
| 15 #include "chrome/browser/history/history.h" |
| 16 #include "chrome/browser/sessions/tab_restore_service.h" |
| 17 |
| 18 class Profile; |
| 19 class PageUsageData; |
| 20 |
| 21 // Represents a class used for creating an IShellLink object by the utility |
| 22 // functions in this file. |
| 23 // This class consists of three strings and a integer. |
| 24 // * arguments (std::wstring) |
| 25 // The arguments for the application. |
| 26 // * title (std::wstring) |
| 27 // The string to be displayed in a JumpList. |
| 28 // * icon (std::wstring) |
| 29 // The absolute path to an icon to be displayed in a JumpList. |
| 30 // * index (int) |
| 31 // The icon index in the icon file. If an icon file consists of two or more |
| 32 // icons, set this value to identify the icon. If an icon file consists of |
| 33 // one icon, this value is 0. |
| 34 // Even though an IShellLink also needs the absolute path to an application to |
| 35 // be executed, this class does not have any variables for it because our |
| 36 // utility functions always use "chrome.exe" as the application and we don't |
| 37 // need it. |
| 38 class ShellLinkItem : public base::RefCounted<ShellLinkItem> { |
| 39 public: |
| 40 ShellLinkItem() : index_(0), favicon_(false) { |
| 41 } |
| 42 |
| 43 ~ShellLinkItem() { |
| 44 } |
| 45 |
| 46 const std::wstring& arguments() const { return arguments_; } |
| 47 const std::wstring& title() const { return title_; } |
| 48 const std::wstring& icon() const { return icon_; } |
| 49 int index() const { return index_; } |
| 50 scoped_refptr<RefCountedBytes> data() const { return data_; } |
| 51 |
| 52 void SetArguments(const std::wstring& arguments) { |
| 53 arguments_ = arguments; |
| 54 } |
| 55 |
| 56 void SetTitle(const std::wstring& title) { |
| 57 title_ = title; |
| 58 } |
| 59 |
| 60 void SetIcon(const std::wstring& icon, int index, bool favicon) { |
| 61 icon_ = icon; |
| 62 index_ = index; |
| 63 favicon_ = favicon; |
| 64 } |
| 65 |
| 66 void SetIconData(scoped_refptr<RefCountedBytes> data) { |
| 67 data_ = data; |
| 68 } |
| 69 |
| 70 private: |
| 71 std::wstring arguments_; |
| 72 std::wstring title_; |
| 73 std::wstring icon_; |
| 74 scoped_refptr<RefCountedBytes> data_; |
| 75 int index_; |
| 76 bool favicon_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ShellLinkItem); |
| 79 }; |
| 80 |
| 81 typedef std::vector<scoped_refptr<ShellLinkItem> > ShellLinkItemList; |
| 82 |
| 83 // A class which implements an application JumpList. |
| 84 // This class encapsulates operations required for updating an application |
| 85 // JumpList: |
| 86 // * Retrieving "Most Visited" pages from HistoryService; |
| 87 // * Retrieving strings from the application resource; |
| 88 // * Creatng COM objects used by JumpList from PageUsageData objects; |
| 89 // * Adding COM objects to JumpList, etc. |
| 90 // |
| 91 // This class also implements TabRestoreService::Observer. So, once we call |
| 92 // AddObserver() and register this class as an observer, it automatically |
| 93 // updates a JumpList when a tab is added or removed. |
| 94 // |
| 95 // Updating a JumpList requires some file operations and it is not good to |
| 96 // update it in a UI thread. To solve this problem, this class posts a |
| 97 // task when it actually updates a JumpList. (This task is implemented in an |
| 98 // anomynous namespace in "jumplist_win.cc".) |
| 99 class JumpList : public TabRestoreService::Observer { |
| 100 public: |
| 101 JumpList(); |
| 102 ~JumpList(); |
| 103 |
| 104 // Registers (or unregisters) this object as an observer. |
| 105 // When the TabRestoreService object notifies the tab status is changed, this |
| 106 // class automatically updates an application JumpList. |
| 107 bool AddObserver(Profile* profile); |
| 108 void RemoveObserver(); |
| 109 |
| 110 // Observer callback for TabRestoreService::Observer to notify when a tab is |
| 111 // added or removed. |
| 112 // This function sends a query that retrieves "Most Visited" pages to |
| 113 // HistoryService. When the query finishes successfully, HistoryService call |
| 114 // OnSegmentUsageAvailable(). |
| 115 virtual void TabRestoreServiceChanged(TabRestoreService* service); |
| 116 |
| 117 // Observer callback to notice when our associated TabRestoreService |
| 118 // is destroyed. |
| 119 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); |
| 120 |
| 121 // Returns true if the custom JumpList is enabled. |
| 122 // We use the custom JumpList when we satisfy the following conditions: |
| 123 // * Chromium is running on Windows 7 and; |
| 124 // * Chromium is lauched with an "--enable-custom-jumplist" option. |
| 125 // TODO(hbono): to be enabled by default when we finalize the categories and |
| 126 // items of our JumpList. |
| 127 static bool Enabled(); |
| 128 |
| 129 protected: |
| 130 // Creates a ShellLinkItem object from a tab (or a window) and add it to the |
| 131 // given list. |
| 132 // These functions are copied from the RecentlyClosedTabsHandler class for |
| 133 // compatibility with the new-tab page. |
| 134 bool AddTab(const TabRestoreService::Tab* tab, |
| 135 ShellLinkItemList* list, |
| 136 size_t max_items); |
| 137 bool AddWindow(const TabRestoreService::Window* window, |
| 138 ShellLinkItemList* list, |
| 139 size_t max_items); |
| 140 |
| 141 // Starts loading a fav icon for each URL in |icon_urls_|. |
| 142 // This function just sends a query to HistoryService. |
| 143 bool StartLoadingFavIcon(); |
| 144 |
| 145 // A callback function for HistoryService that notify when the "Most Visited" |
| 146 // list is available. |
| 147 // This function updates the ShellLinkItemList objects and send another query |
| 148 // that retrieves a fav icon for each URL in the list. |
| 149 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, |
| 150 std::vector<PageUsageData*>* data); |
| 151 |
| 152 // a callback function for HistoryService that notify when a requested fav |
| 153 // icon is available. |
| 154 // To avoid file operations, this function just attaches the given data to |
| 155 // a ShellLinkItem object. |
| 156 // When finishing loading all fav icons, this function posts a task that |
| 157 // decompresses collected fav icons and updates a JumpList. |
| 158 void OnFavIconDataAvailable(HistoryService::Handle handle, |
| 159 bool know_favicon, |
| 160 scoped_refptr<RefCountedBytes> data, |
| 161 bool expired, |
| 162 GURL icon_url); |
| 163 |
| 164 private: |
| 165 // Our consumers for HistoryService. |
| 166 CancelableRequestConsumer most_visited_consumer_; |
| 167 CancelableRequestConsumer fav_icon_consumer_; |
| 168 |
| 169 // The Profile object used for listening its events. |
| 170 Profile* profile_; |
| 171 |
| 172 // The directory which contains JumpList icons. |
| 173 std::wstring icon_dir_; |
| 174 |
| 175 // Items in the "Most Visited" category of the application JumpList. |
| 176 ShellLinkItemList most_visited_pages_; |
| 177 |
| 178 // Items in the "Recently Closed" category of the application JumpList. |
| 179 ShellLinkItemList recently_closed_pages_; |
| 180 |
| 181 // A list of URLs we need to retrieve their fav icons. |
| 182 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; |
| 183 std::list<URLPair> icon_urls_; |
| 184 }; |
| 185 |
| 186 #endif // CHROME_BROWSER_JUMPLIST_H_ |
| OLD | NEW |