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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 user_manager::User* FakeChromeUserManager::AddArcKioskAppUser( | 96 user_manager::User* FakeChromeUserManager::AddArcKioskAppUser( |
97 const AccountId& account_id) { | 97 const AccountId& account_id) { |
98 user_manager::User* user = | 98 user_manager::User* user = |
99 user_manager::User::CreateArcKioskAppUser(account_id); | 99 user_manager::User::CreateArcKioskAppUser(account_id); |
100 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | 100 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
101 account_id.GetUserEmail())); | 101 account_id.GetUserEmail())); |
102 users_.push_back(user); | 102 users_.push_back(user); |
103 return user; | 103 return user; |
104 } | 104 } |
105 | 105 |
106 user_manager::User* FakeChromeUserManager::AddSupervisedUser( | |
107 const AccountId& account_id) { | |
108 user_manager::User* user = | |
109 user_manager::User::CreateSupervisedUser(account_id); | |
110 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | |
111 account_id.GetUserEmail())); | |
112 users_.push_back(user); | |
113 return user; | |
114 } | |
115 | |
106 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( | 116 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( |
107 const AccountId& account_id) { | 117 const AccountId& account_id) { |
108 user_manager::User* user = | 118 user_manager::User* user = |
109 user_manager::User::CreatePublicAccountUser(account_id); | 119 user_manager::User::CreatePublicAccountUser(account_id); |
110 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( | 120 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
111 account_id.GetUserEmail())); | 121 account_id.GetUserEmail())); |
112 user->SetStubImage(base::MakeUnique<user_manager::UserImage>( | 122 user->SetStubImage(base::MakeUnique<user_manager::UserImage>( |
113 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 123 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
114 IDR_PROFILE_PICTURE_LOADING)), | 124 IDR_PROFILE_PICTURE_LOADING)), |
115 user_manager::User::USER_IMAGE_PROFILE, false); | 125 user_manager::User::USER_IMAGE_PROFILE, false); |
116 users_.push_back(user); | 126 users_.push_back(user); |
117 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 127 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
118 return user; | 128 return user; |
119 } | 129 } |
120 | 130 |
121 bool FakeChromeUserManager::AreEphemeralUsersEnabled() const { | 131 bool FakeChromeUserManager::AreEphemeralUsersEnabled() const { |
122 return fake_ephemeral_users_enabled_; | 132 return fake_ephemeral_users_enabled_; |
123 } | 133 } |
124 | 134 |
125 void FakeChromeUserManager::LoginUser(const AccountId& account_id) { | 135 void FakeChromeUserManager::LoginUser(const AccountId& account_id, |
136 bool set_profile_created) { | |
126 UserLoggedIn(account_id, ProfileHelper::GetUserIdHashByUserIdForTesting( | 137 UserLoggedIn(account_id, ProfileHelper::GetUserIdHashByUserIdForTesting( |
127 account_id.GetUserEmail()), | 138 account_id.GetUserEmail()), |
128 false /* browser_restart */); | 139 false /* browser_restart */); |
140 | |
141 // NOTE: This does not match production. See function comment. | |
142 if (set_profile_created) { | |
143 for (auto* user : users_) { | |
144 if (user->GetAccountId() == account_id) | |
145 user->set_profile_is_created(); | |
xiyuan
2017/04/21 23:14:35
break; ?
James Cook
2017/04/24 17:47:26
Done.
| |
146 } | |
147 } | |
129 } | 148 } |
130 | 149 |
131 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { | 150 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { |
132 return bootstrap_manager_; | 151 return bootstrap_manager_; |
133 } | 152 } |
134 | 153 |
135 MultiProfileUserController* | 154 MultiProfileUserController* |
136 FakeChromeUserManager::GetMultiProfileUserController() { | 155 FakeChromeUserManager::GetMultiProfileUserController() { |
137 return multi_profile_user_controller_; | 156 return multi_profile_user_controller_; |
138 } | 157 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 user_manager::UserList FakeChromeUserManager::GetUnlockUsers() const { | 382 user_manager::UserList FakeChromeUserManager::GetUnlockUsers() const { |
364 return users_; | 383 return users_; |
365 } | 384 } |
366 | 385 |
367 void FakeChromeUserManager::UserLoggedIn(const AccountId& account_id, | 386 void FakeChromeUserManager::UserLoggedIn(const AccountId& account_id, |
368 const std::string& username_hash, | 387 const std::string& username_hash, |
369 bool browser_restart) { | 388 bool browser_restart) { |
370 for (auto* user : users_) { | 389 for (auto* user : users_) { |
371 if (user->username_hash() == username_hash) { | 390 if (user->username_hash() == username_hash) { |
372 user->set_is_logged_in(true); | 391 user->set_is_logged_in(true); |
373 user->set_profile_is_created(); | |
374 logged_in_users_.push_back(user); | 392 logged_in_users_.push_back(user); |
375 | 393 |
376 if (!primary_user_) | 394 if (!primary_user_) |
377 primary_user_ = user; | 395 primary_user_ = user; |
378 break; | 396 break; |
379 } | 397 } |
380 } | 398 } |
399 // TODO(jamescook): This should set active_user_ and call NotifyOnLogin(). | |
381 } | 400 } |
382 | 401 |
383 void FakeChromeUserManager::SwitchToLastActiveUser() { | 402 void FakeChromeUserManager::SwitchToLastActiveUser() { |
384 NOTREACHED(); | 403 NOTREACHED(); |
385 } | 404 } |
386 | 405 |
387 bool FakeChromeUserManager::IsKnownUser(const AccountId& account_id) const { | 406 bool FakeChromeUserManager::IsKnownUser(const AccountId& account_id) const { |
388 return true; | 407 return true; |
389 } | 408 } |
390 | 409 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 if (active_account_id_.is_valid()) { | 650 if (active_account_id_.is_valid()) { |
632 for (auto* user : users_) { | 651 for (auto* user : users_) { |
633 if (user->GetAccountId() == active_account_id_) | 652 if (user->GetAccountId() == active_account_id_) |
634 return user; | 653 return user; |
635 } | 654 } |
636 } | 655 } |
637 return users_[0]; | 656 return users_[0]; |
638 } | 657 } |
639 | 658 |
640 } // namespace chromeos | 659 } // namespace chromeos |
OLD | NEW |