OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 using GetNameCallback = | 30 using GetNameCallback = |
31 test::mojom::ApplicationPackageApptestService::GetNameCallback; | 31 test::mojom::ApplicationPackageApptestService::GetNameCallback; |
32 | 32 |
33 class ProvidedApplicationDelegate | 33 class ProvidedApplicationDelegate |
34 : public ApplicationDelegate, | 34 : public ApplicationDelegate, |
35 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, | 35 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, |
36 public test::mojom::ApplicationPackageApptestService, | 36 public test::mojom::ApplicationPackageApptestService, |
37 public base::SimpleThread { | 37 public base::SimpleThread { |
38 public: | 38 public: |
39 ProvidedApplicationDelegate(const std::string& name, | 39 ProvidedApplicationDelegate(const std::string& name, |
40 InterfaceRequest<Application> request, | 40 InterfaceRequest<mojom::Application> request, |
41 const Callback<void()>& destruct_callback) | 41 const Callback<void()>& destruct_callback) |
42 : base::SimpleThread(name), | 42 : base::SimpleThread(name), |
43 name_(name), | 43 name_(name), |
44 request_(std::move(request)), | 44 request_(std::move(request)), |
45 destruct_callback_(destruct_callback) { | 45 destruct_callback_(destruct_callback) { |
46 Start(); | 46 Start(); |
47 } | 47 } |
48 ~ProvidedApplicationDelegate() override { | 48 ~ProvidedApplicationDelegate() override { |
49 Join(); | 49 Join(); |
50 destruct_callback_.Run(); | 50 destruct_callback_.Run(); |
(...skipping 21 matching lines...) Expand all Loading... |
72 } | 72 } |
73 | 73 |
74 // base::SimpleThread: | 74 // base::SimpleThread: |
75 void Run() override { | 75 void Run() override { |
76 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), | 76 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), |
77 false); | 77 false); |
78 delete this; | 78 delete this; |
79 } | 79 } |
80 | 80 |
81 const std::string name_; | 81 const std::string name_; |
82 InterfaceRequest<Application> request_; | 82 InterfaceRequest<mojom::Application> request_; |
83 const Callback<void()> destruct_callback_; | 83 const Callback<void()> destruct_callback_; |
84 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; | 84 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(ProvidedApplicationDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(ProvidedApplicationDelegate); |
87 }; | 87 }; |
88 | 88 |
89 class ApplicationPackageApptestDelegate | 89 class ApplicationPackageApptestDelegate |
90 : public ApplicationDelegate, | 90 : public ApplicationDelegate, |
91 public InterfaceFactory<ContentHandler>, | 91 public InterfaceFactory<mojom::ContentHandler>, |
92 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, | 92 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, |
93 public ContentHandler, | 93 public mojom::ContentHandler, |
94 public test::mojom::ApplicationPackageApptestService { | 94 public test::mojom::ApplicationPackageApptestService { |
95 public: | 95 public: |
96 ApplicationPackageApptestDelegate() {} | 96 ApplicationPackageApptestDelegate() {} |
97 ~ApplicationPackageApptestDelegate() override {} | 97 ~ApplicationPackageApptestDelegate() override {} |
98 | 98 |
99 private: | 99 private: |
100 // ApplicationDelegate: | 100 // ApplicationDelegate: |
101 void Initialize(ApplicationImpl* app) override {} | 101 void Initialize(ApplicationImpl* app) override {} |
102 bool AcceptConnection(ApplicationConnection* connection) override { | 102 bool AcceptConnection(ApplicationConnection* connection) override { |
103 connection->AddService<ContentHandler>(this); | 103 connection->AddService<ContentHandler>(this); |
104 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); | 104 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 // InterfaceFactory<ContentHandler>: | 108 // InterfaceFactory<mojom::ContentHandler>: |
109 void Create(ApplicationConnection* connection, | 109 void Create(ApplicationConnection* connection, |
110 InterfaceRequest<ContentHandler> request) override { | 110 InterfaceRequest<mojom::ContentHandler> request) override { |
111 content_handler_bindings_.AddBinding(this, std::move(request)); | 111 content_handler_bindings_.AddBinding(this, std::move(request)); |
112 } | 112 } |
113 | 113 |
114 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: | 114 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: |
115 void Create(ApplicationConnection* connection, | 115 void Create(ApplicationConnection* connection, |
116 InterfaceRequest<test::mojom::ApplicationPackageApptestService> | 116 InterfaceRequest<test::mojom::ApplicationPackageApptestService> |
117 request) override { | 117 request) override { |
118 bindings_.AddBinding(this, std::move(request)); | 118 bindings_.AddBinding(this, std::move(request)); |
119 } | 119 } |
120 | 120 |
121 // ContentHandler: | 121 // mojom::ContentHandler: |
122 void StartApplication(InterfaceRequest<Application> request, | 122 void StartApplication(InterfaceRequest<mojom::Application> request, |
123 URLResponsePtr response, | 123 URLResponsePtr response, |
124 const Callback<void()>& destruct_callback) override { | 124 const Callback<void()>& destruct_callback) override { |
125 const std::string url = response->url; | 125 const std::string url = response->url; |
126 if (url == "mojo://package_test_a/") { | 126 if (url == "mojo://package_test_a/") { |
127 new ProvidedApplicationDelegate("A", std::move(request), | 127 new ProvidedApplicationDelegate("A", std::move(request), |
128 destruct_callback); | 128 destruct_callback); |
129 } else if (url == "mojo://package_test_b/") { | 129 } else if (url == "mojo://package_test_b/") { |
130 new ProvidedApplicationDelegate("B", std::move(request), | 130 new ProvidedApplicationDelegate("B", std::move(request), |
131 destruct_callback); | 131 destruct_callback); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 // test::mojom::ApplicationPackageApptestService: | 135 // test::mojom::ApplicationPackageApptestService: |
136 void GetName(const GetNameCallback& callback) override { | 136 void GetName(const GetNameCallback& callback) override { |
137 callback.Run("ROOT"); | 137 callback.Run("ROOT"); |
138 } | 138 } |
139 | 139 |
140 std::vector<scoped_ptr<ApplicationDelegate>> delegates_; | 140 std::vector<scoped_ptr<ApplicationDelegate>> delegates_; |
141 WeakBindingSet<ContentHandler> content_handler_bindings_; | 141 WeakBindingSet<mojom::ContentHandler> content_handler_bindings_; |
142 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; | 142 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; |
143 | 143 |
144 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptestDelegate); | 144 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptestDelegate); |
145 }; | 145 }; |
146 | 146 |
147 void ReceiveName(std::string* out_name, | 147 void ReceiveName(std::string* out_name, |
148 base::RunLoop* loop, | 148 base::RunLoop* loop, |
149 const String& name) { | 149 const String& name) { |
150 *out_name = name; | 150 *out_name = name; |
151 loop->Quit(); | 151 loop->Quit(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 base::RunLoop run_loop; | 201 base::RunLoop run_loop; |
202 std::string b_name; | 202 std::string b_name; |
203 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop)); | 203 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop)); |
204 run_loop.Run(); | 204 run_loop.Run(); |
205 EXPECT_EQ("B", b_name); | 205 EXPECT_EQ("B", b_name); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 } // namespace shell | 209 } // namespace shell |
210 } // namespace mojo | 210 } // namespace mojo |
OLD | NEW |