OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
6 | |
7 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" | |
8 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
9 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
10 #include "chrome/grit/theme_resources.h" | |
11 #include "components/user_manager/user_image/user_image.h" | |
12 #include "components/user_manager/user_type.h" | |
13 #include "ui/base/resource/resource_bundle.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 class FakeSupervisedUserManager; | |
18 | |
19 FakeChromeUserManager::FakeChromeUserManager() | |
20 : supervised_user_manager_(new FakeSupervisedUserManager), | |
21 multi_profile_user_controller_(NULL) { | |
22 } | |
23 | |
24 FakeChromeUserManager::~FakeChromeUserManager() { | |
25 // Can't use STLDeleteElements because of the private destructor of User. | |
ygorshenin1
2015/01/20 18:33:40
Feel free to mark User::~User() as public. BTW, wh
merkulova
2015/01/21 14:10:33
Removed the d-tor.
| |
26 for (user_manager::UserList::iterator it = user_list_.begin(); | |
27 it != user_list_.end(); | |
28 it = user_list_.erase(it)) { | |
29 delete *it; | |
30 } | |
31 } | |
32 | |
33 const user_manager::User* | |
34 FakeChromeUserManager::AddUser(const std::string& email) { | |
35 user_manager::User* user = user_manager::User::CreateRegularUser(email); | |
36 user->set_username_hash( | |
37 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | |
38 user->SetStubImage(user_manager::UserImage( | |
39 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
40 IDR_PROFILE_PICTURE_LOADING)), | |
41 user_manager::User::USER_IMAGE_PROFILE, | |
42 false); | |
43 user_list_.push_back(user); | |
44 return user; | |
45 } | |
46 | |
47 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( | |
48 const std::string& email) { | |
49 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | |
50 user->set_username_hash( | |
51 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | |
52 user->SetStubImage(user_manager::UserImage( | |
53 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
54 IDR_PROFILE_PICTURE_LOADING)), | |
55 user_manager::User::USER_IMAGE_PROFILE, | |
56 false); | |
57 user_list_.push_back(user); | |
58 return user; | |
59 } | |
60 | |
61 void FakeChromeUserManager::AddKioskAppUser( | |
62 const std::string& kiosk_app_username) { | |
63 user_manager::User* user = | |
64 user_manager::User::CreateKioskAppUser(kiosk_app_username); | |
65 user->set_username_hash( | |
66 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username)); | |
67 user_list_.push_back(user); | |
68 } | |
69 | |
70 void FakeChromeUserManager::LoginUser(const std::string& email) { | |
71 UserLoggedIn( | |
72 email, ProfileHelper::GetUserIdHashByUserIdForTesting(email), false); | |
ygorshenin1
2015/01/20 18:33:40
Could you please add /* browser_restart */ after f
merkulova
2015/01/21 14:10:33
Done.
| |
73 } | |
74 | |
75 MultiProfileUserController* | |
76 FakeChromeUserManager::GetMultiProfileUserController() { | |
77 return multi_profile_user_controller_; | |
78 } | |
79 | |
80 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { | |
81 return supervised_user_manager_.get(); | |
82 } | |
83 | |
84 UserImageManager* FakeChromeUserManager::GetUserImageManager( | |
85 const std::string& /* user_id */) { | |
86 return NULL; | |
ygorshenin1
2015/01/20 18:33:40
Modern fancy approach is to use nullptr instead of
merkulova
2015/01/21 14:10:33
Done.
| |
87 } | |
88 | |
89 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { | |
90 return NULL; | |
91 } | |
92 | |
93 UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const { | |
94 return NULL; | |
95 } | |
96 | |
97 void FakeChromeUserManager::SwitchActiveUser(const std::string& email) { | |
98 active_user_id_ = email; | |
99 ProfileHelper::Get()->ActiveUserHashChanged( | |
100 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | |
101 if (user_list_.size() && !active_user_id_.empty()) { | |
102 for (user_manager::UserList::const_iterator it = user_list_.begin(); | |
ygorshenin1
2015/01/20 18:33:40
for (User* user : user_list_)
user->set_is_activ
merkulova
2015/01/21 14:10:33
Done.
| |
103 it != user_list_.end(); ++it) { | |
104 (*it)->set_is_active((*it)->email() == active_user_id_); | |
105 } | |
106 } | |
107 } | |
108 | |
109 const std::string& FakeChromeUserManager::GetOwnerEmail() const { | |
110 return owner_email_; | |
111 } | |
112 | |
113 user_manager::UserList | |
114 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { | |
115 CrosSettings* cros_settings = CrosSettings::Get(); | |
116 bool allow_new_user = true; | |
117 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | |
118 bool supervised_users_allowed = AreSupervisedUsersAllowed(); | |
119 | |
120 // Restricted either by policy or by owner. | |
121 if (!allow_new_user || !supervised_users_allowed) | |
122 return user_manager::UserList(); | |
123 | |
124 return GetUsersAllowedAsSupervisedUserManagers(GetUsers()); | |
125 } | |
126 | |
127 user_manager::UserList | |
128 FakeChromeUserManager::GetUsersAllowedForMultiProfile() const { | |
129 // Supervised users are not allowed to use multi-profiles. | |
130 if (GetLoggedInUsers().size() == 1 && | |
131 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) { | |
132 return user_manager::UserList(); | |
133 } | |
134 | |
135 user_manager::UserList result; | |
136 const user_manager::UserList& users = GetUsers(); | |
137 for (user_manager::UserList::const_iterator it = users.begin(); | |
138 it != users.end(); | |
139 ++it) { | |
140 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && | |
141 !(*it)->is_logged_in()) | |
142 result.push_back(*it); | |
ygorshenin1
2015/01/20 18:33:40
Could you please add curly braces around branch?
merkulova
2015/01/21 14:10:33
Done.
| |
143 } | |
144 | |
145 return result; | |
146 } | |
147 | |
148 } // namespace chromeos | |
OLD | NEW |