| 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 "base/guid.h" | 10 #include "base/guid.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(mojo::Connector* connector, Login* login) { | 39 static void Show(shell::Connector* connector, Login* login) { |
| 40 UI* ui = new UI(login, connector); | 40 UI* ui = new UI(login, connector); |
| 41 ui->StartWindowManager(); | 41 ui->StartWindowManager(); |
| 42 | 42 |
| 43 views::WindowManagerConnection::Create(connector); | 43 views::WindowManagerConnection::Create(connector); |
| 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[mash::wm::mojom::kWindowContainer_Property] = | 51 properties[mash::wm::mojom::kWindowContainer_Property] = |
| 52 mojo::ConvertTo<std::vector<uint8_t>>( | 52 mojo::ConvertTo<std::vector<uint8_t>>( |
| 53 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS)); | 53 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS)); |
| 54 mus::Window* window = | 54 mus::Window* window = |
| 55 views::WindowManagerConnection::Get()->NewWindow(properties); | 55 views::WindowManagerConnection::Get()->NewWindow(properties); |
| 56 params.native_widget = new views::NativeWidgetMus( | 56 params.native_widget = new views::NativeWidgetMus( |
| 57 widget, connector, window, mus::mojom::SurfaceType::DEFAULT); | 57 widget, connector, window, mus::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, mojo::Connector* connector) | 63 UI(Login* login, shell::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 new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), | 69 new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), |
| 70 login_button_2_( | 70 login_button_2_( |
| 71 new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { | 71 new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { |
| 72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); | 72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); |
| 73 login_button_1_->SetStyle(views::Button::STYLE_BUTTON); | 73 login_button_1_->SetStyle(views::Button::STYLE_BUTTON); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Overridden from views::ButtonListener: | 112 // Overridden from views::ButtonListener: |
| 113 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 113 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 114 | 114 |
| 115 void StartWindowManager() { | 115 void StartWindowManager() { |
| 116 window_manager_connection_ = connector_->Connect("mojo:desktop_wm"); | 116 window_manager_connection_ = connector_->Connect("mojo:desktop_wm"); |
| 117 window_manager_connection_->SetConnectionLostClosure( | 117 window_manager_connection_->SetConnectionLostClosure( |
| 118 base::Bind(&UI::StartWindowManager, base::Unretained(this))); | 118 base::Bind(&UI::StartWindowManager, base::Unretained(this))); |
| 119 } | 119 } |
| 120 | 120 |
| 121 Login* login_; | 121 Login* login_; |
| 122 mojo::Connector* connector_; | 122 shell::Connector* connector_; |
| 123 const std::string user_id_1_; | 123 const std::string user_id_1_; |
| 124 const std::string user_id_2_; | 124 const std::string user_id_2_; |
| 125 views::LabelButton* login_button_1_; | 125 views::LabelButton* login_button_1_; |
| 126 views::LabelButton* login_button_2_; | 126 views::LabelButton* login_button_2_; |
| 127 std::unique_ptr<mojo::Connection> window_manager_connection_; | 127 std::unique_ptr<shell::Connection> 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 mojo::ShellClient, | 132 class Login : public shell::ShellClient, |
| 133 public mojo::InterfaceFactory<mojom::Login>, | 133 public shell::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("mojo:mash_init", &init); | 142 connector_->ConnectToInterface("mojo:mash_init", &init); |
| 143 init->StartService("mojo:mash_session", user_id); | 143 init->StartService("mojo:mash_session", user_id); |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 // mojo::ShellClient: | 147 // shell::ShellClient: |
| 148 void Initialize(mojo::Connector* connector, const mojo::Identity& identity, | 148 void Initialize(shell::Connector* connector, |
| 149 const shell::Identity& identity, |
| 149 uint32_t id) override { | 150 uint32_t id) override { |
| 150 connector_ = connector; | 151 connector_ = connector; |
| 151 tracing_.Initialize(connector, identity.name()); | 152 tracing_.Initialize(connector, identity.name()); |
| 152 | 153 |
| 153 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); | 154 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 154 | 155 |
| 155 connector_->ConnectToInterface("mojo:mus", &user_access_manager_); | 156 connector_->ConnectToInterface("mojo:mus", &user_access_manager_); |
| 156 user_access_manager_->SetActiveUser(identity.user_id()); | 157 user_access_manager_->SetActiveUser(identity.user_id()); |
| 157 } | 158 } |
| 158 bool AcceptConnection(mojo::Connection* connection) override { | 159 bool AcceptConnection(shell::Connection* connection) override { |
| 159 connection->AddInterface<mojom::Login>(this); | 160 connection->AddInterface<mojom::Login>(this); |
| 160 return true; | 161 return true; |
| 161 } | 162 } |
| 162 | 163 |
| 163 // mojo::InterfaceFactory<mojom::Login>: | 164 // shell::InterfaceFactory<mojom::Login>: |
| 164 void Create(mojo::Connection* connection, | 165 void Create(shell::Connection* connection, |
| 165 mojom::LoginRequest request) override { | 166 mojom::LoginRequest request) override { |
| 166 bindings_.AddBinding(this, std::move(request)); | 167 bindings_.AddBinding(this, std::move(request)); |
| 167 } | 168 } |
| 168 | 169 |
| 169 // mojom::Login: | 170 // mojom::Login: |
| 170 void ShowLoginUI() override { | 171 void ShowLoginUI() override { |
| 171 UI::Show(connector_, this); | 172 UI::Show(connector_, this); |
| 172 } | 173 } |
| 173 void SwitchUser() override { | 174 void SwitchUser() override { |
| 174 UI::Show(connector_, this); | 175 UI::Show(connector_, this); |
| 175 } | 176 } |
| 176 | 177 |
| 177 void StartWindowManager(); | 178 void StartWindowManager(); |
| 178 | 179 |
| 179 mojo::Connector* connector_; | 180 shell::Connector* connector_; |
| 180 mojo::TracingImpl tracing_; | 181 mojo::TracingImpl tracing_; |
| 181 std::unique_ptr<views::AuraInit> aura_init_; | 182 std::unique_ptr<views::AuraInit> aura_init_; |
| 182 mojo::BindingSet<mojom::Login> bindings_; | 183 mojo::BindingSet<mojom::Login> bindings_; |
| 183 mus::mojom::UserAccessManagerPtr user_access_manager_; | 184 mus::mojom::UserAccessManagerPtr user_access_manager_; |
| 184 std::unique_ptr<mojo::Connection> window_manager_connection_; | 185 std::unique_ptr<shell::Connection> window_manager_connection_; |
| 185 | 186 |
| 186 DISALLOW_COPY_AND_ASSIGN(Login); | 187 DISALLOW_COPY_AND_ASSIGN(Login); |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { | 190 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 190 // Login... | 191 // Login... |
| 191 if (sender == login_button_1_) { | 192 if (sender == login_button_1_) { |
| 192 login_->LoginAs(user_id_1_); | 193 login_->LoginAs(user_id_1_); |
| 193 } else if (sender == login_button_2_) { | 194 } else if (sender == login_button_2_) { |
| 194 login_->LoginAs(user_id_2_); | 195 login_->LoginAs(user_id_2_); |
| 195 } else { | 196 } else { |
| 196 NOTREACHED(); | 197 NOTREACHED(); |
| 197 } | 198 } |
| 198 GetWidget()->Close(); | 199 GetWidget()->Close(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 } // namespace | 202 } // namespace |
| 202 | 203 |
| 203 mojo::ShellClient* CreateLogin() { | 204 shell::ShellClient* CreateLogin() { |
| 204 return new Login; | 205 return new Login; |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace login | 208 } // namespace login |
| 208 } // namespace main | 209 } // namespace main |
| OLD | NEW |