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

Unified Diff: chrome/browser/background/background_mode_manager.cc

Issue 1420163003: Fixed Windows system tray icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile-icon-imagefamily
Patch Set: Remove IDR_STATUS_TRAY_ICON on Win, and update tests to account for this. Created 5 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/background/background_mode_manager.cc
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc
index 3f741565eb6b5da15efd33744e0678c72d33df94..e18ffed5c8e44b3d9df5c6d665db4209dd1487a1 100644
--- a/chrome/browser/background/background_mode_manager.cc
+++ b/chrome/browser/background/background_mode_manager.cc
@@ -49,6 +49,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "extensions/browser/extension_system.h"
@@ -61,6 +62,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#if defined(OS_WIN)
+#include "chrome/browser/app_icon_win.h"
+#endif
+
using base::UserMetricsAction;
using extensions::Extension;
@@ -788,7 +793,15 @@ void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() {
keeping_alive_ = true;
chrome::IncrementKeepAliveCount();
}
- CreateStatusTrayIcon();
+
+ // Creating the status tray icon can take time (as it has to load and
+ // potentially scale the icon resource), so this task should not block
+ // startup time.
+ content::BrowserThread::PostAfterStartupTask(
+ FROM_HERE, content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI),
+ base::Bind(&BackgroundModeManager::CreateStatusTrayIcon,
+ weak_factory_.GetWeakPtr()));
return;
}
@@ -890,6 +903,32 @@ void BackgroundModeManager::OnBackgroundClientInstalled(
DisplayClientInstalledNotification(name);
}
+// Gets the image for the status tray icon, at the correct size for the current
+// platform and display settings.
+gfx::ImageSkia GetStatusTrayIcon() {
+#if defined(OS_WIN)
+ // On Windows, use GetSmallAppIconSize to get the correct image size. The
+ // user's "text size" setting in Windows determines how large the system tray
+ // icon should be.
+ gfx::Size size = GetSmallAppIconSize();
+
+ // This loads all of the icon images, which is a bit wasteful because we're
+ // going to pick one and throw the rest away, but that is the price of using
+ // the ImageFamily abstraction. Note: We could just use the LoadImage function
+ // from the Windows API, but that does a *terrible* job scaling images.
+ // Therefore, we fetch the images and do our own high-quality scaling.
+ scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily();
+ if (!family)
msw 2015/11/12 00:43:29 Maybe invert the check to conditionally return the
Matt Giuca 2015/11/12 04:44:39 There should never be an error here (in fact, I'll
msw 2015/11/12 18:27:23 Fair enough... Where is that image used? Can it be
Matt Giuca 2015/11/13 07:21:49 It is used for the status tray on Mac and Linux (b
+ return gfx::ImageSkia();
+
+ return family->CreateExact(size).AsImageSkia();
+#else
+ // On other platforms, just get a static resource image.
+ return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_STATUS_TRAY_ICON);
+#endif
+}
+
void BackgroundModeManager::CreateStatusTrayIcon() {
// Only need status icons on windows/linux. ChromeOS doesn't allow exiting
// Chrome and Mac can use the dock icon instead.
@@ -906,12 +945,8 @@ void BackgroundModeManager::CreateStatusTrayIcon() {
if (!status_tray_ || status_icon_)
return;
- gfx::ImageSkia* image_skia = ui::ResourceBundle::GetSharedInstance().
- GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
-
status_icon_ = status_tray_->CreateStatusIcon(
- StatusTray::BACKGROUND_MODE_ICON,
- *image_skia,
+ StatusTray::BACKGROUND_MODE_ICON, GetStatusTrayIcon(),
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
if (!status_icon_)
return;

Powered by Google App Engine
This is Rietveld 408576698