Chromium Code Reviews| 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 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/prefs/pref_change_registrar.h" | 14 #include "base/prefs/pref_change_registrar.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "extensions/browser/error_map.h" | 19 #include "extensions/browser/error_map.h" |
| 20 #include "extensions/browser/extension_error.h" | 20 #include "extensions/browser/extension_error.h" |
| 21 #include "extensions/browser/extension_registry_observer.h" | |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class NotificationDetails; | 24 class NotificationDetails; |
| 24 class NotificationSource; | 25 class NotificationSource; |
| 25 class RenderViewHost; | 26 class RenderViewHost; |
| 26 } | 27 } |
| 27 | 28 |
| 28 class ExtensionService; | 29 class ExtensionService; |
| 29 class Profile; | 30 class Profile; |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 class ErrorConsoleUnitTest; | 33 class ErrorConsoleUnitTest; |
| 33 class Extension; | 34 class Extension; |
| 34 | 35 |
| 35 // 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 |
| 36 // reported. This includes errors detected in extensions core, as well as | 37 // reported. This includes errors detected in extensions core, as well as |
| 37 // runtime Javascript errors. If FeatureSwitch::error_console() is enabled these | 38 // runtime Javascript errors. If FeatureSwitch::error_console() is enabled these |
| 38 // errors can be viewed at chrome://extensions in developer mode. | 39 // errors can be viewed at chrome://extensions in developer mode. |
| 39 // This class is owned by ExtensionSystem, making it, in effect, a | 40 // This class is owned by ExtensionSystem, making it, in effect, a |
| 40 // BrowserContext-keyed service. | 41 // BrowserContext-keyed service. |
| 41 class ErrorConsole : public content::NotificationObserver { | 42 class ErrorConsole : public content::NotificationObserver, |
| 43 public ExtensionRegistryObserver { | |
| 42 public: | 44 public: |
| 43 class Observer { | 45 class Observer { |
| 44 public: | 46 public: |
| 45 // Sent when a new error is reported to the error console. | 47 // Sent when a new error is reported to the error console. |
| 46 virtual void OnErrorAdded(const ExtensionError* error) = 0; | 48 virtual void OnErrorAdded(const ExtensionError* error) = 0; |
| 47 | 49 |
| 48 // Sent upon destruction to allow any observers to invalidate any references | 50 // Sent upon destruction to allow any observers to invalidate any references |
| 49 // they have to the error console. | 51 // they have to the error console. |
| 50 virtual void OnErrorConsoleDestroyed(); | 52 virtual void OnErrorConsoleDestroyed(); |
| 51 }; | 53 }; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 71 | 73 |
| 72 // Get a collection of weak pointers to all errors relating to the extension | 74 // Get a collection of weak pointers to all errors relating to the extension |
| 73 // with the given |extension_id|. | 75 // with the given |extension_id|. |
| 74 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; | 76 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; |
| 75 | 77 |
| 76 // Add or remove observers of the ErrorConsole to be notified of any errors | 78 // Add or remove observers of the ErrorConsole to be notified of any errors |
| 77 // added. | 79 // added. |
| 78 void AddObserver(Observer* observer); | 80 void AddObserver(Observer* observer); |
| 79 void RemoveObserver(Observer* observer); | 81 void RemoveObserver(Observer* observer); |
| 80 | 82 |
| 81 bool enabled() const { return enabled_; } | 83 // Returns whether or not the ErrorConsole is enabled for the |
| 84 // chrome:extensions page or the Chrome Apps Developer Tools. | |
|
not at google - send to devlin
2014/03/31 18:52:43
nit: put a blank line here (with a //) to make it
Devlin
2014/03/31 21:18:24
Done.
| |
| 85 // TODO(rdevlin.cronin): These have different answers - ErrorConsole is | |
| 86 // enabled by default in ADT, but only Dev Channel for chrome:extensions (or | |
| 87 // with the commandline switch). Once we do a full launch, clean all this up. | |
| 88 bool IsEnabledForChromeExtensionsPage() const; | |
| 89 bool IsEnabledForAppsDeveloperTools() const; | |
| 82 | 90 |
| 83 // Return the number of entries (extensions) in the error map. | 91 // Return the number of entries (extensions) in the error map. |
| 84 size_t get_num_entries_for_test() const { return errors_.size(); } | 92 size_t get_num_entries_for_test() const { return errors_.size(); } |
| 85 | 93 |
| 86 // Set the default reporting for all extensions. | 94 // Set the default reporting for all extensions. |
| 87 void set_default_reporting_for_test(ExtensionError::Type type, bool enabled) { | 95 void set_default_reporting_for_test(ExtensionError::Type type, bool enabled) { |
| 88 default_mask_ = | 96 default_mask_ = |
| 89 enabled ? default_mask_ | (1 << type) : default_mask_ & ~(1 << type); | 97 enabled ? default_mask_ | (1 << type) : default_mask_ & ~(1 << type); |
| 90 } | 98 } |
| 91 | 99 |
| 92 private: | 100 private: |
| 93 // A map which stores the reporting preferences for each Extension. If there | 101 // A map which stores the reporting preferences for each Extension. If there |
| 94 // is no entry in the map, it signals that the |default_mask_| should be used. | 102 // is no entry in the map, it signals that the |default_mask_| should be used. |
| 95 typedef std::map<std::string, int32> ErrorPreferenceMap; | 103 typedef std::map<std::string, int32> ErrorPreferenceMap; |
| 96 | 104 |
| 105 // Checks whether or not the ErrorConsole should be enabled or disabled. If it | |
| 106 // is in the wrong state, enables or disables it appropriately. | |
| 107 void CheckEnabled(); | |
| 108 | |
| 97 // Enable the error console for error collection and retention. This involves | 109 // Enable the error console for error collection and retention. This involves |
| 98 // subscribing to the appropriate notifications and fetching manifest errors. | 110 // subscribing to the appropriate notifications and fetching manifest errors. |
| 99 void Enable(ExtensionService* extension_service); | 111 void Enable(ExtensionService* extension_service); |
| 100 | 112 |
| 101 // Disable the error console, removing the subscriptions to notifications and | 113 // Disable the error console, removing the subscriptions to notifications and |
| 102 // removing all current errors. | 114 // removing all current errors. |
| 103 void Disable(); | 115 void Disable(); |
| 104 | 116 |
| 105 // Called when the Developer Mode preference is changed; this is important | 117 // Called when the Developer Mode preference is changed; this is important |
| 106 // since we use this as a heuristic to determine if the console is enabled or | 118 // since we use this as a heuristic to determine if the console is enabled or |
| 107 // not. | 119 // not. |
| 108 void OnPrefChanged(); | 120 void OnPrefChanged(); |
| 109 | 121 |
| 122 // ExtensionRegistry implementation. If the Apps Developer Tools app is | |
| 123 // installed or uninstalled, we may need to turn the ErrorConsole on/off. | |
| 124 virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE; | |
| 125 virtual void OnExtensionLoaded(const Extension* extension) OVERRIDE; | |
| 126 | |
| 110 // Add manifest errors from an extension's install warnings. | 127 // Add manifest errors from an extension's install warnings. |
| 111 void AddManifestErrorsForExtension(const Extension* extension); | 128 void AddManifestErrorsForExtension(const Extension* extension); |
| 112 | 129 |
| 113 // content::NotificationObserver implementation. | 130 // content::NotificationObserver implementation. |
| 114 virtual void Observe(int type, | 131 virtual void Observe(int type, |
| 115 const content::NotificationSource& source, | 132 const content::NotificationSource& source, |
| 116 const content::NotificationDetails& details) OVERRIDE; | 133 const content::NotificationDetails& details) OVERRIDE; |
| 117 | 134 |
| 118 // Whether or not the error console is enabled; it is enabled if the | 135 // Whether or not the error console should record errors. This is true if |
| 119 // FeatureSwitch (FeatureSwitch::error_console) is enabled and the user is | 136 // the user is in developer mode, and at least one of the following is true: |
| 120 // in Developer Mode. | 137 // - The Chrome Apps Developer Tools are installed. |
| 138 // - FeatureSwitch::error_console() is enabled. | |
| 139 // - This is a Dev Channel release. | |
| 121 bool enabled_; | 140 bool enabled_; |
| 122 | 141 |
| 123 // Needed because ObserverList is not thread-safe. | 142 // Needed because ObserverList is not thread-safe. |
| 124 base::ThreadChecker thread_checker_; | 143 base::ThreadChecker thread_checker_; |
| 125 | 144 |
| 126 // The list of all observers for the ErrorConsole. | 145 // The list of all observers for the ErrorConsole. |
| 127 ObserverList<Observer> observers_; | 146 ObserverList<Observer> observers_; |
| 128 | 147 |
| 129 // The errors which we have received so far. | 148 // The errors which we have received so far. |
| 130 ErrorMap errors_; | 149 ErrorMap errors_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 142 | 161 |
| 143 content::NotificationRegistrar notification_registrar_; | 162 content::NotificationRegistrar notification_registrar_; |
| 144 PrefChangeRegistrar pref_registrar_; | 163 PrefChangeRegistrar pref_registrar_; |
| 145 | 164 |
| 146 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); | 165 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); |
| 147 }; | 166 }; |
| 148 | 167 |
| 149 } // namespace extensions | 168 } // namespace extensions |
| 150 | 169 |
| 151 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 170 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
| OLD | NEW |