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