| 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 // static | 90 // static |
| 91 MultiProfileUserController::UserAllowedInSessionReason | 91 MultiProfileUserController::UserAllowedInSessionReason |
| 92 MultiProfileUserController::GetPrimaryUserPolicy() { | 92 MultiProfileUserController::GetPrimaryUserPolicy() { |
| 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* user = user_manager->GetPrimaryUser(); | 96 const user_manager::User* user = user_manager->GetPrimaryUser(); |
| 97 if (!user) | 97 if (!user) |
| 98 return ALLOWED; | 98 return ALLOWED; |
| 99 | 99 |
| 100 // Don't allow any secondary profiles if the primary profile is tainted. | 100 // Don't allow any secondary profiles if the primary profile is tainted. |
| 101 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user->email())) { | 101 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user->email())) { |
| 102 // Check directly in local_state before checking if the primary user has | 102 // Check directly in local_state before checking if the primary user has |
| 103 // a PolicyCertService. His profile may have been tainted previously though | 103 // a PolicyCertService. His profile may have been tainted previously though |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 prefs::kMultiProfileUserBehavior); | 122 prefs::kMultiProfileUserBehavior); |
| 123 if (behavior == kBehaviorNotAllowed) | 123 if (behavior == kBehaviorNotAllowed) |
| 124 return NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS; | 124 return NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS; |
| 125 | 125 |
| 126 return ALLOWED; | 126 return ALLOWED; |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool MultiProfileUserController::IsUserAllowedInSession( | 129 bool MultiProfileUserController::IsUserAllowedInSession( |
| 130 const std::string& user_email, | 130 const std::string& user_email, |
| 131 MultiProfileUserController::UserAllowedInSessionReason* reason) const { | 131 MultiProfileUserController::UserAllowedInSessionReason* reason) const { |
| 132 UserManager* user_manager = UserManager::Get(); | 132 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 133 CHECK(user_manager); | 133 CHECK(user_manager); |
| 134 | 134 |
| 135 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); | 135 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); |
| 136 std::string primary_user_email; | 136 std::string primary_user_email; |
| 137 if (primary_user) | 137 if (primary_user) |
| 138 primary_user_email = primary_user->email(); | 138 primary_user_email = primary_user->email(); |
| 139 | 139 |
| 140 // Always allow if there is no primary user or user being checked is the | 140 // Always allow if there is no primary user or user being checked is the |
| 141 // primary user. | 141 // primary user. |
| 142 if (primary_user_email.empty() || primary_user_email == user_email) | 142 if (primary_user_email.empty() || primary_user_email == user_email) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void MultiProfileUserController::SetCachedValue( | 201 void MultiProfileUserController::SetCachedValue( |
| 202 const std::string& user_email, | 202 const std::string& user_email, |
| 203 const std::string& behavior) { | 203 const std::string& behavior) { |
| 204 DictionaryPrefUpdate update(local_state_, | 204 DictionaryPrefUpdate update(local_state_, |
| 205 prefs::kCachedMultiProfileUserBehavior); | 205 prefs::kCachedMultiProfileUserBehavior); |
| 206 update->SetStringWithoutPathExpansion(user_email, | 206 update->SetStringWithoutPathExpansion(user_email, |
| 207 SanitizeBehaviorValue(behavior)); | 207 SanitizeBehaviorValue(behavior)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void MultiProfileUserController::CheckSessionUsers() { | 210 void MultiProfileUserController::CheckSessionUsers() { |
| 211 const user_manager::UserList& users = UserManager::Get()->GetLoggedInUsers(); | 211 const user_manager::UserList& users = |
| 212 user_manager::UserManager::Get()->GetLoggedInUsers(); |
| 212 for (user_manager::UserList::const_iterator it = users.begin(); | 213 for (user_manager::UserList::const_iterator it = users.begin(); |
| 213 it != users.end(); | 214 it != users.end(); |
| 214 ++it) { | 215 ++it) { |
| 215 if (!IsUserAllowedInSession((*it)->email(), NULL)) { | 216 if (!IsUserAllowedInSession((*it)->email(), NULL)) { |
| 216 delegate_->OnUserNotAllowed((*it)->email()); | 217 delegate_->OnUserNotAllowed((*it)->email()); |
| 217 return; | 218 return; |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 } else { | 237 } else { |
| 237 const std::string behavior = | 238 const std::string behavior = |
| 238 prefs->GetString(prefs::kMultiProfileUserBehavior); | 239 prefs->GetString(prefs::kMultiProfileUserBehavior); |
| 239 SetCachedValue(user_email, behavior); | 240 SetCachedValue(user_email, behavior); |
| 240 } | 241 } |
| 241 | 242 |
| 242 CheckSessionUsers(); | 243 CheckSessionUsers(); |
| 243 } | 244 } |
| 244 | 245 |
| 245 } // namespace chromeos | 246 } // namespace chromeos |
| OLD | NEW |