| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/toolbar/app_menu_badge_controller.h" | 5 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/global_error/global_error_service.h" | 10 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 12 #include "chrome/browser/upgrade_detector.h" | 12 #include "chrome/browser/upgrade_detector.h" |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 45 bool should_animate = true; | 45 bool should_animate = true; |
| 46 if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) { | 46 if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) { |
| 47 // Only animate low severity upgrades once. | 47 // Only animate low severity upgrades once. |
| 48 static bool should_animate_low_severity = true; | 48 static bool should_animate_low_severity = true; |
| 49 should_animate = should_animate_low_severity; | 49 should_animate = should_animate_low_severity; |
| 50 should_animate_low_severity = false; | 50 should_animate_low_severity = false; |
| 51 } | 51 } |
| 52 return should_animate; | 52 return should_animate; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Returns true if we should show the upgrade recommended badge. | 55 // Returns true if we should show the upgrade recommended icon. |
| 56 bool ShouldShowUpgradeRecommended() { | 56 bool ShouldShowUpgradeRecommended() { |
| 57 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 58 // In chromeos, the update recommendation is shown in the system tray. So it | 58 // In chromeos, the update recommendation is shown in the system tray. So it |
| 59 // should not be displayed in the app menu. | 59 // should not be displayed in the app menu. |
| 60 return false; | 60 return false; |
| 61 #else | 61 #else |
| 62 return UpgradeDetector::GetInstance()->notify_upgrade(); | 62 return UpgradeDetector::GetInstance()->notify_upgrade(); |
| 63 #endif | 63 #endif |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Returns true if we should show the warning for incompatible software. | 66 // Returns true if we should show the warning for incompatible software. |
| 67 bool ShouldShowIncompatibilityWarning() { | 67 bool ShouldShowIncompatibilityWarning() { |
| 68 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
| 69 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance(); | 69 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance(); |
| 70 loaded_modules->MaybePostScanningTask(); | 70 loaded_modules->MaybePostScanningTask(); |
| 71 return loaded_modules->ShouldShowConflictWarning(); | 71 return loaded_modules->ShouldShowConflictWarning(); |
| 72 #else | 72 #else |
| 73 return false; | 73 return false; |
| 74 #endif | 74 #endif |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 AppMenuBadgeController::AppMenuBadgeController(Profile* profile, | 79 AppMenuIconController::AppMenuIconController(Profile* profile, |
| 80 Delegate* delegate) | 80 Delegate* delegate) |
| 81 : profile_(profile), delegate_(delegate) { | 81 : profile_(profile), delegate_(delegate) { |
| 82 DCHECK(profile_); | 82 DCHECK(profile_); |
| 83 DCHECK(delegate_); | 83 DCHECK(delegate_); |
| 84 | 84 |
| 85 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 85 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 86 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
| 87 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 87 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 88 content::Source<Profile>(profile_)); | 88 content::Source<Profile>(profile_)); |
| 89 | 89 |
| 90 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
| 91 if (base::win::GetVersion() == base::win::VERSION_XP) { | 91 registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_ICON_CHANGE, |
| 92 registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED, | |
| 93 content::NotificationService::AllSources()); | |
| 94 } | |
| 95 registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE, | |
| 96 content::NotificationService::AllSources()); | 92 content::NotificationService::AllSources()); |
| 97 #endif | 93 #endif |
| 98 } | 94 } |
| 99 | 95 |
| 100 AppMenuBadgeController::~AppMenuBadgeController() { | 96 AppMenuIconController::~AppMenuIconController() {} |
| 101 } | |
| 102 | 97 |
| 103 void AppMenuBadgeController::UpdateDelegate() { | 98 void AppMenuIconController::UpdateDelegate() { |
| 104 if (ShouldShowUpgradeRecommended()) { | 99 if (ShouldShowUpgradeRecommended()) { |
| 105 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = | 100 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = |
| 106 UpgradeDetector::GetInstance()->upgrade_notification_stage(); | 101 UpgradeDetector::GetInstance()->upgrade_notification_stage(); |
| 107 delegate_->UpdateBadgeSeverity(BadgeType::UPGRADE_NOTIFICATION, | 102 delegate_->UpdateSeverity(IconType::UPGRADE_NOTIFICATION, |
| 108 SeverityFromUpgradeLevel(level), | 103 SeverityFromUpgradeLevel(level), |
| 109 ShouldAnimateUpgradeLevel(level)); | 104 ShouldAnimateUpgradeLevel(level)); |
| 110 return; | 105 return; |
| 111 } | 106 } |
| 112 | 107 |
| 113 if (ShouldShowIncompatibilityWarning()) { | 108 if (ShouldShowIncompatibilityWarning()) { |
| 114 delegate_->UpdateBadgeSeverity(BadgeType::INCOMPATIBILITY_WARNING, | 109 delegate_->UpdateSeverity(IconType::INCOMPATIBILITY_WARNING, |
| 115 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 110 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
| 116 return; | 111 return; |
| 117 } | 112 } |
| 118 | 113 |
| 119 if (GlobalErrorServiceFactory::GetForProfile(profile_)-> | 114 if (GlobalErrorServiceFactory::GetForProfile(profile_) |
| 120 GetHighestSeverityGlobalErrorWithAppMenuItem()) { | 115 ->GetHighestSeverityGlobalErrorWithAppMenuItem()) { |
| 121 // If you change the severity here, make sure to also change the menu icon | 116 // If you change the severity here, make sure to also change the menu icon |
| 122 // and the bubble icon. | 117 // and the bubble icon. |
| 123 delegate_->UpdateBadgeSeverity(BadgeType::GLOBAL_ERROR, | 118 delegate_->UpdateSeverity(IconType::GLOBAL_ERROR, |
| 124 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 119 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
| 125 return; | 120 return; |
| 126 } | 121 } |
| 127 | 122 |
| 128 delegate_->UpdateBadgeSeverity(BadgeType::NONE, | 123 delegate_->UpdateSeverity(IconType::NONE, |
| 129 AppMenuIconPainter::SEVERITY_NONE, true); | 124 AppMenuIconPainter::SEVERITY_NONE, true); |
| 130 } | 125 } |
| 131 | 126 void AppMenuIconController::Observe( |
| 132 void AppMenuBadgeController::Observe( | |
| 133 int type, | 127 int type, |
| 134 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
| 135 const content::NotificationDetails& details) { | 129 const content::NotificationDetails& details) { |
| 136 UpdateDelegate(); | 130 UpdateDelegate(); |
| 137 } | 131 } |
| OLD | NEW |