| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/background/background_mode_manager.h" | 5 #include "chrome/browser/background/background_mode_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "extensions/browser/extension_system.h" | 54 #include "extensions/browser/extension_system.h" |
| 55 #include "extensions/common/constants.h" | 55 #include "extensions/common/constants.h" |
| 56 #include "extensions/common/extension.h" | 56 #include "extensions/common/extension.h" |
| 57 #include "extensions/common/manifest_handlers/options_page_info.h" | 57 #include "extensions/common/manifest_handlers/options_page_info.h" |
| 58 #include "extensions/common/one_shot_event.h" | 58 #include "extensions/common/one_shot_event.h" |
| 59 #include "extensions/common/permissions/permission_set.h" | 59 #include "extensions/common/permissions/permission_set.h" |
| 60 #include "grit/chrome_unscaled_resources.h" | 60 #include "grit/chrome_unscaled_resources.h" |
| 61 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
| 62 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
| 63 | 63 |
| 64 #if defined(OS_WIN) |
| 65 #include "chrome/browser/app_icon_win.h" |
| 66 #endif |
| 67 |
| 64 using base::UserMetricsAction; | 68 using base::UserMetricsAction; |
| 65 using extensions::Extension; | 69 using extensions::Extension; |
| 66 | 70 |
| 67 namespace { | 71 namespace { |
| 68 | 72 |
| 69 // Enum for recording menu item clicks in UMA. | 73 // Enum for recording menu item clicks in UMA. |
| 70 // NOTE: Do not renumber these as that would confuse interpretation of | 74 // NOTE: Do not renumber these as that would confuse interpretation of |
| 71 // previously logged data. When making changes, also update histograms.xml. | 75 // previously logged data. When making changes, also update histograms.xml. |
| 72 enum MenuItem { | 76 enum MenuItem { |
| 73 MENU_ITEM_ABOUT = 0, | 77 MENU_ITEM_ABOUT = 0, |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 | 853 |
| 850 // Ensure we have a tray icon (needed so we can display the app-installed | 854 // Ensure we have a tray icon (needed so we can display the app-installed |
| 851 // notification below). | 855 // notification below). |
| 852 EnableBackgroundMode(); | 856 EnableBackgroundMode(); |
| 853 ResumeBackgroundMode(); | 857 ResumeBackgroundMode(); |
| 854 | 858 |
| 855 // Notify the user that a background client has been installed. | 859 // Notify the user that a background client has been installed. |
| 856 DisplayClientInstalledNotification(name); | 860 DisplayClientInstalledNotification(name); |
| 857 } | 861 } |
| 858 | 862 |
| 863 // Gets the image for the status tray icon, at the correct size for the current |
| 864 // platform and display settings. |
| 865 gfx::ImageSkia GetStatusTrayIcon() { |
| 866 #if defined(OS_WIN) |
| 867 // On Windows, use GetSmallAppIconSize to get the correct image size. The |
| 868 // user's "text size" setting in Windows determines how large the system tray |
| 869 // icon should be. |
| 870 gfx::Size size = GetSmallAppIconSize(); |
| 871 |
| 872 // This loads all of the icon images, which is a bit wasteful because we're |
| 873 // going to pick one and throw the rest away, but that is the price of using |
| 874 // the ImageFamily abstraction. Note: We could just use the LoadImage function |
| 875 // from the Windows API, but that does a *terrible* job scaling images. |
| 876 // Therefore, we fetch the images and do our own high-quality scaling. |
| 877 scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); |
| 878 DCHECK(family); |
| 879 if (!family) |
| 880 return gfx::ImageSkia(); |
| 881 |
| 882 return family->CreateExact(size).AsImageSkia(); |
| 883 #else |
| 884 // On other platforms, just get a static resource image. |
| 885 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 886 IDR_STATUS_TRAY_ICON); |
| 887 #endif |
| 888 } |
| 889 |
| 859 void BackgroundModeManager::CreateStatusTrayIcon() { | 890 void BackgroundModeManager::CreateStatusTrayIcon() { |
| 860 // Only need status icons on windows/linux. ChromeOS doesn't allow exiting | 891 // Only need status icons on windows/linux. ChromeOS doesn't allow exiting |
| 861 // Chrome and Mac can use the dock icon instead. | 892 // Chrome and Mac can use the dock icon instead. |
| 862 | 893 |
| 863 // Since there are multiple profiles which share the status tray, we now | 894 // Since there are multiple profiles which share the status tray, we now |
| 864 // use the browser process to keep track of it. | 895 // use the browser process to keep track of it. |
| 865 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | 896 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
| 866 if (!status_tray_) | 897 if (!status_tray_) |
| 867 status_tray_ = g_browser_process->status_tray(); | 898 status_tray_ = g_browser_process->status_tray(); |
| 868 #endif | 899 #endif |
| 869 | 900 |
| 870 // If the platform doesn't support status icons, or we've already created | 901 // If the platform doesn't support status icons, or we've already created |
| 871 // our status icon, just return. | 902 // our status icon, just return. |
| 872 if (!status_tray_ || status_icon_) | 903 if (!status_tray_ || status_icon_) |
| 873 return; | 904 return; |
| 874 | 905 |
| 875 gfx::ImageSkia* image_skia = ui::ResourceBundle::GetSharedInstance(). | |
| 876 GetImageSkiaNamed(IDR_STATUS_TRAY_ICON); | |
| 877 | |
| 878 status_icon_ = status_tray_->CreateStatusIcon( | 906 status_icon_ = status_tray_->CreateStatusIcon( |
| 879 StatusTray::BACKGROUND_MODE_ICON, | 907 StatusTray::BACKGROUND_MODE_ICON, GetStatusTrayIcon(), |
| 880 *image_skia, | |
| 881 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 908 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 882 if (!status_icon_) | 909 if (!status_icon_) |
| 883 return; | 910 return; |
| 884 UpdateStatusTrayIconContextMenu(); | 911 UpdateStatusTrayIconContextMenu(); |
| 885 } | 912 } |
| 886 | 913 |
| 887 void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { | 914 void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { |
| 888 // Ensure we have a tray icon if appropriate. | 915 // Ensure we have a tray icon if appropriate. |
| 889 UpdateKeepAliveAndTrayIcon(); | 916 UpdateKeepAliveAndTrayIcon(); |
| 890 | 917 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 } | 1019 } |
| 993 } | 1020 } |
| 994 return profile_it; | 1021 return profile_it; |
| 995 } | 1022 } |
| 996 | 1023 |
| 997 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 1024 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 998 PrefService* service = g_browser_process->local_state(); | 1025 PrefService* service = g_browser_process->local_state(); |
| 999 DCHECK(service); | 1026 DCHECK(service); |
| 1000 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 1027 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 1001 } | 1028 } |
| OLD | NEW |