From c1906b331bb9a3af681a778e49f88b8e94434208 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Wed, 17 Jun 2015 12:28:26 -0400 Subject: [PATCH] Bug 968923 - part 6 - add use counters for deprecated operations; r=bz --- dom/base/UseCounter.h | 6 +++++ dom/base/nsDocument.cpp | 14 ++++++++++ .../components/telemetry/histogram_tools.py | 26 +++++++++++++++++++ toolkit/components/telemetry/moz.build | 1 + 4 files changed, 47 insertions(+) diff --git a/dom/base/UseCounter.h b/dom/base/UseCounter.h index 590ede2e261..01cdb9969ed 100644 --- a/dom/base/UseCounter.h +++ b/dom/base/UseCounter.h @@ -22,6 +22,12 @@ enum UseCounter : int16_t { #undef USE_COUNTER_DOM_METHOD #undef USE_COUNTER_DOM_ATTRIBUTE #undef USE_COUNTER_CSS_PROPERTY + +#define DEPRECATED_OPERATION(op_) \ + eUseCounter_##op_, +#include "nsDeprecatedOperationList.h" +#undef DEPRECATED_OPERATION + eUseCounter_Count }; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 83a37f84a42..861ec413ff1 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -10405,6 +10405,19 @@ static const char* kDocumentWarnings[] = { }; #undef DOCUMENT_WARNING +static UseCounter +OperationToUseCounter(nsIDocument::DeprecatedOperations aOperation) +{ + switch(aOperation) { +#define DEPRECATED_OPERATION(_op) \ + case nsIDocument::e##_op: return eUseCounter_##_op; +#include "nsDeprecatedOperationList.h" +#undef DEPRECATED_OPERATION + default: + MOZ_CRASH(); + } +} + bool nsIDocument::HasWarnedAbout(DeprecatedOperations aOperation) const { @@ -10420,6 +10433,7 @@ nsIDocument::WarnOnceAbout(DeprecatedOperations aOperation, return; } mDeprecationWarnedAbout[aOperation] = true; + const_cast(this)->SetDocumentAndPageUseCounter(OperationToUseCounter(aOperation)); uint32_t flags = asError ? nsIScriptError::errorFlag : nsIScriptError::warningFlag; nsContentUtils::ReportToConsole(flags, diff --git a/toolkit/components/telemetry/histogram_tools.py b/toolkit/components/telemetry/histogram_tools.py index 9e9886c1548..0b9d8b170dc 100644 --- a/toolkit/components/telemetry/histogram_tools.py +++ b/toolkit/components/telemetry/histogram_tools.py @@ -2,6 +2,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +import collections import json import math import os @@ -279,8 +280,33 @@ def from_Histograms_json(filename): def from_UseCounters_conf(filename): return usecounters.generate_histograms(filename) +def from_nsDeprecatedOperationList(filename): + operation_regex = re.compile('^DEPRECATED_OPERATION\\(([^)]+)\\)') + histograms = collections.OrderedDict() + + with open(filename, 'r') as f: + for line in f: + match = operation_regex.search(line) + if not match: + continue + + op = match.group(1) + + def add_counter(context): + name = 'USE_COUNTER_DEPRECATED_%s_%s' % (op, context.upper()) + histograms[name] = { + 'expires_in_version': 'never', + 'kind': 'boolean', + 'description': 'Whether a %s used %s' % (context, op) + } + add_counter('document') + add_counter('page') + + return histograms + FILENAME_PARSERS = { 'Histograms.json': from_Histograms_json, + 'nsDeprecatedOperationList.h': from_nsDeprecatedOperationList, } # Similarly to the dance above with buildconfig, usecounters may not be diff --git a/toolkit/components/telemetry/moz.build b/toolkit/components/telemetry/moz.build index 83609d88746..63f25ec0214 100644 --- a/toolkit/components/telemetry/moz.build +++ b/toolkit/components/telemetry/moz.build @@ -65,6 +65,7 @@ GENERATED_FILES = [ histogram_files = [ 'Histograms.json', '/dom/base/UseCounters.conf', + '/dom/base/nsDeprecatedOperationList.h', ] data = GENERATED_FILES['TelemetryHistogramData.inc']