Commit 764b1341 authored by yilkal's avatar yilkal Committed by Commit Bot

Correct bug in AppActivityRegistry.

This CL corrects a bug which occurs in the following
situation:
1. Chrome and its web apps are active for X(example 1 hour).
2. Chrome is still active when time limit is changed to anywhere in 0 >
new_limit < X(above).
3. Observe that other web apps are paused where chrome is not.

Bug: 1057724
Change-Id: I1984057fff376e07bf738aaa31e6cc7eb49b5908
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083630
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746125}
parent a386e492
......@@ -428,8 +428,6 @@ void AppActivityRegistry::SetAppLimit(
return;
}
// TODO(agawronska): Handle web limit changes here.
// Limit for the active app changed - adjust the timers.
// Handling of active app is different, because ongoing activity needs to be
// taken into account.
......@@ -607,6 +605,11 @@ void AppActivityRegistry::SetAppState(const AppId& app_id, AppState app_state) {
AppDetails& app_details = activity_registry_.at(app_id);
AppActivity& app_activity = app_details.activity;
AppState previous_state = app_activity.app_state();
// There was no change in state, return.
if (previous_state == app_state)
return;
app_activity.SetAppState(app_state);
if (app_activity.app_state() == AppState::kLimitReached) {
......@@ -700,6 +703,11 @@ void AppActivityRegistry::ScheduleTimeLimitCheckForApp(const AppId& app_id) {
time_limit = time_limit.value() - kFiveMinutes;
} else if (time_limit > kOneMinute) {
time_limit = time_limit.value() - kOneMinute;
} else if (time_limit == kZeroMinutes) {
// Zero minutes case could be handled by using the timer below, but we call
// it explicitly to simplify tests.
CheckTimeLimitForApp(app_id);
return;
}
VLOG(1) << "Schedule app time limit check for " << app_id << " for "
......@@ -850,13 +858,8 @@ base::TimeDelta AppActivityRegistry::GetWebActiveRunningTime() const {
void AppActivityRegistry::WebTimeLimitReached(base::Time timestamp) {
for (auto& app_info : activity_registry_) {
const AppId& app_id = app_info.first;
AppDetails& details = app_info.second;
if (!ContributesToWebTimeLimit(app_id, GetAppState(app_id))) {
if (!ContributesToWebTimeLimit(app_id, GetAppState(app_id)))
continue;
}
if (details.activity.app_state() == AppState::kLimitReached)
return;
SetAppState(app_id, AppState::kLimitReached);
}
......
......@@ -743,5 +743,26 @@ TEST_F(AppActivityRegistryTest, RemoveOldEntries) {
}
}
TEST_F(AppActivityRegistryTest, ActiveWebAppBlocked) {
// Create activity for web app.
CreateAppActivityForApp(kApp2, base::TimeDelta::FromHours(1));
// Set Chrome as active.
registry().OnChromeAppActivityChanged(ChromeAppActivityState::kActive,
base::Time::Now());
// Update the time limits for Chrome.
AppLimit chrome_limit(AppRestriction::kTimeLimit,
base::TimeDelta::FromMinutes(30), base::Time::Now());
std::map<AppId, AppLimit> app_limits = {{GetChromeAppId(), chrome_limit}};
registry().UpdateAppLimits(app_limits);
// Web time limit should be reached.
EXPECT_EQ(registry().GetAppState(kApp2), AppState::kLimitReached);
EXPECT_EQ(registry().GetAppState(GetChromeAppId()), AppState::kLimitReached);
}
} // namespace app_time
} // namespace chromeos
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