1 // Copyright 2018 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_STATUS_REPORTING_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_CHILD_STATUS_REPORTING_SERVICE_H_ 7 8 #include <memory> 9 10 #include "base/time/time.h" 11 #include "components/keyed_service/core/keyed_service.h" 12 13 class PrefChangeRegistrar; 14 15 namespace content { 16 class BrowserContext; 17 } 18 19 namespace policy { 20 class CloudPolicyClient; 21 class StatusUploader; 22 class UserCloudPolicyManagerChromeOS; 23 } // namespace policy 24 25 namespace chromeos { 26 27 // Controls reporting for child user. 28 // Child user should be registered with DMServer and periodically upload the 29 // information about the device usage. The reports are only sent during user's 30 // session and they do not interfere with enterprise reporting that is 31 // controlled by DeviceCloudPolicyManagerChromeOS. 32 class ChildStatusReportingService : public KeyedService { 33 public: 34 explicit ChildStatusReportingService(content::BrowserContext* context); 35 ChildStatusReportingService(const ChildStatusReportingService&) = delete; 36 ChildStatusReportingService& operator=(const ChildStatusReportingService&) = 37 delete; 38 ~ChildStatusReportingService() override; 39 40 // Returns true if the status report has been scheduled. Otherwise, returns 41 // false. 42 virtual bool RequestImmediateStatusReport(); 43 44 // Get the child's usage time so far today. 45 base::TimeDelta GetChildScreenTime() const; 46 47 private: 48 // Creates new status uploader if parameters changed. 49 void CreateStatusUploaderIfNeeded(policy::CloudPolicyClient* client); 50 51 // Called when the UsageTimeLimits policy changes. 52 void OnTimeLimitsPolicyChanged(); 53 54 // Helper object that controls device status collection/storage and uploads 55 // gathered reports to the server. 56 std::unique_ptr<policy::StatusUploader> status_uploader_; 57 58 // Preference changes observer. 59 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; 60 61 // Day start/reset time used for aggregating activity data for child status 62 // reporting. 63 base::TimeDelta day_reset_time_; 64 65 content::BrowserContext* const context_; 66 67 policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager_; 68 }; 69 70 } // namespace chromeos 71 72 #endif // CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_CHILD_STATUS_REPORTING_SERVICE_H_ 73