1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_CHILD_USER_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_CHILD_USER_SERVICE_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "chrome/browser/chromeos/child_accounts/time_limits/app_activity_report_interface.h" 12 #include "chrome/browser/chromeos/child_accounts/time_limits/app_time_limit_interface.h" 13 #include "components/keyed_service/core/keyed_service.h" 14 15 namespace base { 16 class TimeDelta; 17 } // namespace base 18 19 namespace content { 20 class BrowserContext; 21 } // namespace content 22 23 namespace enterprise_management { 24 class ChildStatusReportRequest; 25 } // namespace enterprise_management 26 27 class GURL; 28 29 namespace chromeos { 30 namespace app_time { 31 class AppId; 32 class AppTimeController; 33 class WebTimeLimitEnforcer; 34 } // namespace app_time 35 36 // Facade that exposes child user related functionality on Chrome OS. 37 // TODO(crbug.com/1022231): Migrate ConsumerStatusReportingService, 38 // EventBasedStatusReporting and ScreenTimeController to ChildUserService. 39 class ChildUserService : public KeyedService, 40 public app_time::AppTimeLimitInterface, 41 public app_time::AppActivityReportInterface { 42 public: 43 // Used for tests to get internal implementation details. 44 class TestApi { 45 public: 46 explicit TestApi(ChildUserService* service); 47 ~TestApi(); 48 49 app_time::WebTimeLimitEnforcer* web_time_enforcer(); 50 app_time::AppTimeController* app_time_controller(); 51 52 private: 53 ChildUserService* const service_; 54 }; 55 56 // Family Link helper(for child and teens) is an app available to supervised 57 // users and the companion app of Family Link app(for parents). 58 static const char kFamilyLinkHelperAppPackageName[]; 59 static const char kFamilyLinkHelperAppPlayStoreURL[]; 60 61 explicit ChildUserService(content::BrowserContext* context); 62 ChildUserService(const ChildUserService&) = delete; 63 ChildUserService& operator=(const ChildUserService&) = delete; 64 ~ChildUserService() override; 65 66 // app_time::AppTimeLimitInterface: 67 void PauseWebActivity(const std::string& app_service_id) override; 68 void ResumeWebActivity(const std::string& app_service_id) override; 69 base::Optional<base::TimeDelta> GetTimeLimitForApp( 70 const std::string& app_service_id, 71 apps::mojom::AppType app_type) override; 72 73 // app_time::AppActivityReportInterface: 74 app_time::AppActivityReportInterface::ReportParams GenerateAppActivityReport( 75 enterprise_management::ChildStatusReportRequest* report) override; 76 void AppActivityReportSubmitted( 77 base::Time report_generation_timestamp) override; 78 79 // Returns whether web time limit was reached for child user. 80 // Always returns false if per-app times limits feature is disabled. 81 bool WebTimeLimitReached() const; 82 83 // Returns whether given |url| can be used without any time restrictions. 84 // Viewing of allowlisted |url| does not count towards usage web time. 85 // Always returns false if per-app times limits feature is disabled. 86 bool WebTimeLimitAllowlistedURL(const GURL& url) const; 87 88 // Returns whether the application with id |app_id| can be used without any 89 // time restrictions. 90 bool AppTimeLimitAllowlistedApp(const app_time::AppId& app_id) const; 91 92 // Returns time limit set for using the web on a given day. 93 // Should only be called if |features::kPerAppTimeLimits| and 94 // |features::kWebTimeLimits| features are enabled. 95 base::TimeDelta GetWebTimeLimit() const; 96 97 private: 98 // KeyedService: 99 void Shutdown() override; 100 101 std::unique_ptr<app_time::AppTimeController> app_time_controller_; 102 }; 103 104 } // namespace chromeos 105 106 #endif // CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_CHILD_USER_SERVICE_H_ 107