[go: nahoru, domu]

blob: e776a2b4fdba76b2c48251d2542a533c4ef0f412 [file] [log] [blame]
Hidehiko Abe9ec8c0a2023-04-20 17:53:381// 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 Abe1a55caf2023-04-26 03:51:5111#include "base/scoped_observation.h"
Hidehiko Abe9ec8c0a2023-04-20 17:53:3812#include "components/user_manager/user.h"
Hidehiko Abe51fe71422023-04-21 17:21:0013#include "components/user_manager/user_manager.h"
Hidehiko Abe9ec8c0a2023-04-20 17:53:3814
15class AccountId;
16class PrefService;
17class PrefRegistrySimple;
18
19namespace policy {
20
21// Keeps maintaining the list of users to be reported.
22// This maintains persistent data in the given |local_state|.
Hidehiko Abe51fe71422023-04-21 17:21:0023class ReportingUserTracker : public user_manager::UserManager::Observer {
Hidehiko Abe9ec8c0a2023-04-20 17:53:3824 public:
Hidehiko Abe1a55caf2023-04-26 03:51:5125 explicit ReportingUserTracker(user_manager::UserManager* user_manager);
Hidehiko Abe9ec8c0a2023-04-20 17:53:3826 ReportingUserTracker(const ReportingUserTracker&) = delete;
27 ReportingUserTracker& operator=(const ReportingUserTracker&) = delete;
Hidehiko Abe51fe71422023-04-21 17:21:0028 ~ReportingUserTracker() override;
Hidehiko Abe9ec8c0a2023-04-20 17:53:3829
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 Abe51fe71422023-04-21 17:21:0041 // 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 Abe9ec8c0a2023-04-20 17:53:3845
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 Abe1a55caf2023-04-26 03:51:5154 base::ScopedObservation<user_manager::UserManager,
55 user_manager::UserManager::Observer>
56 observation_{this};
Hidehiko Abe9ec8c0a2023-04-20 17:53:3857};
58
59} // namespace policy
60
61#endif // CHROME_BROWSER_ASH_POLICY_CORE_REPORTING_USER_TRACKER_H_