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_icon_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" |
16 #include "chrome/browser/enumerate_modules_model_win.h" | |
17 #endif | 16 #endif |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // Maps an upgrade level to a severity level. | 20 // Maps an upgrade level to a severity level. |
22 AppMenuIconPainter::Severity SeverityFromUpgradeLevel( | 21 AppMenuIconPainter::Severity SeverityFromUpgradeLevel( |
23 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) { | 22 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) { |
24 switch (level) { | 23 switch (level) { |
25 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: | 24 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: |
26 return AppMenuIconPainter::SEVERITY_NONE; | 25 return AppMenuIconPainter::SEVERITY_NONE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // should not be displayed in the app menu. | 58 // should not be displayed in the app menu. |
60 return false; | 59 return false; |
61 #else | 60 #else |
62 return UpgradeDetector::GetInstance()->notify_upgrade(); | 61 return UpgradeDetector::GetInstance()->notify_upgrade(); |
63 #endif | 62 #endif |
64 } | 63 } |
65 | 64 |
66 // Returns true if we should show the warning for incompatible software. | 65 // Returns true if we should show the warning for incompatible software. |
67 bool ShouldShowIncompatibilityWarning() { | 66 bool ShouldShowIncompatibilityWarning() { |
68 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
69 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance(); | 68 return EnumerateModulesModel::GetInstance()->ShouldShowConflictWarning(); |
70 loaded_modules->MaybePostScanningTask(); | |
71 return loaded_modules->ShouldShowConflictWarning(); | |
72 #else | 69 #else |
73 return false; | 70 return false; |
74 #endif | 71 #endif |
75 } | 72 } |
76 | 73 |
77 } // namespace | 74 } // namespace |
78 | 75 |
79 AppMenuIconController::AppMenuIconController(Profile* profile, | 76 AppMenuIconController::AppMenuIconController(Profile* profile, |
80 Delegate* delegate) | 77 Delegate* delegate) |
81 : profile_(profile), delegate_(delegate) { | 78 : profile_(profile), delegate_(delegate) { |
82 DCHECK(profile_); | 79 DCHECK(profile_); |
83 DCHECK(delegate_); | 80 DCHECK(delegate_); |
84 | 81 |
85 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 82 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
86 content::NotificationService::AllSources()); | 83 content::NotificationService::AllSources()); |
87 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 84 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
88 content::Source<Profile>(profile_)); | 85 content::Source<Profile>(profile_)); |
89 | 86 |
90 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
91 registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_ICON_CHANGE, | 88 auto modules = EnumerateModulesModel::GetInstance(); |
92 content::NotificationService::AllSources()); | 89 modules->AddObserver(this); |
| 90 modules->MaybePostScanningTask(); |
93 #endif | 91 #endif |
94 } | 92 } |
95 | 93 |
96 AppMenuIconController::~AppMenuIconController() {} | 94 AppMenuIconController::~AppMenuIconController() { |
| 95 #if defined(OS_WIN) |
| 96 EnumerateModulesModel::GetInstance()->RemoveObserver(this); |
| 97 #endif |
| 98 } |
97 | 99 |
98 void AppMenuIconController::UpdateDelegate() { | 100 void AppMenuIconController::UpdateDelegate() { |
99 if (ShouldShowUpgradeRecommended()) { | 101 if (ShouldShowUpgradeRecommended()) { |
100 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = | 102 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = |
101 UpgradeDetector::GetInstance()->upgrade_notification_stage(); | 103 UpgradeDetector::GetInstance()->upgrade_notification_stage(); |
102 delegate_->UpdateSeverity(IconType::UPGRADE_NOTIFICATION, | 104 delegate_->UpdateSeverity(IconType::UPGRADE_NOTIFICATION, |
103 SeverityFromUpgradeLevel(level), | 105 SeverityFromUpgradeLevel(level), |
104 ShouldAnimateUpgradeLevel(level)); | 106 ShouldAnimateUpgradeLevel(level)); |
105 return; | 107 return; |
106 } | 108 } |
107 | 109 |
108 if (ShouldShowIncompatibilityWarning()) { | 110 if (ShouldShowIncompatibilityWarning()) { |
109 delegate_->UpdateSeverity(IconType::INCOMPATIBILITY_WARNING, | 111 delegate_->UpdateSeverity(IconType::INCOMPATIBILITY_WARNING, |
110 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 112 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
111 return; | 113 return; |
112 } | 114 } |
113 | 115 |
114 if (GlobalErrorServiceFactory::GetForProfile(profile_) | 116 if (GlobalErrorServiceFactory::GetForProfile(profile_) |
115 ->GetHighestSeverityGlobalErrorWithAppMenuItem()) { | 117 ->GetHighestSeverityGlobalErrorWithAppMenuItem()) { |
116 // If you change the severity here, make sure to also change the menu icon | 118 // If you change the severity here, make sure to also change the menu icon |
117 // and the bubble icon. | 119 // and the bubble icon. |
118 delegate_->UpdateSeverity(IconType::GLOBAL_ERROR, | 120 delegate_->UpdateSeverity(IconType::GLOBAL_ERROR, |
119 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 121 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
120 return; | 122 return; |
121 } | 123 } |
122 | 124 |
123 delegate_->UpdateSeverity(IconType::NONE, | 125 delegate_->UpdateSeverity(IconType::NONE, |
124 AppMenuIconPainter::SEVERITY_NONE, true); | 126 AppMenuIconPainter::SEVERITY_NONE, true); |
125 } | 127 } |
| 128 |
| 129 #if defined(OS_WIN) |
| 130 void AppMenuIconController::OnScanCompleted(bool limited_mode) { |
| 131 if (!limited_mode) |
| 132 UpdateDelegate(); |
| 133 } |
| 134 |
| 135 void AppMenuIconController::OnConflictsAcknowledged() { |
| 136 UpdateDelegate(); |
| 137 } |
| 138 #endif |
| 139 |
126 void AppMenuIconController::Observe( | 140 void AppMenuIconController::Observe( |
127 int type, | 141 int type, |
128 const content::NotificationSource& source, | 142 const content::NotificationSource& source, |
129 const content::NotificationDetails& details) { | 143 const content::NotificationDetails& details) { |
130 UpdateDelegate(); | 144 UpdateDelegate(); |
131 } | 145 } |
OLD | NEW |