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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
8 #include "ash/system/tray/system_tray.h"
10 #include "base/memory/singleton.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
15 #include "chrome/browser/chromeos/login/ui/user_adding_screen_input_methods_controller.h"
16 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
17 #include "components/session_manager/core/session_manager.h"
18 #include "components/user_manager/user_manager.h"
19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gfx/geometry/size.h"
26 class UserAddingScreenImpl
: public UserAddingScreen
{
28 void Start() override
;
29 void Cancel() override
;
30 bool IsRunning() override
;
32 void AddObserver(Observer
* observer
) override
;
33 void RemoveObserver(Observer
* observer
) override
;
35 static UserAddingScreenImpl
* GetInstance();
37 friend struct base::DefaultSingletonTraits
<UserAddingScreenImpl
>;
39 void OnDisplayHostCompletion();
41 UserAddingScreenImpl();
42 ~UserAddingScreenImpl() override
;
44 base::ObserverList
<Observer
> observers_
;
45 LoginDisplayHost
* display_host_
;
47 UserAddingScreenInputMethodsController im_controller_
;
50 void UserAddingScreenImpl::Start() {
52 gfx::Rect
screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
53 display_host_
= new chromeos::LoginDisplayHostImpl(screen_bounds
);
54 display_host_
->StartUserAdding(
55 base::Bind(&UserAddingScreenImpl::OnDisplayHostCompletion
,
56 base::Unretained(this)));
58 g_browser_process
->platform_part()->SessionManager()->SetSessionState(
59 session_manager::SESSION_STATE_LOGIN_SECONDARY
);
60 FOR_EACH_OBSERVER(Observer
, observers_
, OnUserAddingStarted());
63 void UserAddingScreenImpl::Cancel() {
66 // Make sure that system tray is enabled after this flow.
67 ash::Shell::GetInstance()->GetPrimarySystemTray()->SetEnabled(true);
68 display_host_
->Finalize();
70 // Reset wallpaper if cancel adding user from multiple user sign in page.
71 if (user_manager::UserManager::Get()->IsUserLoggedIn()) {
72 WallpaperManager::Get()->SetUserWallpaperDelayed(
73 user_manager::UserManager::Get()->GetActiveUser()->email());
77 bool UserAddingScreenImpl::IsRunning() {
78 return display_host_
!= NULL
;
81 void UserAddingScreenImpl::AddObserver(Observer
* observer
) {
82 observers_
.AddObserver(observer
);
85 void UserAddingScreenImpl::RemoveObserver(Observer
* observer
) {
86 observers_
.RemoveObserver(observer
);
89 void UserAddingScreenImpl::OnDisplayHostCompletion() {
93 g_browser_process
->platform_part()->SessionManager()->SetSessionState(
94 session_manager::SESSION_STATE_ACTIVE
);
95 FOR_EACH_OBSERVER(Observer
, observers_
, OnUserAddingFinished());
99 UserAddingScreenImpl
* UserAddingScreenImpl::GetInstance() {
100 return base::Singleton
<UserAddingScreenImpl
>::get();
103 UserAddingScreenImpl::UserAddingScreenImpl()
104 : display_host_(NULL
), im_controller_(this) {
107 UserAddingScreenImpl::~UserAddingScreenImpl() {
110 } // anonymous namespace
112 UserAddingScreen::UserAddingScreen() {}
113 UserAddingScreen::~UserAddingScreen() {}
115 UserAddingScreen
* UserAddingScreen::Get() {
116 return UserAddingScreenImpl::GetInstance();
119 } // namespace chromeos