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

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

Issue 22647007: Resubmit 21609003: Move ExtensionError to extensions/, add error limits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 7 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/extensions/error_console/error_console.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 <vector> 8 #include <deque>
9 #include <map>
9 10
10 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/extension_error.h"
18 19
19 namespace content { 20 namespace content {
20 class NotificationDetails; 21 class NotificationDetails;
21 class NotificationSource; 22 class NotificationSource;
22 class RenderViewHost; 23 class RenderViewHost;
23 } 24 }
24 25
25 class Profile; 26 class Profile;
26 27
27 namespace extensions { 28 namespace extensions {
28 class ErrorConsoleUnitTest; 29 class ErrorConsoleUnitTest;
29 class ExtensionError;
30 30
31 // The ErrorConsole is a central object to which all extension errors are 31 // The ErrorConsole is a central object to which all extension errors are
32 // reported. This includes errors detected in extensions core, as well as 32 // reported. This includes errors detected in extensions core, as well as
33 // runtime Javascript errors. 33 // runtime Javascript errors.
34 // This class is owned by ExtensionSystem, making it, in effect, a 34 // This class is owned by ExtensionSystem, making it, in effect, a
35 // BrowserContext-keyed service. 35 // BrowserContext-keyed service.
36 class ErrorConsole : content::NotificationObserver { 36 class ErrorConsole : public content::NotificationObserver {
37 public: 37 public:
38 typedef ScopedVector<ExtensionError> ErrorList; 38 typedef std::deque<const ExtensionError*> ErrorList;
39 typedef std::vector<const ExtensionError*> WeakErrorList; 39 typedef std::map<std::string, ErrorList> ErrorMap;
40 40
41 class Observer { 41 class Observer {
42 public: 42 public:
43 // Sent when a new error is reported to the error console. 43 // Sent when a new error is reported to the error console.
44 virtual void OnErrorAdded(const ExtensionError* error) = 0; 44 virtual void OnErrorAdded(const ExtensionError* error) = 0;
45 45
46 // Sent upon destruction to allow any observers to invalidate any references 46 // Sent upon destruction to allow any observers to invalidate any references
47 // they have to the error console. 47 // they have to the error console.
48 virtual void OnErrorConsoleDestroyed(); 48 virtual void OnErrorConsoleDestroyed();
49 }; 49 };
50 50
51 explicit ErrorConsole(Profile* profile); 51 explicit ErrorConsole(Profile* profile);
52 virtual ~ErrorConsole(); 52 virtual ~ErrorConsole();
53 53
54 // Convenience method to return the ErrorConsole for a given profile. 54 // Convenience method to return the ErrorConsole for a given profile.
55 static ErrorConsole* Get(Profile* profile); 55 static ErrorConsole* Get(Profile* profile);
56 56
57 // Report an extension error, and add it to the list. 57 // Report an extension error, and add it to the list.
58 void ReportError(scoped_ptr<ExtensionError> error); 58 void ReportError(scoped_ptr<const ExtensionError> error);
59 59
60 // Get a collection of weak pointers to all errors relating to the extension 60 // Get a collection of weak pointers to all errors relating to the extension
61 // with the given |extension_id|. 61 // with the given |extension_id|.
62 WeakErrorList GetErrorsForExtension(const std::string& extension_id) const; 62 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const;
63
64 // Remove an error from the list of observed errors.
65 void RemoveError(const ExtensionError* error);
66
67 // Remove all errors from the list of observed errors.
68 void RemoveAllErrors();
69 63
70 // Add or remove observers of the ErrorConsole to be notified of any errors 64 // Add or remove observers of the ErrorConsole to be notified of any errors
71 // added. 65 // added.
72 void AddObserver(Observer* observer); 66 void AddObserver(Observer* observer);
73 void RemoveObserver(Observer* observer); 67 void RemoveObserver(Observer* observer);
74 68
75 const ErrorList& errors() { return errors_; } 69 const ErrorMap& errors() { return errors_; }
76 70
77 private: 71 private:
78 FRIEND_TEST_ALL_PREFIXES(ErrorConsoleUnitTest, AddAndRemoveErrors); 72 FRIEND_TEST_ALL_PREFIXES(ErrorConsoleUnitTest, AddAndRemoveErrors);
79 73
80 // Remove all errors which happened while incognito; we have to do this once 74 // Remove all errors which happened while incognito; we have to do this once
81 // the incognito profile is destroyed. 75 // the incognito profile is destroyed.
82 void RemoveIncognitoErrors(); 76 void RemoveIncognitoErrors();
83 77
78 // Remove all errors relating to a particular |extension_id|.
79 void RemoveErrorsForExtension(const std::string& extension_id);
80
81 // Remove all errors for all extensions.
82 void RemoveAllErrors();
83
84 // content::NotificationObserver implementation. 84 // content::NotificationObserver implementation.
85 virtual void Observe(int type, 85 virtual void Observe(int type,
86 const content::NotificationSource& source, 86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) OVERRIDE; 87 const content::NotificationDetails& details) OVERRIDE;
88 88
89 // Needed because ObserverList is not thread-safe. 89 // Needed because ObserverList is not thread-safe.
90 base::ThreadChecker thread_checker_; 90 base::ThreadChecker thread_checker_;
91 91
92 // The list of all observers for the ErrorConsole. 92 // The list of all observers for the ErrorConsole.
93 ObserverList<Observer> observers_; 93 ObserverList<Observer> observers_;
94 94
95 // The errors which we have received so far. 95 // The errors which we have received so far.
96 ErrorList errors_; 96 ErrorMap errors_;
97 97
98 // The profile with which the ErrorConsole is associated. Only collect errors 98 // The profile with which the ErrorConsole is associated. Only collect errors
99 // from extensions and RenderViews associated with this Profile (and it's 99 // from extensions and RenderViews associated with this Profile (and it's
100 // incognito fellow). 100 // incognito fellow).
101 Profile* profile_; 101 Profile* profile_;
102 102
103 content::NotificationRegistrar registrar_; 103 content::NotificationRegistrar registrar_;
104 104
105 DISALLOW_COPY_AND_ASSIGN(ErrorConsole); 105 DISALLOW_COPY_AND_ASSIGN(ErrorConsole);
106 }; 106 };
107 107
108 } // namespace extensions 108 } // namespace extensions
109 109
110 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_ 110 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_ERROR_CONSOLE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/error_console/error_console.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698