OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "chrome/browser/browser_process.h" | |
16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/favicon/favicon_service.h" | 18 #include "chrome/browser/favicon/favicon_service.h" |
18 #include "chrome/browser/favicon/favicon_service_factory.h" | 19 #include "chrome/browser/favicon/favicon_service_factory.h" |
19 #include "chrome/browser/history/history_service.h" | 20 #include "chrome/browser/history/history_service.h" |
20 #include "chrome/browser/history/top_sites.h" | 21 #include "chrome/browser/history/top_sites.h" |
22 #include "chrome/browser/jumplist_metrics.h" | |
21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | |
25 #include "chrome/browser/profiles/profile_info_cache.h" | |
26 #include "chrome/browser/profiles/profile_manager.h" | |
22 #include "chrome/browser/sessions/session_types.h" | 27 #include "chrome/browser/sessions/session_types.h" |
23 #include "chrome/browser/sessions/tab_restore_service.h" | 28 #include "chrome/browser/sessions/tab_restore_service.h" |
24 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 29 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
25 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
26 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
30 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
31 #include "components/favicon_base/favicon_types.h" | 36 #include "components/favicon_base/favicon_types.h" |
32 #include "components/history/core/browser/page_usage_data.h" | 37 #include "components/history/core/browser/page_usage_data.h" |
38 #include "components/signin/core/common/profile_management_switches.h" | |
33 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
35 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/gfx/codec/png_codec.h" | 42 #include "ui/gfx/codec/png_codec.h" |
37 #include "ui/gfx/favicon_size.h" | 43 #include "ui/gfx/favicon_size.h" |
38 #include "ui/gfx/icon_util.h" | 44 #include "ui/gfx/icon_util.h" |
39 #include "ui/gfx/image/image_family.h" | 45 #include "ui/gfx/image/image_family.h" |
40 #include "url/gurl.h" | 46 #include "url/gurl.h" |
41 | 47 |
42 using content::BrowserThread; | 48 using content::BrowserThread; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 items.push_back(incognito); | 126 items.push_back(incognito); |
121 } | 127 } |
122 | 128 |
123 return jumplist_updater->AddTasks(items); | 129 return jumplist_updater->AddTasks(items); |
124 } | 130 } |
125 | 131 |
126 // Updates the application JumpList. | 132 // Updates the application JumpList. |
127 bool UpdateJumpList(const wchar_t* app_id, | 133 bool UpdateJumpList(const wchar_t* app_id, |
128 const ShellLinkItemList& most_visited_pages, | 134 const ShellLinkItemList& most_visited_pages, |
129 const ShellLinkItemList& recently_closed_pages, | 135 const ShellLinkItemList& recently_closed_pages, |
136 const ShellLinkItemList& profile_switcher, | |
130 IncognitoModePrefs::Availability incognito_availability) { | 137 IncognitoModePrefs::Availability incognito_availability) { |
131 // JumpList is implemented only on Windows 7 or later. | 138 // JumpList is implemented only on Windows 7 or later. |
132 // So, we should return now when this function is called on earlier versions | 139 // So, we should return now when this function is called on earlier versions |
133 // of Windows. | 140 // of Windows. |
134 if (!JumpListUpdater::IsEnabled()) | 141 if (!JumpListUpdater::IsEnabled()) |
135 return true; | 142 return true; |
136 | 143 |
137 JumpListUpdater jumplist_updater(app_id); | 144 JumpListUpdater jumplist_updater(app_id); |
138 if (!jumplist_updater.BeginUpdate()) | 145 if (!jumplist_updater.BeginUpdate()) |
139 return false; | 146 return false; |
140 | 147 |
141 // We allocate 60% of the given JumpList slots to "most-visited" items | 148 // Depending on the experiment, we are either showing the "Most-Visited" or |
142 // and 40% to "recently-closed" items, respectively. | 149 // "People" categories. |
143 // Nevertheless, if there are not so many items in |recently_closed_pages|, | 150 bool use_profiles_category = switches::HasProfilesJumplistExperiment(); |
tapted
2014/11/10 23:47:41
This might hurt.. but I don't think it's safe to c
noms (inactive)
2014/11/12 19:04:11
Done. Moved it to the constructor (it only needs t
| |
144 // we give the remaining slots to "most-visited" items. | 151 |
145 const int kMostVisited = 60; | 152 size_t recently_closed_items; |
146 const int kRecentlyClosed = 40; | 153 size_t profiles_or_most_visited_items; |
147 const int kTotal = kMostVisited + kRecentlyClosed; | 154 |
148 size_t most_visited_items = | 155 if (use_profiles_category) { |
149 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); | 156 const size_t kMaxProfiles = 8; |
150 size_t recently_closed_items = | 157 // Show at most 8 profiles, and fill the rest of the slots with the |
151 jumplist_updater.user_max_items() - most_visited_items; | 158 // "recently-closed" items. |
152 if (recently_closed_pages.size() < recently_closed_items) { | 159 profiles_or_most_visited_items = std::min(kMaxProfiles, |
153 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 160 profile_switcher.size()); |
154 recently_closed_items = recently_closed_pages.size(); | 161 recently_closed_items = |
162 jumplist_updater.user_max_items() - profiles_or_most_visited_items; | |
tapted
2014/11/10 23:47:41
this could underflow if the user had set the limit
noms (inactive)
2014/11/12 19:04:11
Done.
| |
163 } else { | |
164 // We allocate 60% of the given JumpList slots to "most-visited" items | |
165 // and 40% to "recently-closed" items, respectively. | |
166 // Nevertheless, if there are not so many items in |recently_closed_pages|, | |
167 // we give the remaining slots to "most-visited" items. | |
168 const int kMostVisited = 60; | |
169 const int kRecentlyClosed = 40; | |
170 const int kTotal = kMostVisited + kRecentlyClosed; | |
171 profiles_or_most_visited_items = | |
172 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); | |
173 recently_closed_items = | |
174 jumplist_updater.user_max_items() - profiles_or_most_visited_items; | |
175 if (recently_closed_pages.size() < recently_closed_items) { | |
176 profiles_or_most_visited_items += | |
177 recently_closed_items - recently_closed_pages.size(); | |
178 recently_closed_items = recently_closed_pages.size(); | |
179 } | |
155 } | 180 } |
156 | 181 |
157 // Update the "Most Visited" category of the JumpList. | 182 // Update the "Most Visited" category of the JumpList if it exists. |
158 // This update request is applied into the JumpList when we commit this | 183 // This update request is applied into the JumpList when we commit this |
159 // transaction. | 184 // transaction. |
160 if (!jumplist_updater.AddCustomCategory( | 185 if (!use_profiles_category && !jumplist_updater.AddCustomCategory( |
161 base::UTF16ToWide( | 186 base::UTF16ToWide( |
162 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)), | 187 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)), |
163 most_visited_pages, most_visited_items)) { | 188 most_visited_pages, profiles_or_most_visited_items)) { |
164 return false; | 189 return false; |
165 } | 190 } |
166 | 191 |
167 // Update the "Recently Closed" category of the JumpList. | 192 // Update the "Recently Closed" category of the JumpList. |
168 if (!jumplist_updater.AddCustomCategory( | 193 if (!jumplist_updater.AddCustomCategory( |
169 base::UTF16ToWide( | 194 base::UTF16ToWide( |
170 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED)), | 195 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED)), |
171 recently_closed_pages, recently_closed_items)) { | 196 recently_closed_pages, recently_closed_items)) { |
172 return false; | 197 return false; |
173 } | 198 } |
174 | 199 |
200 // Update the "People" category of the JumpList if it exists. Only display it | |
201 // if there's more than one profile available. | |
202 if (use_profiles_category && profile_switcher.size() > 1 && | |
203 !jumplist_updater.AddCustomCategory( | |
204 l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME), | |
205 profile_switcher, profiles_or_most_visited_items)) { | |
206 return false; | |
207 } | |
208 | |
175 // Update the "Tasks" category of the JumpList. | 209 // Update the "Tasks" category of the JumpList. |
176 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 210 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
177 return false; | 211 return false; |
178 | 212 |
179 // Commit this transaction and send the updated JumpList to Windows. | 213 // Commit this transaction and send the updated JumpList to Windows. |
180 if (!jumplist_updater.CommitUpdate()) | 214 if (!jumplist_updater.CommitUpdate()) |
181 return false; | 215 return false; |
182 | 216 |
183 return true; | 217 return true; |
184 } | 218 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 // observers are detatched at that time. | 251 // observers are detatched at that time. |
218 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 252 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
219 content::Source<Profile>(profile_)); | 253 content::Source<Profile>(profile_)); |
220 } | 254 } |
221 tab_restore_service->AddObserver(this); | 255 tab_restore_service->AddObserver(this); |
222 pref_change_registrar_.reset(new PrefChangeRegistrar); | 256 pref_change_registrar_.reset(new PrefChangeRegistrar); |
223 pref_change_registrar_->Init(profile_->GetPrefs()); | 257 pref_change_registrar_->Init(profile_->GetPrefs()); |
224 pref_change_registrar_->Add( | 258 pref_change_registrar_->Add( |
225 prefs::kIncognitoModeAvailability, | 259 prefs::kIncognitoModeAvailability, |
226 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); | 260 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); |
261 | |
262 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
263 DCHECK(profile_manager); | |
264 avatar_menu_.reset(new AvatarMenu( | |
265 &profile_manager->GetProfileInfoCache(), this, NULL)); | |
266 avatar_menu_->RebuildMenu(); | |
267 UpdateProfileSwitcher(); | |
227 } | 268 } |
228 | 269 |
229 JumpList::~JumpList() { | 270 JumpList::~JumpList() { |
230 Terminate(); | 271 Terminate(); |
231 } | 272 } |
232 | 273 |
233 // static | 274 // static |
234 bool JumpList::Enabled() { | 275 bool JumpList::Enabled() { |
235 return JumpListUpdater::IsEnabled(); | 276 return JumpListUpdater::IsEnabled(); |
236 } | 277 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 if (tab_restore_service) | 315 if (tab_restore_service) |
275 tab_restore_service->RemoveObserver(this); | 316 tab_restore_service->RemoveObserver(this); |
276 registrar_.reset(); | 317 registrar_.reset(); |
277 pref_change_registrar_.reset(); | 318 pref_change_registrar_.reset(); |
278 } | 319 } |
279 profile_ = NULL; | 320 profile_ = NULL; |
280 } | 321 } |
281 | 322 |
282 void JumpList::OnMostVisitedURLsAvailable( | 323 void JumpList::OnMostVisitedURLsAvailable( |
283 const history::MostVisitedURLList& data) { | 324 const history::MostVisitedURLList& data) { |
284 | |
285 // If we have a pending favicon request, cancel it here (it is out of date). | 325 // If we have a pending favicon request, cancel it here (it is out of date). |
286 CancelPendingUpdate(); | 326 CancelPendingUpdate(); |
287 | 327 |
288 { | 328 { |
289 base::AutoLock auto_lock(list_lock_); | 329 base::AutoLock auto_lock(list_lock_); |
290 most_visited_pages_.clear(); | 330 most_visited_pages_.clear(); |
291 for (size_t i = 0; i < data.size(); i++) { | 331 for (size_t i = 0; i < data.size(); i++) { |
292 const history::MostVisitedURL& url = data[i]; | 332 const history::MostVisitedURL& url = data[i]; |
293 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 333 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
294 std::string url_string = url.url.spec(); | 334 std::string url_string = url.url.spec(); |
295 std::wstring url_string_wide = base::UTF8ToWide(url_string); | 335 std::wstring url_string_wide = base::UTF8ToWide(url_string); |
296 link->GetCommandLine()->AppendArgNative(url_string_wide); | 336 link->GetCommandLine()->AppendArgNative(url_string_wide); |
337 link->GetCommandLine()->AppendSwitchASCII( | |
338 switches::kWinJumplistAction, JumplistMetrics::kMostVisitedCategory); | |
297 link->set_title(!url.title.empty()? url.title : url_string_wide); | 339 link->set_title(!url.title.empty()? url.title : url_string_wide); |
298 most_visited_pages_.push_back(link); | 340 most_visited_pages_.push_back(link); |
299 icon_urls_.push_back(make_pair(url_string, link)); | 341 icon_urls_.push_back(make_pair(url_string, link)); |
300 } | 342 } |
301 } | 343 } |
302 | 344 |
303 // Send a query that retrieves the first favicon. | 345 // Send a query that retrieves the first favicon. |
304 StartLoadingFavicon(); | 346 StartLoadingFavicon(); |
305 } | 347 } |
306 | 348 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 recently_closed_pages_ = temp_list; | 385 recently_closed_pages_ = temp_list; |
344 } | 386 } |
345 | 387 |
346 // Send a query that retrieves the first favicon. | 388 // Send a query that retrieves the first favicon. |
347 StartLoadingFavicon(); | 389 StartLoadingFavicon(); |
348 } | 390 } |
349 | 391 |
350 void JumpList::TabRestoreServiceDestroyed(TabRestoreService* service) { | 392 void JumpList::TabRestoreServiceDestroyed(TabRestoreService* service) { |
351 } | 393 } |
352 | 394 |
395 void JumpList::OnAvatarMenuChanged(AvatarMenu* avatar_menu) { | |
396 UpdateProfileSwitcher(); | |
397 PostRunUpdate(); | |
398 } | |
399 | |
353 bool JumpList::AddTab(const TabRestoreService::Tab* tab, | 400 bool JumpList::AddTab(const TabRestoreService::Tab* tab, |
354 ShellLinkItemList* list, | 401 ShellLinkItemList* list, |
355 size_t max_items) { | 402 size_t max_items) { |
356 // This code adds the URL and the title strings of the given tab to the | 403 // This code adds the URL and the title strings of the given tab to the |
357 // specified list. | 404 // specified list. |
358 if (list->size() >= max_items) | 405 if (list->size() >= max_items) |
359 return false; | 406 return false; |
360 | 407 |
361 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 408 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
362 const sessions::SerializedNavigationEntry& current_navigation = | 409 const sessions::SerializedNavigationEntry& current_navigation = |
363 tab->navigations.at(tab->current_navigation_index); | 410 tab->navigations.at(tab->current_navigation_index); |
364 std::string url = current_navigation.virtual_url().spec(); | 411 std::string url = current_navigation.virtual_url().spec(); |
365 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); | 412 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); |
413 link->GetCommandLine()->AppendSwitchASCII( | |
414 switches::kWinJumplistAction, JumplistMetrics::kRecentlyClosedCategory); | |
366 link->set_title(current_navigation.title()); | 415 link->set_title(current_navigation.title()); |
367 list->push_back(link); | 416 list->push_back(link); |
368 icon_urls_.push_back(make_pair(url, link)); | 417 icon_urls_.push_back(make_pair(url, link)); |
369 return true; | 418 return true; |
370 } | 419 } |
371 | 420 |
372 void JumpList::AddWindow(const TabRestoreService::Window* window, | 421 void JumpList::AddWindow(const TabRestoreService::Window* window, |
373 ShellLinkItemList* list, | 422 ShellLinkItemList* list, |
374 size_t max_items) { | 423 size_t max_items) { |
375 // This code enumerates al the tabs in the given window object and add their | 424 // This code enumerates al the tabs in the given window object and add their |
(...skipping 14 matching lines...) Expand all Loading... | |
390 waiting_for_icons = !icon_urls_.empty(); | 439 waiting_for_icons = !icon_urls_.empty(); |
391 if (waiting_for_icons) { | 440 if (waiting_for_icons) { |
392 // Ask FaviconService if it has a favicon of a URL. | 441 // Ask FaviconService if it has a favicon of a URL. |
393 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 442 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
394 url = GURL(icon_urls_.front().first); | 443 url = GURL(icon_urls_.front().first); |
395 } | 444 } |
396 } | 445 } |
397 | 446 |
398 if (!waiting_for_icons) { | 447 if (!waiting_for_icons) { |
399 // No more favicons are needed by the application JumpList. Schedule a | 448 // No more favicons are needed by the application JumpList. Schedule a |
400 // RunUpdate call. | 449 // RunUpdateOnFileThread call. |
401 PostRunUpdate(); | 450 PostRunUpdate(); |
402 return; | 451 return; |
403 } | 452 } |
404 | 453 |
405 FaviconService* favicon_service = | 454 FaviconService* favicon_service = |
406 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 455 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
407 task_id_ = favicon_service->GetFaviconImageForPageURL( | 456 task_id_ = favicon_service->GetFaviconImageForPageURL( |
408 url, | 457 url, |
409 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), | 458 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), |
410 &cancelable_task_tracker_); | 459 &cancelable_task_tracker_); |
411 } | 460 } |
412 | 461 |
413 void JumpList::OnFaviconDataAvailable( | 462 void JumpList::OnFaviconDataAvailable( |
414 const favicon_base::FaviconImageResult& image_result) { | 463 const favicon_base::FaviconImageResult& image_result) { |
415 // If there is currently a favicon request in progress, it is now outdated, | 464 // If there is currently a favicon request in progress, it is now outdated, |
416 // as we have received another, so nullify the handle from the old request. | 465 // as we have received another, so nullify the handle from the old request. |
417 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 466 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
418 // lock the list to set icon data and pop the url | 467 // Lock the list to set icon data and pop the url. |
419 { | 468 { |
420 base::AutoLock auto_lock(list_lock_); | 469 base::AutoLock auto_lock(list_lock_); |
421 // Attach the received data to the ShellLinkItem object. | 470 // Attach the received data to the ShellLinkItem object. |
422 // This data will be decoded by the RunUpdate method. | 471 // This data will be decoded by the RunUpdateOnFileThread method. |
423 if (!image_result.image.IsEmpty()) { | 472 if (!image_result.image.IsEmpty()) { |
424 if (!icon_urls_.empty() && icon_urls_.front().second) | 473 if (!icon_urls_.empty() && icon_urls_.front().second) |
425 icon_urls_.front().second->set_icon_data(image_result.image.AsBitmap()); | 474 icon_urls_.front().second->set_icon_data(image_result.image.AsBitmap()); |
426 } | 475 } |
427 | 476 |
428 if (!icon_urls_.empty()) | 477 if (!icon_urls_.empty()) |
429 icon_urls_.pop_front(); | 478 icon_urls_.pop_front(); |
430 } | 479 } |
431 // Check whether we need to load more favicons. | 480 // Check whether we need to load more favicons. |
432 StartLoadingFavicon(); | 481 StartLoadingFavicon(); |
(...skipping 12 matching lines...) Expand all Loading... | |
445 } | 494 } |
446 | 495 |
447 void JumpList::PostRunUpdate() { | 496 void JumpList::PostRunUpdate() { |
448 // Check if incognito windows (or normal windows) are disabled by policy. | 497 // Check if incognito windows (or normal windows) are disabled by policy. |
449 IncognitoModePrefs::Availability incognito_availability = | 498 IncognitoModePrefs::Availability incognito_availability = |
450 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 499 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
451 : IncognitoModePrefs::ENABLED; | 500 : IncognitoModePrefs::ENABLED; |
452 | 501 |
453 BrowserThread::PostTask( | 502 BrowserThread::PostTask( |
454 BrowserThread::FILE, FROM_HERE, | 503 BrowserThread::FILE, FROM_HERE, |
455 base::Bind(&JumpList::RunUpdate, this, incognito_availability)); | 504 base::Bind(&JumpList::RunUpdateOnFileThread, |
505 this, | |
506 incognito_availability)); | |
456 } | 507 } |
457 | 508 |
458 void JumpList::RunUpdate( | 509 void JumpList::RunUpdateOnFileThread( |
459 IncognitoModePrefs::Availability incognito_availability) { | 510 IncognitoModePrefs::Availability incognito_availability) { |
460 ShellLinkItemList local_most_visited_pages; | 511 ShellLinkItemList local_most_visited_pages; |
461 ShellLinkItemList local_recently_closed_pages; | 512 ShellLinkItemList local_recently_closed_pages; |
513 ShellLinkItemList local_profile_switcher; | |
462 | 514 |
463 { | 515 { |
464 base::AutoLock auto_lock(list_lock_); | 516 base::AutoLock auto_lock(list_lock_); |
465 // Make sure we are not out of date: if icon_urls_ is not empty, then | 517 // Make sure we are not out of date: if icon_urls_ is not empty, then |
466 // another notification has been received since we processed this one | 518 // another notification has been received since we processed this one |
467 if (!icon_urls_.empty()) | 519 if (!icon_urls_.empty()) |
468 return; | 520 return; |
469 | 521 |
470 // Make local copies of lists so we can release the lock. | 522 // Make local copies of lists so we can release the lock. |
471 local_most_visited_pages = most_visited_pages_; | 523 local_most_visited_pages = most_visited_pages_; |
472 local_recently_closed_pages = recently_closed_pages_; | 524 local_recently_closed_pages = recently_closed_pages_; |
525 local_profile_switcher = profile_switcher_; | |
473 } | 526 } |
474 | 527 |
475 // Delete the directory which contains old icon files, rename the current | 528 // Delete the directory which contains old icon files, rename the current |
476 // icon directory, and create a new directory which contains new JumpList | 529 // icon directory, and create a new directory which contains new JumpList |
477 // icon files. | 530 // icon files. |
478 base::FilePath icon_dir_old(icon_dir_.value() + L"Old"); | 531 base::FilePath icon_dir_old(icon_dir_.value() + L"Old"); |
479 if (base::PathExists(icon_dir_old)) | 532 if (base::PathExists(icon_dir_old)) |
480 base::DeleteFile(icon_dir_old, true); | 533 base::DeleteFile(icon_dir_old, true); |
481 base::Move(icon_dir_, icon_dir_old); | 534 base::Move(icon_dir_, icon_dir_old); |
482 base::CreateDirectory(icon_dir_); | 535 base::CreateDirectory(icon_dir_); |
483 | 536 |
484 // Create temporary icon files for shortcuts in the "Most Visited" category. | 537 // Create temporary icon files for shortcuts in the "Most Visited" category. |
485 CreateIconFiles(local_most_visited_pages); | 538 CreateIconFiles(local_most_visited_pages); |
486 | 539 |
487 // Create temporary icon files for shortcuts in the "Recently Closed" | 540 // Create temporary icon files for shortcuts in the "Recently Closed" |
488 // category. | 541 // category. |
489 CreateIconFiles(local_recently_closed_pages); | 542 CreateIconFiles(local_recently_closed_pages); |
490 | 543 |
544 // Create temporary icon files for the profile avatars in the "People" | |
545 // category. | |
546 CreateIconFiles(local_profile_switcher); | |
547 | |
491 // We finished collecting all resources needed for updating an application | 548 // We finished collecting all resources needed for updating an application |
492 // JumpList. So, create a new JumpList and replace the current JumpList | 549 // JumpList. So, create a new JumpList and replace the current JumpList |
493 // with it. | 550 // with it. |
494 UpdateJumpList(app_id_.c_str(), local_most_visited_pages, | 551 UpdateJumpList(app_id_.c_str(), |
495 local_recently_closed_pages, incognito_availability); | 552 local_most_visited_pages, |
553 local_recently_closed_pages, | |
554 local_profile_switcher, | |
555 incognito_availability); | |
496 } | 556 } |
497 | 557 |
498 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { | 558 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
499 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 559 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
500 item != item_list.end(); ++item) { | 560 item != item_list.end(); ++item) { |
501 base::FilePath icon_path; | 561 base::FilePath icon_path; |
502 if (CreateIconFile((*item)->icon_data(), icon_dir_, &icon_path)) | 562 if (CreateIconFile((*item)->icon_data(), icon_dir_, &icon_path)) |
503 (*item)->set_icon(icon_path.value(), 0); | 563 (*item)->set_icon(icon_path.value(), 0); |
504 } | 564 } |
505 } | 565 } |
566 | |
567 void JumpList::UpdateProfileSwitcher() { | |
568 ShellLinkItemList new_profile_switcher; | |
569 | |
570 // Don't display a menu in the single profile case. | |
571 if (avatar_menu_->GetNumberOfItems() > 1) { | |
572 for (size_t i = 0; i < avatar_menu_->GetNumberOfItems(); ++i) { | |
573 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | |
574 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(i); | |
575 | |
576 link->set_title(item.name); | |
577 link->GetCommandLine()->AppendSwitchPath( | |
578 switches::kProfileDirectory, item.profile_path.BaseName()); | |
579 link->GetCommandLine()->AppendSwitch( | |
580 switches::kActivateExistingProfileBrowser); | |
581 link->GetCommandLine()->AppendSwitchASCII( | |
582 switches::kWinJumplistAction, JumplistMetrics::kProfilesCategory); | |
583 | |
584 gfx::Image avatar; | |
585 bool is_rectangle; | |
586 profiles::GetTransparentBackgroundProfileAvatar( | |
587 item.profile_path, &avatar, &is_rectangle); | |
588 link->set_icon_data(avatar.AsBitmap()); | |
589 new_profile_switcher.push_back(link); | |
590 } | |
591 } | |
592 | |
593 { | |
594 base::AutoLock auto_lock(list_lock_); | |
595 profile_switcher_.clear(); | |
tapted
2014/11/10 23:47:41
nit: this clear isn't needed (these will get freed
noms (inactive)
2014/11/12 19:04:11
Done.
| |
596 new_profile_switcher.swap(profile_switcher_); | |
597 } | |
598 } | |
OLD | NEW |