OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/user_manager/fake_user_manager.h" | 5 #include "components/user_manager/fake_user_manager.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
10 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
11 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
12 #include "components/user_manager/user_names.h" | 14 #include "components/user_manager/user_names.h" |
13 #include "components/user_manager/user_type.h" | 15 #include "components/user_manager/user_type.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 29 matching lines...) Expand all Loading... |
46 const user_manager::User* FakeUserManager::AddUserWithAffiliation( | 48 const user_manager::User* FakeUserManager::AddUserWithAffiliation( |
47 const AccountId& account_id, | 49 const AccountId& account_id, |
48 bool is_affiliated) { | 50 bool is_affiliated) { |
49 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); | 51 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); |
50 user->SetAffiliation(is_affiliated); | 52 user->SetAffiliation(is_affiliated); |
51 users_.push_back(user); | 53 users_.push_back(user); |
52 return user; | 54 return user; |
53 } | 55 } |
54 | 56 |
55 void FakeUserManager::RemoveUserFromList(const AccountId& account_id) { | 57 void FakeUserManager::RemoveUserFromList(const AccountId& account_id) { |
56 user_manager::UserList::iterator it = users_.begin(); | 58 const user_manager::UserList::iterator it = |
57 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is | 59 std::find_if(users_.begin(), users_.end(), |
58 // passed. crbug.com/546876 | 60 [&account_id](const user_manager::User* user) { |
59 while (it != users_.end() && (*it)->GetEmail() != account_id.GetUserEmail()) | 61 return user->GetAccountId() == account_id; |
60 ++it; | 62 }); |
61 if (it != users_.end()) { | 63 if (it != users_.end()) { |
62 if (primary_user_ == *it) | 64 if (primary_user_ == *it) |
63 primary_user_ = nullptr; | 65 primary_user_ = nullptr; |
64 if (active_user_ != *it) | 66 if (active_user_ != *it) |
65 delete *it; | 67 delete *it; |
66 users_.erase(it); | 68 users_.erase(it); |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 const user_manager::UserList& FakeUserManager::GetUsers() const { | 72 const user_manager::UserList& FakeUserManager::GetUsers() const { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 user_manager::User* FakeUserManager::GetActiveUser() { | 129 user_manager::User* FakeUserManager::GetActiveUser() { |
128 return GetActiveUserInternal(); | 130 return GetActiveUserInternal(); |
129 } | 131 } |
130 | 132 |
131 void FakeUserManager::SwitchActiveUser(const AccountId& account_id) {} | 133 void FakeUserManager::SwitchActiveUser(const AccountId& account_id) {} |
132 | 134 |
133 void FakeUserManager::SaveUserDisplayName(const AccountId& account_id, | 135 void FakeUserManager::SaveUserDisplayName(const AccountId& account_id, |
134 const base::string16& display_name) { | 136 const base::string16& display_name) { |
135 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 137 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
136 ++it) { | 138 ++it) { |
137 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is | 139 if ((*it)->GetAccountId() == account_id) { |
138 // passed. crbug.com/546876 | |
139 if ((*it)->GetEmail() == account_id.GetUserEmail()) { | |
140 (*it)->set_display_name(display_name); | 140 (*it)->set_display_name(display_name); |
141 return; | 141 return; |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { | 146 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { |
147 return users_; | 147 return users_; |
148 } | 148 } |
149 | 149 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 NOTIMPLEMENTED(); | 356 NOTIMPLEMENTED(); |
357 return; | 357 return; |
358 } | 358 } |
359 | 359 |
360 bool FakeUserManager::IsValidDefaultUserImageId(int image_index) const { | 360 bool FakeUserManager::IsValidDefaultUserImageId(int image_index) const { |
361 NOTIMPLEMENTED(); | 361 NOTIMPLEMENTED(); |
362 return false; | 362 return false; |
363 } | 363 } |
364 | 364 |
365 } // namespace user_manager | 365 } // namespace user_manager |
OLD | NEW |