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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/chrome_notification_types.h" | |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/simple_message_box.h" | 17 #include "chrome/browser/ui/simple_message_box.h" |
19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/notification_types.h" |
20 | 20 |
21 ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL; | 21 ExtensionErrorReporter* ExtensionErrorReporter::instance_ = NULL; |
22 | 22 |
23 // static | 23 // static |
24 void ExtensionErrorReporter::Init(bool enable_noisy_errors) { | 24 void ExtensionErrorReporter::Init(bool enable_noisy_errors) { |
25 if (!instance_) { | 25 if (!instance_) { |
26 instance_ = new ExtensionErrorReporter(enable_noisy_errors); | 26 instance_ = new ExtensionErrorReporter(enable_noisy_errors); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { | 31 ExtensionErrorReporter* ExtensionErrorReporter::GetInstance() { |
32 CHECK(instance_) << "Init() was never called"; | 32 CHECK(instance_) << "Init() was never called"; |
33 return instance_; | 33 return instance_; |
34 } | 34 } |
35 | 35 |
36 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) | 36 ExtensionErrorReporter::ExtensionErrorReporter(bool enable_noisy_errors) |
37 : ui_loop_(base::MessageLoop::current()), | 37 : ui_loop_(base::MessageLoop::current()), |
38 enable_noisy_errors_(enable_noisy_errors) { | 38 enable_noisy_errors_(enable_noisy_errors) { |
39 } | 39 } |
40 | 40 |
41 ExtensionErrorReporter::~ExtensionErrorReporter() {} | 41 ExtensionErrorReporter::~ExtensionErrorReporter() {} |
42 | 42 |
43 void ExtensionErrorReporter::ReportLoadError( | 43 void ExtensionErrorReporter::ReportLoadError( |
44 const base::FilePath& extension_path, | 44 const base::FilePath& extension_path, |
45 const std::string& error, | 45 const std::string& error, |
46 content::BrowserContext* browser_context, | 46 content::BrowserContext* browser_context, |
47 bool be_noisy) { | 47 bool be_noisy) { |
48 content::NotificationService::current()->Notify( | 48 content::NotificationService::current()->Notify( |
49 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 49 extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, |
50 content::Source<Profile>(Profile::FromBrowserContext(browser_context)), | 50 content::Source<Profile>(Profile::FromBrowserContext(browser_context)), |
51 content::Details<const std::string>(&error)); | 51 content::Details<const std::string>(&error)); |
52 | 52 |
53 std::string path_str = base::UTF16ToUTF8(extension_path.LossyDisplayName()); | 53 std::string path_str = base::UTF16ToUTF8(extension_path.LossyDisplayName()); |
54 base::string16 message = base::UTF8ToUTF16( | 54 base::string16 message = base::UTF8ToUTF16( |
55 base::StringPrintf("Could not load extension from '%s'. %s", | 55 base::StringPrintf("Could not load extension from '%s'. %s", |
56 path_str.c_str(), | 56 path_str.c_str(), |
57 error.c_str())); | 57 error.c_str())); |
58 ReportError(message, be_noisy); | 58 ReportError(message, be_noisy); |
59 FOR_EACH_OBSERVER(Observer, | 59 FOR_EACH_OBSERVER(Observer, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 errors_.clear(); | 91 errors_.clear(); |
92 } | 92 } |
93 | 93 |
94 void ExtensionErrorReporter::AddObserver(Observer* observer) { | 94 void ExtensionErrorReporter::AddObserver(Observer* observer) { |
95 observers_.AddObserver(observer); | 95 observers_.AddObserver(observer); |
96 } | 96 } |
97 | 97 |
98 void ExtensionErrorReporter::RemoveObserver(Observer* observer) { | 98 void ExtensionErrorReporter::RemoveObserver(Observer* observer) { |
99 observers_.RemoveObserver(observer); | 99 observers_.RemoveObserver(observer); |
100 } | 100 } |
OLD | NEW |