• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006-2009 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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
7 #pragma once
8 
9 #include <string>
10 #include <vector>
11 
12 class MessageLoop;
13 
14 // Exposes an easy way for the various components of the extension system to
15 // report errors. This is a singleton that lives on the UI thread, with the
16 // exception of ReportError() which may be called from any thread.
17 // TODO(aa): Hook this up to about:extensions, when we have about:extensions.
18 // TODO(aa): Consider exposing directly, or via a helper, to the renderer
19 // process and plumbing the errors out to the browser.
20 // TODO(aa): Add ReportError(extension_id, message, be_noisy), so that we can
21 // report errors that are specific to a particular extension.
22 class ExtensionErrorReporter {
23  public:
24   // Initializes the error reporter. Must be called before any other methods
25   // and on the UI thread.
26   static void Init(bool enable_noisy_errors);
27 
28   // Get the singleton instance.
29   static ExtensionErrorReporter* GetInstance();
30 
31   // Report an error. Errors always go to VLOG(1). Optionally, they can also
32   // cause a noisy alert box. This method can be called from any thread.
33   void ReportError(const std::string& message, bool be_noisy);
34 
35   // Get the errors that have been reported so far.
36   const std::vector<std::string>* GetErrors();
37 
38   // Clear the list of errors reported so far.
39   void ClearErrors();
40 
41  private:
42   static ExtensionErrorReporter* instance_;
43 
44   explicit ExtensionErrorReporter(bool enable_noisy_errors);
45   ~ExtensionErrorReporter();
46 
47   MessageLoop* ui_loop_;
48   std::vector<std::string> errors_;
49   bool enable_noisy_errors_;
50 };
51 
52 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_REPORTER_H_
53