1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SHARING_SHARING_METRICS_H_ 6 #define CHROME_BROWSER_SHARING_SHARING_METRICS_H_ 7 8 #include "base/time/time.h" 9 #include "chrome/browser/sharing/proto/sharing_message.pb.h" 10 #include "chrome/browser/sharing/shared_clipboard/remote_copy_handle_message_result.h" 11 #include "chrome/browser/sharing/sharing_constants.h" 12 #include "chrome/browser/sharing/sharing_send_message_result.h" 13 14 enum class SharingDeviceRegistrationResult; 15 16 // The types of dialogs that can be shown for sharing features. 17 // These values are logged to UMA. Entries should not be renumbered and numeric 18 // values should never be reused. Please keep in sync with 19 // "SharingDialogType" in src/tools/metrics/histograms/enums.xml. 20 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.sharing 21 enum class SharingDialogType { 22 kDialogWithDevicesMaybeApps = 0, 23 kDialogWithoutDevicesWithApp = 1, 24 kEducationalDialog = 2, 25 kErrorDialog = 3, 26 kMaxValue = kErrorDialog, 27 }; 28 29 // These histogram suffixes must match the ones in Sharing{feature}Ui 30 // defined in histograms.xml. 31 const char kSharingUiContextMenu[] = "ContextMenu"; 32 const char kSharingUiDialog[] = "Dialog"; 33 34 // Maps SharingSendMessageResult enums to strings used as histogram suffixes. 35 // Keep in sync with "SharingSendMessageResult" in histograms.xml. 36 std::string SharingSendMessageResultToString(SharingSendMessageResult result); 37 38 // Maps PayloadCase enums to MessageType enums. 39 chrome_browser_sharing::MessageType SharingPayloadCaseToMessageType( 40 chrome_browser_sharing::SharingMessage::PayloadCase payload_case); 41 42 // Maps MessageType enums to strings used as histogram suffixes. Keep in sync 43 // with "SharingMessage" in histograms.xml. 44 const std::string& SharingMessageTypeToString( 45 chrome_browser_sharing::MessageType message_type); 46 47 // Generates trace ids for async traces in the "sharing" category. 48 int GenerateSharingTraceId(); 49 50 // Logs the |payload_case| to UMA. This should be called when a SharingMessage 51 // is received. 52 void LogSharingMessageReceived( 53 chrome_browser_sharing::SharingMessage::PayloadCase payload_case); 54 55 // Logs the |result| to UMA. This should be called after attempting register 56 // Sharing. 57 void LogSharingRegistrationResult(SharingDeviceRegistrationResult result); 58 59 // Logs the |result| to UMA. This should be called after attempting un-register 60 // Sharing. 61 void LogSharingUnegistrationResult(SharingDeviceRegistrationResult result); 62 63 // Logs the number of available devices that are about to be shown in a UI for 64 // picking a device to start a sharing functionality. The |histogram_suffix| 65 // indicates in which UI this event happened and must match one from 66 // Sharing{feature}Ui defined in histograms.xml use the constants defined 67 // in this file for that. 68 // TODO(yasmo): Change histogram_suffix to be an enum type. 69 void LogSharingDevicesToShow(SharingFeatureName feature, 70 const char* histogram_suffix, 71 int count); 72 73 // Logs the number of available apps that are about to be shown in a UI for 74 // picking an app to start a sharing functionality. The |histogram_suffix| 75 // indicates in which UI this event happened and must match one from 76 // Sharing{feature}Ui defined in histograms.xml - use the constants defined 77 // in this file for that. 78 void LogSharingAppsToShow(SharingFeatureName feature, 79 const char* histogram_suffix, 80 int count); 81 82 // Logs the |index| of the user selection for sharing feature. |index_type| is 83 // the type of selection made, either "Device" or "App". The |histogram_suffix| 84 // indicates in which UI this event happened and must match one from 85 // Sharing{feature}Ui defined in histograms.xml - use the constants defined in 86 // this file for that. 87 enum class SharingIndexType { 88 kDevice, 89 kApp, 90 }; 91 void LogSharingSelectedIndex( 92 SharingFeatureName feature, 93 const char* histogram_suffix, 94 int index, 95 SharingIndexType index_type = SharingIndexType::kDevice); 96 97 // Logs to UMA the time from sending a FCM message from the Sharing service 98 // until an ack message is received for it. 99 void LogSharingMessageAckTime(chrome_browser_sharing::MessageType message_type, 100 SharingDevicePlatform receiver_device_platform, 101 SharingChannelType channel_type, 102 base::TimeDelta time); 103 104 // Logs to UMA the time from receiving a SharingMessage to sending 105 // back an ack. 106 void LogSharingMessageHandlerTime( 107 chrome_browser_sharing::MessageType message_type, 108 base::TimeDelta time_taken); 109 110 // Logs to UMA the number of hours since the target device timestamp was last 111 // updated. Logged when a message is sent to the device. 112 void LogSharingDeviceLastUpdatedAge( 113 chrome_browser_sharing::MessageType message_type, 114 base::TimeDelta age); 115 116 // Logs to UMA the number of hours since the target device timestamp was last 117 // updated. Logged when a message is sent to the device and the result is known. 118 void LogSharingDeviceLastUpdatedAgeWithResult(SharingSendMessageResult result, 119 base::TimeDelta age); 120 121 // Logs to UMA the comparison of the major version of Chrome on this 122 // (the sender) device and the receiver device. Logged when a message is sent. 123 // The |receiver_version| should be a dotted version number with optional 124 // modifiers e.g. "1.2.3.4 canary" as generated by 125 // version_info::GetVersionStringWithModifier. 126 void LogSharingVersionComparison( 127 chrome_browser_sharing::MessageType message_type, 128 const std::string& receiver_version); 129 130 // Logs to UMA the |type| of dialog shown for sharing feature. 131 void LogSharingDialogShown(SharingFeatureName feature, SharingDialogType type); 132 133 // Logs to UMA result of sending a SharingMessage. This should not be called for 134 // sending ack messages. 135 void LogSendSharingMessageResult( 136 chrome_browser_sharing::MessageType message_type, 137 SharingDevicePlatform receiver_device_platform, 138 SharingChannelType channel_type, 139 base::TimeDelta receiver_pulse_interval, 140 SharingSendMessageResult result); 141 142 // Logs to UMA result of sending an ack of a SharingMessage. 143 void LogSendSharingAckMessageResult( 144 chrome_browser_sharing::MessageType message_type, 145 SharingDevicePlatform ack_receiver_device_type, 146 SharingChannelType channel_type, 147 SharingSendMessageResult result); 148 149 // Logs to UMA the size of the selected text for Shared Clipboard. 150 void LogSharedClipboardSelectedTextSize(size_t text_size); 151 152 // Logs to UMA the number of retries for sending a Shared Clipboard message. 153 void LogSharedClipboardRetries(int retries, SharingSendMessageResult result); 154 155 // Logs to UMA the result of handling a Remote Copy message. 156 void LogRemoteCopyHandleMessageResult(RemoteCopyHandleMessageResult result); 157 158 // Logs to UMA the size of the received text for Remote Copy. 159 void LogRemoteCopyReceivedTextSize(size_t size); 160 161 // Logs to UMA the size of the received image (before decoding) for Remote Copy. 162 void LogRemoteCopyReceivedImageSizeBeforeDecode(size_t size); 163 164 // Logs to UMA the size of the received image (after decoding) for Remote Copy. 165 void LogRemoteCopyReceivedImageSizeAfterDecode(size_t size); 166 167 // Logs to UMA the status code of an image load request for Remote Copy. 168 void LogRemoteCopyLoadImageStatusCode(int code); 169 170 // Logs to UMA the time to load an image for Remote Copy. 171 void LogRemoteCopyLoadImageTime(base::TimeDelta time); 172 173 // Logs to UMA the time to decode an image for Remote Copy. 174 void LogRemoteCopyDecodeImageTime(base::TimeDelta time); 175 176 // Logs to UMA the time to resize an image for Remote Copy. 177 void LogRemoteCopyResizeImageTime(base::TimeDelta time); 178 179 // Logs to UMA the duration of a clipboard write for Remote Copy. 180 void LogRemoteCopyWriteTime(base::TimeDelta time, bool is_image); 181 182 // Logs to UMA the time to detect a clipboard write for Remote Copy. 183 void LogRemoteCopyWriteDetectionTime(base::TimeDelta time, bool is_image); 184 185 // Logs to UMA if the DeviceInfo for a guid was available locally. 186 void LogSharingDeviceInfoAvailable(bool available); 187 188 #endif // CHROME_BROWSER_SHARING_SHARING_METRICS_H_ 189