Commit cc5f83fa authored by yilkal's avatar yilkal Committed by Commit Bot

Set time limit for web blocking error page.

This CL ensures that the time limit is shown in the
blocking page.

Bug: 1056471
Change-Id: Ia283881a8f4645f130679a48301d84bcdd32ad69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083398
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746154}
parent aa7b4f47
......@@ -47,8 +47,13 @@ void ChildUserService::PauseWebActivity(const std::string& app_id) {
app_time_controller_->web_time_enforcer();
DCHECK(web_time_enforcer);
// TODO(agawronska): Pass the time limit to |web_time_enforcer|.
web_time_enforcer->OnWebTimeLimitReached();
const base::Optional<app_time::AppLimit>& time_limit =
app_time_controller_->app_registry()->GetWebTimeLimit();
DCHECK(time_limit.has_value());
DCHECK_EQ(time_limit->restriction(), app_time::AppRestriction::kTimeLimit);
DCHECK(time_limit->daily_limit().has_value());
web_time_enforcer->OnWebTimeLimitReached(time_limit->daily_limit().value());
}
void ChildUserService::ResumeWebActivity(const std::string& app_id) {
......@@ -58,7 +63,6 @@ void ChildUserService::ResumeWebActivity(const std::string& app_id) {
app_time_controller_->web_time_enforcer();
DCHECK(web_time_enforcer);
web_time_enforcer->set_time_limit(base::TimeDelta());
web_time_enforcer->OnWebTimeLimitEnded();
}
......
......@@ -11,6 +11,10 @@
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/child_accounts/child_user_service_factory.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_activity_registry.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_time_controller.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_time_limit_utils.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_interface.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h"
......@@ -35,6 +39,16 @@ class ChildUserServiceTest : public testing::Test {
service_ = std::make_unique<ChildUserService>(&profile_);
service_test_api_ =
std::make_unique<ChildUserService::TestApi>(service_.get());
// Install Chrome browser and set its app limit.
app_time::AppActivityRegistry* registry =
service_test_api_->app_time_controller()->app_registry();
registry->OnAppInstalled(app_time::GetChromeAppId());
registry->OnAppAvailable(app_time::GetChromeAppId());
registry->SetAppLimit(
app_time::GetChromeAppId(),
app_time::AppLimit(app_time::AppRestriction::kTimeLimit,
base::TimeDelta::FromHours(1), base::Time::Now()));
}
// Enables per-app time limits feature. Recreates ChildUserService object.
......
......@@ -296,6 +296,11 @@ base::TimeDelta AppActivityRegistry::GetActiveTime(const AppId& app_id) const {
return activity_registry_.at(app_id).activity.RunningActiveTime();
}
const base::Optional<AppLimit>& AppActivityRegistry::GetWebTimeLimit() const {
DCHECK(base::Contains(activity_registry_, GetChromeAppId()));
return activity_registry_.at(GetChromeAppId()).limit;
}
AppState AppActivityRegistry::GetAppState(const AppId& app_id) const {
DCHECK(base::Contains(activity_registry_, app_id));
return activity_registry_.at(app_id).activity.app_state();
......
......@@ -113,6 +113,10 @@ class AppActivityRegistry : public AppServiceWrapper::EventListener {
// reset.
base::TimeDelta GetActiveTime(const AppId& app_id) const;
// Web time limit is the time limit set for Chrome browser. It is shared
// between Chrome and Web apps.
const base::Optional<AppLimit>& GetWebTimeLimit() const;
AppState GetAppState(const AppId& app_id) const;
// Returns the vector of paused applications.
......
......@@ -36,9 +36,10 @@ WebTimeLimitEnforcer::WebTimeLimitEnforcer(
WebTimeLimitEnforcer::~WebTimeLimitEnforcer() = default;
void WebTimeLimitEnforcer::OnWebTimeLimitReached() {
void WebTimeLimitEnforcer::OnWebTimeLimitReached(base::TimeDelta time_limit) {
if (chrome_blocked_)
return;
time_limit_ = time_limit;
chrome_blocked_ = true;
ReloadAllWebContents();
......@@ -48,6 +49,7 @@ void WebTimeLimitEnforcer::OnWebTimeLimitEnded() {
if (!chrome_blocked_)
return;
time_limit_ = base::TimeDelta();
chrome_blocked_ = false;
ReloadAllWebContents();
}
......
......@@ -37,14 +37,13 @@ class WebTimeLimitEnforcer {
// TODO(crbug/1015661) The following should be private observer calls once the
// observer pattern has been set up for this.
void OnWebTimeLimitReached();
void OnWebTimeLimitReached(base::TimeDelta time_limit);
void OnWebTimeLimitEnded();
void OnTimeLimitWhitelistChanged(
const AppTimeLimitsWhitelistPolicyWrapper& value);
bool IsURLWhitelisted(const GURL& url) const;
void set_time_limit(base::TimeDelta time_limit) { time_limit_ = time_limit; }
bool blocked() const { return chrome_blocked_; }
base::TimeDelta time_limit() const { return time_limit_; }
......
......@@ -10,6 +10,7 @@
#include "base/json/json_writer.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/child_accounts/child_user_service.h"
#include "chrome/browser/chromeos/child_accounts/child_user_service_factory.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_time_controller.h"
......@@ -163,7 +164,8 @@ void WebTimeLimitEnforcerThrottleTest::WhitelistApp(
}
void WebTimeLimitEnforcerThrottleTest::BlockWeb() {
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached(
base::TimeDelta::FromHours(1));
}
chromeos::app_time::WebTimeLimitEnforcer*
......@@ -224,7 +226,7 @@ void WebTimeLimitEnforcerThrottleTest::UpdatePolicy() {
IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
WebBlockedBeforeBrowser) {
// Alright let's block the browser.
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
GURL url = embedded_test_server()->GetURL(kExampleHost,
"/supervised_user/simple.html");
......@@ -255,7 +257,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
LoadFinishedWaiter waiter(web_contents, url);
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
waiter.Wait();
......@@ -268,7 +270,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
"/supervised_user/simple.html");
// Alright let's block the browser.
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
......@@ -294,7 +296,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
WhitelistUrlRegx(kExampleHost);
// Alright let's block the browser.
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
......@@ -312,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
"/supervised_user/simple.html");
// Alright let's block the browser.
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
......@@ -336,7 +338,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
GURL url = embedded_test_server()->GetURL(kExampleHost,
"/supervised_user/simple.html");
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
......@@ -358,7 +360,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
WhitelistedSchemesNotBlockedChrome) {
GURL url = GURL("chrome://version");
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
......@@ -401,7 +403,7 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
LoadFinishedWaiter waiter1(web_contents1, web_app_url1);
LoadFinishedWaiter waiter2(web_contents2, web_app_url2);
LoadFinishedWaiter waiter3(web_contents3, normal_url);
GetWebTimeLimitEnforcer()->OnWebTimeLimitReached();
BlockWeb();
waiter1.Wait();
waiter2.Wait();
waiter3.Wait();
......
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