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" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 return EnumerateModulesModel::GetInstance()->ShouldShowConflictWarning(); |
70 loaded_modules->MaybePostScanningTask(); | |
71 return loaded_modules->ShouldShowConflictWarning(); | |
72 #else | 70 #else |
73 return false; | 71 return false; |
74 #endif | 72 #endif |
75 } | 73 } |
76 | 74 |
77 } // namespace | 75 } // namespace |
78 | 76 |
79 AppMenuIconController::AppMenuIconController(Profile* profile, | 77 AppMenuIconController::AppMenuIconController(Profile* profile, |
80 Delegate* delegate) | 78 Delegate* delegate) |
81 : profile_(profile), delegate_(delegate) { | 79 : profile_(profile), delegate_(delegate) { |
82 DCHECK(profile_); | 80 DCHECK(profile_); |
83 DCHECK(delegate_); | 81 DCHECK(delegate_); |
84 | 82 |
85 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 83 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
86 content::NotificationService::AllSources()); | 84 content::NotificationService::AllSources()); |
87 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 85 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
88 content::Source<Profile>(profile_)); | 86 content::Source<Profile>(profile_)); |
89 | 87 |
90 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
91 registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_ICON_CHANGE, | 89 auto modules = EnumerateModulesModel::GetInstance(); |
Lei Zhang
2016/08/04 14:33:32
auto*
chrisha
2016/08/12 19:04:40
Done.
| |
92 content::NotificationService::AllSources()); | 90 modules->AddObserver(this); |
Peter Kasting
2016/08/05 00:10:08
Nit: Consider whether it would be cleaner or safer
chrisha
2016/08/12 19:04:40
I'm not a huge fan of precompiler logic in initial
| |
91 modules->MaybePostScanningTask(); | |
93 #endif | 92 #endif |
94 } | 93 } |
95 | 94 |
96 AppMenuIconController::~AppMenuIconController() {} | 95 AppMenuIconController::~AppMenuIconController() { |
96 #if defined(OS_WIN) | |
97 EnumerateModulesModel::GetInstance()->RemoveObserver(this); | |
98 #endif | |
99 } | |
97 | 100 |
98 void AppMenuIconController::UpdateDelegate() { | 101 void AppMenuIconController::UpdateDelegate() { |
99 if (ShouldShowUpgradeRecommended()) { | 102 if (ShouldShowUpgradeRecommended()) { |
100 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = | 103 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level = |
101 UpgradeDetector::GetInstance()->upgrade_notification_stage(); | 104 UpgradeDetector::GetInstance()->upgrade_notification_stage(); |
102 delegate_->UpdateSeverity(IconType::UPGRADE_NOTIFICATION, | 105 delegate_->UpdateSeverity(IconType::UPGRADE_NOTIFICATION, |
103 SeverityFromUpgradeLevel(level), | 106 SeverityFromUpgradeLevel(level), |
104 ShouldAnimateUpgradeLevel(level)); | 107 ShouldAnimateUpgradeLevel(level)); |
105 return; | 108 return; |
106 } | 109 } |
107 | 110 |
108 if (ShouldShowIncompatibilityWarning()) { | 111 if (ShouldShowIncompatibilityWarning()) { |
109 delegate_->UpdateSeverity(IconType::INCOMPATIBILITY_WARNING, | 112 delegate_->UpdateSeverity(IconType::INCOMPATIBILITY_WARNING, |
110 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 113 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
111 return; | 114 return; |
112 } | 115 } |
113 | 116 |
114 if (GlobalErrorServiceFactory::GetForProfile(profile_) | 117 if (GlobalErrorServiceFactory::GetForProfile(profile_) |
115 ->GetHighestSeverityGlobalErrorWithAppMenuItem()) { | 118 ->GetHighestSeverityGlobalErrorWithAppMenuItem()) { |
116 // If you change the severity here, make sure to also change the menu icon | 119 // If you change the severity here, make sure to also change the menu icon |
117 // and the bubble icon. | 120 // and the bubble icon. |
118 delegate_->UpdateSeverity(IconType::GLOBAL_ERROR, | 121 delegate_->UpdateSeverity(IconType::GLOBAL_ERROR, |
119 AppMenuIconPainter::SEVERITY_MEDIUM, true); | 122 AppMenuIconPainter::SEVERITY_MEDIUM, true); |
120 return; | 123 return; |
121 } | 124 } |
122 | 125 |
123 delegate_->UpdateSeverity(IconType::NONE, | 126 delegate_->UpdateSeverity(IconType::NONE, |
124 AppMenuIconPainter::SEVERITY_NONE, true); | 127 AppMenuIconPainter::SEVERITY_NONE, true); |
125 } | 128 } |
129 | |
130 #if defined(OS_WIN) | |
131 void AppMenuIconController::OnScanCompleted() { | |
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 |