1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sharing_message/sharing_metrics.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "components/sharing_message/sharing_device_registration_result.h"
#include "components/version_info/version_info.h"
namespace {
const char* GetEnumStringValue(SharingFeatureName feature) {
DCHECK(feature != SharingFeatureName::kUnknown)
<< "Feature needs to be specified for metrics logging.";
switch (feature) {
case SharingFeatureName::kUnknown:
return "Unknown";
case SharingFeatureName::kClickToCall:
return "ClickToCall";
case SharingFeatureName::kSharedClipboard:
return "SharedClipboard";
case SharingFeatureName::kSmsRemoteFetcher:
return "SmsRemoteFetcher";
}
}
// Maps SharingChannelType enum values to strings used as histogram
// suffixes. Keep in sync with "SharingChannelType" in histograms.xml.
std::string SharingChannelTypeToString(SharingChannelType channel_type) {
switch (channel_type) {
case SharingChannelType::kUnknown:
return "Unknown";
case SharingChannelType::kFcmSenderId:
return "FcmSenderId";
case SharingChannelType::kServer:
return "Server";
case SharingChannelType::kWebRtc:
return "WebRTC";
case SharingChannelType::kIosPush:
return "IosPush";
}
}
// Maps SharingDevicePlatform enum values to strings used as histogram
// suffixes. Keep in sync with "SharingDevicePlatform" in histograms.xml.
std::string DevicePlatformToString(SharingDevicePlatform device_platform) {
switch (device_platform) {
case SharingDevicePlatform::kAndroid:
return "Android";
case SharingDevicePlatform::kChromeOS:
return "ChromeOS";
case SharingDevicePlatform::kIOS:
return "iOS";
case SharingDevicePlatform::kLinux:
return "Linux";
case SharingDevicePlatform::kMac:
return "Mac";
case SharingDevicePlatform::kWindows:
return "Windows";
case SharingDevicePlatform::kServer:
return "Server";
case SharingDevicePlatform::kUnknown:
return "Unknown";
}
}
// Maps pulse intervals to strings used as histogram suffixes. Keep in sync with
// "SharingPulseInterval" in histograms.xml.
std::string PulseIntervalToString(base::TimeDelta pulse_interval) {
if (pulse_interval < base::Hours(4)) {
return "PulseIntervalShort";
}
if (pulse_interval > base::Hours(12)) {
return "PulseIntervalLong";
}
return "PulseIntervalMedium";
}
// Major Chrome version comparison with the receiver device.
// These values are logged to UMA. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// "SharingMajorVersionComparison" in enums.xml.
enum class SharingMajorVersionComparison {
kUnknown = 0,
kSenderIsLower = 1,
kSame = 2,
kSenderIsHigher = 3,
kMaxValue = kSenderIsHigher,
};
} // namespace
std::string SharingSendMessageResultToString(SharingSendMessageResult result) {
switch (result) {
case SharingSendMessageResult::kSuccessful:
return "Successful";
case SharingSendMessageResult::kDeviceNotFound:
return "DeviceNotFound";
case SharingSendMessageResult::kNetworkError:
return "NetworkError";
case SharingSendMessageResult::kPayloadTooLarge:
return "PayloadTooLarge";
case SharingSendMessageResult::kAckTimeout:
return "AckTimeout";
case SharingSendMessageResult::kInternalError:
return "InternalError";
case SharingSendMessageResult::kEncryptionError:
return "EncryptionError";
case SharingSendMessageResult::kCommitTimeout:
return "CommitTimeout";
case SharingSendMessageResult::kCancelled:
return "RequestCancelled";
}
}
sharing_message::MessageType SharingPayloadCaseToMessageType(
components_sharing_message::SharingMessage::PayloadCase payload_case) {
switch (payload_case) {
case components_sharing_message::SharingMessage::PAYLOAD_NOT_SET:
return sharing_message::UNKNOWN_MESSAGE;
case components_sharing_message::SharingMessage::kPingMessage:
return sharing_message::PING_MESSAGE;
case components_sharing_message::SharingMessage::kAckMessage:
return sharing_message::ACK_MESSAGE;
case components_sharing_message::SharingMessage::kClickToCallMessage:
return sharing_message::CLICK_TO_CALL_MESSAGE;
case components_sharing_message::SharingMessage::kSharedClipboardMessage:
return sharing_message::SHARED_CLIPBOARD_MESSAGE;
case components_sharing_message::SharingMessage::kSmsFetchRequest:
return sharing_message::SMS_FETCH_REQUEST;
case components_sharing_message::SharingMessage::kRemoteCopyMessage:
return sharing_message::REMOTE_COPY_MESSAGE;
case components_sharing_message::SharingMessage::
kPeerConnectionOfferMessage:
return sharing_message::PEER_CONNECTION_OFFER_MESSAGE;
case components_sharing_message::SharingMessage::
kPeerConnectionIceCandidatesMessage:
return sharing_message::PEER_CONNECTION_ICE_CANDIDATES_MESSAGE;
case components_sharing_message::SharingMessage::kDiscoveryRequest:
return sharing_message::DISCOVERY_REQUEST;
case components_sharing_message::SharingMessage::kWebRtcSignalingFrame:
return sharing_message::WEB_RTC_SIGNALING_FRAME;
case components_sharing_message::SharingMessage::
kOptimizationGuidePushNotification:
return sharing_message::OPTIMIZATION_GUIDE_PUSH_NOTIFICATION;
}
// For proto3 enums unrecognized enum values are kept when parsing, and a new
// payload case received over the network would not default to
// PAYLOAD_NOT_SET. Explicitly return UNKNOWN_MESSAGE here to handle this
// case.
return sharing_message::UNKNOWN_MESSAGE;
}
sharing_message::MessageType SharingPayloadCaseToMessageType(
sync_pb::UnencryptedSharingMessage::PayloadCase payload_case) {
switch (payload_case) {
case sync_pb::UnencryptedSharingMessage::PAYLOAD_NOT_SET:
return sharing_message::UNKNOWN_MESSAGE;
case sync_pb::UnencryptedSharingMessage::kSendTabMessage:
return sharing_message::SEND_TAB_TO_SELF_PUSH_NOTIFICATION;
}
// For proto3 enums unrecognized enum values are kept when parsing, and a new
// payload case received over the network would not default to
// PAYLOAD_NOT_SET. Explicitly return UNKNOWN_MESSAGE here to handle this
// case.
return sharing_message::UNKNOWN_MESSAGE;
}
const std::string& SharingMessageTypeToString(
sharing_message::MessageType message_type) {
// For proto3 enums unrecognized enum values are kept when parsing and their
// name is an empty string. We don't want to use that as a histogram suffix.
if (!sharing_message::MessageType_IsValid(message_type)) {
return sharing_message::MessageType_Name(sharing_message::UNKNOWN_MESSAGE);
}
return sharing_message::MessageType_Name(message_type);
}
int GenerateSharingTraceId() {
static int next_id = 0;
return next_id++;
}
void LogSharingMessageReceived(
components_sharing_message::SharingMessage::PayloadCase payload_case) {
base::UmaHistogramExactLinear("Sharing.MessageReceivedType",
SharingPayloadCaseToMessageType(payload_case),
sharing_message::MessageType_ARRAYSIZE);
}
void LogSharingDevicesToShow(SharingFeatureName feature,
const char* histogram_suffix,
int count) {
auto* feature_str = GetEnumStringValue(feature);
// Explicitly log both the base and the suffixed histogram because the base
// aggregation is not automatically generated.
base::UmaHistogramExactLinear(
base::StrCat({"Sharing.", feature_str, "DevicesToShow"}), count,
/*value_max=*/20);
if (!histogram_suffix) {
return;
}
base::UmaHistogramExactLinear(
base::StrCat(
{"Sharing.", feature_str, "DevicesToShow.", histogram_suffix}),
count,
/*value_max=*/20);
}
void LogSharingAppsToShow(SharingFeatureName feature,
const char* histogram_suffix,
int count) {
auto* feature_str = GetEnumStringValue(feature);
// Explicitly log both the base and the suffixed histogram because the base
// aggregation is not automatically generated.
base::UmaHistogramExactLinear(
base::StrCat({"Sharing.", feature_str, "AppsToShow"}), count,
/*value_max=*/20);
if (!histogram_suffix) {
return;
}
base::UmaHistogramExactLinear(
base::StrCat({"Sharing.", feature_str, "AppsToShow.", histogram_suffix}),
count,
/*value_max=*/20);
}
void LogSharingSelectedIndex(SharingFeatureName feature,
const char* histogram_suffix,
int index,
SharingIndexType index_type) {
auto* feature_str = GetEnumStringValue(feature);
// Explicitly log both the base and the suffixed histogram because the base
// aggregation is not automatically generated.
std::string name = base::StrCat(
{"Sharing.", feature_str, "Selected",
(index_type == SharingIndexType::kDevice) ? "Device" : "App", "Index"});
base::UmaHistogramExactLinear(name, index, /*value_max=*/20);
if (!histogram_suffix) {
return;
}
base::UmaHistogramExactLinear(base::StrCat({name, ".", histogram_suffix}),
index,
/*value_max=*/20);
}
void LogSharingDialogShown(SharingFeatureName feature, SharingDialogType type) {
base::UmaHistogramEnumeration(
base::StrCat({"Sharing.", GetEnumStringValue(feature), "DialogShown"}),
type);
}
void LogSendSharingMessageResult(
sharing_message::MessageType message_type,
SharingDevicePlatform receiving_device_platform,
SharingChannelType channel_type,
base::TimeDelta pulse_interval,
SharingSendMessageResult result) {
const std::string metric_prefix = "Sharing.SendMessageResult";
base::UmaHistogramEnumeration(metric_prefix, result);
base::UmaHistogramEnumeration(
base::StrCat(
{metric_prefix, ".", SharingMessageTypeToString(message_type)}),
result);
base::UmaHistogramEnumeration(
base::StrCat({metric_prefix, ".",
DevicePlatformToString(receiving_device_platform)}),
result);
base::UmaHistogramEnumeration(
base::StrCat({metric_prefix, ".",
DevicePlatformToString(receiving_device_platform), ".",
SharingMessageTypeToString(message_type)}),
result);
base::UmaHistogramEnumeration(
base::StrCat(
{metric_prefix, ".", SharingChannelTypeToString(channel_type)}),
result);
// There is no "invalid" bucket so only log valid pulse intervals.
if (!pulse_interval.is_zero()) {
base::UmaHistogramEnumeration(
base::StrCat(
{metric_prefix, ".", PulseIntervalToString(pulse_interval)}),
result);
base::UmaHistogramEnumeration(
base::StrCat({metric_prefix, ".",
DevicePlatformToString(receiving_device_platform), ".",
PulseIntervalToString(pulse_interval)}),
result);
}
}
|