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

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

Issue 1254383016: ApplicationConnection lifetime management changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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
« no previous file with comments | « mojo/shell/application_manager_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 WeakBindingSet<Validator> validator_bindings_; 108 WeakBindingSet<Validator> validator_bindings_;
109 109
110 DISALLOW_COPY_AND_ASSIGN(ConnectionValidator); 110 DISALLOW_COPY_AND_ASSIGN(ConnectionValidator);
111 }; 111 };
112 112
113 // This class models an application who will use the shell to interact with a 113 // This class models an application who will use the shell to interact with a
114 // system service. The shell may limit this application's visibility of the full 114 // system service. The shell may limit this application's visibility of the full
115 // set of interfaces exposed by that service. 115 // set of interfaces exposed by that service.
116 class TestApplication : public ApplicationDelegate { 116 class TestApplication : public ApplicationDelegate {
117 public: 117 public:
118 TestApplication() : app_(nullptr) {} 118 TestApplication() : app_(nullptr) {}
119 ~TestApplication() override {} 119 ~TestApplication() override {}
120 120
121 private: 121 private:
122 // Overridden from ApplicationDelegate: 122 // Overridden from ApplicationDelegate:
123 void Initialize(ApplicationImpl* app) override { 123 void Initialize(ApplicationImpl* app) override {
124 app_ = app; 124 app_ = app;
125 } 125 }
126 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 126 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
127 // TestApplications receive their Validator via the inbound connection. 127 // TestApplications receive their Validator via the inbound connection.
128 connection->ConnectToService(&validator_); 128 connection->ConnectToService(&validator_);
129 129
130 URLRequestPtr request(URLRequest::New()); 130 URLRequestPtr request(URLRequest::New());
131 request->url = String::From("test:service"); 131 request->url = String::From("test:service");
132 ApplicationConnection* connection1 = 132 connection1_ = app_->ConnectToApplication(request.Pass());
133 app_->ConnectToApplication(request.Pass()); 133 connection1_->SetRemoteServiceProviderConnectionErrorHandler(
134 connection1->SetRemoteServiceProviderConnectionErrorHandler(
135 base::Bind(&TestApplication::ConnectionClosed, 134 base::Bind(&TestApplication::ConnectionClosed,
136 base::Unretained(this), "test:service")); 135 base::Unretained(this), "test:service"));
137 136
138 URLRequestPtr request2(URLRequest::New()); 137 URLRequestPtr request2(URLRequest::New());
139 request2->url = String::From("test:service2"); 138 request2->url = String::From("test:service2");
140 ApplicationConnection* connection2 = 139 connection2_ = app_->ConnectToApplication(request2.Pass());
141 app_->ConnectToApplication(request2.Pass()); 140 connection2_->SetRemoteServiceProviderConnectionErrorHandler(
142 connection2->SetRemoteServiceProviderConnectionErrorHandler(
143 base::Bind(&TestApplication::ConnectionClosed, 141 base::Bind(&TestApplication::ConnectionClosed,
144 base::Unretained(this), "test:service2")); 142 base::Unretained(this), "test:service2"));
145 return true; 143 return true;
146 } 144 }
147 145
148 void ConnectionClosed(const std::string& service_url) { 146 void ConnectionClosed(const std::string& service_url) {
149 validator_->ConnectionClosed(app_->url(), service_url); 147 validator_->ConnectionClosed(app_->url(), service_url);
150 } 148 }
151 149
152 ApplicationImpl* app_; 150 ApplicationImpl* app_;
153 ValidatorPtr validator_; 151 ValidatorPtr validator_;
152 scoped_ptr<ApplicationConnection> connection1_;
153 scoped_ptr<ApplicationConnection> connection2_;
154 154
155 DISALLOW_COPY_AND_ASSIGN(TestApplication); 155 DISALLOW_COPY_AND_ASSIGN(TestApplication);
156 }; 156 };
157 157
158 class TestContentHandler : public ApplicationDelegate, 158 class TestContentHandler : public ApplicationDelegate,
159 public InterfaceFactory<ContentHandler>, 159 public InterfaceFactory<ContentHandler>,
160 public ContentHandler { 160 public ContentHandler {
161 public: 161 public:
162 TestContentHandler() : app_(nullptr) {} 162 TestContentHandler() : app_(nullptr) {}
163 ~TestContentHandler() override {} 163 ~TestContentHandler() override {}
(...skipping 10 matching lines...) Expand all
174 174
175 // Overridden from InterfaceFactory<ContentHandler>: 175 // Overridden from InterfaceFactory<ContentHandler>:
176 void Create(ApplicationConnection* connection, 176 void Create(ApplicationConnection* connection,
177 InterfaceRequest<ContentHandler> request) override { 177 InterfaceRequest<ContentHandler> request) override {
178 bindings_.AddBinding(this, request.Pass()); 178 bindings_.AddBinding(this, request.Pass());
179 } 179 }
180 180
181 // Overridden from ContentHandler: 181 // Overridden from ContentHandler:
182 void StartApplication(InterfaceRequest<Application> application, 182 void StartApplication(InterfaceRequest<Application> application,
183 URLResponsePtr response) override { 183 URLResponsePtr response) override {
184 scoped_ptr<ApplicationDelegate> delegate(new TestApplication);
184 embedded_apps_.push_back( 185 embedded_apps_.push_back(
185 new ApplicationImpl(new TestApplication, application.Pass())); 186 new ApplicationImpl(delegate.get(), application.Pass()));
187 embedded_app_delegates_.push_back(delegate.Pass());
186 } 188 }
187 189
188 ApplicationImpl* app_; 190 ApplicationImpl* app_;
189 WeakBindingSet<ContentHandler> bindings_; 191 WeakBindingSet<ContentHandler> bindings_;
192 ScopedVector<ApplicationDelegate> embedded_app_delegates_;
190 ScopedVector<ApplicationImpl> embedded_apps_; 193 ScopedVector<ApplicationImpl> embedded_apps_;
191 194
192 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); 195 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
193 }; 196 };
194 197
195 // This class models a system service that exposes two interfaces, Safe and 198 // This class models a system service that exposes two interfaces, Safe and
196 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications. 199 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications.
197 class ServiceApplication : public ApplicationDelegate, 200 class ServiceApplication : public ApplicationDelegate,
198 public InterfaceFactory<Safe>, 201 public InterfaceFactory<Safe>,
199 public InterfaceFactory<Unsafe>, 202 public InterfaceFactory<Unsafe>,
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 RunTest(); 545 RunTest();
543 } 546 }
544 547
545 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { 548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) {
546 RunContentHandlerTest(); 549 RunContentHandlerTest();
547 } 550 }
548 551
549 } // namespace 552 } // namespace
550 } // namespace shell 553 } // namespace shell
551 } // namespace mojo 554 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698