| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/application/application.h" | 6 #include "mojo/public/cpp/application/application.h" |
| 7 #include "mojo/public/cpp/environment/environment.h" | 7 #include "mojo/public/cpp/environment/environment.h" |
| 8 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 8 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 9 #include "mojo/service_manager/service_loader.h" | 9 #include "mojo/service_manager/service_loader.h" |
| 10 #include "mojo/service_manager/service_manager.h" | 10 #include "mojo/service_manager/service_manager.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 int num_connects() const { return num_connects_; } | 143 int num_connects() const { return num_connects_; } |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 virtual void LoadService( | 146 virtual void LoadService( |
| 147 ServiceManager* manager, | 147 ServiceManager* manager, |
| 148 const GURL& url, | 148 const GURL& url, |
| 149 ScopedMessagePipeHandle service_provider_handle) OVERRIDE { | 149 ScopedMessagePipeHandle service_provider_handle) OVERRIDE { |
| 150 BindServiceProvider(service_provider_handle.Pass()); | 150 BindServiceProvider(service_provider_handle.Pass()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 virtual void ConnectToService(const mojo::String& service_url, | 153 virtual bool AllowIncomingConnection(const mojo::String& service_name, |
| 154 const mojo::String& service_name, | 154 const mojo::String& requestor_url) |
| 155 ScopedMessagePipeHandle client_handle, | |
| 156 const mojo::String& requestor_url) | |
| 157 MOJO_OVERRIDE { | 155 MOJO_OVERRIDE { |
| 158 if (requestor_url_.empty() || requestor_url_ == requestor_url) { | 156 if (requestor_url_.empty() || requestor_url_ == requestor_url) { |
| 159 ++num_connects_; | 157 ++num_connects_; |
| 160 Application::ConnectToService(service_url, | 158 return true; |
| 161 service_name, | |
| 162 client_handle.Pass(), | |
| 163 requestor_url); | |
| 164 } else { | 159 } else { |
| 165 base::MessageLoop::current()->Quit(); | 160 base::MessageLoop::current()->Quit(); |
| 161 return false; |
| 166 } | 162 } |
| 167 } | 163 } |
| 168 | 164 |
| 169 virtual void OnServiceError(ServiceManager* manager, | 165 virtual void OnServiceError(ServiceManager* manager, |
| 170 const GURL& url) OVERRIDE {} | 166 const GURL& url) OVERRIDE {} |
| 171 std::string requestor_url_; | 167 std::string requestor_url_; |
| 172 int num_connects_; | 168 int num_connects_; |
| 173 }; | 169 }; |
| 174 | 170 |
| 175 class TestServiceInterceptor : public ServiceManager::Interceptor { | 171 class TestServiceInterceptor : public ServiceManager::Interceptor { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 363 |
| 368 std::string url("test:test3"); | 364 std::string url("test:test3"); |
| 369 TestServicePtr test_service; | 365 TestServicePtr test_service; |
| 370 sm.ConnectTo(GURL(url), &test_service, GURL()); | 366 sm.ConnectTo(GURL(url), &test_service, GURL()); |
| 371 EXPECT_EQ(1, interceptor.call_count()); | 367 EXPECT_EQ(1, interceptor.call_count()); |
| 372 EXPECT_EQ(url, interceptor.url_spec()); | 368 EXPECT_EQ(url, interceptor.url_spec()); |
| 373 EXPECT_EQ(1, default_loader->num_loads()); | 369 EXPECT_EQ(1, default_loader->num_loads()); |
| 374 } | 370 } |
| 375 | 371 |
| 376 } // namespace mojo | 372 } // namespace mojo |
| OLD | NEW |