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

Unified Diff: chrome/browser/jumplist_win.cc

Issue 660813002: [Win] Add a fast profile switcher to the Windows taskbar item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: locking! browser test! nits! Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/jumplist_win.cc
diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc
index dadc19ab3ab14117346d4179a49585b9fc331577..5e20f72fa45bc04c5b7ee3634f9cf6d39b74c8ec 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"
@@ -127,6 +131,7 @@ bool UpdateTaskCategory(
bool UpdateJumpList(const wchar_t* app_id,
const ShellLinkItemList& most_visited_pages,
const ShellLinkItemList& recently_closed_pages,
+ const ShellLinkItemList& profile_switcher,
IncognitoModePrefs::Availability incognito_availability) {
// JumpList is implemented only on Windows 7 or later.
// So, we should return now when this function is called on earlier versions
@@ -172,6 +177,13 @@ bool UpdateJumpList(const wchar_t* app_id,
return false;
}
+ // Update the "Profiles" category of the JumpList.
tapted 2014/11/04 23:10:48 nit: Profiles -> People? (and super-nit: should t
noms (inactive) 2014/11/10 21:46:08 Done re: the comment. Chrome://settings is still p
+ if (!jumplist_updater.AddCustomCategory(
+ l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME),
+ profile_switcher, profile_switcher.size())) {
+ return false;
+ }
+
// Update the "Tasks" category of the JumpList.
if (!UpdateTaskCategory(&jumplist_updater, incognito_availability))
return false;
@@ -224,6 +236,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();
+ UpdateProfileSwitcher();
}
JumpList::~JumpList() {
@@ -350,6 +369,11 @@ void JumpList::TabRestoreServiceChanged(TabRestoreService* service) {
void JumpList::TabRestoreServiceDestroyed(TabRestoreService* service) {
}
+void JumpList::OnAvatarMenuChanged(AvatarMenu* avatar_menu) {
+ UpdateProfileSwitcher();
+ PostRunUpdate();
+}
+
bool JumpList::AddTab(const TabRestoreService::Tab* tab,
ShellLinkItemList* list,
size_t max_items) {
@@ -397,7 +421,7 @@ void JumpList::StartLoadingFavicon() {
if (!waiting_for_icons) {
// No more favicons are needed by the application JumpList. Schedule a
- // RunUpdate call.
+ // RunUpdateOnFileThread call.
PostRunUpdate();
return;
}
@@ -415,11 +439,11 @@ 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.
- // This data will be decoded by the RunUpdate method.
+ // This data will be decoded by the RunUpdateOnFileThread method.
if (!image_result.image.IsEmpty()) {
if (!icon_urls_.empty() && icon_urls_.front().second)
icon_urls_.front().second->set_icon_data(image_result.image.AsBitmap());
@@ -452,13 +476,16 @@ void JumpList::PostRunUpdate() {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&JumpList::RunUpdate, this, incognito_availability));
+ base::Bind(&JumpList::RunUpdateOnFileThread,
+ this,
+ incognito_availability));
}
-void JumpList::RunUpdate(
+void JumpList::RunUpdateOnFileThread(
IncognitoModePrefs::Availability incognito_availability) {
ShellLinkItemList local_most_visited_pages;
ShellLinkItemList local_recently_closed_pages;
+ ShellLinkItemList local_profile_switcher;
{
base::AutoLock auto_lock(list_lock_);
@@ -470,6 +497,7 @@ void JumpList::RunUpdate(
// Make local copies of lists so we can release the lock.
local_most_visited_pages = most_visited_pages_;
local_recently_closed_pages = recently_closed_pages_;
+ local_profile_switcher = profile_switcher_;
}
// Delete the directory which contains old icon files, rename the current
@@ -488,11 +516,18 @@ void JumpList::RunUpdate(
// category.
CreateIconFiles(local_recently_closed_pages);
+ // Create temporary icon files for the profile avatars in the "Profiles"
+ // category.
+ CreateIconFiles(local_profile_switcher);
+
// We finished collecting all resources needed for updating an application
// 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);
+ UpdateJumpList(app_id_.c_str(),
+ local_most_visited_pages,
+ local_recently_closed_pages,
+ local_profile_switcher,
+ incognito_availability);
}
void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) {
@@ -503,3 +538,27 @@ void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) {
(*item)->set_icon(icon_path.value(), 0);
}
}
+
+void JumpList::UpdateProfileSwitcher() {
+ {
+ base::AutoLock auto_lock(list_lock_);
+ profile_switcher_.clear();
+ 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(item.name);
+ link->GetCommandLine()->AppendSwitchPath(
+ switches::kProfileDirectory, item.profile_path.BaseName());
+ link->GetCommandLine()->AppendSwitch(
+ switches::kActivateExistingProfileBrowser);
+
+ gfx::Image avatar;
+ bool is_rectangle;
+ profiles::GetTransparentBackgroundProfileAvatar(
+ item.profile_path, &avatar, &is_rectangle);
+ link->set_icon_data(avatar.AsBitmap());
+ profile_switcher_.push_back(link);
+ }
+ }
tapted 2014/11/04 23:10:48 This is a bit nitty, but it's typically good to av
noms (inactive) 2014/11/10 21:46:08 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698