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

Side by Side Diff: services/shell/tests/connect/connect_test_class_app.cc

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/bindings/binding_set.h" 10 #include "mojo/public/cpp/bindings/binding_set.h"
(...skipping 13 matching lines...) Expand all
24 public InterfaceFactory<test::mojom::ConnectTestService>, 24 public InterfaceFactory<test::mojom::ConnectTestService>,
25 public InterfaceFactory<test::mojom::ClassInterface>, 25 public InterfaceFactory<test::mojom::ClassInterface>,
26 public test::mojom::ConnectTestService, 26 public test::mojom::ConnectTestService,
27 public test::mojom::ClassInterface { 27 public test::mojom::ClassInterface {
28 public: 28 public:
29 ConnectTestClassApp() {} 29 ConnectTestClassApp() {}
30 ~ConnectTestClassApp() override {} 30 ~ConnectTestClassApp() override {}
31 31
32 private: 32 private:
33 // shell::Service: 33 // shell::Service:
34 void OnStart(Connector* connector, const Identity& identity, 34 void OnStart(const Identity& identity) override {
35 uint32_t id) override {
36 connector_ = connector;
37 identity_ = identity; 35 identity_ = identity;
38 } 36 }
39 bool OnConnect(Connection* connection) override { 37 bool OnConnect(Connection* connection) override {
40 connection->AddInterface<test::mojom::ConnectTestService>(this); 38 connection->AddInterface<test::mojom::ConnectTestService>(this);
41 connection->AddInterface<test::mojom::ClassInterface>(this); 39 connection->AddInterface<test::mojom::ClassInterface>(this);
42 inbound_connections_.insert(connection); 40 inbound_connections_.insert(connection);
43 connection->SetConnectionLostClosure( 41 connection->SetConnectionLostClosure(
44 base::Bind(&ConnectTestClassApp::OnConnectionError, 42 base::Bind(&ConnectTestClassApp::OnConnectionError,
45 base::Unretained(this), connection)); 43 base::Unretained(this), connection));
46 return true; 44 return true;
(...skipping 25 matching lines...) Expand all
72 } 70 }
73 71
74 void OnConnectionError(Connection* connection) { 72 void OnConnectionError(Connection* connection) {
75 auto it = inbound_connections_.find(connection); 73 auto it = inbound_connections_.find(connection);
76 DCHECK(it != inbound_connections_.end()); 74 DCHECK(it != inbound_connections_.end());
77 inbound_connections_.erase(it); 75 inbound_connections_.erase(it);
78 if (inbound_connections_.empty()) 76 if (inbound_connections_.empty())
79 base::MessageLoop::current()->QuitWhenIdle(); 77 base::MessageLoop::current()->QuitWhenIdle();
80 } 78 }
81 79
82 Connector* connector_ = nullptr;
83 Identity identity_; 80 Identity identity_;
84 std::set<Connection*> inbound_connections_; 81 std::set<Connection*> inbound_connections_;
85 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; 82 mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
86 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_; 83 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_;
87 84
88 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp); 85 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp);
89 }; 86 };
90 87
91 } // namespace shell 88 } // namespace shell
92 89
93 90
94 MojoResult MojoMain(MojoHandle shell_handle) { 91 MojoResult MojoMain(MojoHandle shell_handle) {
95 MojoResult rv = shell::ServiceRunner(new shell::ConnectTestClassApp) 92 MojoResult rv = shell::ServiceRunner(new shell::ConnectTestClassApp)
96 .Run(shell_handle); 93 .Run(shell_handle);
97 return rv; 94 return rv;
98 } 95 }
OLDNEW
« no previous file with comments | « services/shell/tests/connect/connect_test_app.cc ('k') | services/shell/tests/connect/connect_test_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698