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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/signin_screen_controller.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
9 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h"
10 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h"
11 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
12 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
16 SignInScreenController
* SignInScreenController::instance_
= nullptr;
18 SignInScreenController::SignInScreenController(
19 OobeDisplay
* oobe_display
,
20 LoginDisplay::Delegate
* login_display_delegate
)
21 : oobe_display_(oobe_display
),
23 gaia_screen_(new GaiaScreen()) {
24 DCHECK(instance_
== NULL
);
27 gaia_screen_
->SetScreenHandler(oobe_display_
->GetGaiaScreenActor());
28 std::string display_type
= static_cast<OobeUI
*>(oobe_display
)->display_type();
29 user_selection_screen_
.reset(new ChromeUserSelectionScreen(display_type
));
30 user_selection_screen_
->SetLoginDisplayDelegate(login_display_delegate
);
32 UserBoardView
* user_board_view
= oobe_display_
->GetUserBoardScreenActor();
33 user_selection_screen_
->SetView(user_board_view
);
34 user_board_view
->Bind(*user_selection_screen_
.get());
36 registrar_
.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
37 content::NotificationService::AllSources());
38 registrar_
.Add(this, chrome::NOTIFICATION_SESSION_STARTED
,
39 content::NotificationService::AllSources());
42 SignInScreenController::~SignInScreenController() {
46 void SignInScreenController::Init(const user_manager::UserList
& users
,
48 // TODO(antrim) : This dependency should be inverted, screen should ask about
50 user_selection_screen_
->Init(users
, show_guest
);
53 void SignInScreenController::OnSigninScreenReady() {
54 gaia_screen_
->MaybePreloadAuthExtension();
55 user_selection_screen_
->InitEasyUnlock();
56 if (ScreenLocker::default_screen_locker()) {
57 ScreenLocker::default_screen_locker()->delegate()->OnLockWebUIReady();
61 void SignInScreenController::RemoveUser(const std::string
& user_id
) {
62 user_manager::UserManager::Get()->RemoveUser(user_id
, this);
65 void SignInScreenController::OnBeforeUserRemoved(const std::string
& username
) {
66 user_selection_screen_
->OnBeforeUserRemoved(username
);
69 void SignInScreenController::OnUserRemoved(const std::string
& username
) {
70 user_selection_screen_
->OnUserRemoved(username
);
73 void SignInScreenController::SendUserList() {
74 user_selection_screen_
->HandleGetUsers();
77 const user_manager::UserList
& SignInScreenController::GetUsers() {
78 return user_selection_screen_
->GetUsers();
81 void SignInScreenController::CheckUserStatus(const std::string
& user_id
) {
82 user_selection_screen_
->CheckUserStatus(user_id
);
85 void SignInScreenController::SetWebUIHandler(
86 LoginDisplayWebUIHandler
* webui_handler
) {
87 webui_handler_
= webui_handler
;
88 gaia_screen_
->SetLegacyHandler(webui_handler_
);
89 user_selection_screen_
->SetHandler(webui_handler_
);
92 void SignInScreenController::Observe(
94 const content::NotificationSource
& source
,
95 const content::NotificationDetails
& details
) {
96 if (type
== chrome::NOTIFICATION_SESSION_STARTED
) {
97 // Stop listening to any notification once session has started.
98 // Sign in screen objects are marked for deletion with DeleteSoon so
99 // make sure no object would be used after session has started.
100 // http://crbug.com/125276
101 registrar_
.RemoveAll();
103 } else if (type
== chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
) {
104 user_selection_screen_
->OnUserImageChanged(
105 *content::Details
<user_manager::User
>(details
).ptr());
110 } // namespace chromeos