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

Side by Side Diff: mojo/shell/package_test_package.cc

Issue 1706063002: Eliminate ShellClientFactoryConnection & just have the ApplicationManager do it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@factory
Patch Set: . Created 4 years, 10 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
« no previous file with comments | « mojo/shell/identity.cc ('k') | mojo/shell/public/cpp/connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 29
30 using GetNameCallback = test::mojom::PackageTestService::GetNameCallback; 30 using GetNameCallback = test::mojom::PackageTestService::GetNameCallback;
31 31
32 class ProvidedShellClient 32 class ProvidedShellClient
33 : public ShellClient, 33 : public ShellClient,
34 public InterfaceFactory<test::mojom::PackageTestService>, 34 public InterfaceFactory<test::mojom::PackageTestService>,
35 public test::mojom::PackageTestService, 35 public test::mojom::PackageTestService,
36 public base::SimpleThread { 36 public base::SimpleThread {
37 public: 37 public:
38 ProvidedShellClient(const std::string& name, 38 ProvidedShellClient(const std::string& name,
39 mojom::ShellClientRequest request, 39 mojom::ShellClientRequest request)
40 const Callback<void()>& destruct_callback)
41 : base::SimpleThread(name), 40 : base::SimpleThread(name),
42 name_(name), 41 name_(name),
43 request_(std::move(request)), 42 request_(std::move(request)),
44 destruct_callback_(destruct_callback),
45 shell_(nullptr) { 43 shell_(nullptr) {
46 Start(); 44 Start();
47 } 45 }
48 ~ProvidedShellClient() override { 46 ~ProvidedShellClient() override {
49 Join(); 47 Join();
50 destruct_callback_.Run();
51 } 48 }
52 49
53 private: 50 private:
54 // mojo::ShellClient: 51 // mojo::ShellClient:
55 void Initialize(Shell* shell, const std::string& url, uint32_t id) override { 52 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {
56 shell_ = shell; 53 shell_ = shell;
57 bindings_.set_connection_error_handler( 54 bindings_.set_connection_error_handler(
58 base::Bind(&ProvidedShellClient::OnConnectionError, 55 base::Bind(&ProvidedShellClient::OnConnectionError,
59 base::Unretained(this))); 56 base::Unretained(this)));
60 } 57 }
(...skipping 21 matching lines...) Expand all
82 delete this; 79 delete this;
83 } 80 }
84 81
85 void OnConnectionError() { 82 void OnConnectionError() {
86 if (bindings_.empty()) 83 if (bindings_.empty())
87 shell_->Quit(); 84 shell_->Quit();
88 } 85 }
89 86
90 const std::string name_; 87 const std::string name_;
91 mojom::ShellClientRequest request_; 88 mojom::ShellClientRequest request_;
92 const Callback<void()> destruct_callback_;
93 Shell* shell_; 89 Shell* shell_;
94 WeakBindingSet<test::mojom::PackageTestService> bindings_; 90 WeakBindingSet<test::mojom::PackageTestService> bindings_;
95 91
96 DISALLOW_COPY_AND_ASSIGN(ProvidedShellClient); 92 DISALLOW_COPY_AND_ASSIGN(ProvidedShellClient);
97 }; 93 };
98 94
99 class PackageTestShellClient 95 class PackageTestShellClient
100 : public ShellClient, 96 : public ShellClient,
101 public InterfaceFactory<mojom::ShellClientFactory>, 97 public InterfaceFactory<mojom::ShellClientFactory>,
102 public InterfaceFactory<test::mojom::PackageTestService>, 98 public InterfaceFactory<test::mojom::PackageTestService>,
(...skipping 24 matching lines...) Expand all
127 } 123 }
128 124
129 // InterfaceFactory<test::mojom::PackageTestService>: 125 // InterfaceFactory<test::mojom::PackageTestService>:
130 void Create(Connection* connection, 126 void Create(Connection* connection,
131 test::mojom::PackageTestServiceRequest request) override { 127 test::mojom::PackageTestServiceRequest request) override {
132 bindings_.AddBinding(this, std::move(request)); 128 bindings_.AddBinding(this, std::move(request));
133 } 129 }
134 130
135 // mojom::ShellClientFactory: 131 // mojom::ShellClientFactory:
136 void CreateShellClient(mojom::ShellClientRequest request, 132 void CreateShellClient(mojom::ShellClientRequest request,
137 const String& url, 133 const String& url) override {
138 const Callback<void()>& destruct_callback) override {
139 if (url == "mojo://package_test_a/") 134 if (url == "mojo://package_test_a/")
140 new ProvidedShellClient("A", std::move(request), destruct_callback); 135 new ProvidedShellClient("A", std::move(request));
141 else if (url == "mojo://package_test_b/") 136 else if (url == "mojo://package_test_b/")
142 new ProvidedShellClient("B", std::move(request), destruct_callback); 137 new ProvidedShellClient("B", std::move(request));
143 } 138 }
144 139
145 // test::mojom::PackageTestService: 140 // test::mojom::PackageTestService:
146 void GetName(const GetNameCallback& callback) override { 141 void GetName(const GetNameCallback& callback) override {
147 callback.Run("ROOT"); 142 callback.Run("ROOT");
148 } 143 }
149 144
150 void OnConnectionError() { 145 void OnConnectionError() {
151 if (bindings_.empty()) 146 if (bindings_.empty())
152 shell_->Quit(); 147 shell_->Quit();
153 } 148 }
154 149
155 Shell* shell_; 150 Shell* shell_;
156 std::vector<scoped_ptr<ShellClient>> delegates_; 151 std::vector<scoped_ptr<ShellClient>> delegates_;
157 WeakBindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; 152 WeakBindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_;
158 WeakBindingSet<test::mojom::PackageTestService> bindings_; 153 WeakBindingSet<test::mojom::PackageTestService> bindings_;
159 154
160 DISALLOW_COPY_AND_ASSIGN(PackageTestShellClient); 155 DISALLOW_COPY_AND_ASSIGN(PackageTestShellClient);
161 }; 156 };
162 157
163 } // namespace shell 158 } // namespace shell
164 } // namespace mojo 159 } // namespace mojo
165 160
166 161
167 MojoResult MojoMain(MojoHandle shell_handle) { 162 MojoResult MojoMain(MojoHandle shell_handle) {
168 MojoResult rv = mojo::ApplicationRunner( 163 MojoResult rv = mojo::ApplicationRunner(
169 new mojo::shell::PackageTestShellClient).Run(shell_handle); 164 new mojo::shell::PackageTestShellClient).Run(shell_handle);
170 return rv; 165 return rv;
171 } 166 }
OLDNEW
« no previous file with comments | « mojo/shell/identity.cc ('k') | mojo/shell/public/cpp/connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698