Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "chrome/browser/ui/extensions/app_launch_params.h" | 42 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 43 #include "chrome/browser/ui/extensions/application_launch.h" | 43 #include "chrome/browser/ui/extensions/application_launch.h" |
| 44 #include "chrome/browser/ui/host_desktop.h" | 44 #include "chrome/browser/ui/host_desktop.h" |
| 45 #include "chrome/browser/ui/user_manager.h" | 45 #include "chrome/browser/ui/user_manager.h" |
| 46 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
| 47 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/common/extensions/extension_constants.h" | 48 #include "chrome/common/extensions/extension_constants.h" |
| 49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/grit/chromium_strings.h" | 50 #include "chrome/grit/chromium_strings.h" |
| 51 #include "chrome/grit/generated_resources.h" | 51 #include "chrome/grit/generated_resources.h" |
| 52 #include "content/public/browser/browser_thread.h" | |
| 52 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
| 53 #include "content/public/browser/user_metrics.h" | 54 #include "content/public/browser/user_metrics.h" |
| 54 #include "extensions/browser/extension_system.h" | 55 #include "extensions/browser/extension_system.h" |
| 55 #include "extensions/common/constants.h" | 56 #include "extensions/common/constants.h" |
| 56 #include "extensions/common/extension.h" | 57 #include "extensions/common/extension.h" |
| 57 #include "extensions/common/manifest_handlers/options_page_info.h" | 58 #include "extensions/common/manifest_handlers/options_page_info.h" |
| 58 #include "extensions/common/one_shot_event.h" | 59 #include "extensions/common/one_shot_event.h" |
| 59 #include "extensions/common/permissions/permission_set.h" | 60 #include "extensions/common/permissions/permission_set.h" |
| 60 #include "grit/chrome_unscaled_resources.h" | 61 #include "grit/chrome_unscaled_resources.h" |
| 61 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 62 #include "ui/base/resource/resource_bundle.h" | 63 #include "ui/base/resource/resource_bundle.h" |
| 63 | 64 |
| 65 #if defined(OS_WIN) | |
| 66 #include "chrome/browser/app_icon_win.h" | |
| 67 #endif | |
| 68 | |
| 64 using base::UserMetricsAction; | 69 using base::UserMetricsAction; |
| 65 using extensions::Extension; | 70 using extensions::Extension; |
| 66 | 71 |
| 67 namespace { | 72 namespace { |
| 68 | 73 |
| 69 // Records histogram about which auto-launch pattern (if any) was used to launch | 74 // Records histogram about which auto-launch pattern (if any) was used to launch |
| 70 // the current process based on |command_line|. | 75 // the current process based on |command_line|. |
| 71 void RecordAutoLaunchState(const base::CommandLine& command_line) { | 76 void RecordAutoLaunchState(const base::CommandLine& command_line) { |
| 72 enum AutoLaunchState { | 77 enum AutoLaunchState { |
| 73 AUTO_LAUNCH_NONE = 0, | 78 AUTO_LAUNCH_NONE = 0, |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 background_mode_suspended_ = false; | 786 background_mode_suspended_ = false; |
| 782 UpdateKeepAliveAndTrayIcon(); | 787 UpdateKeepAliveAndTrayIcon(); |
| 783 } | 788 } |
| 784 | 789 |
| 785 void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() { | 790 void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() { |
| 786 if (in_background_mode_ && !background_mode_suspended_) { | 791 if (in_background_mode_ && !background_mode_suspended_) { |
| 787 if (!keeping_alive_) { | 792 if (!keeping_alive_) { |
| 788 keeping_alive_ = true; | 793 keeping_alive_ = true; |
| 789 chrome::IncrementKeepAliveCount(); | 794 chrome::IncrementKeepAliveCount(); |
| 790 } | 795 } |
| 791 CreateStatusTrayIcon(); | 796 |
| 797 // Creating the status tray icon can take time (as it has to load and | |
| 798 // potentially scale the icon resource), so this task should not block | |
| 799 // startup time. | |
| 800 content::BrowserThread::PostAfterStartupTask( | |
| 801 FROM_HERE, content::BrowserThread::GetMessageLoopProxyForThread( | |
| 802 content::BrowserThread::UI), | |
| 803 base::Bind(&BackgroundModeManager::CreateStatusTrayIcon, | |
| 804 weak_factory_.GetWeakPtr())); | |
| 792 return; | 805 return; |
| 793 } | 806 } |
| 794 | 807 |
| 795 RemoveStatusTrayIcon(); | 808 RemoveStatusTrayIcon(); |
| 796 if (keeping_alive_) { | 809 if (keeping_alive_) { |
| 797 keeping_alive_ = false; | 810 keeping_alive_ = false; |
| 798 chrome::DecrementKeepAliveCount(); | 811 chrome::DecrementKeepAliveCount(); |
| 799 } | 812 } |
| 800 } | 813 } |
| 801 | 814 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 | 896 |
| 884 // Ensure we have a tray icon (needed so we can display the app-installed | 897 // Ensure we have a tray icon (needed so we can display the app-installed |
| 885 // notification below). | 898 // notification below). |
| 886 EnableBackgroundMode(); | 899 EnableBackgroundMode(); |
| 887 ResumeBackgroundMode(); | 900 ResumeBackgroundMode(); |
| 888 | 901 |
| 889 // Notify the user that a background client has been installed. | 902 // Notify the user that a background client has been installed. |
| 890 DisplayClientInstalledNotification(name); | 903 DisplayClientInstalledNotification(name); |
| 891 } | 904 } |
| 892 | 905 |
| 906 // Gets the image for the status tray icon, at the correct size for the current | |
| 907 // platform and display settings. | |
| 908 gfx::ImageSkia GetStatusTrayIcon() { | |
| 909 #if defined(OS_WIN) | |
| 910 // On Windows, use GetSmallAppIconSize to get the correct image size. The | |
| 911 // user's "text size" setting in Windows determines how large the system tray | |
| 912 // icon should be. | |
| 913 gfx::Size size = GetSmallAppIconSize(); | |
| 914 | |
| 915 // This loads all of the icon images, which is a bit wasteful because we're | |
| 916 // going to pick one and throw the rest away, but that is the price of using | |
| 917 // the ImageFamily abstraction. Note: We could just use the LoadImage function | |
| 918 // from the Windows API, but that does a *terrible* job scaling images. | |
| 919 // Therefore, we fetch the images and do our own high-quality scaling. | |
| 920 scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); | |
| 921 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
| |
| 922 return gfx::ImageSkia(); | |
| 923 | |
| 924 return family->CreateExact(size).AsImageSkia(); | |
| 925 #else | |
| 926 // On other platforms, just get a static resource image. | |
| 927 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 928 IDR_STATUS_TRAY_ICON); | |
| 929 #endif | |
| 930 } | |
| 931 | |
| 893 void BackgroundModeManager::CreateStatusTrayIcon() { | 932 void BackgroundModeManager::CreateStatusTrayIcon() { |
| 894 // Only need status icons on windows/linux. ChromeOS doesn't allow exiting | 933 // Only need status icons on windows/linux. ChromeOS doesn't allow exiting |
| 895 // Chrome and Mac can use the dock icon instead. | 934 // Chrome and Mac can use the dock icon instead. |
| 896 | 935 |
| 897 // Since there are multiple profiles which share the status tray, we now | 936 // Since there are multiple profiles which share the status tray, we now |
| 898 // use the browser process to keep track of it. | 937 // use the browser process to keep track of it. |
| 899 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | 938 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
| 900 if (!status_tray_) | 939 if (!status_tray_) |
| 901 status_tray_ = g_browser_process->status_tray(); | 940 status_tray_ = g_browser_process->status_tray(); |
| 902 #endif | 941 #endif |
| 903 | 942 |
| 904 // If the platform doesn't support status icons, or we've already created | 943 // If the platform doesn't support status icons, or we've already created |
| 905 // our status icon, just return. | 944 // our status icon, just return. |
| 906 if (!status_tray_ || status_icon_) | 945 if (!status_tray_ || status_icon_) |
| 907 return; | 946 return; |
| 908 | 947 |
| 909 gfx::ImageSkia* image_skia = ui::ResourceBundle::GetSharedInstance(). | |
| 910 GetImageSkiaNamed(IDR_STATUS_TRAY_ICON); | |
| 911 | |
| 912 status_icon_ = status_tray_->CreateStatusIcon( | 948 status_icon_ = status_tray_->CreateStatusIcon( |
| 913 StatusTray::BACKGROUND_MODE_ICON, | 949 StatusTray::BACKGROUND_MODE_ICON, GetStatusTrayIcon(), |
| 914 *image_skia, | |
| 915 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 950 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 916 if (!status_icon_) | 951 if (!status_icon_) |
| 917 return; | 952 return; |
| 918 UpdateStatusTrayIconContextMenu(); | 953 UpdateStatusTrayIconContextMenu(); |
| 919 } | 954 } |
| 920 | 955 |
| 921 void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { | 956 void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { |
| 922 // Ensure we have a tray icon if appropriate. | 957 // Ensure we have a tray icon if appropriate. |
| 923 UpdateKeepAliveAndTrayIcon(); | 958 UpdateKeepAliveAndTrayIcon(); |
| 924 | 959 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 } | 1060 } |
| 1026 } | 1061 } |
| 1027 return profile_it; | 1062 return profile_it; |
| 1028 } | 1063 } |
| 1029 | 1064 |
| 1030 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 1065 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 1031 PrefService* service = g_browser_process->local_state(); | 1066 PrefService* service = g_browser_process->local_state(); |
| 1032 DCHECK(service); | 1067 DCHECK(service); |
| 1033 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 1068 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 1034 } | 1069 } |
| OLD | NEW |