Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/chromeos/login/users/multi_profile_user_controller.cc

Issue 460233004: Fixed misuse of GetProfileByUser in MultiProfileUserController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UserManager* 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;
98 if (primary_user)
99 primary_user_email = primary_user->email();
100 97
101 // Always allow if there is no primary user or user being checked is the 98 // Always allow if there is no primary user or user being checked is the
102 // primary user. 99 // primary user.
103 if (primary_user_email.empty() || primary_user_email == user_email) 100 if (!primary_user || primary_user->email() == user_email)
104 return SetUserAllowedReason(reason, ALLOWED); 101 return SetUserAllowedReason(reason, ALLOWED);
105 102
106 // Owner is not allowed to be secondary user. 103 // Owner is not allowed to be secondary user.
107 if (user_manager->GetOwnerEmail() == user_email) 104 if (user_manager->GetOwnerEmail() == user_email)
108 return SetUserAllowedReason(reason, NOT_ALLOWED_OWNER_AS_SECONDARY); 105 return SetUserAllowedReason(reason, NOT_ALLOWED_OWNER_AS_SECONDARY);
109 106
110 // Don't allow profiles potentially tainted by data fetched with policy-pushed 107 // Don't allow profiles potentially tainted by data fetched with policy-pushed
111 // certificates to join a multiprofile session. 108 // certificates to join a multiprofile session.
112 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email)) 109 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email))
113 return SetUserAllowedReason(reason, NOT_ALLOWED_POLICY_CERT_TAINTED); 110 return SetUserAllowedReason(reason, NOT_ALLOWED_POLICY_CERT_TAINTED);
114 111
115 // Don't allow any secondary profiles if the primary profile is tainted. 112 // Don't allow any secondary profiles if the primary profile is tainted.
116 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates( 113 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(
117 primary_user_email)) { 114 primary_user->email())) {
118 // Check directly in local_state before checking if the primary user has 115 // Check directly in local_state before checking if the primary user has
119 // a PolicyCertService. His profile may have been tainted previously though 116 // a PolicyCertService. His profile may have been tainted previously though
120 // he didn't get a PolicyCertService created for this session. 117 // he didn't get a PolicyCertService created for this session.
121 return SetUserAllowedReason(reason, 118 return SetUserAllowedReason(reason,
122 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED); 119 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED);
123 } 120 }
124 121
125 // If the primary profile already has policy certificates installed but hasn't 122 if (Profile* primary_user_profile =
Nikita (slow) 2014/08/13 09:16:46 I worry that if someone cals IsUserAllowedInSessio
dzhioev (left Google) 2014/08/13 16:41:13 Checked, nobody caches this value.
126 // used them yet then it can become tainted at any time during this session; 123 ProfileHelper::Get()->GetProfileByUser(primary_user)) {
127 // disable secondary profiles in this case too. 124 // If the primary profile already has policy certificates installed but
128 Profile* primary_user_profile = 125 // hasn't used them yet then it can become tainted at any time during this
129 primary_user ? ProfileHelper::Get()->GetProfileByUserUnsafe(primary_user) 126 // session disable secondary profiles in this case too.
130 : NULL; 127 if (policy::PolicyCertService* service =
131 policy::PolicyCertService* service = 128 policy::PolicyCertServiceFactory::GetForProfile(
132 primary_user_profile ? policy::PolicyCertServiceFactory::GetForProfile( 129 primary_user_profile)) {
133 primary_user_profile) 130 if (service->has_policy_certificates()) {
134 : NULL; 131 return SetUserAllowedReason(reason,
135 if (service && service->has_policy_certificates()) 132 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED);
136 return SetUserAllowedReason(reason, 133 }
137 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED); 134 }
138 135
139 // No user is allowed if the primary user policy forbids it. 136 // No user is allowed if the primary user policy forbids it.
140 const std::string primary_user_behavior = 137 const std::string primary_user_behavior =
141 primary_user_profile->GetPrefs()->GetString( 138 primary_user_profile->GetPrefs()->GetString(
142 prefs::kMultiProfileUserBehavior); 139 prefs::kMultiProfileUserBehavior);
143 if (primary_user_behavior == kBehaviorNotAllowed) 140 if (primary_user_behavior == kBehaviorNotAllowed) {
144 return SetUserAllowedReason(reason, 141 return SetUserAllowedReason(reason,
145 NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS); 142 NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS);
143 }
144 }
146 145
147 // The user must have 'unrestricted' policy to be a secondary user. 146 // The user must have 'unrestricted' policy to be a secondary user.
148 const std::string behavior = GetCachedValue(user_email); 147 const std::string behavior = GetCachedValue(user_email);
149 return SetUserAllowedReason( 148 return SetUserAllowedReason(
150 reason, 149 reason,
151 behavior == kBehaviorUnrestricted ? ALLOWED : NOT_ALLOWED_POLICY_FORBIDS); 150 behavior == kBehaviorUnrestricted ? ALLOWED : NOT_ALLOWED_POLICY_FORBIDS);
152 } 151 }
153 152
154 void MultiProfileUserController::StartObserving(Profile* user_profile) { 153 void MultiProfileUserController::StartObserving(Profile* user_profile) {
155 // Profile name could be empty during tests. 154 // Profile name could be empty during tests.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } else { 224 } else {
226 const std::string behavior = 225 const std::string behavior =
227 prefs->GetString(prefs::kMultiProfileUserBehavior); 226 prefs->GetString(prefs::kMultiProfileUserBehavior);
228 SetCachedValue(user_email, behavior); 227 SetCachedValue(user_email, behavior);
229 } 228 }
230 229
231 CheckSessionUsers(); 230 CheckSessionUsers();
232 } 231 }
233 232
234 } // namespace chromeos 233 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698