Chromium Code Reviews| Index: chrome/browser/jumplist_win.cc |
| diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc |
| index dadc19ab3ab14117346d4179a49585b9fc331577..c4ca7a6688b6d57d46eaadd6adb3c12eebb5e42b 100644 |
| --- a/chrome/browser/jumplist_win.cc |
| +++ b/chrome/browser/jumplist_win.cc |
| @@ -13,12 +13,16 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/thread.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/favicon/favicon_service.h" |
| #include "chrome/browser/favicon/favicon_service_factory.h" |
| #include "chrome/browser/history/history_service.h" |
| #include "chrome/browser/history/top_sites.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| +#include "chrome/browser/profiles/profile_info_cache.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/sessions/session_types.h" |
| #include "chrome/browser/sessions/tab_restore_service.h" |
| #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| @@ -123,11 +127,48 @@ bool UpdateTaskCategory( |
| return jumplist_updater->AddTasks(items); |
| } |
| +bool UpdateProfilesCategory(JumpListUpdater* jumplist_updater, |
| + AvatarMenu* avatar_menu, |
| + const std::vector<gfx::Image>& profile_avatars, |
| + const base::FilePath& icon_dir) { |
| + base::FilePath chrome_path; |
| + if (!PathService::Get(base::FILE_EXE, &chrome_path)) |
| + return false; |
| + |
| + ShellLinkItemList profile_items; |
| + |
| + for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| + scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| + const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| + |
| + link->set_title(base::UTF16ToWide(item.name)); |
|
tapted
2014/11/03 23:57:06
is the UTF16ToWide needed? (pretty sure std::wstri
noms (inactive)
2014/11/04 20:03:08
Done.
|
| + link->GetCommandLine()->AppendSwitchPath( |
| + switches::kProfileDirectory, item.profile_path.BaseName()); |
| + link->GetCommandLine()->AppendSwitch( |
| + switches::kReuseExistingProfileBrowser); |
| + |
| + // Icons need to be saved on disk to be used by a ShellLinkItem. |
| + base::FilePath icon_path; |
| + if (CreateIconFile(profile_avatars[i].AsBitmap(), icon_dir, &icon_path)) |
| + link->set_icon(icon_path.value(), 0); |
| + |
| + profile_items.push_back(link); |
| + } |
| + |
| + return jumplist_updater->AddCustomCategory( |
| + base::UTF16ToWide( |
|
tapted
2014/11/03 23:57:05
remove UTF16ToWide?
noms (inactive)
2014/11/04 20:03:08
Done.
|
| + l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME)), |
| + profile_items, profile_items.size()); |
| +} |
| + |
| // Updates the application JumpList. |
| bool UpdateJumpList(const wchar_t* app_id, |
| const ShellLinkItemList& most_visited_pages, |
| const ShellLinkItemList& recently_closed_pages, |
| - IncognitoModePrefs::Availability incognito_availability) { |
| + IncognitoModePrefs::Availability incognito_availability, |
| + AvatarMenu* avatar_menu, |
| + const std::vector<gfx::Image>& profile_avatars, |
| + const base::FilePath& icon_dir) { |
| // JumpList is implemented only on Windows 7 or later. |
| // So, we should return now when this function is called on earlier versions |
| // of Windows. |
| @@ -172,6 +213,12 @@ bool UpdateJumpList(const wchar_t* app_id, |
| return false; |
| } |
| + // Update the "Profiles" category of the JumpList. |
| + if (!UpdateProfilesCategory(&jumplist_updater, avatar_menu, |
| + profile_avatars, icon_dir)) { |
| + return false; |
| + } |
| + |
| // Update the "Tasks" category of the JumpList. |
| if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
| return false; |
| @@ -224,6 +271,13 @@ JumpList::JumpList(Profile* profile) |
| pref_change_registrar_->Add( |
| prefs::kIncognitoModeAvailability, |
| base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + DCHECK(profile_manager); |
| + avatar_menu_.reset(new AvatarMenu( |
| + &profile_manager->GetProfileInfoCache(), this, NULL)); |
| + avatar_menu_->RebuildMenu(); |
| + UpdateProfileAvatars(); |
| } |
| JumpList::~JumpList() { |
| @@ -350,6 +404,11 @@ void JumpList::TabRestoreServiceChanged(TabRestoreService* service) { |
| void JumpList::TabRestoreServiceDestroyed(TabRestoreService* service) { |
| } |
| +void JumpList::OnAvatarMenuChanged(AvatarMenu* avatar_menu) { |
| + UpdateProfileAvatars(); |
| + PostRunUpdate(); |
| +} |
| + |
| bool JumpList::AddTab(const TabRestoreService::Tab* tab, |
| ShellLinkItemList* list, |
| size_t max_items) { |
| @@ -415,7 +474,7 @@ void JumpList::OnFaviconDataAvailable( |
| // If there is currently a favicon request in progress, it is now outdated, |
| // as we have received another, so nullify the handle from the old request. |
| task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| - // lock the list to set icon data and pop the url |
| + // Lock the list to set icon data and pop the url. |
| { |
| base::AutoLock auto_lock(list_lock_); |
| // Attach the received data to the ShellLinkItem object. |
| @@ -492,7 +551,8 @@ void JumpList::RunUpdate( |
| // JumpList. So, create a new JumpList and replace the current JumpList |
| // with it. |
| UpdateJumpList(app_id_.c_str(), local_most_visited_pages, |
| - local_recently_closed_pages, incognito_availability); |
| + local_recently_closed_pages, incognito_availability, |
| + avatar_menu_.get(), profile_avatars_, icon_dir_); |
|
tapted
2014/11/03 23:57:05
RunUpdate runs on the FILE thread, so accessing |a
noms (inactive)
2014/11/04 20:03:08
Done.
|
| } |
| void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
| @@ -503,3 +563,15 @@ void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
| (*item)->set_icon(icon_path.value(), 0); |
| } |
| } |
| + |
| +void JumpList::UpdateProfileAvatars() { |
| + profile_avatars_.clear(); |
| + for (size_t i = 0; i < avatar_menu_->GetNumberOfItems(); ++i) { |
| + const AvatarMenu::Item& item = avatar_menu_->GetItemAt(i); |
| + gfx::Image avatar; |
| + bool is_rectangle; |
| + profiles::GetTransparentBackgroundProfileAvatar( |
| + item.profile_path, &avatar, &is_rectangle); |
| + profile_avatars_.push_back(avatar); |
| + } |
| +} |