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
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/wallpaper_handlers/wallpaper_handlers_metric_utils.h"
#include <string>
#include <string_view>
#include "ash/constants/ash_features.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "chrome/browser/ash/wallpaper_handlers/sea_pen_fetcher.h"
namespace wallpaper_handlers {
namespace {
// NOTE: These strings are persisted to metric logs.
std::string_view ToHistogramBase(GooglePhotosApi api) {
switch (api) {
case GooglePhotosApi::kGetAlbum:
return "Ash.Wallpaper.GooglePhotos.Api.GetAlbum";
case GooglePhotosApi::kGetAlbums:
return "Ash.Wallpaper.GooglePhotos.Api.GetAlbums";
case GooglePhotosApi::kGetEnabled:
return "Ash.Wallpaper.GooglePhotos.Api.GetEnabled";
case GooglePhotosApi::kGetPhoto:
return "Ash.Wallpaper.GooglePhotos.Api.GetPhoto";
case GooglePhotosApi::kGetPhotos:
return "Ash.Wallpaper.GooglePhotos.Api.GetPhotos";
case GooglePhotosApi::kGetSharedAlbums:
return "Ash.Wallpaper.GooglePhotos.Api.GetSharedAlbums";
}
}
// NOTE: These strings are persisted to metric logs and should match
// SeaPenApiType variants in
// //tools/metrics/histograms/metadata/ash/histograms.xml.
std::string ToHistogramString(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
SeaPenApiType sea_pen_api_type,
std::string_view histogram_name) {
const bool is_text_query =
query_tag ==
ash::personalization_app::mojom::SeaPenQuery::Tag::kTextQuery;
const std::string_view freeform = is_text_query ? "Freeform." : "";
const bool for_thumbnails = sea_pen_api_type == SeaPenApiType::kThumbnails;
const std::string api_type = for_thumbnails ? "Thumbnails." : "Wallpaper.";
return base::StrCat(
{"Ash.SeaPen.", freeform, "Api.", api_type, histogram_name});
}
} // namespace
// NOTE: Histogram names are persisted to metric logs.
void RecordGooglePhotosApiResponseParsed(GooglePhotosApi api,
base::TimeDelta response_time,
std::optional<size_t> result_count) {
const std::string_view histogram_base = ToHistogramBase(api);
const bool success = result_count.has_value();
base::UmaHistogramTimes(base::StrCat({histogram_base, ".ResponseTime.",
success ? "Success" : "Failure"}),
response_time);
base::UmaHistogramBoolean(base::StrCat({histogram_base, ".Result"}), success);
if (success) {
base::UmaHistogramCounts1000(
base::StrCat({histogram_base, ".Result.Count"}), result_count.value());
}
}
void RecordGooglePhotosApiRefreshCount(GooglePhotosApi api, int refresh_count) {
// Record refresh count.
base::UmaHistogramExactLinear(
base::StrCat({ToHistogramBase(api), ".RefreshCount"}), refresh_count, 11);
}
void RecordSeaPenLatency(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
base::TimeDelta elapsed_time,
SeaPenApiType sea_pen_api_type) {
base::UmaHistogramCustomTimes(
ToHistogramString(query_tag, sea_pen_api_type, "Latency"), elapsed_time,
/*min=*/base::Seconds(1),
/*max=*/SeaPenFetcher::kRequestTimeout,
/*buckets=*/50);
}
void RecordSeaPenMantaStatusCode(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
manta::MantaStatusCode status_code,
SeaPenApiType sea_pen_api_type) {
base::UmaHistogramEnumeration(
ToHistogramString(query_tag, sea_pen_api_type, "MantaStatusCode"),
status_code);
}
void RecordSeaPenTimeout(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
bool hit_timeout,
SeaPenApiType sea_pen_api_type) {
base::UmaHistogramBoolean(
ToHistogramString(query_tag, sea_pen_api_type, "Timeout"), hit_timeout);
}
void RecordSeaPenThumbnailsCount(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
size_t thumbnails_count) {
if (!ash::features::IsSeaPenTextInputEnabled()) {
const size_t limit = SeaPenFetcher::kNumTemplateThumbnailsRequested;
base::UmaHistogramExactLinear(
ToHistogramString(query_tag, SeaPenApiType::kThumbnails, "Count"),
std::min(thumbnails_count, limit), limit + 1);
return;
}
const size_t limit = SeaPenFetcher::kNumTextThumbnailsRequested;
// The histogram name is different because when SeaPenTextInput is enabled,
// template query will request 4 thumbnails instead of 8.
//
// Ash.SeaPen.Api.Thumbnails.Count: template thumbnails from 0-8.
// Ash.SeaPen.Api.Thumbnails.Count2: template thumbnails from 0-4.
// Ash.SeaPen.Freeform.Api.Thumbnails.Count: text thumbnails from 0-4.
const std::string_view histogram_name =
(query_tag ==
ash::personalization_app::mojom::SeaPenQuery::Tag::kTextQuery)
? "Count"
: "Count2";
base::UmaHistogramExactLinear(
ToHistogramString(query_tag, SeaPenApiType::kThumbnails, histogram_name),
std::min(thumbnails_count, limit), limit + 1);
}
void RecordSeaPenWallpaperHasImage(
ash::personalization_app::mojom::SeaPenQuery::Tag query_tag,
bool has_image) {
base::UmaHistogramBoolean(
ToHistogramString(query_tag, SeaPenApiType::kWallpaper, "HasImage"),
has_image);
}
} // namespace wallpaper_handlers
|