Commit ef5a9996 authored by asargent@chromium.org's avatar asargent@chromium.org

Additional metrics for disabled extensions and content verification


BUG=396319

Review URL: https://codereview.chromium.org/412003003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285688 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d166378
......@@ -10,6 +10,7 @@
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_tokenizer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings.h"
......@@ -227,12 +228,19 @@ class ContentVerifierDelegateImpl : public ContentVerifierDelegate {
return;
ExtensionRegistry* registry = ExtensionRegistry::Get(service_->profile());
const Extension* extension =
registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
if (!extension)
return;
Mode mode = ShouldBeVerified(*extension);
if (mode >= ContentVerifierDelegate::ENFORCE)
if (mode >= ContentVerifierDelegate::ENFORCE) {
service_->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED);
ExtensionPrefs::Get(service_->profile())
->IncrementCorruptedDisableCount();
UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionBecameDisabled", true);
} else if (!ContainsKey(would_be_disabled_ids_, extension_id)) {
UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionWouldBeDisabled", true);
would_be_disabled_ids_.insert(extension_id);
}
}
static Mode GetDefaultMode() {
......@@ -287,6 +295,11 @@ class ContentVerifierDelegateImpl : public ContentVerifierDelegate {
private:
base::WeakPtr<ExtensionService> service_;
ContentVerifierDelegate::Mode default_mode_;
// For reporting metrics in BOOTSTRAP mode, when an extension would be
// disabled if content verification was in ENFORCE mode.
std::set<std::string> would_be_disabled_ids_;
DISALLOW_COPY_AND_ASSIGN(ContentVerifierDelegateImpl);
};
......
......@@ -6,6 +6,7 @@
#include "base/files/file_path.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
......@@ -134,6 +135,27 @@ void RecordCreationFlags(const Extension* extension) {
}
}
// Helper to record a single disable reason histogram value (see
// RecordDisableReasons below).
void RecordDisbleReasonHistogram(int reason) {
UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.DisableReason", reason);
}
// Records the disable reasons for a single extension grouped by
// Extension::DisableReason.
void RecordDisableReasons(int reasons) {
// |reasons| is a bitmask with values from Extension::DisabledReason
// which are increasing powers of 2.
if (reasons == Extension::DISABLE_NONE) {
RecordDisbleReasonHistogram(Extension::DISABLE_NONE);
return;
}
for (int reason = 1; reason < Extension::DISABLE_REASON_LAST; reason <<= 1) {
if (reasons & reason)
RecordDisbleReasonHistogram(reason);
}
}
} // namespace
InstalledLoader::InstalledLoader(ExtensionService* extension_service)
......@@ -473,6 +495,7 @@ void InstalledLoader::LoadAllExtensions() {
if (extension_prefs_->DidExtensionEscalatePermissions((*ex)->id())) {
++disabled_for_permissions_count;
}
RecordDisableReasons(extension_prefs_->GetDisableReasons((*ex)->id()));
if (Manifest::IsExternalLocation((*ex)->location())) {
// See loop above for ENABLED.
if (ManifestURL::UpdatesFromGallery(*ex)) {
......@@ -542,6 +565,8 @@ void InstalledLoader::LoadAllExtensions() {
UMA_HISTOGRAM_COUNTS_100("Extensions.FileAccessNotAllowed",
file_access_not_allowed_count);
}
UMA_HISTOGRAM_COUNTS_100("Extensions.CorruptExtensionTotalDisables",
extension_prefs_->GetCorruptedDisableCount());
}
int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
......
......@@ -195,6 +195,8 @@ const char kInstallSignature[] = "extensions.install_signature";
// synced. Default value is false.
const char kPrefDoNotSync[] = "do_not_sync";
const char kCorruptedDisableCount[] = "extensions.corrupted_disable_count";
// Provider of write access to a dictionary storing extension prefs.
class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
public:
......@@ -1895,6 +1897,15 @@ void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
new base::StringValue(install_parameter));
}
int ExtensionPrefs::GetCorruptedDisableCount() {
return prefs_->GetInteger(kCorruptedDisableCount);
}
void ExtensionPrefs::IncrementCorruptedDisableCount() {
int count = prefs_->GetInteger(kCorruptedDisableCount);
prefs_->SetInteger(kCorruptedDisableCount, count + 1);
}
ExtensionPrefs::ExtensionPrefs(
PrefService* prefs,
const base::FilePath& root_dir,
......@@ -2002,6 +2013,10 @@ void ExtensionPrefs::RegisterProfilePrefs(
pref_names::kNativeMessagingUserLevelHosts,
true, // default value
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterIntegerPref(
kCorruptedDisableCount,
0, // default value
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
template <class ExtensionIdContainer>
......
......@@ -561,6 +561,11 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
void SetInstallParam(const std::string& extension_id,
const std::string& install_parameter);
// The total number of times we've disabled an extension due to corrupted
// contents.
int GetCorruptedDisableCount();
void IncrementCorruptedDisableCount();
private:
friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
friend class ExtensionPrefsUninstallExtension; // Unit test.
......
......@@ -77,6 +77,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
DEPRECATED_DISABLE_LAST, // Not used.
};
// Reasons an extension may be disabled. These are used in histograms, so do
// not remove/reorder entries - only add at the end just before
// DISABLE_REASON_LAST (and update the shift value for it). Also remember to
// update the enum listing in tools/metrics/histograms.xml.
enum DisableReason {
DISABLE_NONE = 0,
DISABLE_USER_ACTION = 1 << 0,
......@@ -91,7 +95,8 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// the install.
DISABLE_GREYLIST = 1 << 9,
DISABLE_CORRUPTED = 1 << 10,
DISABLE_REMOTE_INSTALL = 1 << 11
DISABLE_REMOTE_INSTALL = 1 << 11,
DISABLE_REASON_LAST = 1 << 12, // This should always be the last value
};
// A base class for parsed manifest data that APIs want to store on
......
......@@ -6623,6 +6623,31 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary>
</histogram>
<histogram name="Extensions.CorruptExtensionBecameDisabled">
<owner>asargent@chromium.org</owner>
<summary>
Fired each time an extension was detected to be corrupted (contents not
matching an expected content hash from the webstore) and was disabled.
</summary>
</histogram>
<histogram name="Extensions.CorruptExtensionTotalDisables">
<owner>asargent@chromium.org</owner>
<summary>
Logged once at startup, this is the value of a counter that is incremented
anytime we disable a corrupted extension because its content didn't match an
expected content hash.
</summary>
</histogram>
<histogram name="Extensions.CorruptExtensionWouldBeDisabled">
<owner>asargent@chromium.org</owner>
<summary>
Simiar to Extensions.CorruptExtensionBecameDisabled, but fires when we're in
a bootstrapping mode and would have disabled an extension.
</summary>
</histogram>
<histogram name="Extensions.CrxFetchError" enum="NetErrorCodes">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<summary>Net error results from URLFetcher.</summary>
......@@ -6720,6 +6745,17 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary>
</histogram>
<histogram name="Extensions.DisableReason" enum="ExtensionDisableReason">
<owner>asargent@chromium.org</owner>
<summary>
The count of disabled extensions at startup grouped by disble reason from
Extension::DisableReason. When an extension is disabled, it can be for one
or more reasons (although typically just one), so the sum of these may be
greater than 'Extensions.Disabled' which is a count of the number of unique
extensions that are disabled.
</summary>
</histogram>
<histogram name="Extensions.ErrorCodeFromCrxOpen">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<summary>
......@@ -38208,6 +38244,22 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="2" label="UNINSTALL"/>
</enum>
<enum name="ExtensionDisableReason" type="int">
<int value="0" label="UNKNOWN"/>
<int value="1" label="USER_ACTION"/>
<int value="2" label="PERMISSIONS_INCREASE"/>
<int value="4" label="RELOAD"/>
<int value="8" label="UNSUPPORTED_REQUIREMENT"/>
<int value="16" label="SIDELOAD_WIPEOUT"/>
<int value="32" label="UNKNOWN_FROM_SYNC"/>
<int value="64" label="DEPRECATED_PERMISSIONS_CONSENT"/>
<int value="128" label="DEPRECATED_KNOWN_DISABLED"/>
<int value="256" label="NOT_VERIFIED"/>
<int value="512" label="GREYLIST"/>
<int value="1024" label="CORRUPTED"/>
<int value="2048" label="REMOTE_INSTALL"/>
</enum>
<enum name="ExtensionFileWriteResult" type="int">
<obsolete>
Deprecated 10/2013.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment