| 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..c689ad4400f3327745aec7bd4deb18ee598c0c8f 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 int kDefaultMask = 0;
|
|
|
| const char kAppsDeveloperToolsExtensionId[] =
|
| "ohmmkhmmmpcnpikjeljgnaoabkaalbgc";
|
| @@ -53,6 +53,7 @@ ErrorConsole::ErrorConsole(Profile* profile)
|
| : enabled_(false),
|
| default_mask_(kDefaultMask),
|
| profile_(profile),
|
| + prefs_(NULL),
|
| registry_observer_(this) {
|
| // TODO(rdevlin.cronin): Remove once crbug.com/159265 is fixed.
|
| #if !defined(ENABLE_EXTENSIONS)
|
| @@ -85,20 +86,47 @@ 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.
|
| + prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &mask);
|
|
|
| - if (pref == pref_map_.end()) {
|
| - pref = pref_map_.insert(
|
| - std::pair<std::string, int32>(extension_id, default_mask_)).first;
|
| - }
|
| + if (enabled)
|
| + mask |= 1 << type;
|
| + else
|
| + mask &= ~(1 << type);
|
| +
|
| + prefs_->UpdateExtensionPref(extension_id,
|
| + kStoreExtensionErrorsPref,
|
| + base::Value::CreateIntegerValue(mask));
|
| +}
|
| +
|
| +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);
|
| + int mask = 0;
|
| + if (enabled)
|
| + mask = (1 << ExtensionError::NUM_ERROR_TYPES) - 1;
|
|
|
| - ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
|
| - extension_id,
|
| - kStoreExtensionErrorsPref,
|
| - base::Value::CreateIntegerValue(pref->second));
|
| + prefs_->UpdateExtensionPref(extension_id,
|
| + kStoreExtensionErrorsPref,
|
| + base::Value::CreateIntegerValue(mask));
|
| +}
|
| +
|
| +bool ErrorConsole::IsReportingEnabledForExtension(
|
| + const std::string& extension_id) const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + if (!enabled_ || !Extension::IdIsValid(extension_id))
|
| + return false;
|
| +
|
| + 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.
|
| + prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &mask);
|
| + return mask != 0;
|
| }
|
|
|
| void ErrorConsole::UseDefaultReportingForExtension(
|
| @@ -107,25 +135,14 @@ void ErrorConsole::UseDefaultReportingForExtension(
|
| if (!enabled_ || !Extension::IdIsValid(extension_id))
|
| return;
|
|
|
| - pref_map_.erase(extension_id);
|
| - ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
|
| - extension_id,
|
| - kStoreExtensionErrorsPref,
|
| - NULL);
|
| + prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref, NULL);
|
| }
|
|
|
| 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;
|
| }
|
|
|
| @@ -171,6 +188,11 @@ void ErrorConsole::CheckEnabled() {
|
| void ErrorConsole::Enable() {
|
| enabled_ = true;
|
|
|
| + // We postpone the initialization of |prefs_| until now because they can be
|
| + // NULL in unit_tests. Any unit tests that enable the error console should
|
| + // also create an ExtensionPrefs object.
|
| + prefs_ = ExtensionPrefs::Get(profile_);
|
| +
|
| notification_registrar_.Add(
|
| this,
|
| chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| @@ -184,18 +206,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 +284,28 @@ void ErrorConsole::Observe(int type,
|
| }
|
| }
|
|
|
| +bool ErrorConsole::ShouldReportErrorForExtension(
|
| + const std::string& extension_id, ExtensionError::Type type) const {
|
| + // Registered preferences take priority over everything else.
|
| + int pref = 0;
|
| + if (prefs_->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
|
|
|