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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
11 #include "base/observer_list.h"
12 #include "base/strings/string16.h"
23 // Exposes an easy way for the various components of the extension system to
24 // report errors. This is a singleton that lives on the UI thread, with the
25 // exception of ReportError() which may be called from any thread.
26 // TODO(aa): Hook this up to about:extensions, when we have about:extensions.
27 // TODO(aa): Consider exposing directly, or via a helper, to the renderer
28 // process and plumbing the errors out to the browser.
29 // TODO(aa): Add ReportError(extension_id, message, be_noisy), so that we can
30 // report errors that are specific to a particular extension.
31 class ExtensionErrorReporter
{
35 virtual ~Observer() {}
37 // Called when an unpacked extension fails to load.
38 virtual void OnLoadFailure(content::BrowserContext
* browser_context
,
39 const base::FilePath
& extension_path
,
40 const std::string
& error
) = 0;
43 // Initializes the error reporter. Must be called before any other methods
44 // and on the UI thread.
45 static void Init(bool enable_noisy_errors
);
47 // Get the singleton instance.
48 static ExtensionErrorReporter
* GetInstance();
50 // Report an extension load error. This forwards to ReportError() after
51 // sending an EXTENSION_LOAD_ERROR notification.
52 // TODO(rdevlin.cronin): There's a lot wrong with this. But some of our
53 // systems rely on the notification. Investigate what it will take to remove
54 // the notification and this method.
55 void ReportLoadError(const base::FilePath
& extension_path
,
56 const std::string
& error
,
57 content::BrowserContext
* browser_context
,
60 // Report an error. Errors always go to VLOG(1). Optionally, they can also
61 // cause a noisy alert box.
62 void ReportError(const base::string16
& message
, bool be_noisy
);
64 // Get the errors that have been reported so far.
65 const std::vector
<base::string16
>* GetErrors();
67 // Clear the list of errors reported so far.
70 void AddObserver(Observer
* observer
);
72 void RemoveObserver(Observer
* observer
);
75 static ExtensionErrorReporter
* instance_
;
77 explicit ExtensionErrorReporter(bool enable_noisy_errors
);
78 ~ExtensionErrorReporter();
80 base::MessageLoop
* ui_loop_
;
81 std::vector
<base::string16
> errors_
;
82 bool enable_noisy_errors_
;
84 base::ObserverList
<Observer
> observers_
;
87 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_