Chromium Code Reviews| Index: chrome/browser/extensions/error_console/error_console.cc |
| diff --git a/chrome/browser/extensions/error_console/error_console.cc b/chrome/browser/extensions/error_console/error_console.cc |
| index 2429af614a413b7bf187029e5a40e71f3e11dceb..998525eb928ba11fd56612e8bb31c124487b1069 100644 |
| --- a/chrome/browser/extensions/error_console/error_console.cc |
| +++ b/chrome/browser/extensions/error_console/error_console.cc |
| @@ -37,9 +37,9 @@ namespace { |
| // settings. |
| const char kStoreExtensionErrorsPref[] = "store_extension_errors"; |
| -// The default mask (for the time being) is to report everything. |
| -const int32 kDefaultMask = (1 << ExtensionError::MANIFEST_ERROR) | |
| - (1 << ExtensionError::RUNTIME_ERROR); |
| +// This is the default mask for which errors to report. That is, if an extension |
| +// does not have specific preference set, this will be used instead. |
| +const int32 kDefaultMask = 0; |
| const char kAppsDeveloperToolsExtensionId[] = |
| "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; |
| @@ -85,20 +85,40 @@ void ErrorConsole::SetReportingForExtension(const std::string& extension_id, |
| if (!enabled_ || !Extension::IdIsValid(extension_id)) |
| return; |
| - ErrorPreferenceMap::iterator pref = pref_map_.find(extension_id); |
| + int mask = default_mask_; |
| + // This call can fail if the preference isn't set, but we don't really care |
| + // if it does, because we just use the default mask instead. |
| + ExtensionPrefs::Get(profile_)->ReadPrefAsInteger( |
| + extension_id, kStoreExtensionErrorsPref, &mask); |
|
not at google - send to devlin
2014/04/17 00:15:53
write a GetPref() method? TBH the "extension" in S
|
| + if (enabled) |
| + mask |= 1 << type; |
| + else |
| + mask &= ~(1 << type); |
| + |
| + SetExtensionPref(extension_id, mask); |
| +} |
| - if (pref == pref_map_.end()) { |
| - pref = pref_map_.insert( |
| - std::pair<std::string, int32>(extension_id, default_mask_)).first; |
| - } |
| +void ErrorConsole::SetReportingAllForExtension( |
| + const std::string& extension_id, bool enabled) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!enabled_ || !Extension::IdIsValid(extension_id)) |
| + return; |
| - pref->second = |
| - enabled ? pref->second | (1 << type) : pref->second &~(1 << type); |
| + int32 mask = 0; |
| + if (enabled) |
| + mask = (1 << ExtensionError::NUM_ERROR_TYPES) - 1; |
| - ExtensionPrefs::Get(profile_)->UpdateExtensionPref( |
| - extension_id, |
| - kStoreExtensionErrorsPref, |
| - base::Value::CreateIntegerValue(pref->second)); |
| + SetExtensionPref(extension_id, mask); |
| +} |
| + |
| +bool ErrorConsole::IsReportingEnabledForExtension( |
| + const std::string& extension_id) const { |
| + int mask = default_mask_; |
| + // This call can fail if the preference isn't set, but we don't really care |
| + // if it does, because we just use the default mask instead. |
| + ExtensionPrefs::Get(profile_)->ReadPrefAsInteger( |
| + extension_id, kStoreExtensionErrorsPref, &mask); |
| + return mask != 0; |
| } |
| void ErrorConsole::UseDefaultReportingForExtension( |
| @@ -107,7 +127,6 @@ void ErrorConsole::UseDefaultReportingForExtension( |
| if (!enabled_ || !Extension::IdIsValid(extension_id)) |
| return; |
| - pref_map_.erase(extension_id); |
| ExtensionPrefs::Get(profile_)->UpdateExtensionPref( |
| extension_id, |
| kStoreExtensionErrorsPref, |
| @@ -116,16 +135,9 @@ void ErrorConsole::UseDefaultReportingForExtension( |
| void ErrorConsole::ReportError(scoped_ptr<ExtensionError> error) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - if (!enabled_ || !Extension::IdIsValid(error->extension_id())) |
| - return; |
| - |
| - ErrorPreferenceMap::const_iterator pref = |
| - pref_map_.find(error->extension_id()); |
| - // Check the mask to see if we report the error. If we don't have a specific |
| - // entry, use the default mask. |
| - if ((pref == pref_map_.end() && |
| - ((default_mask_ & (1 << error->type())) == 0)) || |
| - (pref != pref_map_.end() && (pref->second & (1 << error->type())) == 0)) { |
| + if (!enabled_ || |
| + !Extension::IdIsValid(error->extension_id()) || |
| + !ShouldReportErrorForExtension(error->extension_id(), error->type())) { |
| return; |
| } |
| @@ -184,18 +196,11 @@ void ErrorConsole::Enable() { |
| chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| content::Source<Profile>(profile_)); |
| - ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); |
| const ExtensionSet& extensions = |
| ExtensionRegistry::Get(profile_)->enabled_extensions(); |
| for (ExtensionSet::const_iterator iter = extensions.begin(); |
| iter != extensions.end(); |
| ++iter) { |
| - int mask = 0; |
| - if (prefs->ReadPrefAsInteger(iter->get()->id(), |
| - kStoreExtensionErrorsPref, |
| - &mask)) { |
| - pref_map_[iter->get()->id()] = mask; |
| - } |
| AddManifestErrorsForExtension(iter->get()); |
| } |
| } |
| @@ -269,4 +274,36 @@ void ErrorConsole::Observe(int type, |
| } |
| } |
| +void ErrorConsole::SetExtensionPref(const std::string& extension_id, |
| + int32 mask) { |
| + ExtensionPrefs::Get(profile_)->UpdateExtensionPref( |
| + extension_id, |
| + kStoreExtensionErrorsPref, |
| + base::Value::CreateIntegerValue(mask)); |
| +} |
| + |
| +bool ErrorConsole::ShouldReportErrorForExtension( |
| + const std::string& extension_id, ExtensionError::Type type) const { |
| + // Registered preferences take priority over everything else. |
| + int pref = 0; |
| + if (ExtensionPrefs::Get(profile_)->ReadPrefAsInteger( |
| + extension_id, kStoreExtensionErrorsPref, &pref)) { |
| + return (pref & (1 << type)) != 0; |
| + } |
| + |
| + // If the default mask says to report the error, do so. |
| + if ((default_mask_ & (1 << type)) != 0) |
| + return true; |
| + |
| + // One last check: If the extension is unpacked, we report all errors by |
| + // default. |
| + const Extension* extension = |
| + ExtensionRegistry::Get(profile_)->GetExtensionById( |
| + extension_id, ExtensionRegistry::EVERYTHING); |
| + if (extension && extension->location() == Manifest::UNPACKED) |
| + return true; |
| + |
| + return false; |
| +} |
| + |
| } // namespace extensions |