OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/chromeos/chromeos_version.h" | 10 #include "base/chromeos/chromeos_version.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 void LoginUtilsImpl::PrepareProfile( | 319 void LoginUtilsImpl::PrepareProfile( |
320 const UserContext& user_context, | 320 const UserContext& user_context, |
321 const std::string& display_email, | 321 const std::string& display_email, |
322 bool using_oauth, | 322 bool using_oauth, |
323 bool has_cookies, | 323 bool has_cookies, |
324 LoginUtils::Delegate* delegate) { | 324 LoginUtils::Delegate* delegate) { |
325 BootTimesLoader* btl = BootTimesLoader::Get(); | 325 BootTimesLoader* btl = BootTimesLoader::Get(); |
326 | 326 |
327 VLOG(1) << "Completing login for " << user_context.username; | 327 VLOG(1) << "Completing login for " << user_context.username; |
328 | 328 |
| 329 // TODO(nkostylev): Eliminate this flag. http://crbug.com/230349 |
| 330 bool is_primary_user = !UserManager::Get()->IsUserLoggedIn(); |
| 331 |
329 btl->AddLoginTimeMarker("StartSession-Start", false); | 332 btl->AddLoginTimeMarker("StartSession-Start", false); |
330 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( | 333 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
331 user_context.username); | 334 user_context.username); |
332 btl->AddLoginTimeMarker("StartSession-End", false); | 335 btl->AddLoginTimeMarker("StartSession-End", false); |
333 | 336 |
334 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); | 337 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
335 UserManager* user_manager = UserManager::Get(); | 338 UserManager* user_manager = UserManager::Get(); |
336 user_manager->UserLoggedIn(user_context.username, | 339 user_manager->UserLoggedIn(user_context.username, |
337 user_context.username_hash, | 340 user_context.username_hash, |
338 false); | 341 false); |
339 btl->AddLoginTimeMarker("UserLoggedIn-End", false); | 342 btl->AddLoginTimeMarker("UserLoggedIn-End", false); |
340 | 343 |
341 // Switch log file as soon as possible. | 344 // Switch log file as soon as possible. |
342 if (base::chromeos::IsRunningOnChromeOS()) | 345 if (base::chromeos::IsRunningOnChromeOS()) |
343 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); | 346 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); |
344 | 347 |
345 // Update user's displayed email. | 348 // Update user's displayed email. |
346 if (!display_email.empty()) | 349 if (!display_email.empty()) |
347 user_manager->SaveUserDisplayEmail(user_context.username, display_email); | 350 user_manager->SaveUserDisplayEmail(user_context.username, display_email); |
348 | 351 |
349 user_context_ = user_context; | 352 user_context_ = user_context; |
350 | 353 |
351 using_oauth_ = using_oauth; | 354 using_oauth_ = using_oauth; |
352 has_web_auth_cookies_ = has_cookies; | 355 has_web_auth_cookies_ = has_cookies; |
353 delegate_ = delegate; | 356 delegate_ = delegate; |
354 InitSessionRestoreStrategy(); | 357 InitSessionRestoreStrategy(); |
355 | 358 |
356 policy::BrowserPolicyConnector* connector = | 359 bool wait_for_policy_fetch = false; |
357 g_browser_process->browser_policy_connector(); | |
358 | 360 |
359 // If this is an enterprise device and the user belongs to the enterprise | 361 // TODO(nkostylev): Figure out implementation for multiple-profiles. |
360 // domain, then wait for a policy fetch before logging the user in. This | 362 if (is_primary_user) { |
361 // will delay Profile creation until the policy is fetched, so that features | 363 policy::BrowserPolicyConnector* connector = |
362 // controlled by policy (e.g. Sync, Startup tabs) only start after the | 364 g_browser_process->browser_policy_connector(); |
363 // PrefService has the right values. | |
364 // Profile creation is also resumed if the fetch attempt fails. | |
365 bool wait_for_policy_fetch = | |
366 using_oauth_ && | |
367 authenticator_.get() && | |
368 (connector->GetUserAffiliation(user_context_.username) == | |
369 policy::USER_AFFILIATION_MANAGED); | |
370 | 365 |
371 // Initialize user policy before the profile is created so the profile | 366 // If this is an enterprise device and the user belongs to the enterprise |
372 // initialization code sees the cached policy settings. | 367 // domain, then wait for a policy fetch before logging the user in. This |
373 connector->InitializeUserPolicy(user_context_.username, | 368 // will delay Profile creation until the policy is fetched, so that features |
374 user_manager->IsLoggedInAsPublicAccount(), | 369 // controlled by policy (e.g. Sync, Startup tabs) only start after the |
375 wait_for_policy_fetch); | 370 // PrefService has the right values. |
| 371 // Profile creation is also resumed if the fetch attempt fails. |
| 372 wait_for_policy_fetch = |
| 373 using_oauth_ && |
| 374 authenticator_.get() && |
| 375 (connector->GetUserAffiliation(user_context_.username) == |
| 376 policy::USER_AFFILIATION_MANAGED); |
| 377 |
| 378 // Initialize user policy before the profile is created so the profile |
| 379 // initialization code sees the cached policy settings. |
| 380 connector->InitializeUserPolicy(user_context_.username, |
| 381 user_manager->IsLoggedInAsPublicAccount(), |
| 382 wait_for_policy_fetch); |
| 383 } |
376 | 384 |
377 // The default profile will have been changed because the ProfileManager | 385 // The default profile will have been changed because the ProfileManager |
378 // will process the notification that the UserManager sends out. | 386 // will process the notification that the UserManager sends out so |
| 387 // username_hash has been already propogated to ProfileManager. |
379 ProfileManager::CreateDefaultProfileAsync( | 388 ProfileManager::CreateDefaultProfileAsync( |
380 base::Bind(&LoginUtilsImpl::OnProfileCreated, AsWeakPtr())); | 389 base::Bind(&LoginUtilsImpl::OnProfileCreated, AsWeakPtr())); |
381 | 390 |
382 if (wait_for_policy_fetch) { | 391 if (wait_for_policy_fetch) { |
383 // Profile creation will block until user policy is fetched, which | 392 // Profile creation will block until user policy is fetched, which |
384 // requires the DeviceManagement token. Try to fetch it now. | 393 // requires the DeviceManagement token. Try to fetch it now. |
385 // TODO(atwilson): This is somewhat racy, as we are trying to fetch a | 394 // TODO(atwilson): This is somewhat racy, as we are trying to fetch a |
386 // DMToken in parallel with loading the cached policy blob (there could | 395 // DMToken in parallel with loading the cached policy blob (there could |
387 // already be a DMToken in the cached policy). Once the legacy policy | 396 // already be a DMToken in the cached policy). Once the legacy policy |
388 // framework is removed, this code can register a | 397 // framework is removed, this code can register a |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 bool LoginUtils::IsWhitelisted(const std::string& username) { | 960 bool LoginUtils::IsWhitelisted(const std::string& username) { |
952 CrosSettings* cros_settings = CrosSettings::Get(); | 961 CrosSettings* cros_settings = CrosSettings::Get(); |
953 bool allow_new_user = false; | 962 bool allow_new_user = false; |
954 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 963 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
955 if (allow_new_user) | 964 if (allow_new_user) |
956 return true; | 965 return true; |
957 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 966 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
958 } | 967 } |
959 | 968 |
960 } // namespace chromeos | 969 } // namespace chromeos |
OLD | NEW |