Skip to content

Commit

Permalink
Adds two new convenience functions to metricsPrivate
Browse files Browse the repository at this point in the history
Adds recordBoolean and recordEnumerationValue to metricsPrivate.

Bug: 792744
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Id4f3e2baf8f15b6010af1115b34c89f542712f66
Reviewed-on: https://chromium-review.googlesource.com/815296
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Commit-Queue: Katie D <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523148}
  • Loading branch information
dektar authored and Commit Bot committed Dec 11, 2017
1 parent 72f57ae commit 0180ee6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
23 changes: 23 additions & 0 deletions extensions/browser/api/metrics_private/metrics_private_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/hash.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/metrics/user_metrics.h"
Expand All @@ -26,6 +27,8 @@ namespace extensions {
namespace GetVariationParams = api::metrics_private::GetVariationParams;
namespace RecordUserAction = api::metrics_private::RecordUserAction;
namespace RecordValue = api::metrics_private::RecordValue;
namespace RecordBoolean = api::metrics_private::RecordBoolean;
namespace RecordEnumerationValue = api::metrics_private::RecordEnumerationValue;
namespace RecordSparseHashable = api::metrics_private::RecordSparseHashable;
namespace RecordSparseValue = api::metrics_private::RecordSparseValue;
namespace RecordPercentage = api::metrics_private::RecordPercentage;
Expand Down Expand Up @@ -156,6 +159,26 @@ MetricsPrivateRecordSparseValueFunction::Run() {
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction MetricsPrivateRecordBooleanFunction::Run() {
std::unique_ptr<RecordBoolean::Params> params(
RecordBoolean::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
base::UmaHistogramBoolean(params->metric_name, params->value);
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction
MetricsPrivateRecordEnumerationValueFunction::Run() {
std::unique_ptr<RecordEnumerationValue::Params> params(
RecordEnumerationValue::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
// Uses UmaHistogramExactLinear instead of UmaHistogramEnumeration
// because we don't have an enum type on params->value.
base::UmaHistogramExactLinear(params->metric_name, params->value,
params->enum_size);
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction
MetricsPrivateRecordPercentageFunction::Run() {
std::unique_ptr<RecordPercentage::Params> params(
Expand Down
26 changes: 26 additions & 0 deletions extensions/browser/api/metrics_private/metrics_private_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ class MetricsPrivateRecordValueFunction
ResponseAction Run() override;
};

class MetricsPrivateRecordBooleanFunction
: public MetricsHistogramHelperFunction {
public:
DECLARE_EXTENSION_FUNCTION("metricsPrivate.recordBoolean",
METRICSPRIVATE_RECORDBOOLEAN)

protected:
~MetricsPrivateRecordBooleanFunction() override {}

// ExtensionFunction:
ResponseAction Run() override;
};

class MetricsPrivateRecordEnumerationValueFunction
: public MetricsHistogramHelperFunction {
public:
DECLARE_EXTENSION_FUNCTION("metricsPrivate.recordEnumerationValue",
METRICSPRIVATE_RECORDENUMERATIONVALUE)

protected:
~MetricsPrivateRecordEnumerationValueFunction() override {}

// ExtensionFunction:
ResponseAction Run() override;
};

class MetricsPrivateRecordSparseHashableFunction
: public MetricsHistogramHelperFunction {
public:
Expand Down
2 changes: 2 additions & 0 deletions extensions/browser/extension_function_histogram_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,8 @@ enum HistogramValue {
ACCESSIBILITY_PRIVATE_SETHIGHLIGHTS,
WEBRTCLOGGINGPRIVATE_GETLOGSDIRECTORY,
VIRTUALKEYBOARDPRIVATE_SETDRAGGABLEAREA,
METRICSPRIVATE_RECORDBOOLEAN,
METRICSPRIVATE_RECORDENUMERATIONVALUE,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
19 changes: 19 additions & 0 deletions extensions/common/api/metrics_private.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@
{"name": "metric", "$ref": "MetricType"},
{"name": "value", "type": "integer"}
]
},
{
"name": "recordBoolean",
"type": "function",
"description": "Records a boolean value to the given metric. Analogous to base::UmaHistogramBoolean().",
"parameters": [
{"name": "metricName", "type": "string"},
{"name": "value", "type": "boolean"}
]
},
{
"name": "recordEnumerationValue",
"type": "function",
"description": "Records an enumeration value to the given metric. Analogous to base::UmaHistogramEnumeration(). Use recordSparseValue for sparse enums or enums not starting at 0.",
"parameters": [
{"name": "metricName", "type": "string"},
{"name": "value", "type": "integer"},
{"name": "enumSize", "type": "integer"}
]
}
],
"events": []
Expand Down
20 changes: 20 additions & 0 deletions third_party/closure_compiler/externs/metrics_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,23 @@ chrome.metricsPrivate.recordSparseValue = function(metricName, value) {};
* @see https://developer.chrome.com/extensions/metricsPrivate#method-recordValue
*/
chrome.metricsPrivate.recordValue = function(metric, value) {};

/**
* Records a boolean value to the given metric. Analogous to
* base::UmaHistogramBoolean().
* @param {string} metricName
* @param {boolean} value
* @see https://developer.chrome.com/extensions/metricsPrivate#method-recordBoolean
*/
chrome.metricsPrivate.recordBoolean = function(metricName, value) {};

/**
* Records an enumeration value to the given metric. Analogous to
* base::UmaHistogramEnumeration(). Use recordSparseValue for sparse enums or
* enums not starting at 0.
* @param {string} metricName
* @param {number} value
* @param {number} enumSize
* @see https://developer.chrome.com/extensions/metricsPrivate#method-recordEnumerationValue
*/
chrome.metricsPrivate.recordEnumerationValue = function(metricName, value, enumSize) {};
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14208,6 +14208,8 @@ Called by update_net_error_codes.py.-->
<int value="1201" label="ACCESSIBILITY_PRIVATE_SETHIGHLIGHTS"/>
<int value="1202" label="WEBRTCLOGGINGPRIVATE_GETLOGSDIRECTORY"/>
<int value="1203" label="VIRTUALKEYBOARDPRIVATE_SETDRAGGABLEAREA"/>
<int value="1204" label="METRICSPRIVATE_RECORDBOOLEAN"/>
<int value="1205" label="METRICSPRIVATE_RECORDENUMERATIONVALUE"/>
</enum>

<enum name="ExtensionIconState">
Expand Down

0 comments on commit 0180ee6

Please sign in to comment.