| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 76 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 77 registry->RegisterBooleanPref( | 77 registry->RegisterBooleanPref( |
| 78 prefs::kMultiProfileWarningShowDismissed, | 78 prefs::kMultiProfileWarningShowDismissed, |
| 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 = GetUserManager(); |
| 87 CHECK(user_manager); | 87 CHECK(user_manager); |
| 88 | 88 |
| 89 const User* primary_user = user_manager->GetPrimaryUser(); | 89 const 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) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 std::string MultiProfileUserController::GetCachedValue( | 168 std::string MultiProfileUserController::GetCachedValue( |
| 169 const std::string& user_email) const { | 169 const std::string& user_email) const { |
| 170 const base::DictionaryValue* dict = | 170 const base::DictionaryValue* dict = |
| 171 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); | 171 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); |
| 172 std::string value; | 172 std::string value; |
| 173 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) | 173 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) |
| 174 return SanitizeBehaviorValue(value); | 174 return SanitizeBehaviorValue(value); |
| 175 | 175 |
| 176 // Owner is not allowed to be secondary user (see http://crbug.com/385034). | 176 // Owner is not allowed to be secondary user (see http://crbug.com/385034). |
| 177 if (UserManager::Get()->GetOwnerEmail() == user_email) | 177 if (GetUserManager()->GetOwnerEmail() == user_email) |
| 178 return std::string(kBehaviorOwnerPrimaryOnly); | 178 return std::string(kBehaviorOwnerPrimaryOnly); |
| 179 | 179 |
| 180 return std::string(kBehaviorUnrestricted); | 180 return std::string(kBehaviorUnrestricted); |
| 181 } | 181 } |
| 182 | 182 |
| 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 UserList& users = GetUserManager()->GetLoggedInUsers(); |
| 194 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 194 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 195 if (IsUserAllowedInSession((*it)->email()) != ALLOWED) { | 195 if (IsUserAllowedInSession((*it)->email()) != ALLOWED) { |
| 196 delegate_->OnUserNotAllowed((*it)->email()); | 196 delegate_->OnUserNotAllowed((*it)->email()); |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 void MultiProfileUserController::OnUserPrefChanged( | 202 void MultiProfileUserController::OnUserPrefChanged( |
| 203 Profile* user_profile) { | 203 Profile* user_profile) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 } else { | 216 } else { |
| 217 const std::string behavior = | 217 const std::string behavior = |
| 218 prefs->GetString(prefs::kMultiProfileUserBehavior); | 218 prefs->GetString(prefs::kMultiProfileUserBehavior); |
| 219 SetCachedValue(user_email, behavior); | 219 SetCachedValue(user_email, behavior); |
| 220 } | 220 } |
| 221 | 221 |
| 222 CheckSessionUsers(); | 222 CheckSessionUsers(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace chromeos | 225 } // namespace chromeos |
| OLD | NEW |