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 #ifndef CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace content { | 23 namespace content { |
24 class NotificationDetails; | 24 class NotificationDetails; |
25 class NotificationSource; | 25 class NotificationSource; |
26 class RenderViewHost; | 26 class RenderViewHost; |
27 } | 27 } |
28 | 28 |
29 class ExtensionService; | 29 class ExtensionService; |
30 class Profile; | 30 class Profile; |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 class ErrorConsoleUnitTest; | |
34 class Extension; | 33 class Extension; |
| 34 class ExtensionPrefs; |
35 | 35 |
36 // The ErrorConsole is a central object to which all extension errors are | 36 // The ErrorConsole is a central object to which all extension errors are |
37 // reported. This includes errors detected in extensions core, as well as | 37 // reported. This includes errors detected in extensions core, as well as |
38 // runtime Javascript errors. If FeatureSwitch::error_console() is enabled these | 38 // runtime Javascript errors. If FeatureSwitch::error_console() is enabled these |
39 // errors can be viewed at chrome://extensions in developer mode. | 39 // errors can be viewed at chrome://extensions in developer mode. |
40 // This class is owned by ExtensionSystem, making it, in effect, a | 40 // This class is owned by ExtensionSystem, making it, in effect, a |
41 // BrowserContext-keyed service. | 41 // BrowserContext-keyed service. |
42 class ErrorConsole : public content::NotificationObserver, | 42 class ErrorConsole : public content::NotificationObserver, |
43 public ExtensionRegistryObserver { | 43 public ExtensionRegistryObserver { |
44 public: | 44 public: |
(...skipping 13 matching lines...) Expand all Loading... |
58 // Convenience method to return the ErrorConsole for a given profile. | 58 // Convenience method to return the ErrorConsole for a given profile. |
59 static ErrorConsole* Get(Profile* profile); | 59 static ErrorConsole* Get(Profile* profile); |
60 | 60 |
61 // Set whether or not errors of the specified |type| are stored for the | 61 // Set whether or not errors of the specified |type| are stored for the |
62 // extension with the given |extension_id|. This will be stored in the | 62 // extension with the given |extension_id|. This will be stored in the |
63 // preferences. | 63 // preferences. |
64 void SetReportingForExtension(const std::string& extension_id, | 64 void SetReportingForExtension(const std::string& extension_id, |
65 ExtensionError::Type type, | 65 ExtensionError::Type type, |
66 bool enabled); | 66 bool enabled); |
67 | 67 |
| 68 // Set whether or not errors of all types are stored for the extension with |
| 69 // the given |extension_id|. |
| 70 void SetReportingAllForExtension(const std::string& extension_id, |
| 71 bool enabled); |
| 72 |
| 73 // Returns true if reporting for either manifest or runtime errors is enabled |
| 74 // for the extension with the given |extension_id|. |
| 75 bool IsReportingEnabledForExtension(const std::string& extension_id) const; |
| 76 |
68 // Restore default reporting to the given extension. | 77 // Restore default reporting to the given extension. |
69 void UseDefaultReportingForExtension(const std::string& extension_id); | 78 void UseDefaultReportingForExtension(const std::string& extension_id); |
70 | 79 |
71 // Report an extension error, and add it to the list. | 80 // Report an extension error, and add it to the list. |
72 void ReportError(scoped_ptr<ExtensionError> error); | 81 void ReportError(scoped_ptr<ExtensionError> error); |
73 | 82 |
74 // Get a collection of weak pointers to all errors relating to the extension | 83 // Get a collection of weak pointers to all errors relating to the extension |
75 // with the given |extension_id|. | 84 // with the given |extension_id|. |
76 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; | 85 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; |
77 | 86 |
(...skipping 17 matching lines...) Expand all Loading... |
95 // Return the number of entries (extensions) in the error map. | 104 // Return the number of entries (extensions) in the error map. |
96 size_t get_num_entries_for_test() const { return errors_.size(); } | 105 size_t get_num_entries_for_test() const { return errors_.size(); } |
97 | 106 |
98 // Set the default reporting for all extensions. | 107 // Set the default reporting for all extensions. |
99 void set_default_reporting_for_test(ExtensionError::Type type, bool enabled) { | 108 void set_default_reporting_for_test(ExtensionError::Type type, bool enabled) { |
100 default_mask_ = | 109 default_mask_ = |
101 enabled ? default_mask_ | (1 << type) : default_mask_ & ~(1 << type); | 110 enabled ? default_mask_ | (1 << type) : default_mask_ & ~(1 << type); |
102 } | 111 } |
103 | 112 |
104 private: | 113 private: |
105 // A map which stores the reporting preferences for each Extension. If there | |
106 // is no entry in the map, it signals that the |default_mask_| should be used. | |
107 typedef std::map<std::string, int32> ErrorPreferenceMap; | |
108 | |
109 // Checks whether or not the ErrorConsole should be enabled or disabled. If it | 114 // Checks whether or not the ErrorConsole should be enabled or disabled. If it |
110 // is in the wrong state, enables or disables it appropriately. | 115 // is in the wrong state, enables or disables it appropriately. |
111 void CheckEnabled(); | 116 void CheckEnabled(); |
112 | 117 |
113 // Enable the error console for error collection and retention. This involves | 118 // Enable the error console for error collection and retention. This involves |
114 // subscribing to the appropriate notifications and fetching manifest errors. | 119 // subscribing to the appropriate notifications and fetching manifest errors. |
115 void Enable(); | 120 void Enable(); |
116 | 121 |
117 // Disable the error console, removing the subscriptions to notifications and | 122 // Disable the error console, removing the subscriptions to notifications and |
118 // removing all current errors. | 123 // removing all current errors. |
(...skipping 12 matching lines...) Expand all Loading... |
131 const Extension* extension) OVERRIDE; | 136 const Extension* extension) OVERRIDE; |
132 | 137 |
133 // Add manifest errors from an extension's install warnings. | 138 // Add manifest errors from an extension's install warnings. |
134 void AddManifestErrorsForExtension(const Extension* extension); | 139 void AddManifestErrorsForExtension(const Extension* extension); |
135 | 140 |
136 // content::NotificationObserver implementation. | 141 // content::NotificationObserver implementation. |
137 virtual void Observe(int type, | 142 virtual void Observe(int type, |
138 const content::NotificationSource& source, | 143 const content::NotificationSource& source, |
139 const content::NotificationDetails& details) OVERRIDE; | 144 const content::NotificationDetails& details) OVERRIDE; |
140 | 145 |
| 146 // Returns true if we should report the error of the given type for the |
| 147 // extension. |
| 148 bool ShouldReportErrorForExtension(const std::string& extension_id, |
| 149 ExtensionError::Type type) const; |
| 150 |
141 // Whether or not the error console should record errors. This is true if | 151 // Whether or not the error console should record errors. This is true if |
142 // the user is in developer mode, and at least one of the following is true: | 152 // the user is in developer mode, and at least one of the following is true: |
143 // - The Chrome Apps Developer Tools are installed. | 153 // - The Chrome Apps Developer Tools are installed. |
144 // - FeatureSwitch::error_console() is enabled. | 154 // - FeatureSwitch::error_console() is enabled. |
145 // - This is a Dev Channel release. | 155 // - This is a Dev Channel release. |
146 bool enabled_; | 156 bool enabled_; |
147 | 157 |
148 // Needed because ObserverList is not thread-safe. | 158 // Needed because ObserverList is not thread-safe. |
149 base::ThreadChecker thread_checker_; | 159 base::ThreadChecker thread_checker_; |
150 | 160 |
151 // The list of all observers for the ErrorConsole. | 161 // The list of all observers for the ErrorConsole. |
152 ObserverList<Observer> observers_; | 162 ObserverList<Observer> observers_; |
153 | 163 |
154 // The errors which we have received so far. | 164 // The errors which we have received so far. |
155 ErrorMap errors_; | 165 ErrorMap errors_; |
156 | 166 |
157 // The mapping of Extension's error-reporting preferences. | |
158 ErrorPreferenceMap pref_map_; | |
159 | |
160 // The default mask to use if an Extension does not have specific settings. | 167 // The default mask to use if an Extension does not have specific settings. |
161 int32 default_mask_; | 168 int32 default_mask_; |
162 | 169 |
163 // The profile with which the ErrorConsole is associated. Only collect errors | 170 // The profile with which the ErrorConsole is associated. Only collect errors |
164 // from extensions and RenderViews associated with this Profile (and it's | 171 // from extensions and RenderViews associated with this Profile (and it's |
165 // incognito fellow). | 172 // incognito fellow). |
166 Profile* profile_; | 173 Profile* profile_; |
167 | 174 |
| 175 // The ExtensionPrefs with which the ErrorConsole is associated. This weak |
| 176 // pointer is safe because ErrorConsole is owned by ExtensionSystem, which |
| 177 // is dependent on ExtensionPrefs. |
| 178 ExtensionPrefs* prefs_; |
| 179 |
168 content::NotificationRegistrar notification_registrar_; | 180 content::NotificationRegistrar notification_registrar_; |
169 PrefChangeRegistrar pref_registrar_; | 181 PrefChangeRegistrar pref_registrar_; |
170 | 182 |
171 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 183 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
172 registry_observer_; | 184 registry_observer_; |
173 | 185 |
174 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); | 186 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); |
175 }; | 187 }; |
176 | 188 |
177 } // namespace extensions | 189 } // namespace extensions |
178 | 190 |
179 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 191 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
OLD | NEW |