OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/error_console/error_console.h" | 5 #include "chrome/browser/extensions/error_console/error_console.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
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/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
18 #include "chrome/common/extensions/features/feature_channel.h" | 18 #include "chrome/common/extensions/features/feature_channel.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "components/crx_file/id_util.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
23 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
24 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
26 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
28 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
29 #include "extensions/common/feature_switch.h" | 30 #include "extensions/common/feature_switch.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 71 |
71 // static | 72 // static |
72 ErrorConsole* ErrorConsole::Get(Profile* profile) { | 73 ErrorConsole* ErrorConsole::Get(Profile* profile) { |
73 return ExtensionSystem::Get(profile)->error_console(); | 74 return ExtensionSystem::Get(profile)->error_console(); |
74 } | 75 } |
75 | 76 |
76 void ErrorConsole::SetReportingForExtension(const std::string& extension_id, | 77 void ErrorConsole::SetReportingForExtension(const std::string& extension_id, |
77 ExtensionError::Type type, | 78 ExtensionError::Type type, |
78 bool enabled) { | 79 bool enabled) { |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
80 if (!enabled_ || !Extension::IdIsValid(extension_id)) | 81 if (!enabled_ || !crx_file::id_util::IdIsValid(extension_id)) |
81 return; | 82 return; |
82 | 83 |
83 int mask = default_mask_; | 84 int mask = default_mask_; |
84 // This call can fail if the preference isn't set, but we don't really care | 85 // This call can fail if the preference isn't set, but we don't really care |
85 // if it does, because we just use the default mask instead. | 86 // if it does, because we just use the default mask instead. |
86 prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &mask); | 87 prefs_->ReadPrefAsInteger(extension_id, kStoreExtensionErrorsPref, &mask); |
87 | 88 |
88 if (enabled) | 89 if (enabled) |
89 mask |= 1 << type; | 90 mask |= 1 << type; |
90 else | 91 else |
91 mask &= ~(1 << type); | 92 mask &= ~(1 << type); |
92 | 93 |
93 prefs_->UpdateExtensionPref(extension_id, | 94 prefs_->UpdateExtensionPref(extension_id, |
94 kStoreExtensionErrorsPref, | 95 kStoreExtensionErrorsPref, |
95 new base::FundamentalValue(mask)); | 96 new base::FundamentalValue(mask)); |
96 } | 97 } |
97 | 98 |
98 void ErrorConsole::SetReportingAllForExtension( | 99 void ErrorConsole::SetReportingAllForExtension( |
99 const std::string& extension_id, bool enabled) { | 100 const std::string& extension_id, bool enabled) { |
100 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
101 if (!enabled_ || !Extension::IdIsValid(extension_id)) | 102 if (!enabled_ || !crx_file::id_util::IdIsValid(extension_id)) |
102 return; | 103 return; |
103 | 104 |
104 int mask = 0; | 105 int mask = 0; |
105 if (enabled) | 106 if (enabled) |
106 mask = (1 << ExtensionError::NUM_ERROR_TYPES) - 1; | 107 mask = (1 << ExtensionError::NUM_ERROR_TYPES) - 1; |
107 | 108 |
108 prefs_->UpdateExtensionPref(extension_id, | 109 prefs_->UpdateExtensionPref(extension_id, |
109 kStoreExtensionErrorsPref, | 110 kStoreExtensionErrorsPref, |
110 new base::FundamentalValue(mask)); | 111 new base::FundamentalValue(mask)); |
111 } | 112 } |
112 | 113 |
113 bool ErrorConsole::IsReportingEnabledForExtension( | 114 bool ErrorConsole::IsReportingEnabledForExtension( |
114 const std::string& extension_id) const { | 115 const std::string& extension_id) const { |
115 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
116 if (!enabled_ || !Extension::IdIsValid(extension_id)) | 117 if (!enabled_ || !crx_file::id_util::IdIsValid(extension_id)) |
117 return false; | 118 return false; |
118 | 119 |
119 return GetMaskForExtension(extension_id) != 0; | 120 return GetMaskForExtension(extension_id) != 0; |
120 } | 121 } |
121 | 122 |
122 void ErrorConsole::UseDefaultReportingForExtension( | 123 void ErrorConsole::UseDefaultReportingForExtension( |
123 const std::string& extension_id) { | 124 const std::string& extension_id) { |
124 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
125 if (!enabled_ || !Extension::IdIsValid(extension_id)) | 126 if (!enabled_ || !crx_file::id_util::IdIsValid(extension_id)) |
126 return; | 127 return; |
127 | 128 |
128 prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref, NULL); | 129 prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref, NULL); |
129 } | 130 } |
130 | 131 |
131 void ErrorConsole::ReportError(scoped_ptr<ExtensionError> error) { | 132 void ErrorConsole::ReportError(scoped_ptr<ExtensionError> error) { |
132 DCHECK(thread_checker_.CalledOnValidThread()); | 133 DCHECK(thread_checker_.CalledOnValidThread()); |
133 if (!enabled_ || !Extension::IdIsValid(error->extension_id())) | 134 if (!enabled_ || !crx_file::id_util::IdIsValid(error->extension_id())) |
134 return; | 135 return; |
135 | 136 |
136 int mask = GetMaskForExtension(error->extension_id()); | 137 int mask = GetMaskForExtension(error->extension_id()); |
137 if (!(mask & (1 << error->type()))) | 138 if (!(mask & (1 << error->type()))) |
138 return; | 139 return; |
139 | 140 |
140 const ExtensionError* weak_error = errors_.AddError(error.Pass()); | 141 const ExtensionError* weak_error = errors_.AddError(error.Pass()); |
141 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error)); | 142 FOR_EACH_OBSERVER(Observer, observers_, OnErrorAdded(weak_error)); |
142 } | 143 } |
143 | 144 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ExtensionRegistry::Get(profile_)->GetExtensionById( | 275 ExtensionRegistry::Get(profile_)->GetExtensionById( |
275 extension_id, ExtensionRegistry::EVERYTHING); | 276 extension_id, ExtensionRegistry::EVERYTHING); |
276 if (extension && extension->location() == Manifest::UNPACKED) | 277 if (extension && extension->location() == Manifest::UNPACKED) |
277 return (1 << ExtensionError::NUM_ERROR_TYPES) - 1; | 278 return (1 << ExtensionError::NUM_ERROR_TYPES) - 1; |
278 | 279 |
279 // Otherwise, use the default mask. | 280 // Otherwise, use the default mask. |
280 return default_mask_; | 281 return default_mask_; |
281 } | 282 } |
282 | 283 |
283 } // namespace extensions | 284 } // namespace extensions |
OLD | NEW |