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

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

Issue 374853002: Providing more information on why certain users can't be added to multi-profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests. 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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 registry->RegisterBooleanPref( 80 registry->RegisterBooleanPref(
81 prefs::kMultiProfileNeverShowIntro, 81 prefs::kMultiProfileNeverShowIntro,
82 false, 82 false,
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 // static
91 const std::string& user_email, 91 MultiProfileUserController::UserAllowedInSessionReason
92 MultiProfileUserController::UserAllowedInSessionReason* reason) const { 92 MultiProfileUserController::GetPrimaryUserPolicy() {
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; 97 if (!primary_user)
98 if (primary_user) 98 return ALLOWED;
99 primary_user_email = primary_user->email(); 99 Profile* primary_user_profile =
100 ProfileHelper::Get()->GetProfileByUser(primary_user);
100 101
101 // Always allow if there is no primary user or user being checked is the 102 std::string primary_user_email = primary_user->email();
102 // primary user.
103 if (primary_user_email.empty() || primary_user_email == user_email)
104 return SetUserAllowedReason(reason, ALLOWED);
105
106 // Owner is not allowed to be secondary user.
107 if (user_manager->GetOwnerEmail() == user_email)
108 return SetUserAllowedReason(reason, NOT_ALLOWED_OWNER_AS_SECONDARY);
109
110 // Don't allow profiles potentially tainted by data fetched with policy-pushed
111 // certificates to join a multiprofile session.
112 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email))
113 return SetUserAllowedReason(reason, NOT_ALLOWED_POLICY_CERT_TAINTED);
114 103
115 // Don't allow any secondary profiles if the primary profile is tainted. 104 // Don't allow any secondary profiles if the primary profile is tainted.
116 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates( 105 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(
117 primary_user_email)) { 106 primary_user_email)) {
118 // Check directly in local_state before checking if the primary user has 107 // Check directly in local_state before checking if the primary user has
119 // a PolicyCertService. His profile may have been tainted previously though 108 // a PolicyCertService. His profile may have been tainted previously though
120 // he didn't get a PolicyCertService created for this session. 109 // he didn't get a PolicyCertService created for this session.
121 return SetUserAllowedReason(reason, 110 return NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED;
122 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED);
123 } 111 }
124 112
125 // If the primary profile already has policy certificates installed but hasn't 113 // If the primary profile already has policy certificates installed but hasn't
126 // used them yet then it can become tainted at any time during this session; 114 // used them yet then it can become tainted at any time during this session;
127 // disable secondary profiles in this case too. 115 // disable secondary profiles in this case too.
128 Profile* primary_user_profile =
129 primary_user ? ProfileHelper::Get()->GetProfileByUser(primary_user)
130 : NULL;
131 policy::PolicyCertService* service = 116 policy::PolicyCertService* service =
132 primary_user_profile ? policy::PolicyCertServiceFactory::GetForProfile( 117 primary_user_profile ? policy::PolicyCertServiceFactory::GetForProfile(
133 primary_user_profile) 118 primary_user_profile)
134 : NULL; 119 : NULL;
135 if (service && service->has_policy_certificates()) 120 if (service && service->has_policy_certificates())
136 return SetUserAllowedReason(reason, 121 return NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED;
137 NOT_ALLOWED_PRIMARY_POLICY_CERT_TAINTED);
138 122
139 // No user is allowed if the primary user policy forbids it. 123 // No user is allowed if the primary user policy forbids it.
140 const std::string primary_user_behavior = 124 const std::string primary_user_behavior =
141 primary_user_profile->GetPrefs()->GetString( 125 primary_user_profile->GetPrefs()->GetString(
142 prefs::kMultiProfileUserBehavior); 126 prefs::kMultiProfileUserBehavior);
143 if (primary_user_behavior == kBehaviorNotAllowed) 127 if (primary_user_behavior == kBehaviorNotAllowed)
144 return SetUserAllowedReason(reason, 128 return NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS;
145 NOT_ALLOWED_PRIMARY_USER_POLICY_FORBIDS); 129
130 return ALLOWED;
131 }
132
133 bool MultiProfileUserController::IsUserAllowedInSession(
134 const std::string& user_email,
135 MultiProfileUserController::UserAllowedInSessionReason* reason) const {
136 UserManager* user_manager = UserManager::Get();
137 CHECK(user_manager);
138
139 const user_manager::User* primary_user = user_manager->GetPrimaryUser();
140 std::string primary_user_email;
141 if (primary_user)
142 primary_user_email = primary_user->email();
143
144 // Always allow if there is no primary user or user being checked is the
145 // primary user.
146 if (primary_user_email.empty() || primary_user_email == user_email)
147 return SetUserAllowedReason(reason, ALLOWED);
148
149 // Owner is not allowed to be secondary user.
150 if (user_manager->GetOwnerEmail() == user_email)
151 return SetUserAllowedReason(reason, NOT_ALLOWED_OWNER_AS_SECONDARY);
152
153 // Don't allow profiles potentially tainted by data fetched with policy-pushed
154 // certificates to join a multiprofile session.
155 if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email))
156 return SetUserAllowedReason(reason, NOT_ALLOWED_POLICY_CERT_TAINTED);
157
158 UserAllowedInSessionReason primary_user_policy = GetPrimaryUserPolicy();
159 if (primary_user_policy != ALLOWED)
160 return SetUserAllowedReason(reason, primary_user_policy);
146 161
147 // The user must have 'unrestricted' policy to be a secondary user. 162 // The user must have 'unrestricted' policy to be a secondary user.
148 const std::string behavior = GetCachedValue(user_email); 163 const std::string behavior = GetCachedValue(user_email);
149 return SetUserAllowedReason( 164 return SetUserAllowedReason(
150 reason, 165 reason,
151 behavior == kBehaviorUnrestricted ? ALLOWED : NOT_ALLOWED_POLICY_FORBIDS); 166 behavior == kBehaviorUnrestricted ? ALLOWED : NOT_ALLOWED_POLICY_FORBIDS);
152 } 167 }
153 168
154 void MultiProfileUserController::StartObserving(Profile* user_profile) { 169 void MultiProfileUserController::StartObserving(Profile* user_profile) {
155 // Profile name could be empty during tests. 170 // Profile name could be empty during tests.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } else { 240 } else {
226 const std::string behavior = 241 const std::string behavior =
227 prefs->GetString(prefs::kMultiProfileUserBehavior); 242 prefs->GetString(prefs::kMultiProfileUserBehavior);
228 SetCachedValue(user_email, behavior); 243 SetCachedValue(user_email, behavior);
229 } 244 }
230 245
231 CheckSessionUsers(); 246 CheckSessionUsers();
232 } 247 }
233 248
234 } // namespace chromeos 249 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698