#include "ash/wallpaper/wallpaper_metrics_manager.h"
#include <string>
#include <string_view>
#include "ash/public/cpp/wallpaper/online_wallpaper_params.h"
#include "ash/public/cpp/wallpaper/wallpaper_types.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wallpaper/wallpaper_constants.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
namespace ash {
namespace {
std::string GetTimeOfDayHistogramName(const uint64_t unit_id) {
const std::string_view base = "Ash.Wallpaper.SetTimeOfDayAfterOobe.";
switch (unit_id) {
case wallpaper_constants::kAlternateTimeOfDayWallpaperUnitId:
return base::StrCat({base, "Alternate"});
case wallpaper_constants::kDefaultTimeOfDayWallpaperUnitId:
return base::StrCat({base, "Default"});
default:
NOTREACHED() << "Invalid unit_id " << unit_id;
}
}
}
WallpaperMetricsManager::WallpaperMetricsManager() {
wallpaper_controller_observation_.Observe(WallpaperController::Get());
}
WallpaperMetricsManager::~WallpaperMetricsManager() = default;
std::string WallpaperMetricsManager::ToResultHistogram(WallpaperType type) {
switch (type) {
case WallpaperType::kOnline:
return "Ash.Wallpaper.Online.Result2";
case WallpaperType::kCustomized:
return "Ash.Wallpaper.Customized.Result2";
case WallpaperType::kOnceGooglePhotos:
return "Ash.Wallpaper.OnceGooglePhotos.Result2";
case WallpaperType::kDaily:
return "Ash.Wallpaper.Daily.Result2";
case WallpaperType::kDailyGooglePhotos:
return "Ash.Wallpaper.DailyGooglePhotos.Result2";
case WallpaperType::kPolicy:
return "Ash.Wallpaper.Policy.Result2";
case WallpaperType::kThirdParty:
return "Ash.Wallpaper.ThirdParty.Result2";
case WallpaperType::kDefault:
return "Ash.Wallpaper.Default.Result2";
case WallpaperType::kDevice:
return "Ash.Wallpaper.Device.Result2";
case WallpaperType::kOobe:
return "Ash.Wallpaper.Oobe.Result2";
case WallpaperType::kSeaPen:
return "Ash.Wallpaper.SeaPen.Result2";
case WallpaperType::kOneShot:
case WallpaperType::kCount:
NOTREACHED();
}
}
void WallpaperMetricsManager::OnOnlineWallpaperSet(
const OnlineWallpaperParams& params) {
if (params.from_user) {
const std::optional<uint64_t>& unit_id = params.unit_id;
DCHECK(unit_id.has_value());
const int unit_id_val = unit_id.value();
base::UmaHistogramSparse("Ash.Wallpaper.Image", unit_id_val);
const std::string& collection_id = params.collection_id;
DCHECK(!collection_id.empty());
const int collection_id_hash = base::PersistentHash(collection_id);
DVLOG(3) << __PRETTY_FUNCTION__ << " collection_id=" << collection_id
<< " hash=" << collection_id_hash;
base::UmaHistogramSparse("Ash.Wallpaper.Collection", collection_id_hash);
}
}
void WallpaperMetricsManager::OnWallpaperChanged() {
base::UmaHistogramEnumeration(
"Ash.Wallpaper.Type",
Shell::Get()->wallpaper_controller()->GetWallpaperType(),
WallpaperType::kCount);
}
void WallpaperMetricsManager::OnWallpaperPreviewStarted() {
base::UmaHistogramBoolean("Ash.Wallpaper.Preview.Show", true);
}
void WallpaperMetricsManager::LogSettingTimeOfDayWallpaperAfterOobe(
const uint64_t unit_id,
const bool success) {
base::UmaHistogramBoolean(GetTimeOfDayHistogramName(unit_id), success);
}
void WallpaperMetricsManager::LogWallpaperResult(WallpaperType type,
SetWallpaperResult result) {
base::UmaHistogramEnumeration(ToResultHistogram(type), result);
}
}