Commit 10664653 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Extract Click to Call metrics into separate file

This makes it easier to find C2C specific metrics and reduces the amount
of code to be compiled on Android.

TBR=avi@chromium.org

Bug: None
Change-Id: I260080a26e944304e406c6110b96b64931713dac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943238
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720228}
parent fb664851
......@@ -3460,6 +3460,8 @@ jumbo_static_library("browser") {
"serial/serial_chooser_context_factory.h",
"sharing/click_to_call/click_to_call_context_menu_observer.cc",
"sharing/click_to_call/click_to_call_context_menu_observer.h",
"sharing/click_to_call/click_to_call_metrics.cc",
"sharing/click_to_call/click_to_call_metrics.h",
"sharing/click_to_call/click_to_call_ui_controller.cc",
"sharing/click_to_call/click_to_call_ui_controller.h",
"sharing/click_to_call/click_to_call_utils.cc",
......
......@@ -15,9 +15,9 @@
#include "chrome/browser/chromeos/arc/arc_web_contents_data.h"
#include "chrome/browser/chromeos/arc/intent_helper/arc_intent_picker_app_fetcher.h"
#include "chrome/browser/chromeos/external_protocol_dialog.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_ui_controller.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
......
......@@ -60,11 +60,11 @@
#include "chrome/browser/send_tab_to_self/send_tab_to_self_desktop_util.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_context_menu_observer.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/features.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_context_menu_observer.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/translate/translate_service.h"
......
......@@ -9,10 +9,10 @@
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_ui_controller.h"
#include "chrome/browser/sharing/click_to_call/feature.h"
#include "chrome/browser/sharing/sharing_constants.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/grit/generated_resources.h"
#include "components/sync_device_info/device_info.h"
#include "components/vector_icons/vector_icons.h"
......
......@@ -12,7 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/optional.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "components/renderer_context_menu/render_view_context_menu_observer.h"
#include "ui/base/models/simple_menu_model.h"
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include <algorithm>
#include <cctype>
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "components/ukm/content/source_url_recorder.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace {
// The returned values must match the values of the SharingClickToCallEntryPoint
// suffixes defined in histograms.xml.
const char* ClickToCallEntryPointToSuffix(
SharingClickToCallEntryPoint entry_point) {
switch (entry_point) {
case SharingClickToCallEntryPoint::kLeftClickLink:
return "LeftClickLink";
case SharingClickToCallEntryPoint::kRightClickLink:
return "RightClickLink";
case SharingClickToCallEntryPoint::kRightClickSelection:
return "RightClickSelection";
}
}
// The returned values must match the values of the PhoneNumberRegexVariant
// suffixes defined in histograms.xml.
const char* PhoneNumberRegexVariantToSuffix(PhoneNumberRegexVariant variant) {
switch (variant) {
case PhoneNumberRegexVariant::kSimple:
return "Simple";
case PhoneNumberRegexVariant::kLowConfidenceModified:
return "LowConfidenceModified";
}
}
// The returned values must match the values of the
// SharingClickToCallSendToDevice suffixes defined in histograms.xml.
const char* SendToDeviceToSuffix(bool send_to_device) {
return send_to_device ? "Sending" : "Showing";
}
} // namespace
ScopedUmaHistogramMicrosecondsTimer::ScopedUmaHistogramMicrosecondsTimer(
PhoneNumberRegexVariant variant)
: variant_(variant) {}
ScopedUmaHistogramMicrosecondsTimer::~ScopedUmaHistogramMicrosecondsTimer() {
constexpr char kPrefix[] =
"Sharing.ClickToCallContextMenuPhoneNumberParsingDelay";
constexpr base::TimeDelta kMinTime = base::TimeDelta::FromMicroseconds(1);
constexpr base::TimeDelta kMaxTime = base::TimeDelta::FromSeconds(1);
constexpr int kBuckets = 50;
base::TimeDelta elapsed = timer_.Elapsed();
// Default bucket for all variants.
base::UmaHistogramCustomMicrosecondsTimes(kPrefix, elapsed, kMinTime,
kMaxTime, kBuckets);
base::UmaHistogramCustomMicrosecondsTimes(
base::StrCat({kPrefix, ".", PhoneNumberRegexVariantToSuffix(variant_)}),
elapsed, kMinTime, kMaxTime, kBuckets);
}
void LogClickToCallHelpTextClicked(SharingDialogType type) {
base::UmaHistogramEnumeration("Sharing.ClickToCallHelpTextClicked", type);
}
void LogClickToCallUKM(content::WebContents* web_contents,
SharingClickToCallEntryPoint entry_point,
bool has_devices,
bool has_apps,
SharingClickToCallSelection selection) {
ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
if (!ukm_recorder)
return;
ukm::SourceId source_id =
ukm::GetSourceIdForWebContentsDocument(web_contents);
if (source_id == ukm::kInvalidSourceId)
return;
ukm::builders::Sharing_ClickToCall(source_id)
.SetEntryPoint(static_cast<int64_t>(entry_point))
.SetHasDevices(has_devices)
.SetHasApps(has_apps)
.SetSelection(static_cast<int64_t>(selection))
.Record(ukm_recorder);
}
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device) {
int length = number.size();
int digits = std::count_if(number.begin(), number.end(),
[](char c) { return std::isdigit(c); });
std::string suffix =
base::StrCat({ClickToCallEntryPointToSuffix(entry_point), ".",
SendToDeviceToSuffix(send_to_device)});
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberLength", length);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberLength.", suffix}), length);
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberDigits", digits);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberDigits.", suffix}), digits);
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SHARING_CLICK_TO_CALL_CLICK_TO_CALL_METRICS_H_
#define CHROME_BROWSER_SHARING_CLICK_TO_CALL_CLICK_TO_CALL_METRICS_H_
#include <string>
#include "base/timer/elapsed_timer.h"
#include "chrome/browser/sharing/click_to_call/phone_number_regex.h"
#include "chrome/browser/sharing/sharing_metrics.h"
namespace content {
class WebContents;
} // namespace content
// Entry point of a Click to Call journey.
// These values are logged to UKM. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// "SharingClickToCallEntryPoint" in src/tools/metrics/histograms/enums.xml.
enum class SharingClickToCallEntryPoint {
kLeftClickLink = 0,
kRightClickLink = 1,
kRightClickSelection = 2,
kMaxValue = kRightClickSelection,
};
// Selection at the end of a Click to Call journey.
// These values are logged to UKM. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// "SharingClickToCallSelection" in src/tools/metrics/histograms/enums.xml.
enum class SharingClickToCallSelection {
kNone = 0,
kDevice = 1,
kApp = 2,
kMaxValue = kApp,
};
// TODO(himanshujaju): Make it generic and move to base/metrics/histogram_base.h
// Used to Log delay in parsing phone number in highlighted text to UMA.
class ScopedUmaHistogramMicrosecondsTimer {
public:
explicit ScopedUmaHistogramMicrosecondsTimer(PhoneNumberRegexVariant variant);
ScopedUmaHistogramMicrosecondsTimer(
const ScopedUmaHistogramMicrosecondsTimer&) = delete;
ScopedUmaHistogramMicrosecondsTimer& operator=(
const ScopedUmaHistogramMicrosecondsTimer&) = delete;
~ScopedUmaHistogramMicrosecondsTimer();
private:
const PhoneNumberRegexVariant variant_;
const base::ElapsedTimer timer_;
};
// Logs the dialog type when a user clicks on the help text in the Click to Call
// dialog.
void LogClickToCallHelpTextClicked(SharingDialogType type);
// Records a Click to Call selection to UKM. This is logged after a completed
// action like selecting an app or a device to send the phone number to.
void LogClickToCallUKM(content::WebContents* web_contents,
SharingClickToCallEntryPoint entry_point,
bool has_devices,
bool has_apps,
SharingClickToCallSelection selection);
// Logs the raw phone number length and the number of digits in it.
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device);
#endif // CHROME_BROWSER_SHARING_CLICK_TO_CALL_CLICK_TO_CALL_METRICS_H_
......@@ -12,7 +12,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_ui_controller.h"
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
......
......@@ -11,9 +11,9 @@
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/feature.h"
#include "chrome/browser/sharing/click_to_call/phone_number_regex.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/common/pref_names.h"
......
......@@ -4,19 +4,9 @@
#include "chrome/browser/sharing/sharing_metrics.h"
#include <string.h>
#include <algorithm>
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/strcat.h"
#include "chrome/browser/sharing/sharing_device_registration_result.h"
#include "components/cast_channel/enum_table.h"
#include "components/ukm/content/source_url_recorder.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace {
const char* GetEnumStringValue(SharingFeatureName feature) {
......@@ -33,37 +23,6 @@ const char* GetEnumStringValue(SharingFeatureName feature) {
}
}
// The returned values must match the values of the SharingClickToCallEntryPoint
// suffixes defined in histograms.xml.
const char* ClickToCallEntryPointToSuffix(
SharingClickToCallEntryPoint entry_point) {
switch (entry_point) {
case SharingClickToCallEntryPoint::kLeftClickLink:
return "LeftClickLink";
case SharingClickToCallEntryPoint::kRightClickLink:
return "RightClickLink";
case SharingClickToCallEntryPoint::kRightClickSelection:
return "RightClickSelection";
}
}
// The returned values must match the values of the PhoneNumberRegexVariant
// suffixes defined in histograms.xml.
const char* PhoneNumberRegexVariantToSuffix(PhoneNumberRegexVariant variant) {
switch (variant) {
case PhoneNumberRegexVariant::kSimple:
return "Simple";
case PhoneNumberRegexVariant::kLowConfidenceModified:
return "LowConfidenceModified";
}
}
// The returned values must match the values of the
// SharingClickToCallSendToDevice suffixes defined in histograms.xml.
const char* SendToDeviceToSuffix(bool send_to_device) {
return send_to_device ? "Sending" : "Showing";
}
const std::string& MessageTypeToMessageSuffix(
chrome_browser_sharing::MessageType message_type) {
// For proto3 enums unrecognized enum values are kept when parsing and their
......@@ -78,26 +37,6 @@ const std::string& MessageTypeToMessageSuffix(
}
} // namespace
ScopedUmaHistogramMicrosecondsTimer::ScopedUmaHistogramMicrosecondsTimer(
PhoneNumberRegexVariant variant)
: variant_(variant) {}
ScopedUmaHistogramMicrosecondsTimer::~ScopedUmaHistogramMicrosecondsTimer() {
constexpr char kPrefix[] =
"Sharing.ClickToCallContextMenuPhoneNumberParsingDelay";
constexpr base::TimeDelta kMinTime = base::TimeDelta::FromMicroseconds(1);
constexpr base::TimeDelta kMaxTime = base::TimeDelta::FromSeconds(1);
constexpr int kBuckets = 50;
base::TimeDelta elapsed = timer_.Elapsed();
// Default bucket for all variants.
base::UmaHistogramCustomMicrosecondsTimes(kPrefix, elapsed, kMinTime,
kMaxTime, kBuckets);
base::UmaHistogramCustomMicrosecondsTimes(
base::StrCat({kPrefix, ".", PhoneNumberRegexVariantToSuffix(variant_)}),
elapsed, kMinTime, kMaxTime, kBuckets);
}
chrome_browser_sharing::MessageType SharingPayloadCaseToMessageType(
chrome_browser_sharing::SharingMessage::PayloadCase payload_case) {
switch (payload_case) {
......@@ -255,10 +194,6 @@ void LogSharingDialogShown(SharingFeatureName feature, SharingDialogType type) {
type);
}
void LogClickToCallHelpTextClicked(SharingDialogType type) {
base::UmaHistogramEnumeration("Sharing.ClickToCallHelpTextClicked", type);
}
void LogSendSharingMessageResult(
chrome_browser_sharing::MessageType message_type,
SharingSendMessageResult result) {
......@@ -279,53 +214,11 @@ void LogSendSharingAckMessageResult(
result);
}
void LogClickToCallUKM(content::WebContents* web_contents,
SharingClickToCallEntryPoint entry_point,
bool has_devices,
bool has_apps,
SharingClickToCallSelection selection) {
ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
if (!ukm_recorder)
return;
ukm::SourceId source_id =
ukm::GetSourceIdForWebContentsDocument(web_contents);
if (source_id == ukm::kInvalidSourceId)
return;
ukm::builders::Sharing_ClickToCall(source_id)
.SetEntryPoint(static_cast<int64_t>(entry_point))
.SetHasDevices(has_devices)
.SetHasApps(has_apps)
.SetSelection(static_cast<int64_t>(selection))
.Record(ukm_recorder);
}
void LogSharedClipboardSelectedTextSize(size_t size) {
base::UmaHistogramCounts100000("Sharing.SharedClipboardSelectedTextSize",
size);
}
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device) {
int length = number.size();
int digits = std::count_if(number.begin(), number.end(),
[](char c) { return std::isdigit(c); });
std::string suffix =
base::StrCat({ClickToCallEntryPointToSuffix(entry_point), ".",
SendToDeviceToSuffix(send_to_device)});
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberLength", length);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberLength.", suffix}), length);
base::UmaHistogramCounts100("Sharing.ClickToCallPhoneNumberDigits", digits);
base::UmaHistogramCounts100(
base::StrCat({"Sharing.ClickToCallPhoneNumberDigits.", suffix}), digits);
}
void LogRemoteCopyHandleMessageResult(RemoteCopyHandleMessageResult result) {
base::UmaHistogramEnumeration("Sharing.RemoteCopyHandleMessageResult",
result);
......
......@@ -5,21 +5,12 @@
#ifndef CHROME_BROWSER_SHARING_SHARING_METRICS_H_
#define CHROME_BROWSER_SHARING_SHARING_METRICS_H_
#include <string>
#include "base/macros.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "chrome/browser/sharing/click_to_call/phone_number_regex.h"
#include "chrome/browser/sharing/shared_clipboard/remote_copy_handle_message_result.h"
#include "chrome/browser/sharing/sharing_constants.h"
#include "chrome/browser/sharing/sharing_send_message_result.h"
#include "components/sync/protocol/sharing_message.pb.h"
namespace content {
class WebContents;
} // namespace content
enum class SharingDeviceRegistrationResult;
// Result of VAPID key creation during Sharing registration.
......@@ -50,45 +41,6 @@ enum class SharingDialogType {
// defined in histograms.xml.
const char kSharingUiContextMenu[] = "ContextMenu";
const char kSharingUiDialog[] = "Dialog";
// Entry point of a Click to Call journey.
// These values are logged to UKM. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// "SharingClickToCallEntryPoint" in src/tools/metrics/histograms/enums.xml.
enum class SharingClickToCallEntryPoint {
kLeftClickLink = 0,
kRightClickLink = 1,
kRightClickSelection = 2,
kMaxValue = kRightClickSelection,
};
// Selection at the end of a Click to Call journey.
// These values are logged to UKM. Entries should not be renumbered and numeric
// values should never be reused. Please keep in sync with
// "SharingClickToCallSelection" in src/tools/metrics/histograms/enums.xml.
enum class SharingClickToCallSelection {
kNone = 0,
kDevice = 1,
kApp = 2,
kMaxValue = kApp,
};
// TODO(himanshujaju): Make it generic and move to base/metrics/histogram_base.h
// Used to Log delay in parsing phone number in highlighted text to UMA.
struct ScopedUmaHistogramMicrosecondsTimer {
explicit ScopedUmaHistogramMicrosecondsTimer(PhoneNumberRegexVariant variant);
~ScopedUmaHistogramMicrosecondsTimer();
private:
const PhoneNumberRegexVariant variant_;
const base::ElapsedTimer timer_;
DISALLOW_COPY_AND_ASSIGN(ScopedUmaHistogramMicrosecondsTimer);
};
// These histogram suffixes must match the ones in SharingClickToCallUi defined
// in histograms.xml.
const char kSharingClickToCallUiContextMenu[] = "ContextMenu";
const char kSharingClickToCallUiDialog[] = "Dialog";
chrome_browser_sharing::MessageType SharingPayloadCaseToMessageType(
chrome_browser_sharing::SharingMessage::PayloadCase payload_case);
......@@ -156,10 +108,6 @@ void LogSharingMessageAckTime(chrome_browser_sharing::MessageType message_type,
// Logs to UMA the |type| of dialog shown for sharing feature.
void LogSharingDialogShown(SharingFeatureName feature, SharingDialogType type);
// Logs the dialog type when a user clicks on the help text in the Click to Call
// dialog.
void LogClickToCallHelpTextClicked(SharingDialogType type);
// Logs to UMA result of sending a SharingMessage. This should not be called for
// sending ack messages.
void LogSendSharingMessageResult(
......@@ -171,22 +119,9 @@ void LogSendSharingAckMessageResult(
chrome_browser_sharing::MessageType message_type,
SharingSendMessageResult result);
// Records a Click to Call selection to UKM. This is logged after a completed
// action like selecting an app or a device to send the phone number to.
void LogClickToCallUKM(content::WebContents* web_contents,
SharingClickToCallEntryPoint entry_point,
bool has_devices,
bool has_apps,
SharingClickToCallSelection selection);
// Logs to UMA the size of the selected text for Shared Clipboard.
void LogSharedClipboardSelectedTextSize(size_t text_size);
// Logs the raw phone number length and the number of digits in it.
void LogClickToCallPhoneNumberSize(const std::string& number,
SharingClickToCallEntryPoint entry_point,
bool send_to_device);
// Logs to UMA the result of handling a Remote Copy message.
void LogRemoteCopyHandleMessageResult(RemoteCopyHandleMessageResult result);
......
......@@ -15,12 +15,12 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_ui_controller.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/click_to_call/feature.h"
#include "chrome/browser/sharing/features.h"
#include "chrome/browser/sharing/sharing_constants.h"
#include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/sharing/sharing_sync_preference.h"
#include "chrome/browser/sync/test/integration/sessions_helper.h"
#include "chrome/browser/ui/views/hover_button.h"
......
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