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 owner_id_(EmptyAccountId()), | |
achuithb
2015/10/23 00:08:51
in class member initialization
Alexander Alekseev
2015/10/23 09:11:22
Done.
| |
22 bootstrap_manager_(NULL), | 23 bootstrap_manager_(NULL), |
23 multi_profile_user_controller_(NULL) { | 24 multi_profile_user_controller_(NULL) {} |
24 } | |
25 | 25 |
26 FakeChromeUserManager::~FakeChromeUserManager() { | 26 FakeChromeUserManager::~FakeChromeUserManager() { |
27 } | 27 } |
28 | 28 |
29 const user_manager::User* FakeChromeUserManager::AddUser( | 29 const user_manager::User* FakeChromeUserManager::AddUser( |
30 const std::string& email) { | 30 const AccountId& account) { |
achuithb
2015/10/23 00:08:51
account_id? here and below
Alexander Alekseev
2015/10/23 09:11:22
Done.
| |
31 return AddUserWithAffiliation(email, false); | 31 return AddUserWithAffiliation(account, false); |
32 } | 32 } |
33 | 33 |
34 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( | 34 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( |
35 const std::string& email, | 35 const AccountId& account, |
36 bool is_affiliated) { | 36 bool is_affiliated) { |
37 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 37 user_manager::User* user = user_manager::User::CreateRegularUser(account); |
38 user->set_affiliation(is_affiliated); | 38 user->set_affiliation(is_affiliated); |
39 user->set_username_hash( | 39 user->set_username_hash( |
40 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 40 ProfileHelper::GetUserIdHashByUserIdForTesting(account.GetUserEmail())); |
41 user->SetStubImage(user_manager::UserImage( | 41 user->SetStubImage(user_manager::UserImage( |
42 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 42 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
43 IDR_PROFILE_PICTURE_LOADING)), | 43 IDR_PROFILE_PICTURE_LOADING)), |
44 user_manager::User::USER_IMAGE_PROFILE, false); | 44 user_manager::User::USER_IMAGE_PROFILE, false); |
45 users_.push_back(user); | 45 users_.push_back(user); |
46 return user; | 46 return user; |
47 } | 47 } |
48 | 48 |
49 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( | 49 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( |
50 const std::string& email) { | 50 const AccountId& account) { |
51 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | 51 user_manager::User* user = |
52 user_manager::User::CreatePublicAccountUser(account); | |
52 user->set_username_hash( | 53 user->set_username_hash( |
53 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 54 ProfileHelper::GetUserIdHashByUserIdForTesting(account.GetUserEmail())); |
54 user->SetStubImage(user_manager::UserImage( | 55 user->SetStubImage(user_manager::UserImage( |
55 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 56 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
56 IDR_PROFILE_PICTURE_LOADING)), | 57 IDR_PROFILE_PICTURE_LOADING)), |
57 user_manager::User::USER_IMAGE_PROFILE, false); | 58 user_manager::User::USER_IMAGE_PROFILE, false); |
58 users_.push_back(user); | 59 users_.push_back(user); |
59 return user; | 60 return user; |
60 } | 61 } |
61 | 62 |
62 void FakeChromeUserManager::AddKioskAppUser( | 63 void FakeChromeUserManager::AddKioskAppUser( |
63 const std::string& kiosk_app_username) { | 64 const AccountId& kiosk_app_user_id) { |
64 user_manager::User* user = | 65 user_manager::User* user = |
65 user_manager::User::CreateKioskAppUser(kiosk_app_username); | 66 user_manager::User::CreateKioskAppUser(kiosk_app_user_id); |
66 user->set_username_hash( | 67 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
67 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username)); | 68 kiosk_app_user_id.GetUserEmail())); |
68 users_.push_back(user); | 69 users_.push_back(user); |
69 } | 70 } |
70 | 71 |
71 void FakeChromeUserManager::LoginUser(const std::string& email) { | 72 void FakeChromeUserManager::LoginUser(const AccountId& account) { |
72 UserLoggedIn(email, ProfileHelper::GetUserIdHashByUserIdForTesting(email), | 73 UserLoggedIn(account, ProfileHelper::GetUserIdHashByUserIdForTesting( |
74 account.GetUserEmail()), | |
73 false /* browser_restart */); | 75 false /* browser_restart */); |
74 } | 76 } |
75 | 77 |
76 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { | 78 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { |
77 return bootstrap_manager_; | 79 return bootstrap_manager_; |
78 } | 80 } |
79 | 81 |
80 MultiProfileUserController* | 82 MultiProfileUserController* |
81 FakeChromeUserManager::GetMultiProfileUserController() { | 83 FakeChromeUserManager::GetMultiProfileUserController() { |
82 return multi_profile_user_controller_; | 84 return multi_profile_user_controller_; |
83 } | 85 } |
84 | 86 |
85 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { | 87 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { |
86 return supervised_user_manager_.get(); | 88 return supervised_user_manager_.get(); |
87 } | 89 } |
88 | 90 |
89 UserImageManager* FakeChromeUserManager::GetUserImageManager( | 91 UserImageManager* FakeChromeUserManager::GetUserImageManager( |
90 const std::string& /* user_id */) { | 92 const AccountId& /* user_id */) { |
achuithb
2015/10/23 00:08:51
account_id
Alexander Alekseev
2015/10/23 09:11:22
Done.
| |
91 return nullptr; | 93 return nullptr; |
92 } | 94 } |
93 | 95 |
94 void FakeChromeUserManager::SetUserFlow(const std::string& email, | 96 void FakeChromeUserManager::SetUserFlow(const AccountId& account, |
95 UserFlow* flow) { | 97 UserFlow* flow) { |
96 ResetUserFlow(email); | 98 ResetUserFlow(account); |
97 specific_flows_[email] = flow; | 99 specific_flows_[account] = flow; |
98 } | 100 } |
99 | 101 |
100 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { | 102 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { |
101 if (!IsUserLoggedIn()) | 103 if (!IsUserLoggedIn()) |
102 return GetDefaultUserFlow(); | 104 return GetDefaultUserFlow(); |
103 return GetUserFlow(GetLoggedInUser()->email()); | 105 return GetUserFlow(GetLoggedInUser()->GetUserID()); |
104 } | 106 } |
105 | 107 |
106 UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const { | 108 UserFlow* FakeChromeUserManager::GetUserFlow(const AccountId& account) const { |
107 FlowMap::const_iterator it = specific_flows_.find(email); | 109 FlowMap::const_iterator it = specific_flows_.find(account); |
108 if (it != specific_flows_.end()) | 110 if (it != specific_flows_.end()) |
109 return it->second; | 111 return it->second; |
110 return GetDefaultUserFlow(); | 112 return GetDefaultUserFlow(); |
111 } | 113 } |
112 | 114 |
113 void FakeChromeUserManager::ResetUserFlow(const std::string& email) { | 115 void FakeChromeUserManager::ResetUserFlow(const AccountId& account) { |
114 FlowMap::iterator it = specific_flows_.find(email); | 116 FlowMap::iterator it = specific_flows_.find(account); |
115 if (it != specific_flows_.end()) { | 117 if (it != specific_flows_.end()) { |
116 delete it->second; | 118 delete it->second; |
117 specific_flows_.erase(it); | 119 specific_flows_.erase(it); |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 void FakeChromeUserManager::SwitchActiveUser(const std::string& email) { | 123 void FakeChromeUserManager::SwitchActiveUser(const AccountId& account) { |
122 active_user_id_ = email; | 124 active_user_id_ = account; |
123 ProfileHelper::Get()->ActiveUserHashChanged( | 125 ProfileHelper::Get()->ActiveUserHashChanged( |
124 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 126 ProfileHelper::GetUserIdHashByUserIdForTesting(account.GetUserEmail())); |
125 if (!users_.empty() && !active_user_id_.empty()) { | 127 if (!users_.empty() && !active_user_id_.empty()) { |
126 for (user_manager::User* user : users_) | 128 for (user_manager::User* user : users_) |
127 user->set_is_active(user->email() == active_user_id_); | 129 user->set_is_active(user->GetUserID() == active_user_id_); |
128 } | 130 } |
129 } | 131 } |
130 | 132 |
131 const std::string& FakeChromeUserManager::GetOwnerEmail() const { | 133 const AccountId& FakeChromeUserManager::GetOwnerId() const { |
132 return owner_email_; | 134 return owner_id_; |
133 } | 135 } |
134 | 136 |
135 void FakeChromeUserManager::SessionStarted() { | 137 void FakeChromeUserManager::SessionStarted() { |
136 } | 138 } |
137 | 139 |
138 void FakeChromeUserManager::RemoveUser( | 140 void FakeChromeUserManager::RemoveUser( |
139 const std::string& email, | 141 const AccountId& account, |
140 user_manager::RemoveUserDelegate* delegate) { | 142 user_manager::RemoveUserDelegate* delegate) {} |
141 } | |
142 | 143 |
143 user_manager::UserList | 144 user_manager::UserList |
144 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { | 145 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { |
145 CrosSettings* cros_settings = CrosSettings::Get(); | 146 CrosSettings* cros_settings = CrosSettings::Get(); |
146 bool allow_new_user = true; | 147 bool allow_new_user = true; |
147 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 148 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
148 bool supervised_users_allowed = AreSupervisedUsersAllowed(); | 149 bool supervised_users_allowed = AreSupervisedUsersAllowed(); |
149 | 150 |
150 // Restricted either by policy or by owner. | 151 // Restricted either by policy or by owner. |
151 if (!allow_new_user || !supervised_users_allowed) | 152 if (!allow_new_user || !supervised_users_allowed) |
(...skipping 22 matching lines...) Expand all Loading... | |
174 return result; | 175 return result; |
175 } | 176 } |
176 | 177 |
177 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { | 178 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { |
178 if (!default_flow_.get()) | 179 if (!default_flow_.get()) |
179 default_flow_.reset(new DefaultUserFlow()); | 180 default_flow_.reset(new DefaultUserFlow()); |
180 return default_flow_.get(); | 181 return default_flow_.get(); |
181 } | 182 } |
182 | 183 |
183 bool FakeChromeUserManager::FindKnownUserPrefs( | 184 bool FakeChromeUserManager::FindKnownUserPrefs( |
184 const user_manager::UserID& user_id, | 185 const AccountId& user_id, |
185 const base::DictionaryValue** out_value) { | 186 const base::DictionaryValue** out_value) { |
186 return false; | 187 return false; |
187 } | 188 } |
188 | 189 |
189 void FakeChromeUserManager::UpdateKnownUserPrefs( | 190 void FakeChromeUserManager::UpdateKnownUserPrefs( |
190 const user_manager::UserID& user_id, | 191 const AccountId& user_id, |
191 const base::DictionaryValue& values, | 192 const base::DictionaryValue& values, |
192 bool clear) { | 193 bool clear) {} |
193 } | |
194 | 194 |
195 } // namespace chromeos | 195 } // namespace chromeos |
OLD | NEW |