| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/fake_login_utils.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
| 13 #include "chrome/browser/chromeos/login/user_flow.h" | |
| 14 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | |
| 15 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 17 #include "chrome/browser/first_run/first_run.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 20 #include "chrome/browser/ui/startup/startup_browser_creator.h" | |
| 21 #include "chrome/common/pref_names.h" | |
| 22 #include "chrome/test/base/testing_profile.h" | |
| 23 #include "chromeos/login/auth/mock_authenticator.h" | |
| 24 #include "chromeos/login/auth/user_context.h" | |
| 25 #include "components/signin/core/browser/signin_manager.h" | |
| 26 #include "components/user_manager/user.h" | |
| 27 #include "components/user_manager/user_manager.h" | |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "testing/gtest/include/gtest/gtest.h" | |
| 30 | |
| 31 namespace chromeos { | |
| 32 | |
| 33 FakeLoginUtils::FakeLoginUtils() : should_launch_browser_(false) {} | |
| 34 | |
| 35 FakeLoginUtils::~FakeLoginUtils() {} | |
| 36 | |
| 37 void FakeLoginUtils::DoBrowserLaunch(Profile* profile, | |
| 38 LoginDisplayHost* login_host) { | |
| 39 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | |
| 40 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | |
| 41 return; | |
| 42 } | |
| 43 login_host->BeforeSessionStart(); | |
| 44 if (should_launch_browser_) { | |
| 45 StartupBrowserCreator browser_creator; | |
| 46 chrome::startup::IsFirstRun first_run = | |
| 47 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN | |
| 48 : chrome::startup::IS_NOT_FIRST_RUN; | |
| 49 ASSERT_TRUE(browser_creator.LaunchBrowser( | |
| 50 *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(), | |
| 51 chrome::startup::IS_PROCESS_STARTUP, first_run, NULL)); | |
| 52 } | |
| 53 if (login_host) | |
| 54 login_host->Finalize(); | |
| 55 user_manager::UserManager::Get()->SessionStarted(); | |
| 56 } | |
| 57 | |
| 58 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, | |
| 59 bool has_cookies, | |
| 60 bool has_active_session, | |
| 61 LoginUtils::Delegate* delegate) { | |
| 62 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | |
| 63 user_manager->UserLoggedIn( | |
| 64 user_context.GetUserID(), user_context.GetUserIDHash(), false); | |
| 65 user_manager::User* user = | |
| 66 user_manager->FindUserAndModify(user_context.GetUserID()); | |
| 67 DCHECK(user); | |
| 68 | |
| 69 // Make sure that we get the real Profile instead of the login Profile. | |
| 70 user->set_profile_is_created(); | |
| 71 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); | |
| 72 SigninManagerFactory::GetForProfile(profile)->SetAuthenticatedUsername( | |
| 73 user_context.GetUserID()); | |
| 74 | |
| 75 if (user_manager->IsLoggedInAsSupervisedUser()) { | |
| 76 user_manager::User* active_user = user_manager->GetActiveUser(); | |
| 77 std::string supervised_user_sync_id = | |
| 78 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( | |
| 79 active_user->email()); | |
| 80 if (supervised_user_sync_id.empty()) | |
| 81 supervised_user_sync_id = "DUMMY ID"; | |
| 82 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | |
| 83 supervised_user_sync_id); | |
| 84 } | |
| 85 | |
| 86 content::NotificationService::current()->Notify( | |
| 87 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | |
| 88 content::NotificationService::AllSources(), | |
| 89 content::Details<Profile>(profile)); | |
| 90 | |
| 91 // Emulate UserSessionManager::InitializeUserSession() for now till | |
| 92 // FakeLoginUtils are deprecated. | |
| 93 bool browser_launched = false; | |
| 94 if (!user_manager->IsLoggedInAsKioskApp()) { | |
| 95 if (user_manager->IsCurrentUserNew()) { | |
| 96 NOTREACHED() << "Method not implemented."; | |
| 97 } else { | |
| 98 browser_launched = true; | |
| 99 LoginUtils::Get()->DoBrowserLaunch(profile, | |
| 100 LoginDisplayHostImpl::default_host()); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 if (delegate) | |
| 105 delegate->OnProfilePrepared(profile, browser_launched); | |
| 106 } | |
| 107 | |
| 108 void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) { | |
| 109 NOTREACHED() << "Method not implemented."; | |
| 110 } | |
| 111 | |
| 112 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator( | |
| 113 AuthStatusConsumer* consumer) { | |
| 114 authenticator_ = new MockAuthenticator(consumer, expected_user_context_); | |
| 115 return authenticator_; | |
| 116 } | |
| 117 | |
| 118 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { | |
| 119 expected_user_context_ = user_context; | |
| 120 if (authenticator_.get()) { | |
| 121 static_cast<MockAuthenticator*>(authenticator_.get())-> | |
| 122 SetExpectedCredentials(user_context); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 } // namespace chromeos | |
| OLD | NEW |