Commit 22e88766 authored by Sergey Poromov's avatar Sergey Poromov Committed by Commit Bot

Remove child-related code from DeviceStatusCollector.

DeviceStatusCollector is used only for enterprise reporting,
consumer (child) reporting is extracted to ChildStatusCollector,
so it's safe to remove this flag for simplicity and ensure that
DeviceStatusCollector is initialized only for enterprise reporting.

Test: Run trybots.
Change-Id: Ib64ca56c3e402b6c99ededc856a96674a2e025c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864992Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Commit-Queue: Sergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707819}
parent 8e14e369
...@@ -128,10 +128,6 @@ const char kStorageInfoPath[] = "/var/log/storage_info.txt"; ...@@ -128,10 +128,6 @@ const char kStorageInfoPath[] = "/var/log/storage_info.txt";
// The location where stateful partition info is read from. // The location where stateful partition info is read from.
const char kStatefulPartitionPath[] = "/home/.shadow"; const char kStatefulPartitionPath[] = "/home/.shadow";
// How often the child's usage time is stored.
static constexpr base::TimeDelta kUpdateChildActiveTimeInterval =
base::TimeDelta::FromSeconds(30);
// Helper function (invoked via blocking pool) to fetch information about // Helper function (invoked via blocking pool) to fetch information about
// mounted disks. // mounted disks.
std::vector<em::VolumeInfo> GetVolumeInfo( std::vector<em::VolumeInfo> GetVolumeInfo(
...@@ -841,9 +837,6 @@ DeviceStatusCollector::DeviceStatusCollector( ...@@ -841,9 +837,6 @@ DeviceStatusCollector::DeviceStatusCollector(
idle_poll_timer_.Start(FROM_HERE, idle_poll_timer_.Start(FROM_HERE,
TimeDelta::FromSeconds(kIdlePollIntervalSeconds), this, TimeDelta::FromSeconds(kIdlePollIntervalSeconds), this,
&DeviceStatusCollector::CheckIdleState); &DeviceStatusCollector::CheckIdleState);
update_child_usage_timer_.Start(FROM_HERE, kUpdateChildActiveTimeInterval,
this,
&DeviceStatusCollector::UpdateChildUsageTime);
resource_usage_sampling_timer_.Start( resource_usage_sampling_timer_.Start(
FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds), FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds),
this, &DeviceStatusCollector::SampleResourceUsage); this, &DeviceStatusCollector::SampleResourceUsage);
...@@ -878,8 +871,6 @@ DeviceStatusCollector::DeviceStatusCollector( ...@@ -878,8 +871,6 @@ DeviceStatusCollector::DeviceStatusCollector(
chromeos::kReportDeviceBoardStatus, callback); chromeos::kReportDeviceBoardStatus, callback);
power_manager_->AddObserver(this); power_manager_->AddObserver(this);
// Watch for changes on the device state to calculate the child's active time.
chromeos::UsageTimeStateNotifier::GetInstance()->AddObserver(this);
// Fetch the current values of the policies. // Fetch the current values of the policies.
UpdateReportingSettings(); UpdateReportingSettings();
...@@ -916,7 +907,6 @@ DeviceStatusCollector::DeviceStatusCollector( ...@@ -916,7 +907,6 @@ DeviceStatusCollector::DeviceStatusCollector(
DeviceStatusCollector::~DeviceStatusCollector() { DeviceStatusCollector::~DeviceStatusCollector() {
power_manager_->RemoveObserver(this); power_manager_->RemoveObserver(this);
chromeos::UsageTimeStateNotifier::GetInstance()->RemoveObserver(this);
} }
// static // static
...@@ -924,15 +914,6 @@ void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { ...@@ -924,15 +914,6 @@ void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes); registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes);
} }
TimeDelta DeviceStatusCollector::GetActiveChildScreenTime() {
if (!user_manager::UserManager::Get()->IsLoggedInAsChildUser())
return TimeDelta::FromSeconds(0);
UpdateChildUsageTime();
return TimeDelta::FromMilliseconds(
pref_service_->GetInteger(prefs::kChildScreenTimeMilliseconds));
}
void DeviceStatusCollector::CheckIdleState() { void DeviceStatusCollector::CheckIdleState() {
ProcessIdleState(ui::CalculateIdleState(kIdleStateThresholdSeconds)); ProcessIdleState(ui::CalculateIdleState(kIdleStateThresholdSeconds));
} }
...@@ -1016,12 +997,9 @@ void DeviceStatusCollector::ClearCachedResourceUsage() { ...@@ -1016,12 +997,9 @@ void DeviceStatusCollector::ClearCachedResourceUsage() {
} }
void DeviceStatusCollector::ProcessIdleState(ui::IdleState state) { void DeviceStatusCollector::ProcessIdleState(ui::IdleState state) {
// Do nothing if device activity reporting is disabled or if it's a child // Do nothing if device activity reporting is disabled.
// account. Usage time for child accounts are calculated differently. if (!report_activity_times_)
if (!report_activity_times_ ||
user_manager::UserManager::Get()->IsLoggedInAsChildUser()) {
return; return;
}
Time now = GetCurrentTime(); Time now = GetCurrentTime();
...@@ -1048,60 +1026,12 @@ void DeviceStatusCollector::ProcessIdleState(ui::IdleState state) { ...@@ -1048,60 +1026,12 @@ void DeviceStatusCollector::ProcessIdleState(ui::IdleState state) {
last_idle_check_ = now; last_idle_check_ = now;
} }
void DeviceStatusCollector::OnUsageTimeStateChange(
chromeos::UsageTimeStateNotifier::UsageTimeState state) {
UpdateChildUsageTime();
last_state_active_ =
state == chromeos::UsageTimeStateNotifier::UsageTimeState::ACTIVE;
}
void DeviceStatusCollector::PowerChanged( void DeviceStatusCollector::PowerChanged(
const power_manager::PowerSupplyProperties& prop) { const power_manager::PowerSupplyProperties& prop) {
if (!power_status_callback_.is_null()) if (!power_status_callback_.is_null())
std::move(power_status_callback_).Run(prop); std::move(power_status_callback_).Run(prop);
} }
void DeviceStatusCollector::UpdateChildUsageTime() {
if (!report_activity_times_ ||
!user_manager::UserManager::Get()->IsLoggedInAsChildUser()) {
return;
}
// Only child accounts should be using this method.
CHECK(user_manager::UserManager::Get()->IsLoggedInAsChildUser());
Time now = GetCurrentTime();
Time reset_time = activity_storage_->GetBeginningOfDay(now);
if (reset_time > now)
reset_time -= TimeDelta::FromDays(1);
// Reset screen time if it has not been reset today.
if (reset_time > pref_service_->GetTime(prefs::kLastChildScreenTimeReset)) {
pref_service_->SetTime(prefs::kLastChildScreenTimeReset, now);
pref_service_->SetInteger(prefs::kChildScreenTimeMilliseconds, 0);
pref_service_->CommitPendingWrite();
}
if (!last_active_check_.is_null() && last_state_active_) {
// If it's been too long since the last report, or if the activity is
// negative (which can happen when the clock changes), assume a single
// interval of activity. This is the same strategy used to enterprise users.
base::TimeDelta active_seconds = now - last_active_check_;
if (active_seconds < base::TimeDelta::FromSeconds(0) ||
active_seconds >= (2 * kUpdateChildActiveTimeInterval)) {
activity_storage_->AddActivityPeriod(now - kUpdateChildActiveTimeInterval,
now, GetUserForActivityReporting());
} else {
activity_storage_->AddActivityPeriod(last_active_check_, now,
GetUserForActivityReporting());
}
activity_storage_->PruneActivityPeriods(
now, max_stored_past_activity_interval_,
max_stored_future_activity_interval_);
}
last_active_check_ = now;
}
void DeviceStatusCollector::SampleResourceUsage() { void DeviceStatusCollector::SampleResourceUsage() {
// Results must be written in the creation thread since that's where they // Results must be written in the creation thread since that's where they
// are read from in the Get*StatusAsync methods. // are read from in the Get*StatusAsync methods.
...@@ -1350,8 +1280,7 @@ std::string DeviceStatusCollector::GetUserForActivityReporting() const { ...@@ -1350,8 +1280,7 @@ std::string DeviceStatusCollector::GetUserForActivityReporting() const {
if (!primary_user || !primary_user->HasGaiaAccount()) if (!primary_user || !primary_user->HasGaiaAccount())
return std::string(); return std::string();
// Report only affiliated users for enterprise reporting and signed-in user // Report only affiliated users for enterprise reporting.
// for consumer reporting.
std::string primary_user_email = primary_user->GetAccountId().GetUserEmail(); std::string primary_user_email = primary_user->GetAccountId().GetUserEmail();
if (!chromeos::ChromeUserManager::Get()->ShouldReportUser( if (!chromeos::ChromeUserManager::Get()->ShouldReportUser(
primary_user_email)) { primary_user_email)) {
...@@ -1368,10 +1297,6 @@ bool DeviceStatusCollector::IncludeEmailsInActivityReports() const { ...@@ -1368,10 +1297,6 @@ bool DeviceStatusCollector::IncludeEmailsInActivityReports() const {
bool DeviceStatusCollector::GetActivityTimes( bool DeviceStatusCollector::GetActivityTimes(
em::DeviceStatusReportRequest* status) { em::DeviceStatusReportRequest* status) {
if (user_manager::UserManager::Get()->IsLoggedInAsChildUser()) {
UpdateChildUsageTime();
}
// If user reporting is off, data should be aggregated per day. // If user reporting is off, data should be aggregated per day.
// Signed-in user is reported in non-enterprise reporting. // Signed-in user is reported in non-enterprise reporting.
std::vector<ActivityStorage::ActivityPeriod> activity_times = std::vector<ActivityStorage::ActivityPeriod> activity_times =
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/chromeos/child_accounts/usage_time_state_notifier.h"
#include "chrome/browser/chromeos/policy/status_collector/status_collector.h" #include "chrome/browser/chromeos/policy/status_collector/status_collector.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chromeos/dbus/cryptohome/cryptohome_client.h" #include "chromeos/dbus/cryptohome/cryptohome_client.h"
...@@ -111,7 +110,6 @@ class SampledData { ...@@ -111,7 +110,6 @@ class SampledData {
// Collects and summarizes the status of an enterprise-managed ChromeOS device. // Collects and summarizes the status of an enterprise-managed ChromeOS device.
class DeviceStatusCollector : public StatusCollector, class DeviceStatusCollector : public StatusCollector,
public chromeos::UsageTimeStateNotifier::Observer,
public chromeos::PowerManagerClient::Observer { public chromeos::PowerManagerClient::Observer {
public: public:
using VolumeInfoFetcher = using VolumeInfoFetcher =
...@@ -196,10 +194,6 @@ class DeviceStatusCollector : public StatusCollector, ...@@ -196,10 +194,6 @@ class DeviceStatusCollector : public StatusCollector,
// The total number of hardware resource usage samples cached internally. // The total number of hardware resource usage samples cached internally.
static const unsigned int kMaxResourceUsageSamples = 10; static const unsigned int kMaxResourceUsageSamples = 10;
// Returns the amount of time the child has used so far today. If the user is
// not a child or if there is no user logged in, it returns 0.
base::TimeDelta GetActiveChildScreenTime();
protected: protected:
using PowerStatusCallback = base::OnceCallback<void( using PowerStatusCallback = base::OnceCallback<void(
const power_manager::PowerSupplyProperties& prop)>; const power_manager::PowerSupplyProperties& prop)>;
...@@ -217,16 +211,9 @@ class DeviceStatusCollector : public StatusCollector, ...@@ -217,16 +211,9 @@ class DeviceStatusCollector : public StatusCollector,
// next device status update. // next device status update.
void SampleResourceUsage(); void SampleResourceUsage();
// chromeos::UsageTimeStateNotifier::Observer:
void OnUsageTimeStateChange(
chromeos::UsageTimeStateNotifier::UsageTimeState state) override;
// power_manager::PowerManagerClient::Observer: // power_manager::PowerManagerClient::Observer:
void PowerChanged(const power_manager::PowerSupplyProperties& prop) override; void PowerChanged(const power_manager::PowerSupplyProperties& prop) override;
// Updates the child's active time.
void UpdateChildUsageTime();
private: private:
// Callbacks used during sampling data collection, that allows to pass // Callbacks used during sampling data collection, that allows to pass
// additional data using partial function application. // additional data using partial function application.
...@@ -336,13 +323,6 @@ class DeviceStatusCollector : public StatusCollector, ...@@ -336,13 +323,6 @@ class DeviceStatusCollector : public StatusCollector,
// The last time an idle state check was performed. // The last time an idle state check was performed.
base::Time last_idle_check_; base::Time last_idle_check_;
// The last time an active state check was performed.
base::Time last_active_check_;
// Whether the last state of the device was active. This is used for child
// accounts only. Active is defined as having the screen turned on.
bool last_state_active_ = true;
// The maximum key that went into the last report generated by // The maximum key that went into the last report generated by
// GetStatusAsync(), and the duration for it. This is used to trim the stored // GetStatusAsync(), and the duration for it. This is used to trim the stored
// data in OnSubmittedSuccessfully(). Trimming is delayed so unsuccessful // data in OnSubmittedSuccessfully(). Trimming is delayed so unsuccessful
...@@ -351,7 +331,6 @@ class DeviceStatusCollector : public StatusCollector, ...@@ -351,7 +331,6 @@ class DeviceStatusCollector : public StatusCollector,
int duration_for_last_reported_day_ = 0; int duration_for_last_reported_day_ = 0;
base::RepeatingTimer idle_poll_timer_; base::RepeatingTimer idle_poll_timer_;
base::RepeatingTimer update_child_usage_timer_;
base::RepeatingTimer resource_usage_sampling_timer_; base::RepeatingTimer resource_usage_sampling_timer_;
std::string os_version_; std::string os_version_;
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h" #include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_update_engine_client.h" #include "chromeos/dbus/fake_update_engine_client.h"
#include "chromeos/dbus/power/fake_power_manager_client.h"
#include "chromeos/dbus/power_manager/idle.pb.h" #include "chromeos/dbus/power_manager/idle.pb.h"
#include "chromeos/dbus/shill/shill_device_client.h" #include "chromeos/dbus/shill/shill_device_client.h"
#include "chromeos/dbus/shill/shill_ipconfig_client.h" #include "chromeos/dbus/shill/shill_ipconfig_client.h"
...@@ -173,8 +172,6 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { ...@@ -173,8 +172,6 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector {
SetBaselineTime(Time::Now().LocalMidnight() + kHour); SetBaselineTime(Time::Now().LocalMidnight() + kHour);
} }
void UpdateUsageTime() { UpdateChildUsageTime(); }
void Simulate(ui::IdleState* states, int len) { void Simulate(ui::IdleState* states, int len) {
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
ProcessIdleState(states[i]); ProcessIdleState(states[i]);
...@@ -514,56 +511,6 @@ class DeviceStatusCollectorTest : public testing::Test { ...@@ -514,56 +511,6 @@ class DeviceStatusCollectorTest : public testing::Test {
void TearDown() override { status_collector_.reset(); } void TearDown() override { status_collector_.reset(); }
protected: protected:
// States tracked to calculate a child's active time.
enum class DeviceStateTransitions {
kEnterIdleState,
kLeaveIdleState,
kEnterSleep,
kLeaveSleep,
kEnterSessionActive,
kLeaveSessionActive,
kPeriodicCheckTriggered
};
void SimulateStateChanges(DeviceStateTransitions* states, int len) {
for (int i = 0; i < len; i++) {
switch (states[i]) {
case DeviceStateTransitions::kEnterIdleState: {
power_manager::ScreenIdleState state;
state.set_off(true);
chromeos::FakePowerManagerClient::Get()->SendScreenIdleStateChanged(
state);
} break;
case DeviceStateTransitions::kLeaveIdleState: {
power_manager::ScreenIdleState state;
state.set_off(false);
chromeos::FakePowerManagerClient::Get()->SendScreenIdleStateChanged(
state);
} break;
case DeviceStateTransitions::kEnterSleep:
chromeos::FakePowerManagerClient::Get()->SendSuspendImminent(
power_manager::SuspendImminent_Reason_LID_CLOSED);
break;
case DeviceStateTransitions::kLeaveSleep:
chromeos::FakePowerManagerClient::Get()->SendSuspendDone(
base::TimeDelta::FromSeconds(
policy::DeviceStatusCollector::kIdlePollIntervalSeconds));
break;
case DeviceStateTransitions::kEnterSessionActive:
session_manager::SessionManager::Get()->SetSessionState(
session_manager::SessionState::ACTIVE);
break;
case DeviceStateTransitions::kLeaveSessionActive:
session_manager::SessionManager::Get()->SetSessionState(
session_manager::SessionState::LOCKED);
break;
case DeviceStateTransitions::kPeriodicCheckTriggered:
status_collector_->UpdateUsageTime();
break;
}
}
}
void AddMountPoint(const std::string& mount_point) { void AddMountPoint(const std::string& mount_point) {
mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
mount_point, DiskMountManager::MountPointInfo( mount_point, DiskMountManager::MountPointInfo(
...@@ -640,13 +587,6 @@ class DeviceStatusCollectorTest : public testing::Test { ...@@ -640,13 +587,6 @@ class DeviceStatusCollectorTest : public testing::Test {
is_affiliated); is_affiliated);
} }
void MockChildUser(const AccountId& account_id) {
MockUserWithTypeAndAffiliation(account_id, user_manager::USER_TYPE_CHILD,
false);
EXPECT_CALL(*user_manager_, IsLoggedInAsChildUser())
.WillRepeatedly(Return(true));
}
void MockRunningKioskApp(const DeviceLocalAccount& account, bool arc_kiosk) { void MockRunningKioskApp(const DeviceLocalAccount& account, bool arc_kiosk) {
std::vector<DeviceLocalAccount> accounts; std::vector<DeviceLocalAccount> accounts;
accounts.push_back(account); accounts.push_back(account);
......
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