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

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

Issue 1801133002: Restructure login (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 months 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
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 "base/guid.h"
8 #include "base/macros.h" 7 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 8 #include "mash/login/ui.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "mojo/public/cpp/bindings/strong_binding.h"
11 #include "components/mus/public/cpp/property_type_converters.h"
12 #include "mash/wm/public/interfaces/container.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h"
14 #include "mojo/shell/public/cpp/connector.h" 10 #include "mojo/shell/public/cpp/connector.h"
15 #include "ui/views/background.h"
16 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/mus/aura_init.h" 11 #include "ui/views/mus/aura_init.h"
18 #include "ui/views/mus/native_widget_mus.h"
19 #include "ui/views/mus/window_manager_connection.h" 12 #include "ui/views/mus/window_manager_connection.h"
20 #include "ui/views/widget/widget_delegate.h"
21 13
22 namespace mash { 14 namespace mash {
23 namespace login { 15 namespace login {
24 namespace { 16 namespace {
25 17
26 class LoginView : public views::WidgetDelegateView, 18 class Login : public mojom::Login {
27 public views::ButtonListener {
28 public: 19 public:
29 explicit LoginView(Login* login) 20 Login(mojo::Connector* connector,
30 : login_(login), 21 LoginController* controller,
31 user_id_1_(base::GenerateGUID()), 22 const std::string& user_id,
32 user_id_2_(base::GenerateGUID()), 23 mojom::LoginRequest request)
33 login_button_1_( 24 : connector_(connector),
34 new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), 25 controller_(controller),
35 login_button_2_( 26 user_id_(user_id),
36 new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { 27 binding_(this, std::move(request)) {}
37 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); 28 ~Login() override {}
38 login_button_1_->SetStyle(views::Button::STYLE_BUTTON);
39 login_button_2_->SetStyle(views::Button::STYLE_BUTTON);
40 AddChildView(login_button_1_);
41 AddChildView(login_button_2_);
42 }
43 ~LoginView() override {}
44 29
45 private: 30 private:
46 // Overridden from views::WidgetDelegate: 31 // mojom::Login:
47 views::View* GetContentsView() override { return this; } 32 void ShowLoginUI() override {
48 base::string16 GetWindowTitle() const override { 33 UI::Show(connector_, controller_);
49 // TODO(beng): use resources. 34 }
50 return base::ASCIIToUTF16("Login"); 35 void Logout() override {
36 controller_->init()->StopServicesForUser(user_id_);
37 UI::Show(connector_, controller_);
38 }
39 void SwitchUser() override {
40 UI::Show(connector_, controller_);
51 } 41 }
52 42
53 // Overridden from views::View: 43 mojo::Connector* connector_;
54 void Layout() override { 44 LoginController* controller_;
55 gfx::Rect button_box = GetLocalBounds(); 45 const std::string user_id_;
56 button_box.Inset(10, 10); 46 mojo::StrongBinding<mojom::Login> binding_;
57 47
58 gfx::Size ps1 = login_button_1_->GetPreferredSize(); 48 DISALLOW_COPY_AND_ASSIGN(Login);
59 gfx::Size ps2 = login_button_2_->GetPreferredSize();
60
61 DCHECK(ps1.height() == ps2.height());
62
63 // The 10 is inter-button spacing.
64 button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2);
65 button_box.set_y((button_box.height() - ps1.height()) / 2);
66
67 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(),
68 ps1.height());
69 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10,
70 button_box.y(), ps2.width(), ps2.height());
71 }
72
73 // Overridden from views::ButtonListener:
74 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
75 // Login...
76 mojo::Connector::ConnectParams params("mojo:mash_shell");
77 if (sender == login_button_1_) {
78 login_->login()->LoginAs(user_id_1_);
79 } else if (sender == login_button_2_) {
80 login_->login()->LoginAs(user_id_2_);
81 } else {
82 NOTREACHED();
83 }
84 base::MessageLoop::current()->QuitWhenIdle();
85 }
86
87 Login* login_;
88 const std::string user_id_1_;
89 const std::string user_id_2_;
90 views::LabelButton* login_button_1_;
91 views::LabelButton* login_button_2_;
92
93 DISALLOW_COPY_AND_ASSIGN(LoginView);
94 }; 49 };
95 50
96 } // namespace 51 } // namespace
97 52
98 Login::Login() {} 53 LoginController::LoginController() {}
99 Login::~Login() {} 54 LoginController::~LoginController() {}
100 55
101 void Login::Initialize(mojo::Connector* connector, 56 void LoginController::Initialize(mojo::Connector* connector,
102 const mojo::Identity& identity, 57 const mojo::Identity& identity,
103 uint32_t id) { 58 uint32_t id) {
59 connector_ = connector;
60 login_user_id_ = identity.user_id();
104 tracing_.Initialize(connector, identity.name()); 61 tracing_.Initialize(connector, identity.name());
105 62
106 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); 63 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
107 views::WindowManagerConnection::Create(connector);
108
109 views::Widget* widget = new views::Widget;
110 views::Widget::InitParams params(
111 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
112 params.delegate = new LoginView(this);
113
114 std::map<std::string, std::vector<uint8_t>> properties;
115 properties[mash::wm::mojom::kWindowContainer_Property] =
116 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
117 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
118 mus::Window* window =
119 views::WindowManagerConnection::Get()->NewWindow(properties);
120 params.native_widget = new views::NativeWidgetMus(
121 widget, connector, window, mus::mojom::SurfaceType::DEFAULT);
122 widget->Init(params);
123 widget->Show();
124 } 64 }
125 65
126 bool Login::AcceptConnection(mojo::Connection* connection) { 66 bool LoginController::AcceptConnection(mojo::Connection* connection) {
127 if (connection->GetRemoteIdentity().name() == "mojo:mash_init") { 67 if (connection->GetRemoteIdentity().name() == "mojo:mash_init")
128 connection->GetInterface(&login_); 68 connection->GetInterface(&init_);
129 return true; 69 connection->AddInterface<mojom::Login>(this);
130 } 70 return true;
131 return false; 71 }
72
73 void LoginController::Create(mojo::Connection* connection,
74 mojom::LoginRequest request) {
75 new Login(connector_, this, connection->GetRemoteIdentity().user_id(),
76 std::move(request));
132 } 77 }
133 78
134 } // namespace login 79 } // namespace login
135 } // namespace main 80 } // 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