ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / fake_chrome_user_manager.cc
blobe0213a6fb426203fbdd70c3a3f49859cbcb6d06e
1 // Copyright 2015 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 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
7 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/chromeos/settings/cros_settings.h"
11 #include "chrome/grit/theme_resources.h"
12 #include "components/user_manager/user_image/user_image.h"
13 #include "components/user_manager/user_type.h"
14 #include "ui/base/resource/resource_bundle.h"
16 namespace chromeos {
18 class FakeSupervisedUserManager;
20 FakeChromeUserManager::FakeChromeUserManager()
21 : supervised_user_manager_(new FakeSupervisedUserManager),
22 multi_profile_user_controller_(NULL) {
25 FakeChromeUserManager::~FakeChromeUserManager() {
28 const user_manager::User* FakeChromeUserManager::AddUser(
29 const std::string& email) {
30 user_manager::User* user = user_manager::User::CreateRegularUser(email);
31 user->set_username_hash(
32 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
33 user->SetStubImage(user_manager::UserImage(
34 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
35 IDR_PROFILE_PICTURE_LOADING)),
36 user_manager::User::USER_IMAGE_PROFILE, false);
37 users_.push_back(user);
38 return user;
41 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser(
42 const std::string& email) {
43 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email);
44 user->set_username_hash(
45 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
46 user->SetStubImage(user_manager::UserImage(
47 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
48 IDR_PROFILE_PICTURE_LOADING)),
49 user_manager::User::USER_IMAGE_PROFILE, false);
50 users_.push_back(user);
51 return user;
54 void FakeChromeUserManager::AddKioskAppUser(
55 const std::string& kiosk_app_username) {
56 user_manager::User* user =
57 user_manager::User::CreateKioskAppUser(kiosk_app_username);
58 user->set_username_hash(
59 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username));
60 users_.push_back(user);
63 void FakeChromeUserManager::LoginUser(const std::string& email) {
64 UserLoggedIn(email, ProfileHelper::GetUserIdHashByUserIdForTesting(email),
65 false /* browser_restart */);
68 MultiProfileUserController*
69 FakeChromeUserManager::GetMultiProfileUserController() {
70 return multi_profile_user_controller_;
73 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() {
74 return supervised_user_manager_.get();
77 UserImageManager* FakeChromeUserManager::GetUserImageManager(
78 const std::string& /* user_id */) {
79 return nullptr;
82 void FakeChromeUserManager::SetUserFlow(const std::string& email,
83 UserFlow* flow) {
84 ResetUserFlow(email);
85 specific_flows_[email] = flow;
88 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const {
89 if (!IsUserLoggedIn())
90 return GetDefaultUserFlow();
91 return GetUserFlow(GetLoggedInUser()->email());
94 UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const {
95 FlowMap::const_iterator it = specific_flows_.find(email);
96 if (it != specific_flows_.end())
97 return it->second;
98 return GetDefaultUserFlow();
101 void FakeChromeUserManager::ResetUserFlow(const std::string& email) {
102 FlowMap::iterator it = specific_flows_.find(email);
103 if (it != specific_flows_.end()) {
104 delete it->second;
105 specific_flows_.erase(it);
109 void FakeChromeUserManager::SwitchActiveUser(const std::string& email) {
110 active_user_id_ = email;
111 ProfileHelper::Get()->ActiveUserHashChanged(
112 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
113 if (!users_.empty() && !active_user_id_.empty()) {
114 for (user_manager::User* user : users_)
115 user->set_is_active(user->email() == active_user_id_);
119 const std::string& FakeChromeUserManager::GetOwnerEmail() const {
120 return owner_email_;
123 void FakeChromeUserManager::SessionStarted() {
126 void FakeChromeUserManager::RemoveUser(
127 const std::string& email,
128 user_manager::RemoveUserDelegate* delegate) {
131 user_manager::UserList
132 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const {
133 CrosSettings* cros_settings = CrosSettings::Get();
134 bool allow_new_user = true;
135 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
136 bool supervised_users_allowed = AreSupervisedUsersAllowed();
138 // Restricted either by policy or by owner.
139 if (!allow_new_user || !supervised_users_allowed)
140 return user_manager::UserList();
142 return ChromeUserManager::GetUsersAllowedAsSupervisedUserManagers(GetUsers());
145 user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile()
146 const {
147 // Supervised users are not allowed to use multi-profiles.
148 if (GetLoggedInUsers().size() == 1 &&
149 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) {
150 return user_manager::UserList();
153 user_manager::UserList result;
154 const user_manager::UserList& users = GetUsers();
155 for (user_manager::User* user : users) {
156 if (user->GetType() == user_manager::USER_TYPE_REGULAR &&
157 !user->is_logged_in()) {
158 result.push_back(user);
162 return result;
165 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const {
166 if (!default_flow_.get())
167 default_flow_.reset(new DefaultUserFlow());
168 return default_flow_.get();
171 } // namespace chromeos