OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/extensions/extension_error_reporter.h" | 5 #include "chrome/browser/extensions/extension_error_reporter.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 // static | 25 // static |
26 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { | 26 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { |
27 CHECK(instance_) << "Init() was never called"; | 27 CHECK(instance_) << "Init() was never called"; |
28 return instance_; | 28 return instance_; |
29 } | 29 } |
30 | 30 |
31 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) | 31 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) |
32 : ui_loop_(MessageLoop::current()), | 32 : ui_loop_(base::MessageLoop::current()), |
33 enable_noisy_errors_(enable_noisy_errors) { | 33 enable_noisy_errors_(enable_noisy_errors) {} |
34 } | |
35 | 34 |
36 ExtensionErrorReporter::~ExtensionErrorReporter() {} | 35 ExtensionErrorReporter::~ExtensionErrorReporter() {} |
37 | 36 |
38 void ExtensionErrorReporter::ReportError(const string16& message, | 37 void ExtensionErrorReporter::ReportError(const string16& message, |
39 bool be_noisy) { | 38 bool be_noisy) { |
40 // NOTE: There won't be a ui_loop_ in the unit test environment. | 39 // NOTE: There won't be a ui_loop_ in the unit test environment. |
41 if (ui_loop_ && MessageLoop::current() != ui_loop_) { | 40 if (ui_loop_ && base::MessageLoop::current() != ui_loop_) { |
42 // base::Unretained is okay since the ExtensionErrorReporter is a singleton | 41 // base::Unretained is okay since the ExtensionErrorReporter is a singleton |
43 // that lives until the end of the process. | 42 // that lives until the end of the process. |
44 ui_loop_->PostTask(FROM_HERE, | 43 ui_loop_->PostTask(FROM_HERE, |
45 base::Bind(&ExtensionErrorReporter::ReportError, | 44 base::Bind(&ExtensionErrorReporter::ReportError, |
46 base::Unretained(this), | 45 base::Unretained(this), |
47 message, | 46 message, |
48 be_noisy)); | 47 be_noisy)); |
49 return; | 48 return; |
50 } | 49 } |
51 | 50 |
52 errors_.push_back(message); | 51 errors_.push_back(message); |
53 | 52 |
54 // TODO(aa): Print the error message out somewhere better. I think we are | 53 // TODO(aa): Print the error message out somewhere better. I think we are |
55 // going to need some sort of 'extension inspector'. | 54 // going to need some sort of 'extension inspector'. |
56 LOG(ERROR) << "Extension error: " << message; | 55 LOG(ERROR) << "Extension error: " << message; |
57 | 56 |
58 if (enable_noisy_errors_ && be_noisy) { | 57 if (enable_noisy_errors_ && be_noisy) { |
59 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension error"), message, | 58 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension error"), message, |
60 chrome::MESSAGE_BOX_TYPE_WARNING); | 59 chrome::MESSAGE_BOX_TYPE_WARNING); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 const std::vector<string16>* ExtensionErrorReporter::GetErrors() { | 63 const std::vector<string16>* ExtensionErrorReporter::GetErrors() { |
65 return &errors_; | 64 return &errors_; |
66 } | 65 } |
67 | 66 |
68 void ExtensionErrorReporter::ClearErrors() { | 67 void ExtensionErrorReporter::ClearErrors() { |
69 errors_.clear(); | 68 errors_.clear(); |
70 } | 69 } |
OLD | NEW |