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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 // Sets the extension preference for error reporting. |
| 147 void SetExtensionPref(const std::string& extension_id, int32 mask); |
| 148 |
| 149 // Returns true if we should report the error of the given type for the |
| 150 // extension. |
| 151 bool ShouldReportErrorForExtension(const std::string& extension_id, |
| 152 ExtensionError::Type type) const; |
| 153 |
141 // Whether or not the error console should record errors. This is true if | 154 // 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: | 155 // the user is in developer mode, and at least one of the following is true: |
143 // - The Chrome Apps Developer Tools are installed. | 156 // - The Chrome Apps Developer Tools are installed. |
144 // - FeatureSwitch::error_console() is enabled. | 157 // - FeatureSwitch::error_console() is enabled. |
145 // - This is a Dev Channel release. | 158 // - This is a Dev Channel release. |
146 bool enabled_; | 159 bool enabled_; |
147 | 160 |
148 // Needed because ObserverList is not thread-safe. | 161 // Needed because ObserverList is not thread-safe. |
149 base::ThreadChecker thread_checker_; | 162 base::ThreadChecker thread_checker_; |
150 | 163 |
151 // The list of all observers for the ErrorConsole. | 164 // The list of all observers for the ErrorConsole. |
152 ObserverList<Observer> observers_; | 165 ObserverList<Observer> observers_; |
153 | 166 |
154 // The errors which we have received so far. | 167 // The errors which we have received so far. |
155 ErrorMap errors_; | 168 ErrorMap errors_; |
156 | 169 |
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. | 170 // The default mask to use if an Extension does not have specific settings. |
161 int32 default_mask_; | 171 int32 default_mask_; |
162 | 172 |
163 // The profile with which the ErrorConsole is associated. Only collect errors | 173 // The profile with which the ErrorConsole is associated. Only collect errors |
164 // from extensions and RenderViews associated with this Profile (and it's | 174 // from extensions and RenderViews associated with this Profile (and it's |
165 // incognito fellow). | 175 // incognito fellow). |
166 Profile* profile_; | 176 Profile* profile_; |
167 | 177 |
168 content::NotificationRegistrar notification_registrar_; | 178 content::NotificationRegistrar notification_registrar_; |
169 PrefChangeRegistrar pref_registrar_; | 179 PrefChangeRegistrar pref_registrar_; |
170 | 180 |
171 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 181 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
172 registry_observer_; | 182 registry_observer_; |
173 | 183 |
174 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); | 184 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); |
175 }; | 185 }; |
176 | 186 |
177 } // namespace extensions | 187 } // namespace extensions |
178 | 188 |
179 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 189 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
OLD | NEW |