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_manager.h" | |
15 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 14 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
16 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 15 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #include "chrome/browser/prefs/pref_service_syncable.h" | 17 #include "chrome/browser/prefs/pref_service_syncable.h" |
19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "components/user_manager/user.h" | 20 #include "components/user_manager/user.h" |
| 21 #include "components/user_manager/user_manager.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 83 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
84 registry->RegisterBooleanPref( | 84 registry->RegisterBooleanPref( |
85 prefs::kMultiProfileWarningShowDismissed, | 85 prefs::kMultiProfileWarningShowDismissed, |
86 false, | 86 false, |
87 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 87 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
88 } | 88 } |
89 | 89 |
90 bool MultiProfileUserController::IsUserAllowedInSession( | 90 bool MultiProfileUserController::IsUserAllowedInSession( |
91 const std::string& user_email, | 91 const std::string& user_email, |
92 MultiProfileUserController::UserAllowedInSessionReason* reason) const { | 92 MultiProfileUserController::UserAllowedInSessionReason* reason) const { |
93 UserManager* user_manager = UserManager::Get(); | 93 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
94 CHECK(user_manager); | 94 CHECK(user_manager); |
95 | 95 |
96 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); | 96 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); |
97 std::string primary_user_email; | 97 std::string primary_user_email; |
98 if (primary_user) | 98 if (primary_user) |
99 primary_user_email = primary_user->email(); | 99 primary_user_email = primary_user->email(); |
100 | 100 |
101 // Always allow if there is no primary user or user being checked is the | 101 // Always allow if there is no primary user or user being checked is the |
102 // primary user. | 102 // primary user. |
103 if (primary_user_email.empty() || primary_user_email == user_email) | 103 if (primary_user_email.empty() || primary_user_email == user_email) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void MultiProfileUserController::SetCachedValue( | 190 void MultiProfileUserController::SetCachedValue( |
191 const std::string& user_email, | 191 const std::string& user_email, |
192 const std::string& behavior) { | 192 const std::string& behavior) { |
193 DictionaryPrefUpdate update(local_state_, | 193 DictionaryPrefUpdate update(local_state_, |
194 prefs::kCachedMultiProfileUserBehavior); | 194 prefs::kCachedMultiProfileUserBehavior); |
195 update->SetStringWithoutPathExpansion(user_email, | 195 update->SetStringWithoutPathExpansion(user_email, |
196 SanitizeBehaviorValue(behavior)); | 196 SanitizeBehaviorValue(behavior)); |
197 } | 197 } |
198 | 198 |
199 void MultiProfileUserController::CheckSessionUsers() { | 199 void MultiProfileUserController::CheckSessionUsers() { |
200 const user_manager::UserList& users = UserManager::Get()->GetLoggedInUsers(); | 200 const user_manager::UserList& users = |
| 201 user_manager::UserManager::Get()->GetLoggedInUsers(); |
201 for (user_manager::UserList::const_iterator it = users.begin(); | 202 for (user_manager::UserList::const_iterator it = users.begin(); |
202 it != users.end(); | 203 it != users.end(); |
203 ++it) { | 204 ++it) { |
204 if (!IsUserAllowedInSession((*it)->email(), NULL)) { | 205 if (!IsUserAllowedInSession((*it)->email(), NULL)) { |
205 delegate_->OnUserNotAllowed((*it)->email()); | 206 delegate_->OnUserNotAllowed((*it)->email()); |
206 return; | 207 return; |
207 } | 208 } |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
(...skipping 14 matching lines...) Expand all Loading... |
225 } else { | 226 } else { |
226 const std::string behavior = | 227 const std::string behavior = |
227 prefs->GetString(prefs::kMultiProfileUserBehavior); | 228 prefs->GetString(prefs::kMultiProfileUserBehavior); |
228 SetCachedValue(user_email, behavior); | 229 SetCachedValue(user_email, behavior); |
229 } | 230 } |
230 | 231 |
231 CheckSessionUsers(); | 232 CheckSessionUsers(); |
232 } | 233 } |
233 | 234 |
234 } // namespace chromeos | 235 } // namespace chromeos |
OLD | NEW |