Chromium Code Reviews| 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; |