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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mash/login/login.h ('k') | mash/login/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mash/login/login.cc
diff --git a/mash/login/login.cc b/mash/login/login.cc
index 76048502fe3595221d9448972fd95ca05f8c0e7b..05edab5284e69f5c9c3053e00c51a571cd65d7f5 100644
--- a/mash/login/login.cc
+++ b/mash/login/login.cc
@@ -4,131 +4,76 @@
#include "mash/login/login.h"
-#include "base/guid.h"
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/mus/public/cpp/property_type_converters.h"
-#include "mash/wm/public/interfaces/container.mojom.h"
-#include "mojo/public/cpp/bindings/binding.h"
+#include "mash/login/ui.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/shell/public/cpp/connector.h"
-#include "ui/views/background.h"
-#include "ui/views/controls/button/label_button.h"
#include "ui/views/mus/aura_init.h"
-#include "ui/views/mus/native_widget_mus.h"
#include "ui/views/mus/window_manager_connection.h"
-#include "ui/views/widget/widget_delegate.h"
namespace mash {
namespace login {
namespace {
-class LoginView : public views::WidgetDelegateView,
- public views::ButtonListener {
+class Login : public mojom::Login {
public:
- explicit LoginView(Login* login)
- : login_(login),
- user_id_1_(base::GenerateGUID()),
- user_id_2_(base::GenerateGUID()),
- login_button_1_(
- new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))),
- login_button_2_(
- new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) {
- set_background(views::Background::CreateSolidBackground(SK_ColorRED));
- login_button_1_->SetStyle(views::Button::STYLE_BUTTON);
- login_button_2_->SetStyle(views::Button::STYLE_BUTTON);
- AddChildView(login_button_1_);
- AddChildView(login_button_2_);
- }
- ~LoginView() override {}
+ Login(mojo::Connector* connector,
+ LoginController* controller,
+ const std::string& user_id,
+ mojom::LoginRequest request)
+ : connector_(connector),
+ controller_(controller),
+ user_id_(user_id),
+ binding_(this, std::move(request)) {}
+ ~Login() override {}
private:
- // Overridden from views::WidgetDelegate:
- views::View* GetContentsView() override { return this; }
- base::string16 GetWindowTitle() const override {
- // TODO(beng): use resources.
- return base::ASCIIToUTF16("Login");
+ // mojom::Login:
+ void ShowLoginUI() override {
+ UI::Show(connector_, controller_);
}
-
- // Overridden from views::View:
- void Layout() override {
- gfx::Rect button_box = GetLocalBounds();
- button_box.Inset(10, 10);
-
- gfx::Size ps1 = login_button_1_->GetPreferredSize();
- gfx::Size ps2 = login_button_2_->GetPreferredSize();
-
- DCHECK(ps1.height() == ps2.height());
-
- // The 10 is inter-button spacing.
- button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2);
- button_box.set_y((button_box.height() - ps1.height()) / 2);
-
- login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(),
- ps1.height());
- login_button_2_->SetBounds(login_button_1_->bounds().right() + 10,
- button_box.y(), ps2.width(), ps2.height());
+ void Logout() override {
+ controller_->init()->StopServicesForUser(user_id_);
+ UI::Show(connector_, controller_);
}
-
- // Overridden from views::ButtonListener:
- void ButtonPressed(views::Button* sender, const ui::Event& event) override {
- // Login...
- mojo::Connector::ConnectParams params("mojo:mash_shell");
- if (sender == login_button_1_) {
- login_->login()->LoginAs(user_id_1_);
- } else if (sender == login_button_2_) {
- login_->login()->LoginAs(user_id_2_);
- } else {
- NOTREACHED();
- }
- base::MessageLoop::current()->QuitWhenIdle();
+ void SwitchUser() override {
+ UI::Show(connector_, controller_);
}
- Login* login_;
- const std::string user_id_1_;
- const std::string user_id_2_;
- views::LabelButton* login_button_1_;
- views::LabelButton* login_button_2_;
+ mojo::Connector* connector_;
+ LoginController* controller_;
+ const std::string user_id_;
+ mojo::StrongBinding<mojom::Login> binding_;
- DISALLOW_COPY_AND_ASSIGN(LoginView);
+ DISALLOW_COPY_AND_ASSIGN(Login);
};
} // namespace
-Login::Login() {}
-Login::~Login() {}
+LoginController::LoginController() {}
+LoginController::~LoginController() {}
-void Login::Initialize(mojo::Connector* connector,
- const mojo::Identity& identity,
- uint32_t id) {
+void LoginController::Initialize(mojo::Connector* connector,
+ const mojo::Identity& identity,
+ uint32_t id) {
+ connector_ = connector;
+ login_user_id_ = identity.user_id();
tracing_.Initialize(connector, identity.name());
aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak"));
- views::WindowManagerConnection::Create(connector);
-
- views::Widget* widget = new views::Widget;
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.delegate = new LoginView(this);
+}
- std::map<std::string, std::vector<uint8_t>> properties;
- properties[mash::wm::mojom::kWindowContainer_Property] =
- mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
- static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
- mus::Window* window =
- views::WindowManagerConnection::Get()->NewWindow(properties);
- params.native_widget = new views::NativeWidgetMus(
- widget, connector, window, mus::mojom::SurfaceType::DEFAULT);
- widget->Init(params);
- widget->Show();
+bool LoginController::AcceptConnection(mojo::Connection* connection) {
+ if (connection->GetRemoteIdentity().name() == "mojo:mash_init")
+ connection->GetInterface(&init_);
+ connection->AddInterface<mojom::Login>(this);
+ return true;
}
-bool Login::AcceptConnection(mojo::Connection* connection) {
- if (connection->GetRemoteIdentity().name() == "mojo:mash_init") {
- connection->GetInterface(&login_);
- return true;
- }
- return false;
+void LoginController::Create(mojo::Connection* connection,
+ mojom::LoginRequest request) {
+ new Login(connector_, this, connection->GetRemoteIdentity().user_id(),
+ std::move(request));
}
} // namespace login
« 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