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 multiprofile 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 MultiProfileUserController(MultiProfileUserControllerDelegate
* delegate
,
34 PrefService
* local_state
);
35 ~MultiProfileUserController();
37 static void RegisterPrefs(PrefRegistrySimple
* registry
);
38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
40 // Returns true if the user is allowed to be in the current session.
41 bool IsUserAllowedInSession(const std::string
& user_email
) const;
43 // Starts to observe the multiprofile user behavior pref of the given profile.
44 void StartObserving(Profile
* user_profile
);
46 // Removes the cached values for the given user.
47 void RemoveCachedValues(const std::string
& user_email
);
49 // Possible behavior values.
50 static const char kBehaviorUnrestricted
[];
51 static const char kBehaviorPrimaryOnly
[];
52 static const char kBehaviorNotAllowed
[];
55 friend class MultiProfileUserControllerTest
;
57 // Gets/sets the cached policy value.
58 std::string
GetCachedValue(const std::string
& user_email
) const;
59 void SetCachedValue(const std::string
& user_email
,
60 const std::string
& behavior
);
62 // Checks if all users are allowed in the current session.
63 void CheckSessionUsers();
65 // Invoked when user behavior pref value changes.
66 void OnUserPrefChanged(Profile
* profile
);
68 MultiProfileUserControllerDelegate
* delegate_
; // Not owned.
69 PrefService
* local_state_
; // Not owned.
70 ScopedVector
<PrefChangeRegistrar
> pref_watchers_
;
72 DISALLOW_COPY_AND_ASSIGN(MultiProfileUserController
);
75 } // namespace chromeos
77 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MULTI_PROFILE_USER_CONTROLLER_H_