Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1256)

Side by Side Diff: chrome/browser/jumplist_win.h

Issue 7538022: Jumplist Bug (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/jumplist_win.cc » ('j') | chrome/browser/jumplist_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
18 #include "chrome/browser/history/top_sites.h"
16 #include "chrome/browser/sessions/tab_restore_service.h" 19 #include "chrome/browser/sessions/tab_restore_service.h"
17 #include "chrome/browser/sessions/tab_restore_service_observer.h" 20 #include "chrome/browser/sessions/tab_restore_service_observer.h"
21 #include "chrome/browser/ui/webui/ntp/base_most_visited_handler.h"
18 #include "content/browser/cancelable_request.h" 22 #include "content/browser/cancelable_request.h"
19 23
20 class FilePath; 24 class FilePath;
21 class Profile; 25 class Profile;
22 class PageUsageData; 26 class PageUsageData;
23 27
24 // Represents a class used for creating an IShellLink object by the utility 28 // Represents a class used for creating an IShellLink object by the utility
25 // functions in this file. 29 // functions in this file.
26 // This class consists of three strings and a integer. 30 // This class consists of three strings and a integer.
27 // * arguments (std::wstring) 31 // * arguments (std::wstring)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // JumpList: 93 // JumpList:
90 // * Retrieving "Most Visited" pages from HistoryService; 94 // * Retrieving "Most Visited" pages from HistoryService;
91 // * Retrieving strings from the application resource; 95 // * Retrieving strings from the application resource;
92 // * Creatng COM objects used by JumpList from PageUsageData objects; 96 // * Creatng COM objects used by JumpList from PageUsageData objects;
93 // * Adding COM objects to JumpList, etc. 97 // * Adding COM objects to JumpList, etc.
94 // 98 //
95 // This class also implements TabRestoreServiceObserver. So, once we call 99 // This class also implements TabRestoreServiceObserver. So, once we call
96 // AddObserver() and register this class as an observer, it automatically 100 // AddObserver() and register this class as an observer, it automatically
97 // updates a JumpList when a tab is added or removed. 101 // updates a JumpList when a tab is added or removed.
98 // 102 //
103 // This class also implements BaseMostVisitedHandler. So by calling
104 // AddObserver() we also register for TOP_SITES_CHANGED notifications, and the
105 // JumpList is updated when a top site is added or blacklisted.
106 //
99 // Updating a JumpList requires some file operations and it is not good to 107 // 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 108 // 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 109 // task when it actually updates a JumpList. (This task is implemented in an
102 // anomynous namespace in "jumplist_win.cc".) 110 // anomynous namespace in "jumplist_win.cc".)
103 class JumpList : public TabRestoreServiceObserver { 111 class JumpList : public TabRestoreServiceObserver,
112 public NotificationObserver,
113 public base::RefCountedThreadSafe<JumpList> {
104 public: 114 public:
105 JumpList(); 115 JumpList();
106 ~JumpList(); 116 ~JumpList();
107 117
118 // NotificationObserver implementation.
119 virtual void Observe(int type,
120 const NotificationSource& source,
121 const NotificationDetails& details);
122
108 // Registers (or unregisters) this object as an observer. 123 // Registers (or unregisters) this object as an observer.
109 // When the TabRestoreService object notifies the tab status is changed, this 124 // When the TabRestoreService object notifies the tab status is changed, this
110 // class automatically updates an application JumpList. 125 // class automatically updates an application JumpList.
111 bool AddObserver(Profile* profile); 126 bool AddObserver(Profile* profile);
112 void RemoveObserver(); 127 void RemoveObserver();
113 128
114 // Observer callback for TabRestoreService::Observer to notify when a tab is 129 // Observer callback for TabRestoreService::Observer to notify when a tab is
115 // added or removed. 130 // added or removed.
116 // This function sends a query that retrieves "Most Visited" pages to 131 // This function sends a query that retrieves "Most Visited" pages to
117 // HistoryService. When the query finishes successfully, HistoryService call 132 // HistoryService. When the query finishes successfully, HistoryService call
(...skipping 10 matching lines...) Expand all
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,
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. BaseMostVisitedHandler 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);
184
185 // Runnable method that updates the jumplist, once have all the data
186 // has been fetched.
187 void JumpList::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
193 // Cancel a pending jumplist update.
194 void CancelPendingUpdate();
195
165 private: 196 private:
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.
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.
180 ShellLinkItemList most_visited_pages_; 213 ShellLinkItemList most_visited_pages_;
181 214
182 // Items in the "Recently Closed" category of the application JumpList. 215 // Items in the "Recently Closed" category of the application JumpList.
183 ShellLinkItemList recently_closed_pages_; 216 ShellLinkItemList recently_closed_pages_;
184 217
185 // A list of URLs we need to retrieve their favicons. 218 // A list of URLs we need to retrieve their favicons.
186 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair; 219 typedef std::pair<std::string, scoped_refptr<ShellLinkItem> > URLPair;
187 std::list<URLPair> icon_urls_; 220 std::list<URLPair> icon_urls_;
221
222 // Handle of last favicon request used to cancel if a new request
223 // comes in before the current one returns.
224 FaviconService::Handle handle_;
225
226 // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_
227 // as they may be used by up to 3 threads.
228 base::Lock list_lock_;
188 }; 229 };
189 230
190 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ 231 #endif // CHROME_BROWSER_JUMPLIST_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/jumplist_win.cc » ('j') | chrome/browser/jumplist_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698