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

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

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 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 <memory>
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "mojo/public/cpp/bindings/binding_set.h"
11 #include "services/shell/public/c/main.h"
12 #include "services/shell/public/cpp/connector.h"
13 #include "services/shell/public/cpp/interface_factory.h"
14 #include "services/shell/public/cpp/interface_registry.h"
15 #include "services/shell/public/cpp/service.h"
16 #include "services/shell/public/cpp/service_runner.h"
17 #include "services/shell/tests/lifecycle/lifecycle_unittest.mojom.h"
18
19 namespace {
20
21 void QuitLoop(base::RunLoop* loop) {
22 loop->Quit();
23 }
24
25 class Parent : public shell::Service,
26 public shell::InterfaceFactory<shell::test::mojom::Parent>,
27 public shell::test::mojom::Parent {
28 public:
29 Parent() {}
30 ~Parent() override {
31 child_connection_.reset();
32 parent_bindings_.CloseAllBindings();
33 }
34
35 private:
36 // Service:
37 bool OnConnect(const shell::Identity& remote_identity,
38 shell::InterfaceRegistry* registry) override {
39 registry->AddInterface<shell::test::mojom::Parent>(this);
40 return true;
41 }
42
43 // InterfaceFactory<shell::test::mojom::Parent>:
44 void Create(const shell::Identity& remote_identity,
45 shell::test::mojom::ParentRequest request) override {
46 parent_bindings_.AddBinding(this, std::move(request));
47 }
48
49 // Parent:
50 void ConnectToChild(const ConnectToChildCallback& callback) override {
51 child_connection_ = connector()->Connect("service:lifecycle_unittest_app");
52 shell::test::mojom::LifecycleControlPtr lifecycle;
53 child_connection_->GetInterface(&lifecycle);
54 {
55 base::RunLoop loop;
56 lifecycle->Ping(base::Bind(&QuitLoop, &loop));
57 base::MessageLoop::ScopedNestableTaskAllower allow(
58 base::MessageLoop::current());
59 loop.Run();
60 }
61 callback.Run();
62 }
63 void Quit() override {
64 base::MessageLoop::current()->QuitWhenIdle();
65 }
66
67 std::unique_ptr<shell::Connection> child_connection_;
68 mojo::BindingSet<shell::test::mojom::Parent> parent_bindings_;
69
70 DISALLOW_COPY_AND_ASSIGN(Parent);
71 };
72
73 } // namespace
74
75 MojoResult ServiceMain(MojoHandle service_request_handle) {
76 Parent* parent = new Parent;
77 return shell::ServiceRunner(parent).Run(service_request_handle);
78 }
OLDNEW
« no previous file with comments | « services/shell/tests/lifecycle/package_manifest.json ('k') | services/shell/tests/lifecycle/parent_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698