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/fake_login_utils.h" | 5 #include "chrome/browser/chromeos/login/fake_login_utils.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
| 12 #include "chrome/browser/chromeos/login/user_flow.h" | 13 #include "chrome/browser/chromeos/login/user_flow.h" |
| 13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/first_run/first_run.h" | 17 #include "chrome/browser/first_run/first_run.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 19 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 21 #include "chromeos/login/auth/mock_authenticator.h" | 22 #include "chromeos/login/auth/mock_authenticator.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 } | 54 } |
| 54 if (login_host) | 55 if (login_host) |
| 55 login_host->Finalize(); | 56 login_host->Finalize(); |
| 56 user_manager::UserManager::Get()->SessionStarted(); | 57 user_manager::UserManager::Get()->SessionStarted(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, | 60 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, |
| 60 bool has_cookies, | 61 bool has_cookies, |
| 61 bool has_active_session, | 62 bool has_active_session, |
| 62 LoginUtils::Delegate* delegate) { | 63 LoginUtils::Delegate* delegate) { |
| 63 user_manager::UserManager::Get()->UserLoggedIn( | 64 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 65 user_manager->UserLoggedIn( | |
| 64 user_context.GetUserID(), user_context.GetUserIDHash(), false); | 66 user_context.GetUserID(), user_context.GetUserIDHash(), false); |
| 65 user_manager::User* user = | 67 user_manager::User* user = |
| 66 user_manager::UserManager::Get()->FindUserAndModify( | 68 user_manager->FindUserAndModify(user_context.GetUserID()); |
| 67 user_context.GetUserID()); | |
| 68 DCHECK(user); | 69 DCHECK(user); |
| 69 | 70 |
| 70 // Make sure that we get the real Profile instead of the login Profile. | 71 // Make sure that we get the real Profile instead of the login Profile. |
| 71 user->set_profile_is_created(); | 72 user->set_profile_is_created(); |
| 72 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 73 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
| 73 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 74 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 74 user_context.GetUserID()); | 75 user_context.GetUserID()); |
| 75 | 76 |
| 76 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 77 if (user_manager->IsLoggedInAsSupervisedUser()) { |
| 77 user_manager::User* active_user = | 78 user_manager::User* active_user = user_manager->GetActiveUser(); |
| 78 user_manager::UserManager::Get()->GetActiveUser(); | |
| 79 std::string supervised_user_sync_id = | 79 std::string supervised_user_sync_id = |
| 80 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( | 80 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( |
| 81 active_user->email()); | 81 active_user->email()); |
| 82 if (supervised_user_sync_id.empty()) | 82 if (supervised_user_sync_id.empty()) |
| 83 supervised_user_sync_id = "DUMMY ID"; | 83 supervised_user_sync_id = "DUMMY ID"; |
| 84 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 84 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 85 supervised_user_sync_id); | 85 supervised_user_sync_id); |
| 86 } | 86 } |
| 87 | 87 |
| 88 content::NotificationService::current()->Notify( | 88 content::NotificationService::current()->Notify( |
| 89 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 89 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 90 content::NotificationService::AllSources(), | 90 content::NotificationService::AllSources(), |
| 91 content::Details<Profile>(profile)); | 91 content::Details<Profile>(profile)); |
| 92 | |
| 93 // Emulate UserSessionManager::InitializeUserSession() for now till | |
| 94 // FakeLoginUtils are deprecated. | |
| 95 bool browser_launched = false; | |
| 96 if (!user_manager->IsLoggedInAsKioskApp()) { | |
| 97 if (user_manager->IsCurrentUserNew()) { | |
| 98 NOTIMPLEMENTED(); | |
| 99 } else { | |
| 100 LoginUtils::Get()->DoBrowserLaunch(profile, | |
| 101 LoginDisplayHostImpl::default_host()); | |
|
Denis Kuznetsov (DE-MUC)
2014/10/20 13:38:59
browser_launch = true?
Nikita (slow)
2014/10/20 13:52:10
Done.
| |
| 102 } | |
| 103 } | |
| 104 | |
| 92 if (delegate) | 105 if (delegate) |
| 93 delegate->OnProfilePrepared(profile); | 106 delegate->OnProfilePrepared(profile, browser_launched); |
| 94 } | 107 } |
| 95 | 108 |
| 96 void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) { | 109 void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) { |
| 97 NOTREACHED() << "Method not implemented."; | 110 NOTREACHED() << "Method not implemented."; |
| 98 } | 111 } |
| 99 | 112 |
| 100 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator( | 113 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator( |
| 101 AuthStatusConsumer* consumer) { | 114 AuthStatusConsumer* consumer) { |
| 102 authenticator_ = new MockAuthenticator(consumer, expected_user_context_); | 115 authenticator_ = new MockAuthenticator(consumer, expected_user_context_); |
| 103 return authenticator_; | 116 return authenticator_; |
| 104 } | 117 } |
| 105 | 118 |
| 106 bool FakeLoginUtils::RestartToApplyPerSessionFlagsIfNeed(Profile* profile, | 119 bool FakeLoginUtils::RestartToApplyPerSessionFlagsIfNeed(Profile* profile, |
| 107 bool early_restart) { | 120 bool early_restart) { |
| 108 NOTREACHED() << "Method not implemented."; | 121 NOTREACHED() << "Method not implemented."; |
| 109 return false; | 122 return false; |
| 110 } | 123 } |
| 111 | 124 |
| 112 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { | 125 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { |
| 113 expected_user_context_ = user_context; | 126 expected_user_context_ = user_context; |
| 114 if (authenticator_.get()) { | 127 if (authenticator_.get()) { |
| 115 static_cast<MockAuthenticator*>(authenticator_.get())-> | 128 static_cast<MockAuthenticator*>(authenticator_.get())-> |
| 116 SetExpectedCredentials(user_context); | 129 SetExpectedCredentials(user_context); |
| 117 } | 130 } |
| 118 } | 131 } |
| 119 | 132 |
| 120 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |