| OLD | NEW |
| (Empty) |
| 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 #include "chrome/common/extensions/extension_error_reporter.h" | |
| 6 | |
| 7 #include "build/build_config.h" | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "chrome/common/platform_util.h" | |
| 13 | |
| 14 // No AddRef required when using ExtensionErrorReporter with RunnableMethod. | |
| 15 // This is okay since the ExtensionErrorReporter is a singleton that lives until | |
| 16 // the end of the process. | |
| 17 template <> struct RunnableMethodTraits<ExtensionErrorReporter> { | |
| 18 void RetainCallee(ExtensionErrorReporter*) {} | |
| 19 void ReleaseCallee(ExtensionErrorReporter*) {} | |
| 20 }; | |
| 21 | |
| 22 ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL; | |
| 23 | |
| 24 // static | |
| 25 void ExtensionErrorReporter::Init(bool enable_noisy_errors) { | |
| 26 if (!instance_) { | |
| 27 instance_ = new ExtensionErrorReporter(enable_noisy_errors); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { | |
| 33 CHECK(instance_) << "Init() was never called"; | |
| 34 return instance_; | |
| 35 } | |
| 36 | |
| 37 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) | |
| 38 : ui_loop_(MessageLoop::current()), | |
| 39 enable_noisy_errors_(enable_noisy_errors) { | |
| 40 } | |
| 41 | |
| 42 void ExtensionErrorReporter::ReportError(const std::string& message, | |
| 43 bool be_noisy) { | |
| 44 // NOTE: There won't be a ui_loop_ in the unit test environment. | |
| 45 if (ui_loop_ && MessageLoop::current() != ui_loop_) { | |
| 46 ui_loop_->PostTask(FROM_HERE, | |
| 47 NewRunnableMethod(this, &ExtensionErrorReporter::ReportError, message, | |
| 48 be_noisy)); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 errors_.push_back(message); | |
| 53 | |
| 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(ERROR) << "Extension error: " << message; | |
| 57 | |
| 58 if (enable_noisy_errors_ && be_noisy) { | |
| 59 platform_util::SimpleErrorBox(NULL, | |
| 60 UTF8ToUTF16("Extension error"), | |
| 61 UTF8ToUTF16(message)); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 const std::vector<std::string>* ExtensionErrorReporter::GetErrors() { | |
| 66 return &errors_; | |
| 67 } | |
| 68 | |
| 69 void ExtensionErrorReporter::ClearErrors() { | |
| 70 errors_.clear(); | |
| 71 } | |
| OLD | NEW |