OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/login/users/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" | 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
10 #include "chrome/browser/chromeos/settings/cros_settings.h" | 10 #include "chrome/browser/chromeos/settings/cros_settings.h" |
11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" |
12 #include "components/user_manager/user_image/user_image.h" | 12 #include "components/user_manager/user_image/user_image.h" |
13 #include "components/user_manager/user_type.h" | 13 #include "components/user_manager/user_type.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 class FakeSupervisedUserManager; | 18 class FakeSupervisedUserManager; |
19 | 19 |
20 FakeChromeUserManager::FakeChromeUserManager() | 20 FakeChromeUserManager::FakeChromeUserManager() |
21 : supervised_user_manager_(new FakeSupervisedUserManager), | 21 : supervised_user_manager_(new FakeSupervisedUserManager), |
22 bootstrap_manager_(NULL), | 22 bootstrap_manager_(NULL), |
23 multi_profile_user_controller_(NULL) {} | 23 multi_profile_user_controller_(NULL) { |
| 24 } |
24 | 25 |
25 FakeChromeUserManager::~FakeChromeUserManager() { | 26 FakeChromeUserManager::~FakeChromeUserManager() { |
26 } | 27 } |
27 | 28 |
28 const user_manager::User* FakeChromeUserManager::AddUser( | 29 const user_manager::User* FakeChromeUserManager::AddUser( |
29 const AccountId& account_id) { | 30 const std::string& email) { |
30 return AddUserWithAffiliation(account_id, false); | 31 return AddUserWithAffiliation(email, false); |
31 } | 32 } |
32 | 33 |
33 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( | 34 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( |
34 const AccountId& account_id, | 35 const std::string& email, |
35 bool is_affiliated) { | 36 bool is_affiliated) { |
36 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); | 37 user_manager::User* user = user_manager::User::CreateRegularUser(email); |
37 user->set_affiliation(is_affiliated); | 38 user->set_affiliation(is_affiliated); |
38 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | 39 user->set_username_hash( |
39 account_id.GetUserEmail())); | 40 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); |
40 user->SetStubImage(user_manager::UserImage( | 41 user->SetStubImage(user_manager::UserImage( |
41 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 42 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
42 IDR_PROFILE_PICTURE_LOADING)), | 43 IDR_PROFILE_PICTURE_LOADING)), |
43 user_manager::User::USER_IMAGE_PROFILE, false); | 44 user_manager::User::USER_IMAGE_PROFILE, false); |
44 users_.push_back(user); | 45 users_.push_back(user); |
45 return user; | 46 return user; |
46 } | 47 } |
47 | 48 |
48 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( | 49 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( |
49 const AccountId& account_id) { | 50 const std::string& email) { |
50 user_manager::User* user = | 51 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); |
51 user_manager::User::CreatePublicAccountUser(account_id); | 52 user->set_username_hash( |
52 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | 53 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); |
53 account_id.GetUserEmail())); | |
54 user->SetStubImage(user_manager::UserImage( | 54 user->SetStubImage(user_manager::UserImage( |
55 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 55 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
56 IDR_PROFILE_PICTURE_LOADING)), | 56 IDR_PROFILE_PICTURE_LOADING)), |
57 user_manager::User::USER_IMAGE_PROFILE, false); | 57 user_manager::User::USER_IMAGE_PROFILE, false); |
58 users_.push_back(user); | 58 users_.push_back(user); |
59 return user; | 59 return user; |
60 } | 60 } |
61 | 61 |
62 void FakeChromeUserManager::AddKioskAppUser( | 62 void FakeChromeUserManager::AddKioskAppUser( |
63 const AccountId& kiosk_app_account_id) { | 63 const std::string& kiosk_app_username) { |
64 user_manager::User* user = | 64 user_manager::User* user = |
65 user_manager::User::CreateKioskAppUser(kiosk_app_account_id); | 65 user_manager::User::CreateKioskAppUser(kiosk_app_username); |
66 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | 66 user->set_username_hash( |
67 kiosk_app_account_id.GetUserEmail())); | 67 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username)); |
68 users_.push_back(user); | 68 users_.push_back(user); |
69 } | 69 } |
70 | 70 |
71 void FakeChromeUserManager::LoginUser(const AccountId& account_id) { | 71 void FakeChromeUserManager::LoginUser(const std::string& email) { |
72 UserLoggedIn(account_id, ProfileHelper::GetUserIdHashByUserIdForTesting( | 72 UserLoggedIn(email, ProfileHelper::GetUserIdHashByUserIdForTesting(email), |
73 account_id.GetUserEmail()), | |
74 false /* browser_restart */); | 73 false /* browser_restart */); |
75 } | 74 } |
76 | 75 |
77 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { | 76 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { |
78 return bootstrap_manager_; | 77 return bootstrap_manager_; |
79 } | 78 } |
80 | 79 |
81 MultiProfileUserController* | 80 MultiProfileUserController* |
82 FakeChromeUserManager::GetMultiProfileUserController() { | 81 FakeChromeUserManager::GetMultiProfileUserController() { |
83 return multi_profile_user_controller_; | 82 return multi_profile_user_controller_; |
84 } | 83 } |
85 | 84 |
86 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { | 85 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { |
87 return supervised_user_manager_.get(); | 86 return supervised_user_manager_.get(); |
88 } | 87 } |
89 | 88 |
90 UserImageManager* FakeChromeUserManager::GetUserImageManager( | 89 UserImageManager* FakeChromeUserManager::GetUserImageManager( |
91 const AccountId& /* account_id */) { | 90 const std::string& /* user_id */) { |
92 return nullptr; | 91 return nullptr; |
93 } | 92 } |
94 | 93 |
95 void FakeChromeUserManager::SetUserFlow(const AccountId& account_id, | 94 void FakeChromeUserManager::SetUserFlow(const std::string& email, |
96 UserFlow* flow) { | 95 UserFlow* flow) { |
97 ResetUserFlow(account_id); | 96 ResetUserFlow(email); |
98 specific_flows_[account_id] = flow; | 97 specific_flows_[email] = flow; |
99 } | 98 } |
100 | 99 |
101 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { | 100 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { |
102 if (!IsUserLoggedIn()) | 101 if (!IsUserLoggedIn()) |
103 return GetDefaultUserFlow(); | 102 return GetDefaultUserFlow(); |
104 return GetUserFlow(GetLoggedInUser()->GetAccountId()); | 103 return GetUserFlow(GetLoggedInUser()->email()); |
105 } | 104 } |
106 | 105 |
107 UserFlow* FakeChromeUserManager::GetUserFlow( | 106 UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const { |
108 const AccountId& account_id) const { | 107 FlowMap::const_iterator it = specific_flows_.find(email); |
109 FlowMap::const_iterator it = specific_flows_.find(account_id); | |
110 if (it != specific_flows_.end()) | 108 if (it != specific_flows_.end()) |
111 return it->second; | 109 return it->second; |
112 return GetDefaultUserFlow(); | 110 return GetDefaultUserFlow(); |
113 } | 111 } |
114 | 112 |
115 void FakeChromeUserManager::ResetUserFlow(const AccountId& account_id) { | 113 void FakeChromeUserManager::ResetUserFlow(const std::string& email) { |
116 FlowMap::iterator it = specific_flows_.find(account_id); | 114 FlowMap::iterator it = specific_flows_.find(email); |
117 if (it != specific_flows_.end()) { | 115 if (it != specific_flows_.end()) { |
118 delete it->second; | 116 delete it->second; |
119 specific_flows_.erase(it); | 117 specific_flows_.erase(it); |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 void FakeChromeUserManager::SwitchActiveUser(const AccountId& account_id) { | 121 void FakeChromeUserManager::SwitchActiveUser(const std::string& email) { |
124 active_account_id_ = account_id; | 122 active_user_id_ = email; |
125 ProfileHelper::Get()->ActiveUserHashChanged( | 123 ProfileHelper::Get()->ActiveUserHashChanged( |
126 ProfileHelper::GetUserIdHashByUserIdForTesting( | 124 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); |
127 account_id.GetUserEmail())); | 125 if (!users_.empty() && !active_user_id_.empty()) { |
128 if (!users_.empty() && active_account_id_.is_valid()) { | |
129 for (user_manager::User* user : users_) | 126 for (user_manager::User* user : users_) |
130 user->set_is_active(user->GetAccountId() == active_account_id_); | 127 user->set_is_active(user->email() == active_user_id_); |
131 } | 128 } |
132 } | 129 } |
133 | 130 |
134 const AccountId& FakeChromeUserManager::GetOwnerAccountId() const { | 131 const std::string& FakeChromeUserManager::GetOwnerEmail() const { |
135 return owner_account_id_; | 132 return owner_email_; |
136 } | 133 } |
137 | 134 |
138 void FakeChromeUserManager::SessionStarted() { | 135 void FakeChromeUserManager::SessionStarted() { |
139 } | 136 } |
140 | 137 |
141 void FakeChromeUserManager::RemoveUser( | 138 void FakeChromeUserManager::RemoveUser( |
142 const AccountId& account_id, | 139 const std::string& email, |
143 user_manager::RemoveUserDelegate* delegate) {} | 140 user_manager::RemoveUserDelegate* delegate) { |
| 141 } |
144 | 142 |
145 user_manager::UserList | 143 user_manager::UserList |
146 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { | 144 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { |
147 CrosSettings* cros_settings = CrosSettings::Get(); | 145 CrosSettings* cros_settings = CrosSettings::Get(); |
148 bool allow_new_user = true; | 146 bool allow_new_user = true; |
149 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 147 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
150 bool supervised_users_allowed = AreSupervisedUsersAllowed(); | 148 bool supervised_users_allowed = AreSupervisedUsersAllowed(); |
151 | 149 |
152 // Restricted either by policy or by owner. | 150 // Restricted either by policy or by owner. |
153 if (!allow_new_user || !supervised_users_allowed) | 151 if (!allow_new_user || !supervised_users_allowed) |
(...skipping 22 matching lines...) Expand all Loading... |
176 return result; | 174 return result; |
177 } | 175 } |
178 | 176 |
179 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { | 177 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { |
180 if (!default_flow_.get()) | 178 if (!default_flow_.get()) |
181 default_flow_.reset(new DefaultUserFlow()); | 179 default_flow_.reset(new DefaultUserFlow()); |
182 return default_flow_.get(); | 180 return default_flow_.get(); |
183 } | 181 } |
184 | 182 |
185 bool FakeChromeUserManager::FindKnownUserPrefs( | 183 bool FakeChromeUserManager::FindKnownUserPrefs( |
186 const AccountId& account_id, | 184 const user_manager::UserID& user_id, |
187 const base::DictionaryValue** out_value) { | 185 const base::DictionaryValue** out_value) { |
188 return false; | 186 return false; |
189 } | 187 } |
190 | 188 |
191 void FakeChromeUserManager::UpdateKnownUserPrefs( | 189 void FakeChromeUserManager::UpdateKnownUserPrefs( |
192 const AccountId& account_id, | 190 const user_manager::UserID& user_id, |
193 const base::DictionaryValue& values, | 191 const base::DictionaryValue& values, |
194 bool clear) {} | 192 bool clear) { |
| 193 } |
195 | 194 |
196 } // namespace chromeos | 195 } // namespace chromeos |
OLD | NEW |