Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: chrome/browser/extensions/error_console/error_console.cc

Issue 238073002: Provide UI for per-extension enabling/disabling of error collection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 19 matching lines...) Expand all
30 #include "extensions/common/feature_switch.h" 30 #include "extensions/common/feature_switch.h"
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 namespace { 34 namespace {
35 35
36 // The key into the Extension prefs for an Extension's specific reporting 36 // The key into the Extension prefs for an Extension's specific reporting
37 // settings. 37 // settings.
38 const char kStoreExtensionErrorsPref[] = "store_extension_errors"; 38 const char kStoreExtensionErrorsPref[] = "store_extension_errors";
39 39
40 // The default mask (for the time being) is to report everything. 40 // The default mask (for the time being) is to report nothing.
not at google - send to devlin 2014/04/15 21:57:41 "default" mask is pretty meaningless without conte
Devlin 2014/04/16 18:10:48 Done.
41 const int32 kDefaultMask = (1 << ExtensionError::MANIFEST_ERROR) | 41 const int32 kDefaultMask = 0;
42 (1 << ExtensionError::RUNTIME_ERROR);
43 42
44 const char kAppsDeveloperToolsExtensionId[] = 43 const char kAppsDeveloperToolsExtensionId[] =
45 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc"; 44 "ohmmkhmmmpcnpikjeljgnaoabkaalbgc";
46 45
47 } // namespace 46 } // namespace
48 47
49 void ErrorConsole::Observer::OnErrorConsoleDestroyed() { 48 void ErrorConsole::Observer::OnErrorConsoleDestroyed() {
50 } 49 }
51 50
52 ErrorConsole::ErrorConsole(Profile* profile) 51 ErrorConsole::ErrorConsole(Profile* profile)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 93
95 pref->second = 94 pref->second =
96 enabled ? pref->second | (1 << type) : pref->second &~(1 << type); 95 enabled ? pref->second | (1 << type) : pref->second &~(1 << type);
97 96
98 ExtensionPrefs::Get(profile_)->UpdateExtensionPref( 97 ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
99 extension_id, 98 extension_id,
100 kStoreExtensionErrorsPref, 99 kStoreExtensionErrorsPref,
101 base::Value::CreateIntegerValue(pref->second)); 100 base::Value::CreateIntegerValue(pref->second));
102 } 101 }
103 102
103 bool ErrorConsole::IsReportingEnabledForExtension(
104 const std::string& extension_id) const {
105 return ShouldReportErrorForExtension(extension_id,
106 ExtensionError::MANIFEST_ERROR) ||
107 ShouldReportErrorForExtension(extension_id,
108 ExtensionError::RUNTIME_ERROR);
109 }
110
104 void ErrorConsole::UseDefaultReportingForExtension( 111 void ErrorConsole::UseDefaultReportingForExtension(
105 const std::string& extension_id) { 112 const std::string& extension_id) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
107 if (!enabled_ || !Extension::IdIsValid(extension_id)) 114 if (!enabled_ || !Extension::IdIsValid(extension_id))
108 return; 115 return;
109 116
110 pref_map_.erase(extension_id); 117 pref_map_.erase(extension_id);
111 ExtensionPrefs::Get(profile_)->UpdateExtensionPref( 118 ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
112 extension_id, 119 extension_id,
113 kStoreExtensionErrorsPref, 120 kStoreExtensionErrorsPref,
114 NULL); 121 NULL);
115 } 122 }
116 123
117 void ErrorConsole::ReportError(scoped_ptr<ExtensionError> error) { 124 void ErrorConsole::ReportError(scoped_ptr<ExtensionError> error) {
118 DCHECK(thread_checker_.CalledOnValidThread()); 125 DCHECK(thread_checker_.CalledOnValidThread());
119 if (!enabled_ || !Extension::IdIsValid(error->extension_id())) 126 if (!enabled_ ||
120 return; 127 !Extension::IdIsValid(error->extension_id()) ||
121 128 !ShouldReportErrorForExtension(error->extension_id(), error->type())) {
122 ErrorPreferenceMap::const_iterator pref =
123 pref_map_.find(error->extension_id());
124 // Check the mask to see if we report the error. If we don't have a specific
125 // entry, use the default mask.
126 if ((pref == pref_map_.end() &&
127 ((default_mask_ & (1 << error->type())) == 0)) ||
128 (pref != pref_map_.end() && (pref->second & (1 << error->type())) == 0)) {
129 return; 129 return;
130 } 130 }
131 131
132 const ExtensionError* weak_error = errors_.AddError(error.Pass()); 132 const ExtensionError* weak_error = errors_.AddError(error.Pass());
133 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error)); 133 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error));
134 } 134 }
135 135
136 const ErrorList& ErrorConsole::GetErrorsForExtension( 136 const ErrorList& ErrorConsole::GetErrorsForExtension(
137 const std::string& extension_id) const { 137 const std::string& extension_id) const {
138 return errors_.GetErrorsForExtension(extension_id); 138 return errors_.GetErrorsForExtension(extension_id);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 ExtensionError::MANIFEST_ERROR); 262 ExtensionError::MANIFEST_ERROR);
263 263
264 AddManifestErrorsForExtension(info->extension); 264 AddManifestErrorsForExtension(info->extension);
265 break; 265 break;
266 } 266 }
267 default: 267 default:
268 NOTREACHED(); 268 NOTREACHED();
269 } 269 }
270 } 270 }
271 271
272 bool ErrorConsole::ShouldReportErrorForExtension(
273 const std::string& extension_id, ExtensionError::Type type) const {
274 ErrorPreferenceMap::const_iterator pref = pref_map_.find(extension_id);
275 // Registered preferences take priority over everything else.
not at google - send to devlin 2014/04/15 21:57:41 nit: put this comment above the declaration of |pr
Devlin 2014/04/16 18:10:48 Done.
276 if (pref != pref_map_.end())
277 return (pref->second & (1 << type)) != 0;
278
279 // If the default mask says to report the error, do so.
280 if ((default_mask_ & (1 << type)) != 0)
281 return true;
282
283 // One last check: If the extension is unpacked, we report all errors by
284 // default.
285 const Extension* extension =
286 ExtensionRegistry::Get(profile_)->GetExtensionById(
287 extension_id, ExtensionRegistry::EVERYTHING);
288 if (extension && extension->location() == Manifest::UNPACKED)
289 return true;
290
291 return false;
292 }
293
272 } // namespace extensions 294 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698