| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/login/login.h" | 5 #include "mash/login/login.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/public/interfaces/container.mojom.h" | 10 #include "ash/public/interfaces/container.mojom.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace mash { | 30 namespace mash { |
| 31 namespace login { | 31 namespace login { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 class Login; | 34 class Login; |
| 35 | 35 |
| 36 class UI : public views::WidgetDelegateView, | 36 class UI : public views::WidgetDelegateView, |
| 37 public views::ButtonListener { | 37 public views::ButtonListener { |
| 38 public: | 38 public: |
| 39 static void Show(shell::Connector* connector, | 39 static void Show(service_manager::Connector* connector, |
| 40 const shell::Identity& identity, | 40 const service_manager::Identity& identity, |
| 41 Login* login) { | 41 Login* login) { |
| 42 UI* ui = new UI(login, connector); | 42 UI* ui = new UI(login, connector); |
| 43 ui->StartWindowManager(identity); | 43 ui->StartWindowManager(identity); |
| 44 | 44 |
| 45 views::Widget* widget = new views::Widget; | 45 views::Widget* widget = new views::Widget; |
| 46 views::Widget::InitParams params( | 46 views::Widget::InitParams params( |
| 47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 48 params.delegate = ui; | 48 params.delegate = ui; |
| 49 | 49 |
| 50 std::map<std::string, std::vector<uint8_t>> properties; | 50 std::map<std::string, std::vector<uint8_t>> properties; |
| 51 properties[ash::mojom::kWindowContainer_Property] = | 51 properties[ash::mojom::kWindowContainer_Property] = |
| 52 mojo::ConvertTo<std::vector<uint8_t>>( | 52 mojo::ConvertTo<std::vector<uint8_t>>( |
| 53 static_cast<int32_t>(ash::mojom::Container::LOGIN_WINDOWS)); | 53 static_cast<int32_t>(ash::mojom::Container::LOGIN_WINDOWS)); |
| 54 ui::Window* window = | 54 ui::Window* window = |
| 55 views::WindowManagerConnection::Get()->NewTopLevelWindow(properties); | 55 views::WindowManagerConnection::Get()->NewTopLevelWindow(properties); |
| 56 params.native_widget = new views::NativeWidgetMus( | 56 params.native_widget = new views::NativeWidgetMus( |
| 57 widget, window, ui::mojom::SurfaceType::DEFAULT); | 57 widget, window, ui::mojom::SurfaceType::DEFAULT); |
| 58 widget->Init(params); | 58 widget->Init(params); |
| 59 widget->Show(); | 59 widget->Show(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 UI(Login* login, shell::Connector* connector) | 63 UI(Login* login, service_manager::Connector* connector) |
| 64 : login_(login), | 64 : login_(login), |
| 65 connector_(connector), | 65 connector_(connector), |
| 66 user_id_1_("00000000-0000-4000-8000-000000000000"), | 66 user_id_1_("00000000-0000-4000-8000-000000000000"), |
| 67 user_id_2_("00000000-0000-4000-8000-000000000001"), | 67 user_id_2_("00000000-0000-4000-8000-000000000001"), |
| 68 login_button_1_( | 68 login_button_1_( |
| 69 views::MdTextButton::Create(this, base::ASCIIToUTF16("Timothy"))), | 69 views::MdTextButton::Create(this, base::ASCIIToUTF16("Timothy"))), |
| 70 login_button_2_( | 70 login_button_2_( |
| 71 views::MdTextButton::Create(this, base::ASCIIToUTF16("Jimothy"))) { | 71 views::MdTextButton::Create(this, base::ASCIIToUTF16("Jimothy"))) { |
| 72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); | 72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); |
| 73 AddChildView(login_button_1_); | 73 AddChildView(login_button_1_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 102 | 102 |
| 103 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(), | 103 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(), |
| 104 ps1.height()); | 104 ps1.height()); |
| 105 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10, | 105 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10, |
| 106 button_box.y(), ps2.width(), ps2.height()); | 106 button_box.y(), ps2.width(), ps2.height()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Overridden from views::ButtonListener: | 109 // Overridden from views::ButtonListener: |
| 110 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 110 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 111 | 111 |
| 112 void StartWindowManager(const shell::Identity& identity) { | 112 void StartWindowManager(const service_manager::Identity& identity) { |
| 113 mash_wm_connection_ = connector_->Connect("service:ash"); | 113 mash_wm_connection_ = connector_->Connect("service:ash"); |
| 114 mash_wm_connection_->SetConnectionLostClosure( | 114 mash_wm_connection_->SetConnectionLostClosure( |
| 115 base::Bind(&UI::StartWindowManager, base::Unretained(this), identity)); | 115 base::Bind(&UI::StartWindowManager, base::Unretained(this), identity)); |
| 116 window_manager_connection_ = | 116 window_manager_connection_ = |
| 117 views::WindowManagerConnection::Create(connector_, identity); | 117 views::WindowManagerConnection::Create(connector_, identity); |
| 118 } | 118 } |
| 119 | 119 |
| 120 Login* login_; | 120 Login* login_; |
| 121 shell::Connector* connector_; | 121 service_manager::Connector* connector_; |
| 122 const std::string user_id_1_; | 122 const std::string user_id_1_; |
| 123 const std::string user_id_2_; | 123 const std::string user_id_2_; |
| 124 views::MdTextButton* login_button_1_; | 124 views::MdTextButton* login_button_1_; |
| 125 views::MdTextButton* login_button_2_; | 125 views::MdTextButton* login_button_2_; |
| 126 std::unique_ptr<shell::Connection> mash_wm_connection_; | 126 std::unique_ptr<service_manager::Connection> mash_wm_connection_; |
| 127 std::unique_ptr<views::WindowManagerConnection> window_manager_connection_; | 127 std::unique_ptr<views::WindowManagerConnection> window_manager_connection_; |
| 128 | 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(UI); | 129 DISALLOW_COPY_AND_ASSIGN(UI); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 class Login : public shell::Service, | 132 class Login : public service_manager::Service, |
| 133 public shell::InterfaceFactory<mojom::Login>, | 133 public service_manager::InterfaceFactory<mojom::Login>, |
| 134 public mojom::Login { | 134 public mojom::Login { |
| 135 public: | 135 public: |
| 136 Login() {} | 136 Login() {} |
| 137 ~Login() override {} | 137 ~Login() override {} |
| 138 | 138 |
| 139 void LoginAs(const std::string& user_id) { | 139 void LoginAs(const std::string& user_id) { |
| 140 user_access_manager_->SetActiveUser(user_id); | 140 user_access_manager_->SetActiveUser(user_id); |
| 141 mash::init::mojom::InitPtr init; | 141 mash::init::mojom::InitPtr init; |
| 142 connector()->ConnectToInterface("service:mash_init", &init); | 142 connector()->ConnectToInterface("service:mash_init", &init); |
| 143 init->StartService("service:mash_session", user_id); | 143 init->StartService("service:mash_session", user_id); |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 // shell::Service: | 147 // service_manager::Service: |
| 148 void OnStart(const shell::Identity& identity) override { | 148 void OnStart(const service_manager::Identity& identity) override { |
| 149 identity_ = identity; | 149 identity_ = identity; |
| 150 tracing_.Initialize(connector(), identity.name()); | 150 tracing_.Initialize(connector(), identity.name()); |
| 151 | 151 |
| 152 aura_init_.reset( | 152 aura_init_.reset( |
| 153 new views::AuraInit(connector(), "views_mus_resources.pak")); | 153 new views::AuraInit(connector(), "views_mus_resources.pak")); |
| 154 | 154 |
| 155 connector()->ConnectToInterface("service:ui", &user_access_manager_); | 155 connector()->ConnectToInterface("service:ui", &user_access_manager_); |
| 156 user_access_manager_->SetActiveUser(identity.user_id()); | 156 user_access_manager_->SetActiveUser(identity.user_id()); |
| 157 } | 157 } |
| 158 bool OnConnect(const shell::Identity& remote_identity, | 158 bool OnConnect(const service_manager::Identity& remote_identity, |
| 159 shell::InterfaceRegistry* registry) override { | 159 service_manager::InterfaceRegistry* registry) override { |
| 160 registry->AddInterface<mojom::Login>(this); | 160 registry->AddInterface<mojom::Login>(this); |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // shell::InterfaceFactory<mojom::Login>: | 164 // service_manager::InterfaceFactory<mojom::Login>: |
| 165 void Create(const shell::Identity& remote_identity, | 165 void Create(const service_manager::Identity& remote_identity, |
| 166 mojom::LoginRequest request) override { | 166 mojom::LoginRequest request) override { |
| 167 bindings_.AddBinding(this, std::move(request)); | 167 bindings_.AddBinding(this, std::move(request)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // mojom::Login: | 170 // mojom::Login: |
| 171 void ShowLoginUI() override { | 171 void ShowLoginUI() override { |
| 172 UI::Show(connector(), identity_, this); | 172 UI::Show(connector(), identity_, this); |
| 173 } | 173 } |
| 174 void SwitchUser() override { | 174 void SwitchUser() override { |
| 175 UI::Show(connector(), identity_, this); | 175 UI::Show(connector(), identity_, this); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void StartWindowManager(); | 178 void StartWindowManager(); |
| 179 | 179 |
| 180 shell::Identity identity_; | 180 service_manager::Identity identity_; |
| 181 tracing::Provider tracing_; | 181 tracing::Provider tracing_; |
| 182 std::unique_ptr<views::AuraInit> aura_init_; | 182 std::unique_ptr<views::AuraInit> aura_init_; |
| 183 mojo::BindingSet<mojom::Login> bindings_; | 183 mojo::BindingSet<mojom::Login> bindings_; |
| 184 ui::mojom::UserAccessManagerPtr user_access_manager_; | 184 ui::mojom::UserAccessManagerPtr user_access_manager_; |
| 185 | 185 |
| 186 DISALLOW_COPY_AND_ASSIGN(Login); | 186 DISALLOW_COPY_AND_ASSIGN(Login); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { | 189 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 190 // Login... | 190 // Login... |
| 191 if (sender == login_button_1_) { | 191 if (sender == login_button_1_) { |
| 192 login_->LoginAs(user_id_1_); | 192 login_->LoginAs(user_id_1_); |
| 193 } else if (sender == login_button_2_) { | 193 } else if (sender == login_button_2_) { |
| 194 login_->LoginAs(user_id_2_); | 194 login_->LoginAs(user_id_2_); |
| 195 } else { | 195 } else { |
| 196 NOTREACHED(); | 196 NOTREACHED(); |
| 197 } | 197 } |
| 198 GetWidget()->Close(); | 198 GetWidget()->Close(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace | 201 } // namespace |
| 202 | 202 |
| 203 shell::Service* CreateLogin() { | 203 service_manager::Service* CreateLogin() { |
| 204 return new Login; | 204 return new Login; |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace login | 207 } // namespace login |
| 208 } // namespace main | 208 } // namespace main |
| OLD | NEW |