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..fd4b5b5ff2fb795312aa26fc26bfdbb6b38547f4 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,76 @@ const size_t kExtensionListClientKeys = 4096; |
| // the possible output range of the HashExtension function. |
| const size_t kExtensionListBuckets = 1024; |
| +enum ExtensionState { |
| + NO_EXTENSIONS, |
| + FROM_STORE_VERIFIED, |
| + FROM_STORE_UNVERIFIED, |
| + OFF_STORE |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Can you use the proto's enum directly instead of t
jwd
2014/08/12 18:45:28
Done.
|
| +}; |
| + |
| +metrics::SystemProfileProto::ExtensionsState ExtensionStateAsProto( |
| + ExtensionState value) { |
| + switch (value) { |
| + case NO_EXTENSIONS: |
| + return metrics::SystemProfileProto::NO_EXTENSIONS; |
| + case FROM_STORE_VERIFIED: |
| + return metrics::SystemProfileProto::NO_OFFSTORE_VERIFIED; |
| + case FROM_STORE_UNVERIFIED: |
| + return metrics::SystemProfileProto::NO_OFFSTORE_UNVERIFIED; |
| + case OFF_STORE: |
| + return metrics::SystemProfileProto::HAS_OFFSTORE; |
| + } |
| + NOTREACHED(); |
| + return metrics::SystemProfileProto::NO_EXTENSIONS; |
| +} |
| + |
| +// Determines if the |extension| is an extension (can use extension APIs) and is |
| +// not from the webstore. If local information claims the extension is from the |
| +// webstore, we attempt to verifie with the |InstallVerifier| by checking if it |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: verify
jwd
2014/08/12 18:45:28
Done.
|
| +// has been explicitly deemed invalid. If the |InstallVerifier| is inactive or |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: No need for |'s around InstallVerifier since
jwd
2014/08/12 18:45:28
Done.
|
| +// if the extension is unknown to the |InstallVerifier|, the local information |
| +// is trusted. |
| +ExtensionState IsOffStoreExtension( |
| + const extensions::Extension& extension, |
| + const extensions::InstallVerifier& verifier) { |
| + if (!extension.is_extension() && !extension.is_legacy_packaged_app()) |
| + return NO_EXTENSIONS; |
| + |
| + // Component extensions are considered safe. |
| + if (extension.location() == extensions::Manifest::COMPONENT || |
| + extension.location() == extensions::Manifest::EXTERNAL_COMPONENT) { |
| + return NO_EXTENSIONS; |
| + } |
| + |
| + if (verifier.AllowedByEnterprisePolicy(extension.id())) |
| + return NO_EXTENSIONS; |
| + |
| + if (!extensions::InstallVerifier::FromStore(extension)) |
| + return OFF_STORE; |
| + |
| + // Local information about the extension implies it is from the store. We try |
| + // to use the install verifier to vereify this. |
| + if (!verifier.IsKnownId(extension.id())) |
| + return FROM_STORE_UNVERIFIED; |
| + |
| + if (verifier.IsInvalid(extension.id())) |
| + return OFF_STORE; |
| + else |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: Remove else and unindent return below.
jwd
2014/08/12 18:45:28
Done.
|
| + return FROM_STORE_VERIFIED; |
| +} |
| + |
| +ExtensionState CheckForOffStore(const extensions::ExtensionSet& extensions, |
| + const extensions::InstallVerifier& verifier) { |
| + ExtensionState extensions_state = NO_EXTENSIONS; |
| + for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
| + it != extensions.end(); |
| + ++it) { |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: for (size_t i = 0; i < extensions.size(); ++i
jwd
2014/08/12 18:45:28
Done below, not done her as discussed.
|
| + extensions_state = |
| + std::max(extensions_state, IsOffStoreExtension(**it, verifier)); |
| + } |
| + return extensions_state; |
| +} |
| + |
| } // namespace |
| ExtensionsMetricsProvider::ExtensionsMetricsProvider( |
| @@ -74,13 +146,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 +165,46 @@ 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; |
| + |
| + ExtensionState extensions_state = NO_EXTENSIONS; |
| + |
| + std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
|
Alexei Svitkine (slow)
2014/08/12 15:22:40
Add a comment explaining how we treat multi-profil
jwd
2014/08/12 18:45:28
Done.
|
| + 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)); |
| + |
| + extensions_state = std::max(extensions_state, |
|
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: This deserves a comment.
Alexei Svitkine (slow)
2014/08/12 15:22:39
Nit: Add a comment about the max() logic.
jwd
2014/08/12 18:45:28
Done.
jwd
2014/08/12 18:45:28
Done.
|
| + CheckForOffStore(*extensions.get(), *verifier)); |
| + } |
| + |
| + system_profile->set_offstore_extensions_state( |
| + ExtensionStateAsProto(extensions_state)); |
| +} |
| + |
| +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; |