 Chromium Code Reviews
 Chromium Code Reviews Issue 1420163003:
  Fixed Windows system tray icon.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@profile-icon-imagefamily
    
  
    Issue 1420163003:
  Fixed Windows system tray icon.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@profile-icon-imagefamily| 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 7cd746708b3c3ce691492e25eb8333998d96fe41..f392156ee77a0052224a3464fa075ec0a730f01a 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; | 
| @@ -754,6 +759,7 @@ void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() { | 
| keeping_alive_ = true; | 
| chrome::IncrementKeepAliveCount(); | 
| } | 
| + | 
| CreateStatusTrayIcon(); | 
| return; | 
| } | 
| @@ -856,7 +862,45 @@ 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(); | 
| + DCHECK(family); | 
| + if (!family) | 
| + 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() { | 
| + // 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( | 
| 
Andrew T Wilson (Slow)
2015/11/23 11:28:11
This seems incorrect, because it's possible that s
 
Matt Giuca
2015/11/24 07:07:46
That's a good point. But we can work around it by
 | 
| + FROM_HERE, content::BrowserThread::GetMessageLoopProxyForThread( | 
| + content::BrowserThread::UI), | 
| + base::Bind(&BackgroundModeManager::CreateStatusTrayIconTask, | 
| + weak_factory_.GetWeakPtr())); | 
| +} | 
| + | 
| +void BackgroundModeManager::CreateStatusTrayIconTask() { | 
| // Only need status icons on windows/linux. ChromeOS doesn't allow exiting | 
| // Chrome and Mac can use the dock icon instead. | 
| @@ -872,12 +916,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; |