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 "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 5 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_change_registrar.h" | 9 #include "base/prefs/pref_change_registrar.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
13 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_dele
gate.h" | 13 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_dele
gate.h" |
14 #include "chrome/browser/chromeos/login/users/user.h" | |
15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/user_manager.h" |
16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 15 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 16 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
19 #include "chrome/browser/prefs/pref_service_syncable.h" | 18 #include "chrome/browser/prefs/pref_service_syncable.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_manager/user.h" |
22 #include "google_apis/gaia/gaia_auth_util.h" | 22 #include "google_apis/gaia/gaia_auth_util.h" |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 std::string SanitizeBehaviorValue(const std::string& value) { | 28 std::string SanitizeBehaviorValue(const std::string& value) { |
29 if (value == MultiProfileUserController::kBehaviorUnrestricted || | 29 if (value == MultiProfileUserController::kBehaviorUnrestricted || |
30 value == MultiProfileUserController::kBehaviorPrimaryOnly || | 30 value == MultiProfileUserController::kBehaviorPrimaryOnly || |
31 value == MultiProfileUserController::kBehaviorNotAllowed || | 31 value == MultiProfileUserController::kBehaviorNotAllowed || |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 false, | 79 false, |
80 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 80 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
81 } | 81 } |
82 | 82 |
83 MultiProfileUserController::UserAllowedInSessionResult | 83 MultiProfileUserController::UserAllowedInSessionResult |
84 MultiProfileUserController::IsUserAllowedInSession( | 84 MultiProfileUserController::IsUserAllowedInSession( |
85 const std::string& user_email) const { | 85 const std::string& user_email) const { |
86 UserManager* user_manager = UserManager::Get(); | 86 UserManager* user_manager = UserManager::Get(); |
87 CHECK(user_manager); | 87 CHECK(user_manager); |
88 | 88 |
89 const User* primary_user = user_manager->GetPrimaryUser(); | 89 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); |
90 std::string primary_user_email; | 90 std::string primary_user_email; |
91 if (primary_user) | 91 if (primary_user) |
92 primary_user_email = primary_user->email(); | 92 primary_user_email = primary_user->email(); |
93 | 93 |
94 // Always allow if there is no primary user or user being checked is the | 94 // Always allow if there is no primary user or user being checked is the |
95 // primary user. | 95 // primary user. |
96 if (primary_user_email.empty() || primary_user_email == user_email) | 96 if (primary_user_email.empty() || primary_user_email == user_email) |
97 return ALLOWED; | 97 return ALLOWED; |
98 | 98 |
99 // Owner is not allowed to be secondary user. | 99 // Owner is not allowed to be secondary user. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void MultiProfileUserController::SetCachedValue( | 183 void MultiProfileUserController::SetCachedValue( |
184 const std::string& user_email, | 184 const std::string& user_email, |
185 const std::string& behavior) { | 185 const std::string& behavior) { |
186 DictionaryPrefUpdate update(local_state_, | 186 DictionaryPrefUpdate update(local_state_, |
187 prefs::kCachedMultiProfileUserBehavior); | 187 prefs::kCachedMultiProfileUserBehavior); |
188 update->SetStringWithoutPathExpansion(user_email, | 188 update->SetStringWithoutPathExpansion(user_email, |
189 SanitizeBehaviorValue(behavior)); | 189 SanitizeBehaviorValue(behavior)); |
190 } | 190 } |
191 | 191 |
192 void MultiProfileUserController::CheckSessionUsers() { | 192 void MultiProfileUserController::CheckSessionUsers() { |
193 const UserList& users = UserManager::Get()->GetLoggedInUsers(); | 193 const user_manager::UserList& users = UserManager::Get()->GetLoggedInUsers(); |
194 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 194 for (user_manager::UserList::const_iterator it = users.begin(); |
| 195 it != users.end(); |
| 196 ++it) { |
195 if (IsUserAllowedInSession((*it)->email()) != ALLOWED) { | 197 if (IsUserAllowedInSession((*it)->email()) != ALLOWED) { |
196 delegate_->OnUserNotAllowed((*it)->email()); | 198 delegate_->OnUserNotAllowed((*it)->email()); |
197 return; | 199 return; |
198 } | 200 } |
199 } | 201 } |
200 } | 202 } |
201 | 203 |
202 void MultiProfileUserController::OnUserPrefChanged( | 204 void MultiProfileUserController::OnUserPrefChanged( |
203 Profile* user_profile) { | 205 Profile* user_profile) { |
204 std::string user_email = user_profile->GetProfileName(); | 206 std::string user_email = user_profile->GetProfileName(); |
(...skipping 11 matching lines...) Expand all Loading... |
216 } else { | 218 } else { |
217 const std::string behavior = | 219 const std::string behavior = |
218 prefs->GetString(prefs::kMultiProfileUserBehavior); | 220 prefs->GetString(prefs::kMultiProfileUserBehavior); |
219 SetCachedValue(user_email, behavior); | 221 SetCachedValue(user_email, behavior); |
220 } | 222 } |
221 | 223 |
222 CheckSessionUsers(); | 224 CheckSessionUsers(); |
223 } | 225 } |
224 | 226 |
225 } // namespace chromeos | 227 } // namespace chromeos |
OLD | NEW |