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

Side by Side Diff: mojo/shell/tests/lifecycle/parent.cc

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 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
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 "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/bindings/binding_set.h"
10 #include "mojo/shell/public/cpp/application_runner.h"
11 #include "mojo/shell/public/cpp/connector.h"
12 #include "mojo/shell/public/cpp/shell_client.h"
13 #include "mojo/shell/tests/lifecycle/lifecycle_unittest.mojom.h"
14
15 namespace {
16
17 void QuitLoop(base::RunLoop* loop) {
18 loop->Quit();
19 }
20
21 class Parent
22 : public mojo::ShellClient,
23 public mojo::InterfaceFactory<mojo::shell::test::mojom::Parent>,
24 public mojo::shell::test::mojom::Parent {
25 public:
26 Parent() {}
27 ~Parent() override {
28 connector_ = nullptr;
29 child_connection_.reset();
30 parent_bindings_.CloseAllBindings();
31 }
32
33 private:
34 // ShellClient:
35 void Initialize(mojo::Connector* connector, const mojo::Identity& identity,
36 uint32_t id) override {
37 connector_ = connector;
38 }
39 bool AcceptConnection(mojo::Connection* connection) override {
40 connection->AddInterface<mojo::shell::test::mojom::Parent>(this);
41 return true;
42 }
43
44 // InterfaceFactory<mojo::shell::test::mojom::Parent>:
45 void Create(mojo::Connection* connection,
46 mojo::shell::test::mojom::ParentRequest request) override {
47 parent_bindings_.AddBinding(this, std::move(request));
48 }
49
50 // Parent:
51 void ConnectToChild(const ConnectToChildCallback& callback) override {
52 child_connection_ = connector_->Connect("mojo:lifecycle_unittest_app");
53 mojo::shell::test::mojom::LifecycleControlPtr lifecycle;
54 child_connection_->GetInterface(&lifecycle);
55 {
56 base::RunLoop loop;
57 lifecycle->Ping(base::Bind(&QuitLoop, &loop));
58 base::MessageLoop::ScopedNestableTaskAllower allow(
59 base::MessageLoop::current());
60 loop.Run();
61 }
62 callback.Run();
63 }
64 void Quit() override {
65 base::MessageLoop::current()->QuitWhenIdle();
66 }
67
68 mojo::Connector* connector_;
69 scoped_ptr<mojo::Connection> child_connection_;
70 mojo::BindingSet<mojo::shell::test::mojom::Parent> parent_bindings_;
71
72 DISALLOW_COPY_AND_ASSIGN(Parent);
73 };
74
75 } // namespace
76
77 MojoResult MojoMain(MojoHandle shell_handle) {
78 Parent* parent = new Parent;
79 return mojo::ApplicationRunner(parent).Run(shell_handle);
80 }
OLDNEW
« no previous file with comments | « mojo/shell/tests/lifecycle/package_manifest.json ('k') | mojo/shell/tests/lifecycle/parent_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698