Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 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_ASH_POLICY_CORE_REPORTING_USER_TRACKER_H_ |
| 6 | #define CHROME_BROWSER_ASH_POLICY_CORE_REPORTING_USER_TRACKER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/memory/raw_ptr.h" |
Hidehiko Abe | 1a55caf | 2023-04-26 03:51:51 | [diff] [blame] | 11 | #include "base/scoped_observation.h" |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 12 | #include "components/user_manager/user.h" |
Hidehiko Abe | 51fe7142 | 2023-04-21 17:21:00 | [diff] [blame] | 13 | #include "components/user_manager/user_manager.h" |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 14 | |
| 15 | class AccountId; |
| 16 | class PrefService; |
| 17 | class PrefRegistrySimple; |
| 18 | |
| 19 | namespace policy { |
| 20 | |
| 21 | // Keeps maintaining the list of users to be reported. |
| 22 | // This maintains persistent data in the given |local_state|. |
Hidehiko Abe | 51fe7142 | 2023-04-21 17:21:00 | [diff] [blame] | 23 | class ReportingUserTracker : public user_manager::UserManager::Observer { |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 24 | public: |
Hidehiko Abe | 1a55caf | 2023-04-26 03:51:51 | [diff] [blame] | 25 | explicit ReportingUserTracker(user_manager::UserManager* user_manager); |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 26 | ReportingUserTracker(const ReportingUserTracker&) = delete; |
| 27 | ReportingUserTracker& operator=(const ReportingUserTracker&) = delete; |
Hidehiko Abe | 51fe7142 | 2023-04-21 17:21:00 | [diff] [blame] | 28 | ~ReportingUserTracker() override; |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 29 | |
| 30 | // Registers prefs used by this class. |
| 31 | static void RegisterPrefs(PrefRegistrySimple* registry); |
| 32 | |
| 33 | // Return whether the given user should be reported |
| 34 | // Returns whether the user email can be included in the report. By default, |
| 35 | // only affiliated user emails are included. Function can accept |
| 36 | // canonicalized and non canonicalized user_email. |
| 37 | // Must be called on UI task runner. |
| 38 | // See also policy::DeviceStatusCollector. |
| 39 | bool ShouldReportUser(const std::string& user_email) const; |
| 40 | |
Hidehiko Abe | 51fe7142 | 2023-04-21 17:21:00 | [diff] [blame] | 41 | // user_manager::UserManager::Observer: |
| 42 | void OnUserAffiliationUpdated(const user_manager::User& user) override; |
| 43 | void OnUserRemoved(const AccountId& account_id, |
| 44 | user_manager::UserRemovalReason reasonx) override; |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | // Adds user to the list of the users who should be reported. |
| 48 | void AddReportingUser(const AccountId& account_id); |
| 49 | |
| 50 | // Removes user from the list of the users who should be reported. |
| 51 | void RemoveReportingUser(const AccountId& account_id); |
| 52 | |
| 53 | const base::raw_ptr<PrefService> local_state_; |
Hidehiko Abe | 1a55caf | 2023-04-26 03:51:51 | [diff] [blame] | 54 | base::ScopedObservation<user_manager::UserManager, |
| 55 | user_manager::UserManager::Observer> |
| 56 | observation_{this}; |
Hidehiko Abe | 9ec8c0a | 2023-04-20 17:53:38 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace policy |
| 60 | |
| 61 | #endif // CHROME_BROWSER_ASH_POLICY_CORE_REPORTING_USER_TRACKER_H_ |