summaryrefslogtreecommitdiffstats
path: root/mash/init
diff options
context:
space:
mode:
authorben <ben@chromium.org>2016-02-29 15:12:33 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-29 23:13:49 +0000
commitc6ec81a1d269112b0220fa575f8bba529b4e53c2 (patch)
tree9c56bd8a9241c9ae62cc0dc4764e2e32bfd5acbe /mash/init
parent2a28406877d06cc4d7511295067c6be031e70e9d (diff)
downloadchromium_src-c6ec81a1d269112b0220fa575f8bba529b4e53c2.zip
chromium_src-c6ec81a1d269112b0220fa575f8bba529b4e53c2.tar.gz
chromium_src-c6ec81a1d269112b0220fa575f8bba529b4e53c2.tar.bz2
Primitive login screen to mock out login flow.
BUG= Review URL: https://codereview.chromium.org/1734063005 Cr-Commit-Position: refs/heads/master@{#378310}
Diffstat (limited to 'mash/init')
-rw-r--r--mash/init/BUILD.gn33
-rw-r--r--mash/init/init.cc69
-rw-r--r--mash/init/init.h63
-rw-r--r--mash/init/main.cc12
-rw-r--r--mash/init/manifest.json5
-rw-r--r--mash/init/public/interfaces/BUILD.gn11
-rw-r--r--mash/init/public/interfaces/login.mojom10
7 files changed, 203 insertions, 0 deletions
diff --git a/mash/init/BUILD.gn b/mash/init/BUILD.gn
new file mode 100644
index 0000000..010fb38
--- /dev/null
+++ b/mash/init/BUILD.gn
@@ -0,0 +1,33 @@
+# 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.
+
+import("//build/config/ui.gni")
+import("//mojo/public/mojo_application.gni")
+import("//mojo/public/mojo_application_manifest.gni")
+import("//mojo/public/tools/bindings/mojom.gni")
+import("//tools/grit/repack.gni")
+
+mojo_native_application("init") {
+ output_name = "mash_init"
+ sources = [
+ "init.cc",
+ "init.h",
+ "main.cc",
+ ]
+
+ deps = [
+ ":manifest",
+ "//base",
+ "//components/mus/public/cpp",
+ "//mash/init/public/interfaces",
+ "//mojo/public/cpp/bindings",
+ "//mojo/services/tracing/public/cpp",
+ "//mojo/shell/public/cpp",
+ ]
+}
+
+mojo_application_manifest("manifest") {
+ application_name = "mash_init"
+ source = "manifest.json"
+}
diff --git a/mash/init/init.cc b/mash/init/init.cc
new file mode 100644
index 0000000..f8e1d6b
--- /dev/null
+++ b/mash/init/init.cc
@@ -0,0 +1,69 @@
+// 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/init/init.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "mojo/shell/public/cpp/connection.h"
+#include "mojo/shell/public/cpp/connector.h"
+
+namespace mash {
+namespace init {
+
+Init::Init() : connector_(nullptr) {}
+Init::~Init() {}
+
+void Init::Initialize(mojo::Connector* connector, const std::string& url,
+ uint32_t id, uint32_t user_id) {
+ connector_ = connector;
+ mus_connection_ = connector_->Connect("mojo:mus");
+ StartWindowManager();
+ StartLogin();
+}
+
+void Init::LoginAs(uint32_t user_id) {
+ connections_["mojo:mash_login"].reset();
+ connections_["mojo:desktop_wm"].reset();
+ mojo::Connector::ConnectParams params("mojo:mash_shell");
+ params.set_user_id(user_id);
+ connector_->Connect(&params);
+}
+
+void Init::Create(mojo::Connection* connection, mojom::LoginRequest request) {
+ login_bindings_.AddBinding(this, std::move(request));
+}
+
+void Init::StartWindowManager() {
+ mojo::Connector::ConnectParams params("mojo:desktop_wm");
+ params.set_user_id(2);
+ StartRestartableService(
+ &params,
+ base::Bind(&Init::StartWindowManager, base::Unretained(this)));
+}
+
+void Init::StartLogin() {
+ mojo::Connector::ConnectParams params("mojo:mash_login");
+ params.set_user_id(2);
+ StartRestartableService(
+ &params,
+ base::Bind(&Init::StartLogin, base::Unretained(this)));
+}
+
+void Init::StartRestartableService(mojo::Connector::ConnectParams* params,
+ const base::Closure& restart_callback) {
+ // TODO(beng): This would be the place to insert logic that counted restarts
+ // to avoid infinite crash-restart loops.
+ scoped_ptr<mojo::Connection> connection = connector_->Connect(params);
+ // Note: |connection| may be null if we've lost our connection to the shell.
+ if (connection) {
+ connection->SetRemoteInterfaceProviderConnectionErrorHandler(
+ restart_callback);
+ connection->AddInterface<mojom::Login>(this);
+ connections_[params->name()] = std::move(connection);
+ }
+}
+
+} // namespace init
+} // namespace main
diff --git a/mash/init/init.h b/mash/init/init.h
new file mode 100644
index 0000000..10a8a0e
--- /dev/null
+++ b/mash/init/init.h
@@ -0,0 +1,63 @@
+// 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_INIT_INIT_H_
+#define MASH_INIT_INIT_H_
+
+#include <map>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "mash/init/public/interfaces/login.mojom.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
+#include "mojo/shell/public/cpp/connector.h"
+#include "mojo/shell/public/cpp/shell_client.h"
+
+namespace mojo {
+class Connection;
+}
+
+namespace mash {
+namespace init{
+
+class Init : public mojo::ShellClient,
+ public mojom::Login,
+ public mojo::InterfaceFactory<mojom::Login> {
+ public:
+ Init();
+ ~Init() override;
+
+ private:
+ // mojo::ShellClient:
+ void Initialize(mojo::Connector* connector, const std::string& url,
+ uint32_t id, uint32_t user_id) override;
+
+ // mojom::Login:
+ void LoginAs(uint32_t user_id) override;
+
+ // mojo::InterfaceFactory<mojom::Login>:
+ void Create(mojo::Connection* connection,
+ mojom::LoginRequest request) override;
+
+ void StartWindowManager();
+ void StartLogin();
+
+ // Starts the application at |url|, running |restart_callback| if the
+ // connection to the application is closed.
+ void StartRestartableService(mojo::Connector::ConnectParams* params,
+ const base::Closure& restart_callback);
+
+ mojo::Connector* connector_;
+ std::map<std::string, scoped_ptr<mojo::Connection>> connections_;
+ mojo::BindingSet<mojom::Login> login_bindings_;
+ scoped_ptr<mojo::Connection> mus_connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(Init);
+};
+
+} // namespace init
+} // namespace mash
+
+#endif // MASH_INIT_INIT_H_
diff --git a/mash/init/main.cc b/mash/init/main.cc
new file mode 100644
index 0000000..65d4789
--- /dev/null
+++ b/mash/init/main.cc
@@ -0,0 +1,12 @@
+// 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/init/init.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/shell/public/cpp/application_runner.h"
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunner runner(new mash::init::Init);
+ return runner.Run(shell_handle);
+}
diff --git a/mash/init/manifest.json b/mash/init/manifest.json
new file mode 100644
index 0000000..d55a0a75
--- /dev/null
+++ b/mash/init/manifest.json
@@ -0,0 +1,5 @@
+{
+ "name": "mojo:mash_init",
+ "display_name": "Root Controller",
+ "capabilities": { "*": [ "*" ] }
+}
diff --git a/mash/init/public/interfaces/BUILD.gn b/mash/init/public/interfaces/BUILD.gn
new file mode 100644
index 0000000..0ea747b
--- /dev/null
+++ b/mash/init/public/interfaces/BUILD.gn
@@ -0,0 +1,11 @@
+# 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.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("interfaces") {
+ sources = [
+ "login.mojom",
+ ]
+}
diff --git a/mash/init/public/interfaces/login.mojom b/mash/init/public/interfaces/login.mojom
new file mode 100644
index 0000000..3ea6f10
--- /dev/null
+++ b/mash/init/public/interfaces/login.mojom
@@ -0,0 +1,10 @@
+// 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.
+
+module mash.init.mojom;
+
+interface Login {
+ LoginAs(uint32 user_id);
+};
+