Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2188)

Side by Side Diff: mash/login/login.cc

Issue 2569953002: Removes example code that isn't correctly wired up (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mash/login/login.h ('k') | mash/login/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mash/login/login.h"
6
7 #include <map>
8 #include <memory>
9
10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "base/guid.h"
12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "mash/common/config.h"
17 #include "mash/init/public/interfaces/constants.mojom.h"
18 #include "mash/init/public/interfaces/init.mojom.h"
19 #include "mash/login/public/interfaces/login.mojom.h"
20 #include "mojo/public/cpp/bindings/binding_set.h"
21 #include "services/service_manager/public/cpp/connector.h"
22 #include "services/service_manager/public/cpp/interface_factory.h"
23 #include "services/service_manager/public/cpp/interface_registry.h"
24 #include "services/service_manager/public/cpp/service.h"
25 #include "services/service_manager/public/cpp/service_context.h"
26 #include "services/tracing/public/cpp/provider.h"
27 #include "services/ui/public/cpp/property_type_converters.h"
28 #include "services/ui/public/interfaces/constants.mojom.h"
29 #include "services/ui/public/interfaces/user_access_manager.mojom.h"
30 #include "services/ui/public/interfaces/window_manager.mojom.h"
31 #include "ui/views/background.h"
32 #include "ui/views/controls/button/md_text_button.h"
33 #include "ui/views/mus/aura_init.h"
34 #include "ui/views/mus/native_widget_mus.h"
35 #include "ui/views/mus/window_manager_connection.h"
36 #include "ui/views/widget/widget_delegate.h"
37
38 namespace mash {
39 namespace login {
40 namespace {
41
42 class Login;
43
44 class UI : public views::WidgetDelegateView,
45 public views::ButtonListener {
46 public:
47 static void Show(service_manager::Connector* connector,
48 const service_manager::Identity& identity,
49 Login* login) {
50 UI* ui = new UI(login, connector);
51 ui->StartWindowManager(identity);
52
53 views::Widget* widget = new views::Widget;
54 views::Widget::InitParams params(
55 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
56 params.delegate = ui;
57
58 std::map<std::string, std::vector<uint8_t>> properties;
59 properties[ui::mojom::WindowManager::kContainerId_InitProperty] =
60 mojo::ConvertTo<std::vector<uint8_t>>(
61 ash::kShellWindowId_LockScreenContainer);
62 ui::Window* window =
63 views::WindowManagerConnection::Get()->NewTopLevelWindow(properties);
64 params.native_widget = new views::NativeWidgetMus(
65 widget, window, ui::mojom::CompositorFrameSinkType::DEFAULT);
66 widget->Init(params);
67 widget->Show();
68 }
69
70 private:
71 UI(Login* login, service_manager::Connector* connector)
72 : login_(login),
73 connector_(connector),
74 user_id_1_("00000000-0000-4000-8000-000000000000"),
75 user_id_2_("00000000-0000-4000-8000-000000000001"),
76 login_button_1_(
77 views::MdTextButton::Create(this, base::ASCIIToUTF16("Timothy"))),
78 login_button_2_(
79 views::MdTextButton::Create(this, base::ASCIIToUTF16("Jimothy"))) {
80 set_background(views::Background::CreateSolidBackground(SK_ColorRED));
81 AddChildView(login_button_1_);
82 AddChildView(login_button_2_);
83 }
84 ~UI() override {
85 // Prevent the window manager from restarting during graceful shutdown.
86 mash_wm_connection_->SetConnectionLostClosure(base::Closure());
87 base::MessageLoop::current()->QuitWhenIdle();
88 }
89
90 // Overridden from views::WidgetDelegate:
91 base::string16 GetWindowTitle() const override {
92 // TODO(beng): use resources.
93 return base::ASCIIToUTF16("Login");
94 }
95 void DeleteDelegate() override { delete this; }
96
97 // Overridden from views::View:
98 void Layout() override {
99 gfx::Rect button_box = GetLocalBounds();
100 button_box.Inset(10, 10);
101
102 gfx::Size ps1 = login_button_1_->GetPreferredSize();
103 gfx::Size ps2 = login_button_2_->GetPreferredSize();
104
105 DCHECK(ps1.height() == ps2.height());
106
107 // The 10 is inter-button spacing.
108 button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2);
109 button_box.set_y((button_box.height() - ps1.height()) / 2);
110
111 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(),
112 ps1.height());
113 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10,
114 button_box.y(), ps2.width(), ps2.height());
115 }
116
117 // Overridden from views::ButtonListener:
118 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
119
120 void StartWindowManager(const service_manager::Identity& identity) {
121 mash_wm_connection_ =
122 connector_->Connect(common::GetWindowManagerServiceName());
123 mash_wm_connection_->SetConnectionLostClosure(
124 base::Bind(&UI::StartWindowManager, base::Unretained(this), identity));
125 window_manager_connection_ =
126 views::WindowManagerConnection::Create(connector_, identity);
127 }
128
129 Login* login_;
130 service_manager::Connector* connector_;
131 const std::string user_id_1_;
132 const std::string user_id_2_;
133 views::MdTextButton* login_button_1_;
134 views::MdTextButton* login_button_2_;
135 std::unique_ptr<service_manager::Connection> mash_wm_connection_;
136 std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;
137
138 DISALLOW_COPY_AND_ASSIGN(UI);
139 };
140
141 class Login : public service_manager::Service,
142 public service_manager::InterfaceFactory<mojom::Login>,
143 public mojom::Login {
144 public:
145 Login() {}
146 ~Login() override {}
147
148 void LoginAs(const std::string& user_id) {
149 user_access_manager_->SetActiveUser(user_id);
150 mash::init::mojom::InitPtr init;
151 context()->connector()->ConnectToInterface(init::mojom::kServiceName,
152 &init);
153 init->StartService("mash_session", user_id);
154 }
155
156 private:
157 // service_manager::Service:
158 void OnStart() override {
159 tracing_.Initialize(context()->connector(), context()->identity().name());
160
161 aura_init_ = base::MakeUnique<views::AuraInit>(
162 context()->connector(), context()->identity(),
163 "views_mus_resources.pak");
164
165 context()->connector()->ConnectToInterface(ui::mojom::kServiceName,
166 &user_access_manager_);
167 user_access_manager_->SetActiveUser(context()->identity().user_id());
168 }
169
170 bool OnConnect(const service_manager::ServiceInfo& remote_info,
171 service_manager::InterfaceRegistry* registry) override {
172 registry->AddInterface<mojom::Login>(this);
173 return true;
174 }
175
176 // service_manager::InterfaceFactory<mojom::Login>:
177 void Create(const service_manager::Identity& remote_identity,
178 mojom::LoginRequest request) override {
179 bindings_.AddBinding(this, std::move(request));
180 }
181
182 // mojom::Login:
183 void ShowLoginUI() override {
184 UI::Show(context()->connector(), context()->identity(), this);
185 }
186 void SwitchUser() override {
187 UI::Show(context()->connector(), context()->identity(), this);
188 }
189
190 void StartWindowManager();
191
192 tracing::Provider tracing_;
193 std::unique_ptr<views::AuraInit> aura_init_;
194 mojo::BindingSet<mojom::Login> bindings_;
195 ui::mojom::UserAccessManagerPtr user_access_manager_;
196
197 DISALLOW_COPY_AND_ASSIGN(Login);
198 };
199
200 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) {
201 // Login...
202 if (sender == login_button_1_) {
203 login_->LoginAs(user_id_1_);
204 } else if (sender == login_button_2_) {
205 login_->LoginAs(user_id_2_);
206 } else {
207 NOTREACHED();
208 }
209 GetWidget()->Close();
210 }
211
212 } // namespace
213
214 service_manager::Service* CreateLogin() {
215 return new Login;
216 }
217
218 } // namespace login
219 } // namespace main
OLDNEW
« no previous file with comments | « mash/login/login.h ('k') | mash/login/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698