OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/error_console/error_console.h" | 5 #include "chrome/browser/extensions/error_console/error_console.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 // This is the default mask for which errors to report. That is, if an extension | 40 // This is the default mask for which errors to report. That is, if an extension |
41 // does not have specific preference set, this will be used instead. | 41 // does not have specific preference set, this will be used instead. |
42 const int kDefaultMask = 0; | 42 const int kDefaultMask = 0; |
43 | 43 |
44 const char kAppsDeveloperToolsExtensionId[] = | 44 const char kAppsDeveloperToolsExtensionId[] = |
45 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; | 45 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 void ErrorConsole::Observer::OnErrorAdded(const ExtensionError* error) { | |
50 } | |
51 | |
52 void ErrorConsole::Observer::OnErrorsRemoved( | |
53 const std::set<std::string>& extension_ids) { | |
54 } | |
55 | |
49 void ErrorConsole::Observer::OnErrorConsoleDestroyed() { | 56 void ErrorConsole::Observer::OnErrorConsoleDestroyed() { |
50 } | 57 } |
Dan Beam
2015/04/22 21:02:37
why not just {} in the .h? is this preferred for
Devlin
2015/04/22 23:17:31
I think there was some rule that it was preferred
| |
51 | 58 |
52 ErrorConsole::ErrorConsole(Profile* profile) | 59 ErrorConsole::ErrorConsole(Profile* profile) |
53 : enabled_(false), | 60 : enabled_(false), |
54 default_mask_(kDefaultMask), | 61 default_mask_(kDefaultMask), |
55 profile_(profile), | 62 profile_(profile), |
56 prefs_(NULL), | 63 prefs_(NULL), |
57 registry_observer_(this) { | 64 registry_observer_(this) { |
58 pref_registrar_.Init(profile_->GetPrefs()); | 65 pref_registrar_.Init(profile_->GetPrefs()); |
59 pref_registrar_.Add(prefs::kExtensionsUIDeveloperMode, | 66 pref_registrar_.Add(prefs::kExtensionsUIDeveloperMode, |
60 base::Bind(&ErrorConsole::OnPrefChanged, | 67 base::Bind(&ErrorConsole::OnPrefChanged, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 141 |
135 int mask = GetMaskForExtension(error->extension_id()); | 142 int mask = GetMaskForExtension(error->extension_id()); |
136 if (!(mask & (1 << error->type()))) | 143 if (!(mask & (1 << error->type()))) |
137 return; | 144 return; |
138 | 145 |
139 const ExtensionError* weak_error = errors_.AddError(error.Pass()); | 146 const ExtensionError* weak_error = errors_.AddError(error.Pass()); |
140 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error)); | 147 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error)); |
141 } | 148 } |
142 | 149 |
143 void ErrorConsole::RemoveErrors(const ErrorMap::Filter& filter) { | 150 void ErrorConsole::RemoveErrors(const ErrorMap::Filter& filter) { |
144 errors_.RemoveErrors(filter); | 151 std::set<std::string> affected_ids; |
152 errors_.RemoveErrors(filter, &affected_ids); | |
153 FOR_EACH_OBSERVER(Observer, observers_, OnErrorsRemoved(affected_ids)); | |
145 } | 154 } |
146 | 155 |
147 const ErrorList& ErrorConsole::GetErrorsForExtension( | 156 const ErrorList& ErrorConsole::GetErrorsForExtension( |
148 const std::string& extension_id) const { | 157 const std::string& extension_id) const { |
149 return errors_.GetErrorsForExtension(extension_id); | 158 return errors_.GetErrorsForExtension(extension_id); |
150 } | 159 } |
151 | 160 |
152 void ErrorConsole::AddObserver(Observer* observer) { | 161 void ErrorConsole::AddObserver(Observer* observer) { |
153 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
154 observers_.AddObserver(observer); | 163 observers_.AddObserver(observer); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 | 233 |
225 void ErrorConsole::OnExtensionInstalled( | 234 void ErrorConsole::OnExtensionInstalled( |
226 content::BrowserContext* browser_context, | 235 content::BrowserContext* browser_context, |
227 const Extension* extension, | 236 const Extension* extension, |
228 bool is_update) { | 237 bool is_update) { |
229 // We don't want to have manifest errors from previous installs. We want | 238 // We don't want to have manifest errors from previous installs. We want |
230 // to keep runtime errors, though, because extensions are reloaded on a | 239 // to keep runtime errors, though, because extensions are reloaded on a |
231 // refresh of chrome:extensions, and we don't want to wipe our history | 240 // refresh of chrome:extensions, and we don't want to wipe our history |
232 // whenever that happens. | 241 // whenever that happens. |
233 errors_.RemoveErrors(ErrorMap::Filter::ErrorsForExtensionWithType( | 242 errors_.RemoveErrors(ErrorMap::Filter::ErrorsForExtensionWithType( |
234 extension->id(), ExtensionError::MANIFEST_ERROR)); | 243 extension->id(), ExtensionError::MANIFEST_ERROR), nullptr); |
235 AddManifestErrorsForExtension(extension); | 244 AddManifestErrorsForExtension(extension); |
236 } | 245 } |
237 | 246 |
238 void ErrorConsole::OnExtensionUninstalled( | 247 void ErrorConsole::OnExtensionUninstalled( |
239 content::BrowserContext* browser_context, | 248 content::BrowserContext* browser_context, |
240 const Extension* extension, | 249 const Extension* extension, |
241 extensions::UninstallReason reason) { | 250 extensions::UninstallReason reason) { |
242 errors_.RemoveErrors(ErrorMap::Filter::ErrorsForExtension(extension->id())); | 251 errors_.RemoveErrors(ErrorMap::Filter::ErrorsForExtension(extension->id()), |
252 nullptr); | |
243 } | 253 } |
244 | 254 |
245 void ErrorConsole::AddManifestErrorsForExtension(const Extension* extension) { | 255 void ErrorConsole::AddManifestErrorsForExtension(const Extension* extension) { |
246 const std::vector<InstallWarning>& warnings = | 256 const std::vector<InstallWarning>& warnings = |
247 extension->install_warnings(); | 257 extension->install_warnings(); |
248 for (std::vector<InstallWarning>::const_iterator iter = warnings.begin(); | 258 for (std::vector<InstallWarning>::const_iterator iter = warnings.begin(); |
249 iter != warnings.end(); ++iter) { | 259 iter != warnings.end(); ++iter) { |
250 ReportError(scoped_ptr<ExtensionError>(new ManifestError( | 260 ReportError(scoped_ptr<ExtensionError>(new ManifestError( |
251 extension->id(), | 261 extension->id(), |
252 base::UTF8ToUTF16(iter->message), | 262 base::UTF8ToUTF16(iter->message), |
253 base::UTF8ToUTF16(iter->key), | 263 base::UTF8ToUTF16(iter->key), |
254 base::UTF8ToUTF16(iter->specific)))); | 264 base::UTF8ToUTF16(iter->specific)))); |
255 } | 265 } |
256 } | 266 } |
257 | 267 |
258 void ErrorConsole::Observe(int type, | 268 void ErrorConsole::Observe(int type, |
259 const content::NotificationSource& source, | 269 const content::NotificationSource& source, |
260 const content::NotificationDetails& details) { | 270 const content::NotificationDetails& details) { |
261 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 271 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
262 Profile* profile = content::Source<Profile>(source).ptr(); | 272 Profile* profile = content::Source<Profile>(source).ptr(); |
263 // If incognito profile which we are associated with is destroyed, also | 273 // If incognito profile which we are associated with is destroyed, also |
264 // destroy all incognito errors. | 274 // destroy all incognito errors. |
265 if (profile->IsOffTheRecord() && profile_->IsSameProfile(profile)) | 275 if (profile->IsOffTheRecord() && profile_->IsSameProfile(profile)) |
266 errors_.RemoveErrors(ErrorMap::Filter::IncognitoErrors()); | 276 errors_.RemoveErrors(ErrorMap::Filter::IncognitoErrors(), nullptr); |
267 } | 277 } |
268 | 278 |
269 int ErrorConsole::GetMaskForExtension(const std::string& extension_id) const { | 279 int ErrorConsole::GetMaskForExtension(const std::string& extension_id) const { |
270 // Registered preferences take priority over everything else. | 280 // Registered preferences take priority over everything else. |
271 int pref = 0; | 281 int pref = 0; |
272 if (prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &pref)) | 282 if (prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &pref)) |
273 return pref; | 283 return pref; |
274 | 284 |
275 // If the extension is unpacked, we report all error types by default. | 285 // If the extension is unpacked, we report all error types by default. |
276 const Extension* extension = | 286 const Extension* extension = |
277 ExtensionRegistry::Get(profile_)->GetExtensionById( | 287 ExtensionRegistry::Get(profile_)->GetExtensionById( |
278 extension_id, ExtensionRegistry::EVERYTHING); | 288 extension_id, ExtensionRegistry::EVERYTHING); |
279 if (extension && extension->location() == Manifest::UNPACKED) | 289 if (extension && extension->location() == Manifest::UNPACKED) |
280 return (1 << ExtensionError::NUM_ERROR_TYPES) - 1; | 290 return (1 << ExtensionError::NUM_ERROR_TYPES) - 1; |
281 | 291 |
282 // Otherwise, use the default mask. | 292 // Otherwise, use the default mask. |
283 return default_mask_; | 293 return default_mask_; |
284 } | 294 } |
285 | 295 |
286 } // namespace extensions | 296 } // namespace extensions |
OLD | NEW |