| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "mojo/service_manager/service_manager.h" | 7 #include "mojo/service_manager/service_manager.h" |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { | 88 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { |
| 89 return manager_->url_to_shell_impl_.find(url) != | 89 return manager_->url_to_shell_impl_.find(url) != |
| 90 manager_->url_to_shell_impl_.end(); | 90 manager_->url_to_shell_impl_.end(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ServiceManager::ServiceManager() : interceptor_(NULL) { | 93 ServiceManager::ServiceManager() : interceptor_(NULL) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 ServiceManager::~ServiceManager() { | 96 ServiceManager::~ServiceManager() { |
| 97 STLDeleteValues(&url_to_shell_impl_); | 97 DCHECK(url_to_shell_impl_.empty()); |
| 98 STLDeleteValues(&url_to_loader_); | 98 STLDeleteValues(&url_to_loader_); |
| 99 STLDeleteValues(&scheme_to_loader_); | 99 STLDeleteValues(&scheme_to_loader_); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ServiceManager::TerminateShellConnections() { |
| 103 STLDeleteValues(&url_to_shell_impl_); |
| 104 } |
| 105 |
| 102 // static | 106 // static |
| 103 ServiceManager* ServiceManager::GetInstance() { | 107 ServiceManager* ServiceManager::GetInstance() { |
| 104 static base::LazyInstance<ServiceManager> instance = | 108 static base::LazyInstance<ServiceManager> instance = |
| 105 LAZY_INSTANCE_INITIALIZER; | 109 LAZY_INSTANCE_INITIALIZER; |
| 106 has_created_instance = true; | 110 has_created_instance = true; |
| 107 return &instance.Get(); | 111 return &instance.Get(); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void ServiceManager::ConnectToApplication(const GURL& url, | 114 void ServiceManager::ConnectToApplication(const GURL& url, |
| 111 const GURL& requestor_url, | 115 const GURL& requestor_url, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 154 } |
| 151 | 155 |
| 152 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) { | 156 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) { |
| 153 URLToLoaderMap::const_iterator url_it = url_to_loader_.find(url); | 157 URLToLoaderMap::const_iterator url_it = url_to_loader_.find(url); |
| 154 if (url_it != url_to_loader_.end()) | 158 if (url_it != url_to_loader_.end()) |
| 155 return url_it->second; | 159 return url_it->second; |
| 156 SchemeToLoaderMap::const_iterator scheme_it = | 160 SchemeToLoaderMap::const_iterator scheme_it = |
| 157 scheme_to_loader_.find(url.scheme()); | 161 scheme_to_loader_.find(url.scheme()); |
| 158 if (scheme_it != scheme_to_loader_.end()) | 162 if (scheme_it != scheme_to_loader_.end()) |
| 159 return scheme_it->second; | 163 return scheme_it->second; |
| 160 DCHECK(default_loader_); | |
| 161 return default_loader_.get(); | 164 return default_loader_.get(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void ServiceManager::OnShellImplError(ShellImpl* shell_impl) { | 167 void ServiceManager::OnShellImplError(ShellImpl* shell_impl) { |
| 165 // Called from ~ShellImpl, so we do not need to call Destroy here. | 168 // Called from ~ShellImpl, so we do not need to call Destroy here. |
| 166 const GURL url = shell_impl->url(); | 169 const GURL url = shell_impl->url(); |
| 167 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); | 170 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); |
| 168 DCHECK(it != url_to_shell_impl_.end()); | 171 DCHECK(it != url_to_shell_impl_.end()); |
| 169 delete it->second; | 172 delete it->second; |
| 170 url_to_shell_impl_.erase(it); | 173 url_to_shell_impl_.erase(it); |
| 171 ServiceLoader* loader = GetLoaderForURL(url); | 174 ServiceLoader* loader = GetLoaderForURL(url); |
| 172 if (loader) | 175 if (loader) |
| 173 loader->OnServiceError(this, url); | 176 loader->OnServiceError(this, url); |
| 174 } | 177 } |
| 175 | 178 |
| 176 ScopedMessagePipeHandle ServiceManager::ConnectToServiceByName( | 179 ScopedMessagePipeHandle ServiceManager::ConnectToServiceByName( |
| 177 const GURL& application_url, | 180 const GURL& application_url, |
| 178 const std::string& interface_name) { | 181 const std::string& interface_name) { |
| 179 StubServiceProvider* stub_sp = new StubServiceProvider; | 182 StubServiceProvider* stub_sp = new StubServiceProvider; |
| 180 ServiceProviderPtr spp; | 183 ServiceProviderPtr spp; |
| 181 BindToProxy(stub_sp, &spp); | 184 BindToProxy(stub_sp, &spp); |
| 182 ConnectToApplication(application_url, GURL(), spp.Pass()); | 185 ConnectToApplication(application_url, GURL(), spp.Pass()); |
| 183 MessagePipe pipe; | 186 MessagePipe pipe; |
| 184 stub_sp->GetRemoteServiceProvider()->ConnectToService( | 187 stub_sp->GetRemoteServiceProvider()->ConnectToService( |
| 185 interface_name, pipe.handle1.Pass()); | 188 interface_name, pipe.handle1.Pass()); |
| 186 return pipe.handle0.Pass(); | 189 return pipe.handle0.Pass(); |
| 187 } | 190 } |
| 188 } // namespace mojo | 191 } // namespace mojo |
| OLD | NEW |