Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Side by Side Diff: chrome/browser/extensions/extension_error_reporter.cc

Issue 263643005: Move ExtensionService::ReportExtensionLoadError to ExtensionErrorReporter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/files/file_path.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/ui/simple_message_box.h" 17 #include "chrome/browser/ui/simple_message_box.h"
18 #include "content/public/browser/notification_service.h"
15 19
16 ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL; 20 ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL;
17 21
18 // static 22 // static
19 void ExtensionErrorReporter::Init(bool enable_noisy_errors) { 23 void ExtensionErrorReporter::Init(bool enable_noisy_errors) {
20 if (!instance_) { 24 if (!instance_) {
21 instance_ = new ExtensionErrorReporter(enable_noisy_errors); 25 instance_ = new ExtensionErrorReporter(enable_noisy_errors);
22 } 26 }
23 } 27 }
24 28
25 // static 29 // static
26 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { 30 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() {
27 CHECK(instance_) << "Init() was never called"; 31 CHECK(instance_) << "Init() was never called";
28 return instance_; 32 return instance_;
29 } 33 }
30 34
31 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) 35 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors)
32 : ui_loop_(base::MessageLoop::current()), 36 : ui_loop_(base::MessageLoop::current()),
33 enable_noisy_errors_(enable_noisy_errors) { 37 enable_noisy_errors_(enable_noisy_errors) {
34 } 38 }
35 39
36 ExtensionErrorReporter::~ExtensionErrorReporter() {} 40 ExtensionErrorReporter::~ExtensionErrorReporter() {}
37 41
42 void ExtensionErrorReporter::ReportLoadError(
43 const base::FilePath& extension_path,
44 const std::string& error,
45 Profile* profile,
46 bool be_noisy) {
47 content::NotificationService::current()->Notify(
48 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
49 content::Source<Profile>(profile),
50 content::Details<const std::string>(&error));
51
52 std::string path_str = base::UTF16ToUTF8(extension_path.LossyDisplayName());
53 base::string16 message = base::UTF8ToUTF16(
54 base::StringPrintf("Could not load extension from '%s'. %s",
55 path_str.c_str(),
56 error.c_str()));
57 ReportError(message, be_noisy);
58 }
59
38 void ExtensionErrorReporter::ReportError(const base::string16& message, 60 void ExtensionErrorReporter::ReportError(const base::string16& message,
39 bool be_noisy) { 61 bool be_noisy) {
40 // NOTE: There won't be a ui_loop_ in the unit test environment. 62 // NOTE: There won't be a ui_loop_ in the unit test environment.
41 if (ui_loop_) { 63 if (ui_loop_) {
42 CHECK(base::MessageLoop::current() == ui_loop_) 64 CHECK(base::MessageLoop::current() == ui_loop_)
43 << "ReportError can only be called from the UI thread."; 65 << "ReportError can only be called from the UI thread.";
44 } 66 }
45 67
46 errors_.push_back(message); 68 errors_.push_back(message);
47 69
48 // TODO(aa): Print the error message out somewhere better. I think we are 70 // TODO(aa): Print the error message out somewhere better. I think we are
49 // going to need some sort of 'extension inspector'. 71 // going to need some sort of 'extension inspector'.
50 LOG(WARNING) << "Extension error: " << message; 72 LOG(WARNING) << "Extension error: " << message;
51 73
52 if (enable_noisy_errors_ && be_noisy) { 74 if (enable_noisy_errors_ && be_noisy) {
53 chrome::ShowMessageBox(NULL, 75 chrome::ShowMessageBox(NULL,
54 base::ASCIIToUTF16("Extension error"), 76 base::ASCIIToUTF16("Extension error"),
55 message, 77 message,
56 chrome::MESSAGE_BOX_TYPE_WARNING); 78 chrome::MESSAGE_BOX_TYPE_WARNING);
57 } 79 }
58 } 80 }
59 81
60 const std::vector<base::string16>* ExtensionErrorReporter::GetErrors() { 82 const std::vector<base::string16>* ExtensionErrorReporter::GetErrors() {
61 return &errors_; 83 return &errors_;
62 } 84 }
63 85
64 void ExtensionErrorReporter::ClearErrors() { 86 void ExtensionErrorReporter::ClearErrors() {
65 errors_.clear(); 87 errors_.clear();
66 } 88 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_error_reporter.h ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698