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

Side by Side Diff: mojo/service_manager/service_manager.cc

Issue 225203002: Mojo Spy core first cut (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gcc fix Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/shell/context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // static 63 // static
64 bool ServiceManager::TestAPI::HasCreatedInstance() { 64 bool ServiceManager::TestAPI::HasCreatedInstance() {
65 return has_created_instance; 65 return has_created_instance;
66 } 66 }
67 67
68 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { 68 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
69 return manager_->url_to_service_factory_.find(url) != 69 return manager_->url_to_service_factory_.find(url) !=
70 manager_->url_to_service_factory_.end(); 70 manager_->url_to_service_factory_.end();
71 } 71 }
72 72
73 ServiceManager::ServiceManager() : default_loader_(NULL) { 73 ServiceManager::ServiceManager()
74 : default_loader_(NULL),
75 interceptor_(NULL) {
74 } 76 }
75 77
76 ServiceManager::~ServiceManager() { 78 ServiceManager::~ServiceManager() {
77 for (URLToServiceFactoryMap::iterator it = url_to_service_factory_.begin(); 79 for (URLToServiceFactoryMap::iterator it = url_to_service_factory_.begin();
78 it != url_to_service_factory_.end(); ++it) { 80 it != url_to_service_factory_.end(); ++it) {
79 delete it->second; 81 delete it->second;
80 } 82 }
81 url_to_service_factory_.clear(); 83 url_to_service_factory_.clear();
82 } 84 }
83 85
84 // static 86 // static
85 ServiceManager* ServiceManager::GetInstance() { 87 ServiceManager* ServiceManager::GetInstance() {
86 static base::LazyInstance<ServiceManager> instance = 88 static base::LazyInstance<ServiceManager> instance =
87 LAZY_INSTANCE_INITIALIZER; 89 LAZY_INSTANCE_INITIALIZER;
88 has_created_instance = true; 90 has_created_instance = true;
89 return &instance.Get(); 91 return &instance.Get();
90 } 92 }
91 93
92 void ServiceManager::Connect(const GURL& url, 94 void ServiceManager::Connect(const GURL& url,
93 ScopedMessagePipeHandle client_handle) { 95 ScopedMessagePipeHandle client_handle) {
94 URLToServiceFactoryMap::const_iterator service_it = 96 URLToServiceFactoryMap::const_iterator service_it =
95 url_to_service_factory_.find(url); 97 url_to_service_factory_.find(url);
96 ServiceFactory* service_factory; 98 ServiceFactory* service_factory;
97 if (service_it != url_to_service_factory_.end()) { 99 if (service_it != url_to_service_factory_.end()) {
98 service_factory = service_it->second; 100 service_factory = service_it->second;
99 } else { 101 } else {
100 service_factory = new ServiceFactory(this, url); 102 service_factory = new ServiceFactory(this, url);
101 url_to_service_factory_[url] = service_factory; 103 url_to_service_factory_[url] = service_factory;
102 } 104 }
103 service_factory->ConnectToClient(client_handle.Pass()); 105 if (interceptor_) {
106 service_factory->ConnectToClient(
107 interceptor_->OnConnectToClient(url, client_handle.Pass()));
108 } else {
109 service_factory->ConnectToClient(client_handle.Pass());
110 }
104 } 111 }
105 112
106 void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& url) { 113 void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& url) {
107 DCHECK(url_to_loader_.find(url) == url_to_loader_.end()); 114 DCHECK(url_to_loader_.find(url) == url_to_loader_.end());
108 url_to_loader_[url] = loader; 115 url_to_loader_[url] = loader;
109 } 116 }
110 117
111 void ServiceManager::SetLoaderForScheme(ServiceLoader* loader, 118 void ServiceManager::SetLoaderForScheme(ServiceLoader* loader,
112 const std::string& scheme) { 119 const std::string& scheme) {
113 DCHECK(scheme_to_loader_.find(scheme) == scheme_to_loader_.end()); 120 DCHECK(scheme_to_loader_.find(scheme) == scheme_to_loader_.end());
114 scheme_to_loader_[scheme] = loader; 121 scheme_to_loader_[scheme] = loader;
115 } 122 }
116 123
124 void ServiceManager::SetInterceptor(Interceptor* interceptor) {
125 interceptor_ = interceptor;
126 }
127
117 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) { 128 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) {
118 URLToLoaderMap::const_iterator url_it = url_to_loader_.find(url); 129 URLToLoaderMap::const_iterator url_it = url_to_loader_.find(url);
119 if (url_it != url_to_loader_.end()) 130 if (url_it != url_to_loader_.end())
120 return url_it->second; 131 return url_it->second;
121 SchemeToLoaderMap::const_iterator scheme_it = 132 SchemeToLoaderMap::const_iterator scheme_it =
122 scheme_to_loader_.find(url.scheme()); 133 scheme_to_loader_.find(url.scheme());
123 if (scheme_it != scheme_to_loader_.end()) 134 if (scheme_it != scheme_to_loader_.end())
124 return scheme_it->second; 135 return scheme_it->second;
125 DCHECK(default_loader_); 136 DCHECK(default_loader_);
126 return default_loader_; 137 return default_loader_;
127 } 138 }
128 139
129 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) { 140 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
130 const GURL url = service_factory->url(); 141 const GURL url = service_factory->url();
131 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); 142 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
132 DCHECK(it != url_to_service_factory_.end()); 143 DCHECK(it != url_to_service_factory_.end());
133 delete it->second; 144 delete it->second;
134 url_to_service_factory_.erase(it); 145 url_to_service_factory_.erase(it);
135 GetLoaderForURL(url)->OnServiceError(this, url); 146 GetLoaderForURL(url)->OnServiceError(this, url);
136 } 147 }
137 148
138 } // namespace mojo 149 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/shell/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698