Chromium Code Reviews| Index: chrome/browser/metrics/extensions_metrics_provider.cc |
| diff --git a/chrome/browser/metrics/extensions_metrics_provider.cc b/chrome/browser/metrics/extensions_metrics_provider.cc |
| index 38b4a296ca881126da2790c38228ea5bd08f05b2..e44013ac65fe9971fceb74eae28ce43cbf9fdf30 100644 |
| --- a/chrome/browser/metrics/extensions_metrics_provider.cc |
| +++ b/chrome/browser/metrics/extensions_metrics_provider.cc |
| @@ -10,11 +10,13 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/stringprintf.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/install_verifier.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "components/metrics/metrics_log.h" |
| #include "components/metrics/metrics_state_manager.h" |
| #include "components/metrics/proto/system_profile.pb.h" |
| #include "extensions/browser/extension_registry.h" |
| +#include "extensions/browser/extension_system.h" |
| #include "extensions/common/extension_set.h" |
| #include "third_party/smhasher/src/City.h" |
| @@ -29,6 +31,37 @@ const size_t kExtensionListClientKeys = 4096; |
| // the possible output range of the HashExtension function. |
| const size_t kExtensionListBuckets = 1024; |
| +bool IsOffStoreExtension(const extensions::Extension& extension, |
|
Alexei Svitkine (slow)
2014/08/11 15:01:57
Add a comment.
jwd
2014/08/11 20:06:27
Done.
|
| + const extensions::InstallVerifier& verifier) { |
| + if (!extension.is_extension() && !extension.is_legacy_packaged_app()) |
| + return false; |
| + |
| + // Component extensions are considered safe. |
| + if (extension.location() == extensions::Manifest::COMPONENT || |
| + extension.location() == extensions::Manifest::EXTERNAL_COMPONENT) |
|
Alexei Svitkine (slow)
2014/08/11 15:01:57
Nit: {}'s
jwd
2014/08/11 20:06:27
Done.
|
| + return false; |
| + |
| + // TODO(jwd): add whitelist |
| + |
| + if (!extensions::InstallVerifier::FromStore(extension)) |
| + return true; |
| + |
| + // Local information about the extension implies it is from the store. We try |
| + // to use the install verifier to vereify this. |
| + return verifier.IsInvalid(extension.id()); |
| +} |
| + |
| +bool CheckForOffStore(const extensions::ExtensionSet& extensions, |
| + const extensions::InstallVerifier& verifier) { |
| + for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
| + it != extensions.end(); |
| + ++it) { |
| + if (IsOffStoreExtension(**it, verifier)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| } // namespace |
| ExtensionsMetricsProvider::ExtensionsMetricsProvider( |
| @@ -74,13 +107,8 @@ Profile* ExtensionsMetricsProvider::GetMetricsProfile() { |
| } |
| scoped_ptr<extensions::ExtensionSet> |
| -ExtensionsMetricsProvider::GetInstalledExtensions() { |
| +ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) { |
| #if defined(ENABLE_EXTENSIONS) |
| - // UMA reports do not support multiple profiles, but extensions are installed |
| - // per-profile. We return the extensions installed in the primary profile. |
| - // In the future, we might consider reporting data about extensions in all |
| - // profiles. |
| - Profile* profile = GetMetricsProfile(); |
| if (profile) { |
| return extensions::ExtensionRegistry::Get(profile) |
| ->GenerateInstalledExtensionsSet(); |
| @@ -98,7 +126,44 @@ uint64 ExtensionsMetricsProvider::GetClientID() { |
| void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( |
| metrics::SystemProfileProto* system_profile) { |
| - scoped_ptr<extensions::ExtensionSet> extensions(GetInstalledExtensions()); |
| + ProvideOffStoreMetric(system_profile); |
| + ProvideOccupiedBucketMetric(system_profile); |
| +} |
| + |
| +void ExtensionsMetricsProvider::ProvideOffStoreMetric( |
| + metrics::SystemProfileProto* system_profile) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + if (!profile_manager) |
| + return; |
| + |
| + bool hasOffStore = false; |
| + |
| + std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| + for (std::vector<Profile*>::const_iterator it = profiles.begin(); |
| + it != profiles.end(); |
| + ++it) { |
| + extensions::InstallVerifier* verifier = |
| + extensions::ExtensionSystem::Get(*it)->install_verifier(); |
| + |
| + scoped_ptr<extensions::ExtensionSet> extensions( |
| + GetInstalledExtensions(*it)); |
| + |
| + hasOffStore = hasOffStore || CheckForOffStore(*extensions.get(), *verifier); |
|
Alexei Svitkine (slow)
2014/08/11 15:01:57
Nit: hacker_style please
jwd
2014/08/11 20:06:27
Done.
|
| + } |
| + |
| + system_profile->set_has_offstore_extensions(hasOffStore); |
| +} |
| + |
| +void ExtensionsMetricsProvider::ProvideOccupiedBucketMetric( |
| + metrics::SystemProfileProto* system_profile) { |
| + // UMA reports do not support multiple profiles, but extensions are installed |
| + // per-profile. We return the extensions installed in the primary profile. |
| + // In the future, we might consider reporting data about extensions in all |
| + // profiles. |
| + Profile* profile = GetMetricsProfile(); |
| + |
| + scoped_ptr<extensions::ExtensionSet> extensions( |
| + GetInstalledExtensions(profile)); |
| if (!extensions) |
| return; |