1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MULTI_PROFILE_USER_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MULTI_PROFILE_USER_CONTROLLER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_vector.h"
13 class PrefChangeRegistrar
;
14 class PrefRegistrySimple
;
18 namespace user_prefs
{
19 class PrefRegistrySyncable
;
24 class MultiProfileUserControllerDelegate
;
27 // MultiProfileUserController decides whether a user is allowed to be in a
28 // multi-profiles session. It caches the multi-profile user behavior pref backed
29 // by user policy into local state so that the value is available before the
30 // user login and checks if the meaning of the value is respected.
31 class MultiProfileUserController
{
33 // Return value of IsUserAllowedInSession().
34 enum UserAllowedInSessionResult
{
35 // User is allowed in multi-profile session.
38 // Owner of the device is not allowed to be added as a secondary user.
39 NOT_ALLOWED_OWNER_AS_SECONDARY
,
41 // Not allowed since it is potentially "tainted" with policy-pushed
43 NOT_ALLOWED_POLICY_CERT_TAINTED
,
45 // Not allowed since primary user is already "tainted" with policy-pushed
47 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED
,
49 // Not allowed since primary user policy forbids it to be part of
50 // multi-profiles session.
51 NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS
,
53 // Not allowed since user policy forbids this user being part of
54 // multi-profiles session. Either 'primary-only' or 'not-allowed'.
55 NOT_ALLOWED_POLICY_FORBIDS
58 MultiProfileUserController(MultiProfileUserControllerDelegate
* delegate
,
59 PrefService
* local_state
);
60 ~MultiProfileUserController();
62 static void RegisterPrefs(PrefRegistrySimple
* registry
);
63 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
65 // Returns the cached policy value for |user_email|.
66 std::string
GetCachedValue(const std::string
& user_email
) const;
68 // Returns UserAllowedInSessionResult enum that describe whether the user is
69 // allowed to be in the current session.
70 UserAllowedInSessionResult
IsUserAllowedInSession(
71 const std::string
& user_email
) const;
73 // Starts to observe the multiprofile user behavior pref of the given profile.
74 void StartObserving(Profile
* user_profile
);
76 // Removes the cached values for the given user.
77 void RemoveCachedValues(const std::string
& user_email
);
79 // Possible behavior values.
80 static const char kBehaviorUnrestricted
[];
81 static const char kBehaviorPrimaryOnly
[];
82 static const char kBehaviorNotAllowed
[];
85 friend class MultiProfileUserControllerTest
;
87 // Sets the cached policy value.
88 void SetCachedValue(const std::string
& user_email
,
89 const std::string
& behavior
);
91 // Checks if all users are allowed in the current session.
92 void CheckSessionUsers();
94 // Invoked when user behavior pref value changes.
95 void OnUserPrefChanged(Profile
* profile
);
97 MultiProfileUserControllerDelegate
* delegate_
; // Not owned.
98 PrefService
* local_state_
; // Not owned.
99 ScopedVector
<PrefChangeRegistrar
> pref_watchers_
;
101 DISALLOW_COPY_AND_ASSIGN(MultiProfileUserController
);
104 } // namespace chromeos
106 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MULTI_PROFILE_USER_CONTROLLER_H_