Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: chrome/browser/ui/toolbar/app_menu_badge_controller.cc

Issue 2039403002: Renamed AppMenuBadgeController to AppMenuIconController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed identifiers in Cocoa file Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/toolbar/app_menu_badge_controller.h"
6
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/ui/global_error/global_error_service.h"
11 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
12 #include "chrome/browser/upgrade_detector.h"
13
14 #if defined(OS_WIN)
15 #include "base/win/windows_version.h"
16 #include "chrome/browser/enumerate_modules_model_win.h"
17 #endif
18
19 namespace {
20
21 // Maps an upgrade level to a severity level.
22 AppMenuIconPainter::Severity SeverityFromUpgradeLevel(
23 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
24 switch (level) {
25 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
26 return AppMenuIconPainter::SEVERITY_NONE;
27 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
28 return AppMenuIconPainter::SEVERITY_LOW;
29 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
30 return AppMenuIconPainter::SEVERITY_MEDIUM;
31 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
32 return AppMenuIconPainter::SEVERITY_HIGH;
33 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
34 return AppMenuIconPainter::SEVERITY_HIGH;
35 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
36 return AppMenuIconPainter::SEVERITY_HIGH;
37 }
38 NOTREACHED();
39 return AppMenuIconPainter::SEVERITY_NONE;
40 }
41
42 // Checks if the app menu icon should be animated for the given upgrade level.
43 bool ShouldAnimateUpgradeLevel(
44 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
45 bool should_animate = true;
46 if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) {
47 // Only animate low severity upgrades once.
48 static bool should_animate_low_severity = true;
49 should_animate = should_animate_low_severity;
50 should_animate_low_severity = false;
51 }
52 return should_animate;
53 }
54
55 // Returns true if we should show the upgrade recommended badge.
56 bool ShouldShowUpgradeRecommended() {
57 #if defined(OS_CHROMEOS)
58 // In chromeos, the update recommendation is shown in the system tray. So it
59 // should not be displayed in the app menu.
60 return false;
61 #else
62 return UpgradeDetector::GetInstance()->notify_upgrade();
63 #endif
64 }
65
66 // Returns true if we should show the warning for incompatible software.
67 bool ShouldShowIncompatibilityWarning() {
68 #if defined(OS_WIN)
69 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
70 loaded_modules->MaybePostScanningTask();
71 return loaded_modules->ShouldShowConflictWarning();
72 #else
73 return false;
74 #endif
75 }
76
77 } // namespace
78
79 AppMenuBadgeController::AppMenuBadgeController(Profile* profile,
80 Delegate* delegate)
81 : profile_(profile), delegate_(delegate) {
82 DCHECK(profile_);
83 DCHECK(delegate_);
84
85 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
86 content::NotificationService::AllSources());
87 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
88 content::Source<Profile>(profile_));
89
90 #if defined(OS_WIN)
91 if (base::win::GetVersion() == base::win::VERSION_XP) {
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());
97 #endif
98 }
99
100 AppMenuBadgeController::~AppMenuBadgeController() {
101 }
102
103 void AppMenuBadgeController::UpdateDelegate() {
104 if (ShouldShowUpgradeRecommended()) {
105 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
106 UpgradeDetector::GetInstance()->upgrade_notification_stage();
107 delegate_->UpdateBadgeSeverity(BadgeType::UPGRADE_NOTIFICATION,
108 SeverityFromUpgradeLevel(level),
109 ShouldAnimateUpgradeLevel(level));
110 return;
111 }
112
113 if (ShouldShowIncompatibilityWarning()) {
114 delegate_->UpdateBadgeSeverity(BadgeType::INCOMPATIBILITY_WARNING,
115 AppMenuIconPainter::SEVERITY_MEDIUM, true);
116 return;
117 }
118
119 if (GlobalErrorServiceFactory::GetForProfile(profile_)->
120 GetHighestSeverityGlobalErrorWithAppMenuItem()) {
121 // If you change the severity here, make sure to also change the menu icon
122 // and the bubble icon.
123 delegate_->UpdateBadgeSeverity(BadgeType::GLOBAL_ERROR,
124 AppMenuIconPainter::SEVERITY_MEDIUM, true);
125 return;
126 }
127
128 delegate_->UpdateBadgeSeverity(BadgeType::NONE,
129 AppMenuIconPainter::SEVERITY_NONE, true);
130 }
131
132 void AppMenuBadgeController::Observe(
133 int type,
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) {
136 UpdateDelegate();
137 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/app_menu_badge_controller.h ('k') | chrome/browser/ui/toolbar/app_menu_icon_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698