Commit d3412849 authored by Rachel Wong's avatar Rachel Wong Committed by Commit Bot

[settings logging] Log whether or not video is playing.

Bug: 1014839
Change-Id: Id8d23da26d5d5fa796f3f53e921ac1d7adccb34f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093958Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Rachel Wong <wrong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748121}
parent 0406fc0b
......@@ -53,14 +53,17 @@ UserSettingsEventLogger::UserSettingsEventLogger()
is_recently_fullscreen_(false),
used_cellular_in_session_(false),
is_playing_audio_(false),
is_playing_video_(false),
clock_(base::DefaultClock::GetInstance()) {
Shell::Get()->AddShellObserver(this);
chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
Shell::Get()->video_detector()->AddObserver(this);
}
UserSettingsEventLogger::~UserSettingsEventLogger() {
Shell::Get()->RemoveShellObserver(this);
chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
Shell::Get()->video_detector()->RemoveObserver(this);
}
void UserSettingsEventLogger::LogNetworkUkmEvent(
......@@ -274,6 +277,11 @@ void UserSettingsEventLogger::OnOutputStopped() {
is_playing_audio_ = false;
}
void UserSettingsEventLogger::OnVideoStateChanged(
const VideoDetector::State state) {
is_playing_video_ = (state != VideoDetector::State::NOT_PLAYING);
}
void UserSettingsEventLogger::SetClockForTesting(const base::Clock* clock) {
clock_ = clock;
}
......@@ -300,7 +308,7 @@ void UserSettingsEventLogger::PopulateSharedFeatures(
// Set activity features.
features->set_is_playing_audio(is_playing_audio_);
// TODO(crbug/1014839): Set the |is_playing_video| field.
features->set_is_playing_video(is_playing_video_);
// Set orientation features.
features->set_device_mode(
......@@ -347,6 +355,8 @@ void UserSettingsEventLogger::SendToUkmAndAppList(
ukm_event.SetIsCharging(features.is_charging());
if (features.has_is_playing_audio())
ukm_event.SetIsPlayingAudio(features.is_playing_audio());
if (features.has_is_playing_video())
ukm_event.SetIsPlayingVideo(features.is_playing_video());
if (features.has_device_mode())
ukm_event.SetDeviceMode(features.device_mode());
if (features.has_device_orientation())
......
......@@ -9,6 +9,7 @@
#include "ash/shell_observer.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/machine_learning/user_settings_event.pb.h"
#include "ash/wm/video_detector.h"
#include "base/sequence_checker.h"
#include "base/time/clock.h"
#include "base/timer/timer.h"
......@@ -24,7 +25,8 @@ static constexpr base::TimeDelta kSliderDelay = base::TimeDelta::FromSeconds(1);
// user from the quick settings tray. Exported for tests.
class ASH_EXPORT UserSettingsEventLogger
: public ShellObserver,
public chromeos::CrasAudioHandler::AudioObserver {
public chromeos::CrasAudioHandler::AudioObserver,
public VideoDetector::Observer {
public:
UserSettingsEventLogger(const UserSettingsEventLogger&) = delete;
UserSettingsEventLogger& operator=(const UserSettingsEventLogger&) = delete;
......@@ -73,6 +75,9 @@ class ASH_EXPORT UserSettingsEventLogger
void OnOutputStarted() override;
void OnOutputStopped() override;
// VideoDetector::Observer overrides:
void OnVideoStateChanged(VideoDetector::State state) override;
void SetClockForTesting(const base::Clock* clock);
private:
......@@ -113,6 +118,7 @@ class ASH_EXPORT UserSettingsEventLogger
bool used_cellular_in_session_;
bool is_playing_audio_;
bool is_playing_video_;
const base::Clock* clock_;
......
......@@ -492,6 +492,24 @@ TEST_F(UserSettingsEventLoggerTest, TestLogAudio) {
TestUkmRecorder::ExpectEntryMetric(entries[2], "IsPlayingAudio", false);
}
TEST_F(UserSettingsEventLoggerTest, TestLogVideo) {
LogSharedFeatures();
logger_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN);
LogSharedFeatures();
logger_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING);
LogSharedFeatures();
logger_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED);
LogSharedFeatures();
const auto& entries = GetUkmEntries();
ASSERT_EQ(4ul, entries.size());
TestUkmRecorder::ExpectEntryMetric(entries[0], "IsPlayingVideo", false);
TestUkmRecorder::ExpectEntryMetric(entries[1], "IsPlayingVideo", true);
TestUkmRecorder::ExpectEntryMetric(entries[2], "IsPlayingVideo", false);
TestUkmRecorder::ExpectEntryMetric(entries[3], "IsPlayingVideo", true);
}
TEST_F(UserSettingsEventLoggerTest, TestLogTabletMode) {
auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
......
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