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/extensions/warning_badge_service.h" | 5 #include "chrome/browser/extensions/warning_badge_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/extensions/warning_badge_service_factory.h" | 13 #include "chrome/browser/extensions/warning_badge_service_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/global_error/global_error.h" | 16 #include "chrome/browser/ui/global_error/global_error.h" |
17 #include "chrome/browser/ui/global_error/global_error_service.h" | 17 #include "chrome/browser/ui/global_error/global_error_service.h" |
18 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 18 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "content/public/browser/browser_thread.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 namespace { | 25 namespace { |
25 // Non-modal GlobalError implementation that warns the user if extensions | 26 // Non-modal GlobalError implementation that warns the user if extensions |
26 // created warnings or errors. If the user clicks on the wrench menu, the user | 27 // created warnings or errors. If the user clicks on the wrench menu, the user |
27 // is redirected to chrome://extensions to inspect the errors. | 28 // is redirected to chrome://extensions to inspect the errors. |
28 class ErrorBadge : public GlobalError { | 29 class ErrorBadge : public GlobalError { |
29 public: | 30 public: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 95 |
95 // static | 96 // static |
96 int ErrorBadge::GetMenuItemCommandID() { | 97 int ErrorBadge::GetMenuItemCommandID() { |
97 return IDC_EXTENSION_ERRORS; | 98 return IDC_EXTENSION_ERRORS; |
98 } | 99 } |
99 | 100 |
100 } // namespace | 101 } // namespace |
101 | 102 |
102 WarningBadgeService::WarningBadgeService(Profile* profile) | 103 WarningBadgeService::WarningBadgeService(Profile* profile) |
103 : profile_(profile), warning_service_observer_(this) { | 104 : profile_(profile), warning_service_observer_(this) { |
104 DCHECK(CalledOnValidThread()); | 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
105 warning_service_observer_.Add(WarningService::Get(profile_)); | 106 warning_service_observer_.Add(WarningService::Get(profile_)); |
106 } | 107 } |
107 | 108 |
108 WarningBadgeService::~WarningBadgeService() { | 109 WarningBadgeService::~WarningBadgeService() { |
| 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
109 } | 111 } |
110 | 112 |
111 // static | 113 // static |
112 WarningBadgeService* WarningBadgeService::Get( | 114 WarningBadgeService* WarningBadgeService::Get( |
113 content::BrowserContext* context) { | 115 content::BrowserContext* context) { |
114 return WarningBadgeServiceFactory::GetForBrowserContext(context); | 116 return WarningBadgeServiceFactory::GetForBrowserContext(context); |
115 } | 117 } |
116 | 118 |
117 void WarningBadgeService::SuppressCurrentWarnings() { | 119 void WarningBadgeService::SuppressCurrentWarnings() { |
118 DCHECK(CalledOnValidThread()); | 120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
119 size_t old_size = suppressed_warnings_.size(); | 121 size_t old_size = suppressed_warnings_.size(); |
120 | 122 |
121 const WarningSet& warnings = GetCurrentWarnings(); | 123 const WarningSet& warnings = GetCurrentWarnings(); |
122 suppressed_warnings_.insert(warnings.begin(), warnings.end()); | 124 suppressed_warnings_.insert(warnings.begin(), warnings.end()); |
123 | 125 |
124 if (old_size != suppressed_warnings_.size()) | 126 if (old_size != suppressed_warnings_.size()) |
125 UpdateBadgeStatus(); | 127 UpdateBadgeStatus(); |
126 } | 128 } |
127 | 129 |
128 const WarningSet& WarningBadgeService::GetCurrentWarnings() const { | 130 const WarningSet& WarningBadgeService::GetCurrentWarnings() const { |
129 return WarningService::Get(profile_)->warnings(); | 131 return WarningService::Get(profile_)->warnings(); |
130 } | 132 } |
131 | 133 |
132 void WarningBadgeService::ExtensionWarningsChanged( | 134 void WarningBadgeService::ExtensionWarningsChanged( |
133 const ExtensionIdSet& affected_extensions) { | 135 const ExtensionIdSet& affected_extensions) { |
134 DCHECK(CalledOnValidThread()); | 136 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
135 UpdateBadgeStatus(); | 137 UpdateBadgeStatus(); |
136 } | 138 } |
137 | 139 |
138 void WarningBadgeService::UpdateBadgeStatus() { | 140 void WarningBadgeService::UpdateBadgeStatus() { |
139 const std::set<Warning>& warnings = GetCurrentWarnings(); | 141 const std::set<Warning>& warnings = GetCurrentWarnings(); |
140 bool non_suppressed_warnings_exist = false; | 142 bool non_suppressed_warnings_exist = false; |
141 for (std::set<Warning>::const_iterator i = warnings.begin(); | 143 for (std::set<Warning>::const_iterator i = warnings.begin(); |
142 i != warnings.end(); ++i) { | 144 i != warnings.end(); ++i) { |
143 if (!base::ContainsKey(suppressed_warnings_, *i)) { | 145 if (!base::ContainsKey(suppressed_warnings_, *i)) { |
144 non_suppressed_warnings_exist = true; | 146 non_suppressed_warnings_exist = true; |
(...skipping 10 matching lines...) Expand all Loading... |
155 ErrorBadge::GetMenuItemCommandID()); | 157 ErrorBadge::GetMenuItemCommandID()); |
156 | 158 |
157 // Activate or hide the warning badge in case the current state is incorrect. | 159 // Activate or hide the warning badge in case the current state is incorrect. |
158 if (error && !show) | 160 if (error && !show) |
159 service->RemoveGlobalError(error); | 161 service->RemoveGlobalError(error); |
160 else if (!error && show) | 162 else if (!error && show) |
161 service->AddGlobalError(base::MakeUnique<ErrorBadge>(this)); | 163 service->AddGlobalError(base::MakeUnique<ErrorBadge>(this)); |
162 } | 164 } |
163 | 165 |
164 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |