1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_USER_MANAGER_MULTI_USER_MULTI_USER_SIGN_IN_POLICY_CONTROLLER_H_
#define COMPONENTS_USER_MANAGER_MULTI_USER_MULTI_USER_SIGN_IN_POLICY_CONTROLLER_H_
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "components/user_manager/multi_user/multi_user_sign_in_policy.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_manager_export.h"
class PrefChangeRegistrar;
class PrefRegistrySimple;
class PrefService;
namespace user_manager {
class User;
class UserManager;
// MultiUserSignInPolicyController decides whether a user is allowed to be in a
// multi user sign-in session. It caches the multi user sign-in behavior pref
// backed by user policy into local state so that the value is available before
// the user login and checks if the meaning of the value is respected.
class USER_MANAGER_EXPORT MultiUserSignInPolicyController
: public UserManager::Observer {
public:
MultiUserSignInPolicyController(PrefService* local_state,
UserManager* user_manager);
MultiUserSignInPolicyController(const MultiUserSignInPolicyController&) =
delete;
MultiUserSignInPolicyController& operator=(
const MultiUserSignInPolicyController&) = delete;
~MultiUserSignInPolicyController() override;
static void RegisterPrefs(PrefRegistrySimple* registry);
// Returns the cached policy value for `user_email`.
MultiUserSignInPolicy GetCachedValue(std::string_view user_email) const;
// Returns true if user allowed to be in the current session.
bool IsUserAllowedInSession(const std::string& user_email) const;
// Starts to observe the multi-user signin policy for the given user.
void StartObserving(User& user);
// Stops to observe the multi-user signin policy for the given user.
void StopObserving(const User& user);
// Removes the cached values for the given user.
void RemoveCachedValues(std::string_view user_email);
// UserManager::Observer:
void OnUserProfileCreated(const User& user) override;
void OnUserProfileWillBeDestroyed(const User& user) override;
void OnUserToBeRemoved(const AccountId& account_id) override;
private:
friend class MultiUserSignInPolicyControllerTest;
// Sets the cached policy value.
void SetCachedValue(std::string_view user_email,
MultiUserSignInPolicy policy);
// Checks if all users are allowed in the current session.
void CheckSessionUsers();
// Invoked when user behavior pref value changes.
void OnUserPrefChanged(User* user);
raw_ptr<PrefService, DanglingUntriaged> local_state_;
raw_ptr<UserManager> user_manager_;
base::ScopedObservation<UserManager, UserManager::Observer> observation_{
this};
std::vector<std::unique_ptr<PrefChangeRegistrar>> pref_watchers_;
};
} // namespace user_manager
#endif // COMPONENTS_USER_MANAGER_MULTI_USER_MULTI_USER_SIGN_IN_POLICY_CONTROLLER_H_
|