Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/multi_profile_user_controller.h" | 5 #include "chrome/browser/chromeos/login/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/multi_profile_user_controller_delegate.h " | 13 #include "chrome/browser/chromeos/login/multi_profile_user_controller_delegate.h " |
| 14 #include "chrome/browser/chromeos/login/user.h" | |
| 14 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | |
| 17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | |
| 15 #include "chrome/browser/prefs/pref_service_syncable.h" | 18 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 19 | 22 |
| 20 namespace chromeos { | 23 namespace chromeos { |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 std::string SanitizeBehaviorValue(const std::string& value) { | 27 std::string SanitizeBehaviorValue(const std::string& value) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 76 |
| 74 // Always allow if there is no primary user or user being checked is the | 77 // Always allow if there is no primary user or user being checked is the |
| 75 // primary user. | 78 // primary user. |
| 76 if (primary_user_email.empty() || primary_user_email == user_email) | 79 if (primary_user_email.empty() || primary_user_email == user_email) |
| 77 return true; | 80 return true; |
| 78 | 81 |
| 79 // Owner is not allowed to be secondary user. | 82 // Owner is not allowed to be secondary user. |
| 80 if (user_manager->GetOwnerEmail() == user_email) | 83 if (user_manager->GetOwnerEmail() == user_email) |
| 81 return false; | 84 return false; |
| 82 | 85 |
| 86 // Don't allow profiles potentially tainted by data fetched with policy-pushed | |
| 87 // certificates to join a multiprofile session. | |
| 88 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email)) | |
| 89 return false; | |
| 90 | |
| 91 // Don't allow any secondary profiles if the primary profile is potentially | |
| 92 // tainted. | |
| 93 const User* primary_user = user_manager->GetPrimaryUser(); | |
| 94 Profile* profile = | |
| 95 primary_user ? user_manager->GetProfileByUser(primary_user) : NULL; | |
| 96 policy::PolicyCertService* service = | |
| 97 profile ? policy::PolicyCertServiceFactory::GetForProfile(profile) : NULL; | |
| 98 if (service && (service->UsedPolicyCertificates() || | |
| 99 service->has_policy_certificates())) { | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 83 // No user is allowed if the primary user policy forbids it. | 103 // No user is allowed if the primary user policy forbids it. |
| 84 const std::string primary_user_behavior = GetCachedValue(primary_user_email); | 104 const std::string primary_user_behavior = GetCachedValue(primary_user_email); |
| 85 if (primary_user_behavior == kBehaviorNotAllowed) | 105 if (primary_user_behavior == kBehaviorNotAllowed) |
| 86 return false; | 106 return false; |
| 87 | 107 |
| 88 // The user must have 'unrestricted' policy to be a secondary user. | 108 // The user must have 'unrestricted' policy to be a secondary user. |
| 89 const std::string behavior = GetCachedValue(user_email); | 109 const std::string behavior = GetCachedValue(user_email); |
| 90 return behavior == kBehaviorUnrestricted; | 110 return behavior == kBehaviorUnrestricted; |
| 91 } | 111 } |
| 92 | 112 |
| 93 void MultiProfileUserController::StartObserving(Profile* user_profile) { | 113 void MultiProfileUserController::StartObserving(Profile* user_profile) { |
| 94 // Profile name could be empty during tests. | 114 // Profile name could be empty during tests. |
| 95 if (user_profile->GetProfileName().empty()) | 115 if (user_profile->GetProfileName().empty()) |
| 96 return; | 116 return; |
| 97 | 117 |
| 98 scoped_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar); | 118 scoped_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar); |
| 99 registrar->Init(user_profile->GetPrefs()); | 119 registrar->Init(user_profile->GetPrefs()); |
| 100 registrar->Add( | 120 registrar->Add( |
| 101 prefs::kMultiProfileUserBehavior, | 121 prefs::kMultiProfileUserBehavior, |
| 102 base::Bind(&MultiProfileUserController::OnUserPrefChanged, | 122 base::Bind(&MultiProfileUserController::OnUserPrefChanged, |
| 103 base::Unretained(this), | 123 base::Unretained(this), |
| 104 user_profile)); | 124 user_profile)); |
| 105 pref_watchers_.push_back(registrar.release()); | 125 pref_watchers_.push_back(registrar.release()); |
| 106 | 126 |
| 107 OnUserPrefChanged(user_profile); | 127 OnUserPrefChanged(user_profile); |
| 108 } | 128 } |
| 109 | 129 |
| 110 void MultiProfileUserController::RemoveCachedValue( | 130 void MultiProfileUserController::RemoveCachedValues( |
| 111 const std::string& user_email) { | 131 const std::string& user_email) { |
| 112 DictionaryPrefUpdate update(local_state_, | 132 DictionaryPrefUpdate update(local_state_, |
| 113 prefs::kCachedMultiProfileUserBehavior); | 133 prefs::kCachedMultiProfileUserBehavior); |
| 114 update->RemoveWithoutPathExpansion(user_email, NULL); | 134 update->RemoveWithoutPathExpansion(user_email, NULL); |
| 135 policy::PolicyCertServiceFactory::ClearUsedPolicyCertificates(user_email); | |
|
pneubeck (no reviews)
2013/12/18 09:11:07
i think the old place was better for this as the t
Joao da Silva
2013/12/18 09:40:13
I'd prefer to have this next to the code that call
| |
| 115 } | 136 } |
| 116 | 137 |
| 117 std::string MultiProfileUserController::GetCachedValue( | 138 std::string MultiProfileUserController::GetCachedValue( |
| 118 const std::string& user_email) const { | 139 const std::string& user_email) const { |
| 119 const DictionaryValue* dict = | 140 const DictionaryValue* dict = |
| 120 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); | 141 local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior); |
| 121 std::string value; | 142 std::string value; |
| 122 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) | 143 if (dict && dict->GetStringWithoutPathExpansion(user_email, &value)) |
| 123 return SanitizeBehaviorValue(value); | 144 return SanitizeBehaviorValue(value); |
| 124 | 145 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 152 | 173 |
| 153 PrefService* prefs = user_profile->GetPrefs(); | 174 PrefService* prefs = user_profile->GetPrefs(); |
| 154 const std::string behavior = | 175 const std::string behavior = |
| 155 prefs->GetString(prefs::kMultiProfileUserBehavior); | 176 prefs->GetString(prefs::kMultiProfileUserBehavior); |
| 156 SetCachedValue(user_email, behavior); | 177 SetCachedValue(user_email, behavior); |
| 157 | 178 |
| 158 CheckSessionUsers(); | 179 CheckSessionUsers(); |
| 159 } | 180 } |
| 160 | 181 |
| 161 } // namespace chromeos | 182 } // namespace chromeos |
| OLD | NEW |