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

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

Issue 342003005: Show alert failure for reloading unpacked extensions with bad manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed be_noisy, support interaction with multiple failures Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_EXTENSION_ERROR_REPORTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/observer_list.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
12 13
13 namespace base { 14 namespace base {
14 class MessageLoop; 15 class MessageLoop;
15 class FilePath; 16 class FilePath;
16 } 17 }
17 18
18 class Profile; 19 class Profile;
19 20
20 // Exposes an easy way for the various components of the extension system to 21 // Exposes an easy way for the various components of the extension system to
21 // report errors. This is a singleton that lives on the UI thread, with the 22 // report errors. This is a singleton that lives on the UI thread, with the
22 // exception of ReportError() which may be called from any thread. 23 // exception of ReportError() which may be called from any thread.
23 // TODO(aa): Hook this up to about:extensions, when we have about:extensions. 24 // TODO(aa): Hook this up to about:extensions, when we have about:extensions.
24 // TODO(aa): Consider exposing directly, or via a helper, to the renderer 25 // TODO(aa): Consider exposing directly, or via a helper, to the renderer
25 // process and plumbing the errors out to the browser. 26 // process and plumbing the errors out to the browser.
26 // TODO(aa): Add ReportError(extension_id, message, be_noisy), so that we can 27 // TODO(aa): Add ReportError(extension_id, message, be_noisy), so that we can
27 // report errors that are specific to a particular extension. 28 // report errors that are specific to a particular extension.
28 class ExtensionErrorReporter { 29 class ExtensionErrorReporter {
29 public: 30 public:
31 class Observer {
32 public:
33 virtual ~Observer() {}
34
35 // Called when an unpacked extension fails to load.
36 virtual void OnLoadFailure(const base::FilePath& extension_path,
37 const std::string& error) = 0;
38 };
39
30 // Initializes the error reporter. Must be called before any other methods 40 // Initializes the error reporter. Must be called before any other methods
31 // and on the UI thread. 41 // and on the UI thread.
32 static void Init(bool enable_noisy_errors); 42 static void Init(bool enable_noisy_errors);
33 43
34 // Get the singleton instance. 44 // Get the singleton instance.
35 static ExtensionErrorReporter* GetInstance(); 45 static ExtensionErrorReporter* GetInstance();
36 46
37 // Report an extension load error. This forwards to ReportError() after 47 // Report an extension load error. This forwards to ReportError() after
38 // sending an EXTENSION_LOAD_ERROR notification. 48 // sending an EXTENSION_LOAD_ERROR notification.
39 // TODO(rdevlin.cronin): There's a lot wrong with this. But some of our 49 // TODO(rdevlin.cronin): There's a lot wrong with this. But some of our
40 // systems rely on the notification. Investigate what it will take to remove 50 // systems rely on the notification. Investigate what it will take to remove
41 // the notification and this method. 51 // the notification and this method.
42 void ReportLoadError(const base::FilePath& extension_path, 52 void ReportLoadError(const base::FilePath& extension_path,
43 const std::string& error, 53 const std::string& error,
44 Profile* profile, 54 Profile* profile,
45 bool be_noisy); 55 bool be_noisy);
46 56
47 // Report an error. Errors always go to VLOG(1). Optionally, they can also 57 // Report an error. Errors always go to VLOG(1). Optionally, they can also
48 // cause a noisy alert box. 58 // cause a noisy alert box.
49 void ReportError(const base::string16& message, bool be_noisy); 59 void ReportError(const base::string16& message, bool be_noisy);
50 60
51 // Get the errors that have been reported so far. 61 // Get the errors that have been reported so far.
52 const std::vector<base::string16>* GetErrors(); 62 const std::vector<base::string16>* GetErrors();
53 63
54 // Clear the list of errors reported so far. 64 // Clear the list of errors reported so far.
55 void ClearErrors(); 65 void ClearErrors();
56 66
67 void AddObserver(Observer* observer);
68 void RemoveObserver(Observer* observer);
69
57 private: 70 private:
58 static ExtensionErrorReporter* instance_; 71 static ExtensionErrorReporter* instance_;
59 72
60 explicit ExtensionErrorReporter(bool enable_noisy_errors); 73 explicit ExtensionErrorReporter(bool enable_noisy_errors);
61 ~ExtensionErrorReporter(); 74 ~ExtensionErrorReporter();
62 75
63 base::MessageLoop* ui_loop_; 76 base::MessageLoop* ui_loop_;
64 std::vector<base::string16> errors_; 77 std::vector<base::string16> errors_;
65 bool enable_noisy_errors_; 78 bool enable_noisy_errors_;
79
80 ObserverList<Observer> observers_;
66 }; 81 };
67 82
68 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_ 83 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698