diff options
-rw-r--r-- | mash/init/init.cc | 7 | ||||
-rw-r--r-- | mash/init/init.h | 1 | ||||
-rw-r--r-- | mash/init/manifest.json | 2 | ||||
-rw-r--r-- | mash/login/BUILD.gn | 2 | ||||
-rw-r--r-- | mash/login/login.cc | 209 | ||||
-rw-r--r-- | mash/login/login.h | 41 | ||||
-rw-r--r-- | mash/login/main.cc | 2 | ||||
-rw-r--r-- | mash/login/ui.cc | 136 | ||||
-rw-r--r-- | mash/login/ui.h | 69 | ||||
-rw-r--r-- | mojo/shell/runner/host/child_process_host.cc | 7 | ||||
-rw-r--r-- | mojo/shell/runner/host/child_process_host.h | 2 | ||||
-rw-r--r-- | mojo/shell/runner/host/child_process_host_unittest.cc | 2 | ||||
-rw-r--r-- | mojo/shell/runner/host/out_of_process_native_runner.cc | 2 | ||||
-rw-r--r-- | ui/views/mus/screen_mus.cc | 2 |
14 files changed, 191 insertions, 293 deletions
diff --git a/mash/init/init.cc b/mash/init/init.cc index aab8448..118482a 100644 --- a/mash/init/init.cc +++ b/mash/init/init.cc @@ -28,6 +28,11 @@ void Init::Initialize(mojo::Connector* connector, StartLogin(); } +bool Init::AcceptConnection(mojo::Connection* connection) { + connection->AddInterface<mojom::Init>(this); + return true; +} + void Init::StartService(const mojo::String& name, const mojo::String& user_id) { if (user_services_.find(user_id) == user_services_.end()) { @@ -66,8 +71,6 @@ void Init::StartResourceProvider() { void Init::StartLogin() { login_connection_ = connector_->Connect("mojo:login"); login_connection_->AddInterface<mojom::Init>(this); - login_connection_->SetConnectionLostClosure( - base::Bind(&Init::StartLogin, base::Unretained(this))); mash::login::mojom::LoginPtr login; login_connection_->GetInterface(&login); login->ShowLoginUI(); diff --git a/mash/init/init.h b/mash/init/init.h index 452b089..7f27a6d 100644 --- a/mash/init/init.h +++ b/mash/init/init.h @@ -33,6 +33,7 @@ class Init : public mojo::ShellClient, // mojo::ShellClient: void Initialize(mojo::Connector* connector, const mojo::Identity& identity, uint32_t id) override; + bool AcceptConnection(mojo::Connection* connection) override; // mojo::InterfaceFactory<mojom::Login>: void Create(mojo::Connection* connection, diff --git a/mash/init/manifest.json b/mash/init/manifest.json index c407094..70c79e2 100644 --- a/mash/init/manifest.json +++ b/mash/init/manifest.json @@ -5,7 +5,7 @@ "capabilities": { "required": { "*": { "interfaces": [ "*" ] }, - "mojo:shell": { "classes": ["user_id"] } + "mojo:shell": { "classes": ["user_id", "all_users"] } } } } diff --git a/mash/login/BUILD.gn b/mash/login/BUILD.gn index bf0bbb9..a9d7f98 100644 --- a/mash/login/BUILD.gn +++ b/mash/login/BUILD.gn @@ -13,8 +13,6 @@ mojo_native_application("login") { "login.cc", "login.h", "main.cc", - "ui.cc", - "ui.h", ] deps = [ diff --git a/mash/login/login.cc b/mash/login/login.cc index 1ae4e77..e5c566b 100644 --- a/mash/login/login.cc +++ b/mash/login/login.cc @@ -4,72 +4,203 @@ #include "mash/login/login.h" +#include <map> + +#include "base/guid.h" #include "base/macros.h" -#include "mash/login/ui.h" -#include "mojo/public/cpp/bindings/strong_binding.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 "components/mus/public/interfaces/user_access_manager.mojom.h" +#include "mash/init/public/interfaces/init.mojom.h" +#include "mash/login/public/interfaces/login.mojom.h" +#include "mash/wm/public/interfaces/container.mojom.h" +#include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/services/tracing/public/cpp/tracing_impl.h" #include "mojo/shell/public/cpp/connector.h" +#include "mojo/shell/public/cpp/shell_client.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 Login : public mojom::Login { +class Login; + +class UI : public views::WidgetDelegateView, + public views::ButtonListener { + public: + static void Show(mojo::Connector* connector, Login* login) { + UI* ui = new UI(login, connector); + ui->StartWindowManager(); + + views::WindowManagerConnection::Create(connector); + + views::Widget* widget = new views::Widget; + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.delegate = ui; + + 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(); + } + + private: + UI(Login* login, mojo::Connector* connector) + : login_(login), + connector_(connector), + user_id_1_("00000000-0000-4000-8000-000000000000"), + user_id_2_("00000000-0000-4000-8000-000000000001"), + 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_); + } + ~UI() override { + // Prevent the window manager from restarting during graceful shutdown. + window_manager_connection_->SetConnectionLostClosure(base::Closure()); + base::MessageLoop::current()->QuitWhenIdle(); + } + + // Overridden from views::WidgetDelegate: + views::View* GetContentsView() override { return this; } + base::string16 GetWindowTitle() const override { + // TODO(beng): use resources. + return base::ASCIIToUTF16("Login"); + } + void DeleteDelegate() override { delete this; } + + // 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()); + } + + // Overridden from views::ButtonListener: + void ButtonPressed(views::Button* sender, const ui::Event& event) override; + + void StartWindowManager() { + window_manager_connection_ = connector_->Connect("mojo:desktop_wm"); + window_manager_connection_->SetConnectionLostClosure( + base::Bind(&UI::StartWindowManager, base::Unretained(this))); + } + + Login* login_; + mojo::Connector* connector_; + const std::string user_id_1_; + const std::string user_id_2_; + views::LabelButton* login_button_1_; + views::LabelButton* login_button_2_; + scoped_ptr<mojo::Connection> window_manager_connection_; + + DISALLOW_COPY_AND_ASSIGN(UI); +}; + +class Login : public mojo::ShellClient, + public mojo::InterfaceFactory<mojom::Login>, + public mojom::Login { public: - 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() {} ~Login() override {} + void LoginAs(const std::string& user_id) { + user_access_manager_->SetActiveUser(user_id); + mash::init::mojom::InitPtr init; + connector_->ConnectToInterface("mojo:mash_init", &init); + init->StartService("mojo:mash_shell", user_id); + } + private: + // mojo::ShellClient: + void Initialize(mojo::Connector* connector, const mojo::Identity& identity, + uint32_t id) override { + connector_ = connector; + tracing_.Initialize(connector, identity.name()); + + aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); + + connector_->ConnectToInterface("mojo:mus", &user_access_manager_); + user_access_manager_->SetActiveUser(identity.user_id()); + } + bool AcceptConnection(mojo::Connection* connection) override { + connection->AddInterface<mojom::Login>(this); + return true; + } + + // mojo::InterfaceFactory<mojom::Login>: + void Create(mojo::Connection* connection, + mojom::LoginRequest request) override { + bindings_.AddBinding(this, std::move(request)); + } + // mojom::Login: void ShowLoginUI() override { - UI::Show(connector_, controller_); + UI::Show(connector_, this); } void SwitchUser() override { - UI::Show(connector_, controller_); + UI::Show(connector_, this); } + void StartWindowManager(); + mojo::Connector* connector_; - LoginController* controller_; - const std::string user_id_; - mojo::StrongBinding<mojom::Login> binding_; + mojo::TracingImpl tracing_; + scoped_ptr<views::AuraInit> aura_init_; + mojo::BindingSet<mojom::Login> bindings_; + mus::mojom::UserAccessManagerPtr user_access_manager_; + scoped_ptr<mojo::Connection> window_manager_connection_; DISALLOW_COPY_AND_ASSIGN(Login); }; -} // namespace - -LoginController::LoginController() {} -LoginController::~LoginController() {} - -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")); +void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { + // Login... + if (sender == login_button_1_) { + login_->LoginAs(user_id_1_); + } else if (sender == login_button_2_) { + login_->LoginAs(user_id_2_); + } else { + NOTREACHED(); + } + GetWidget()->Close(); } -bool LoginController::AcceptConnection(mojo::Connection* connection) { - if (connection->GetRemoteIdentity().name() == "mojo:mash_init") - connection->GetInterface(&init_); - connection->AddInterface<mojom::Login>(this); - return true; -} +} // namespace -void LoginController::Create(mojo::Connection* connection, - mojom::LoginRequest request) { - new Login(connector_, this, connection->GetRemoteIdentity().user_id(), - std::move(request)); +mojo::ShellClient* CreateLogin() { + return new Login; } } // namespace login diff --git a/mash/login/login.h b/mash/login/login.h index b50837d..8f2c9f3 100644 --- a/mash/login/login.h +++ b/mash/login/login.h @@ -5,49 +5,14 @@ #ifndef MASH_LOGIN_LOGIN_H_ #define MASH_LOGIN_LOGIN_H_ -#include <map> - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "mash/init/public/interfaces/init.mojom.h" -#include "mash/login/public/interfaces/login.mojom.h" -#include "mojo/services/tracing/public/cpp/tracing_impl.h" -#include "mojo/shell/public/cpp/shell_client.h" - -namespace views { -class AuraInit; +namespace mojo { +class ShellClient; } namespace mash { namespace login { -class LoginController : public mojo::ShellClient, - public mojo::InterfaceFactory<mojom::Login> { - public: - LoginController(); - ~LoginController() override; - - init::mojom::Init* init() { return init_.get(); } - const std::string& login_user_id() const { return login_user_id_; } - - private: - // mojo::ShellClient: - void Initialize(mojo::Connector* connector, const mojo::Identity& identity, - uint32_t id) override; - bool AcceptConnection(mojo::Connection* connection) override; - - // mojo::InterfaceFactory<mojom::Login>: - void Create(mojo::Connection* connection, - mojom::LoginRequest request) override; - - mojo::Connector* connector_; - std::string login_user_id_; - mojo::TracingImpl tracing_; - scoped_ptr<views::AuraInit> aura_init_; - init::mojom::InitPtr init_; - - DISALLOW_COPY_AND_ASSIGN(LoginController); -}; +mojo::ShellClient* CreateLogin(); } // namespace login } // namespace mash diff --git a/mash/login/main.cc b/mash/login/main.cc index 1901dd0..753f7db 100644 --- a/mash/login/main.cc +++ b/mash/login/main.cc @@ -7,6 +7,6 @@ #include "mojo/shell/public/cpp/application_runner.h" MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunner runner(new mash::login::LoginController); + mojo::ApplicationRunner runner(mash::login::CreateLogin()); return runner.Run(shell_handle); } diff --git a/mash/login/ui.cc b/mash/login/ui.cc deleted file mode 100644 index b2f1770..0000000 --- a/mash/login/ui.cc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "mash/login/ui.h" - -#include "base/guid.h" -#include "base/strings/utf_string_conversions.h" -#include "components/mus/public/cpp/property_type_converters.h" -#include "mash/login/login.h" -#include "mash/wm/public/interfaces/container.mojom.h" -#include "mojo/shell/public/cpp/connector.h" -#include "ui/views/background.h" -#include "ui/views/mus/native_widget_mus.h" -#include "ui/views/mus/window_manager_connection.h" - -namespace mash { -namespace login { - -// static -bool UI::is_showing_ = false; - -// static -void UI::Show(mojo::Connector* connector, LoginController* login_controller) { - // It's possible multiple clients may have a connection to the Login service, - // so make sure that only one login UI can be shown at a time. - if (is_showing_) - return; - - UI* ui = new UI(login_controller, connector); - - // TODO(beng): If this is only done once, it should be done in - // LoginController::Initialize(). However, for as yet unknown reasons it needs - // to be done the first time after UI(). Figure this out. Also, I'm not - // certain the window manager is being killed when this UI is closed. - if (!views::WindowManagerConnection::Exists()) - views::WindowManagerConnection::Create(connector); - - views::Widget* widget = new views::Widget; - views::Widget::InitParams params( - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.delegate = ui; - - 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(); - - is_showing_ = true; -} - -UI::UI(LoginController* login_controller, mojo::Connector* connector) - : login_controller_(login_controller), - connector_(connector), - user_id_1_("00000000-0000-4000-8000-000000000000"), - user_id_2_("00000000-0000-4000-8000-000000000001"), - login_button_1_( - new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), - login_button_2_( - new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { - connector_->ConnectToInterface("mojo:mus", &user_access_manager_); - user_access_manager_->SetActiveUser(login_controller->login_user_id()); - StartWindowManager(); - - 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_); -} - -UI::~UI() { - // Prevent the window manager from restarting during graceful shutdown. - window_manager_connection_->SetConnectionLostClosure(base::Closure()); - is_showing_ = false; - // TODO(beng): we should be terminating this app at this point. -} - -views::View* UI::GetContentsView() { return this; } - -base::string16 UI::GetWindowTitle() const { - // TODO(beng): use resources. - return base::ASCIIToUTF16("Login"); -} - -void UI::DeleteDelegate() { - delete this; -} - -void UI::Layout() { - 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 UI::ButtonPressed(views::Button* sender, const ui::Event& event) { - // Login... - if (sender == login_button_1_) { - user_access_manager_->SetActiveUser(user_id_1_); - login_controller_->init()->StartService("mojo:mash_shell", user_id_1_); - } else if (sender == login_button_2_) { - user_access_manager_->SetActiveUser(user_id_2_); - login_controller_->init()->StartService("mojo:mash_shell", user_id_2_); - } else { - NOTREACHED(); - } - GetWidget()->Close(); -} - -void UI::StartWindowManager() { - window_manager_connection_ = connector_->Connect("mojo:desktop_wm"); - window_manager_connection_->SetConnectionLostClosure( - base::Bind(&UI::StartWindowManager, base::Unretained(this))); -} - -} // namespace login -} // namespace mash diff --git a/mash/login/ui.h b/mash/login/ui.h deleted file mode 100644 index 4c141c4..0000000 --- a/mash/login/ui.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MASH_LOGIN_UI_H_ -#define MASH_LOGIN_UI_H_ - -#include <map> - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "components/mus/public/interfaces/user_access_manager.mojom.h" -#include "ui/views/controls/button/label_button.h" -#include "ui/views/widget/widget_delegate.h" - -namespace mojo { -class Connection; -class Connector; -} - -namespace views { -class AuraInit; -} - -namespace mash { -namespace login { - -class LoginController; - -class UI : public views::WidgetDelegateView, - public views::ButtonListener { - public: - static void Show(mojo::Connector* connector, - LoginController* login_controller); - - private: - UI(LoginController* login_controller, mojo::Connector* connector); - ~UI() override; - - // Overridden from views::WidgetDelegate: - views::View* GetContentsView() override; - base::string16 GetWindowTitle() const override; - void DeleteDelegate() override; - - // Overridden from views::View: - void Layout() override; - - // Overridden from views::ButtonListener: - void ButtonPressed(views::Button* sender, const ui::Event& event) override; - - void StartWindowManager(); - - static bool is_showing_; - LoginController* login_controller_; - mojo::Connector* connector_; - const std::string user_id_1_; - const std::string user_id_2_; - views::LabelButton* login_button_1_; - views::LabelButton* login_button_2_; - mus::mojom::UserAccessManagerPtr user_access_manager_; - scoped_ptr<mojo::Connection> window_manager_connection_; - - DISALLOW_COPY_AND_ASSIGN(UI); -}; - -} // namespace login -} // namespace mash - -#endif // MASH_LOGIN_UI_H_ diff --git a/mojo/shell/runner/host/child_process_host.cc b/mojo/shell/runner/host/child_process_host.cc index 1083128..f887dbd 100644 --- a/mojo/shell/runner/host/child_process_host.cc +++ b/mojo/shell/runner/host/child_process_host.cc @@ -58,7 +58,7 @@ ChildProcessHost::~ChildProcessHost() { } mojom::ShellClientPtr ChildProcessHost::Start( - const String& name, + const Identity& target, const ProcessReadyCallback& callback, const base::Closure& quit_closure) { DCHECK(!child_process_.IsValid()); @@ -77,6 +77,11 @@ mojom::ShellClientPtr ChildProcessHost::Start( child_command_line->AppendArguments(*parent_command_line, false); +#ifndef NDEBUG + child_command_line->AppendSwitchASCII("n", target.name()); + child_command_line->AppendSwitchASCII("u", target.user_id()); +#endif + if (target_path != app_path_) child_command_line->AppendSwitchPath(switches::kChildProcess, app_path_); diff --git a/mojo/shell/runner/host/child_process_host.h b/mojo/shell/runner/host/child_process_host.h index c13251a..9e0fb83 100644 --- a/mojo/shell/runner/host/child_process_host.h +++ b/mojo/shell/runner/host/child_process_host.h @@ -61,7 +61,7 @@ class ChildProcessHost { // |Start()|s the child process; calls |DidStart()| (on the thread on which // |Start()| was called) when the child has been started (or failed to start). - mojom::ShellClientPtr Start(const String& name, + mojom::ShellClientPtr Start(const Identity& target, const ProcessReadyCallback& callback, const base::Closure& quit_closure); diff --git a/mojo/shell/runner/host/child_process_host_unittest.cc b/mojo/shell/runner/host/child_process_host_unittest.cc index 593360d..ae513ab 100644 --- a/mojo/shell/runner/host/child_process_host_unittest.cc +++ b/mojo/shell/runner/host/child_process_host_unittest.cc @@ -96,7 +96,7 @@ TEST(ChildProcessHostTest, MAYBE_StartJoin) { Identity(), base::FilePath()); base::RunLoop run_loop; child_process_host.Start( - String(), + Identity(), base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), base::Bind(&base::DoNothing)); run_loop.Run(); diff --git a/mojo/shell/runner/host/out_of_process_native_runner.cc b/mojo/shell/runner/host/out_of_process_native_runner.cc index 0bf38d5..30104dd 100644 --- a/mojo/shell/runner/host/out_of_process_native_runner.cc +++ b/mojo/shell/runner/host/out_of_process_native_runner.cc @@ -44,7 +44,7 @@ mojom::ShellClientPtr OutOfProcessNativeRunner::Start( child_process_host_.reset(new ChildProcessHost( launch_process_runner_, delegate_, start_sandboxed, target, app_path)); return child_process_host_->Start( - target.name(), pid_available_callback, + target, pid_available_callback, base::Bind(&OutOfProcessNativeRunner::AppCompleted, base::Unretained(this))); } diff --git a/ui/views/mus/screen_mus.cc b/ui/views/mus/screen_mus.cc index 60fe8cf..855f475 100644 --- a/ui/views/mus/screen_mus.cc +++ b/ui/views/mus/screen_mus.cc @@ -162,7 +162,7 @@ gfx::Display ScreenMus::GetPrimaryDisplay() const { } gfx::Display ScreenMus::GetDisplayNearestWindow(gfx::NativeView view) const { - NOTIMPLEMENTED(); + //NOTIMPLEMENTED(); return GetPrimaryDisplay(); } |