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/strings/string16.h" | 15 #include "base/strings/string16.h" |
15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "extensions/browser/extension_error.h" | 19 #include "extensions/browser/extension_error.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class NotificationDetails; | 22 class NotificationDetails; |
22 class NotificationSource; | 23 class NotificationSource; |
23 class RenderViewHost; | 24 class RenderViewHost; |
(...skipping 24 matching lines...) Expand all Loading... |
48 virtual void OnErrorConsoleDestroyed(); | 49 virtual void OnErrorConsoleDestroyed(); |
49 }; | 50 }; |
50 | 51 |
51 explicit ErrorConsole(Profile* profile); | 52 explicit ErrorConsole(Profile* profile); |
52 virtual ~ErrorConsole(); | 53 virtual ~ErrorConsole(); |
53 | 54 |
54 // Convenience method to return the ErrorConsole for a given profile. | 55 // Convenience method to return the ErrorConsole for a given profile. |
55 static ErrorConsole* Get(Profile* profile); | 56 static ErrorConsole* Get(Profile* profile); |
56 | 57 |
57 // Report an extension error, and add it to the list. | 58 // Report an extension error, and add it to the list. |
58 void ReportError(scoped_ptr<const ExtensionError> error); | 59 void ReportError(scoped_ptr<ExtensionError> error); |
59 | 60 |
60 // Get a collection of weak pointers to all errors relating to the extension | 61 // Get a collection of weak pointers to all errors relating to the extension |
61 // with the given |extension_id|. | 62 // with the given |extension_id|. |
62 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; | 63 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; |
63 | 64 |
64 // Add or remove observers of the ErrorConsole to be notified of any errors | 65 // Add or remove observers of the ErrorConsole to be notified of any errors |
65 // added. | 66 // added. |
66 void AddObserver(Observer* observer); | 67 void AddObserver(Observer* observer); |
67 void RemoveObserver(Observer* observer); | 68 void RemoveObserver(Observer* observer); |
68 | 69 |
69 const ErrorMap& errors() { return errors_; } | 70 const ErrorMap& errors() const { return errors_; } |
70 | 71 |
71 private: | 72 private: |
72 FRIEND_TEST_ALL_PREFIXES(ErrorConsoleUnitTest, AddAndRemoveErrors); | 73 FRIEND_TEST_ALL_PREFIXES(ErrorConsoleUnitTest, AddAndRemoveErrors); |
73 | 74 |
| 75 // Enable the error console for error collection and retention. |
| 76 void Enable(); |
| 77 // Disable the error console, removing the subscriptions to notifications and |
| 78 // removing all current errors. |
| 79 void Disable(); |
| 80 |
| 81 // Called when the Developer Mode preference is changed; this is important |
| 82 // since we use this as a heuristic to determine if the console is enabled or |
| 83 // not. |
| 84 void OnPrefChanged(); |
| 85 |
74 // Remove all errors which happened while incognito; we have to do this once | 86 // Remove all errors which happened while incognito; we have to do this once |
75 // the incognito profile is destroyed. | 87 // the incognito profile is destroyed. |
76 void RemoveIncognitoErrors(); | 88 void RemoveIncognitoErrors(); |
77 | 89 |
78 // Remove all errors relating to a particular |extension_id|. | 90 // Remove all errors relating to a particular |extension_id|. |
79 void RemoveErrorsForExtension(const std::string& extension_id); | 91 void RemoveErrorsForExtension(const std::string& extension_id); |
80 | 92 |
81 // Remove all errors for all extensions. | 93 // Remove all errors for all extensions. |
82 void RemoveAllErrors(); | 94 void RemoveAllErrors(); |
83 | 95 |
84 // content::NotificationObserver implementation. | 96 // content::NotificationObserver implementation. |
85 virtual void Observe(int type, | 97 virtual void Observe(int type, |
86 const content::NotificationSource& source, | 98 const content::NotificationSource& source, |
87 const content::NotificationDetails& details) OVERRIDE; | 99 const content::NotificationDetails& details) OVERRIDE; |
88 | 100 |
| 101 // Whether or not the error console is enabled; it is enabled if the |
| 102 // FeatureSwitch (FeatureSwitch::error_console) is enabled and the user is |
| 103 // in Developer Mode. |
| 104 bool enabled_; |
| 105 |
89 // Needed because ObserverList is not thread-safe. | 106 // Needed because ObserverList is not thread-safe. |
90 base::ThreadChecker thread_checker_; | 107 base::ThreadChecker thread_checker_; |
91 | 108 |
92 // The list of all observers for the ErrorConsole. | 109 // The list of all observers for the ErrorConsole. |
93 ObserverList<Observer> observers_; | 110 ObserverList<Observer> observers_; |
94 | 111 |
95 // The errors which we have received so far. | 112 // The errors which we have received so far. |
96 ErrorMap errors_; | 113 ErrorMap errors_; |
97 | 114 |
98 // The profile with which the ErrorConsole is associated. Only collect errors | 115 // The profile with which the ErrorConsole is associated. Only collect errors |
99 // from extensions and RenderViews associated with this Profile (and it's | 116 // from extensions and RenderViews associated with this Profile (and it's |
100 // incognito fellow). | 117 // incognito fellow). |
101 Profile* profile_; | 118 Profile* profile_; |
102 | 119 |
103 content::NotificationRegistrar registrar_; | 120 content::NotificationRegistrar notification_registrar_; |
| 121 PrefChangeRegistrar pref_registrar_; |
104 | 122 |
105 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); | 123 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); |
106 }; | 124 }; |
107 | 125 |
108 } // namespace extensions | 126 } // namespace extensions |
109 | 127 |
110 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ |
OLD | NEW |