1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/extension_error_reporter.h"
7 #include "build/build_config.h"
10 #include "base/bind_helpers.h"
11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/ui/simple_message_box.h"
16 ExtensionErrorReporter
* ExtensionErrorReporter::instance_
= NULL
;
19 void ExtensionErrorReporter::Init(bool enable_noisy_errors
) {
21 instance_
= new ExtensionErrorReporter(enable_noisy_errors
);
26 ExtensionErrorReporter
* ExtensionErrorReporter::GetInstance() {
27 CHECK(instance_
) << "Init() was never called";
31 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors
)
32 : ui_loop_(base::MessageLoop::current()),
33 enable_noisy_errors_(enable_noisy_errors
) {
36 ExtensionErrorReporter::~ExtensionErrorReporter() {}
38 void ExtensionErrorReporter::ReportError(const string16
& message
,
40 // NOTE: There won't be a ui_loop_ in the unit test environment.
41 if (ui_loop_
&& base::MessageLoop::current() != ui_loop_
) {
42 // base::Unretained is okay since the ExtensionErrorReporter is a singleton
43 // that lives until the end of the process.
44 ui_loop_
->PostTask(FROM_HERE
,
45 base::Bind(&ExtensionErrorReporter::ReportError
,
46 base::Unretained(this),
52 errors_
.push_back(message
);
54 // TODO(aa): Print the error message out somewhere better. I think we are
55 // going to need some sort of 'extension inspector'.
56 LOG(WARNING
) << "Extension error: " << message
;
58 if (enable_noisy_errors_
&& be_noisy
) {
59 chrome::ShowMessageBox(NULL
, ASCIIToUTF16("Extension error"), message
,
60 chrome::MESSAGE_BOX_TYPE_WARNING
);
64 const std::vector
<string16
>* ExtensionErrorReporter::GetErrors() {
68 void ExtensionErrorReporter::ClearErrors() {