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

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

Issue 214513009: Change ServiceManager::SetLoaderForUrl() to SetLoaderForScheme() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Leave GetLoaderForURL() as is Created 6 years, 9 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
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 14 matching lines...) Expand all
25 public: 25 public:
26 ServiceFactory(ServiceManager* manager, const GURL& url) 26 ServiceFactory(ServiceManager* manager, const GURL& url)
27 : manager_(manager), 27 : manager_(manager),
28 url_(url) { 28 url_(url) {
29 InterfacePipe<Shell> pipe; 29 InterfacePipe<Shell> pipe;
30 shell_client_.reset(pipe.handle_to_peer.Pass(), this, this); 30 shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
31 manager_->GetLoaderForURL(url)->LoadService(manager_, 31 manager_->GetLoaderForURL(url)->LoadService(manager_,
32 url, 32 url,
33 pipe.handle_to_self.Pass()); 33 pipe.handle_to_self.Pass());
34 } 34 }
35
35 virtual ~ServiceFactory() {} 36 virtual ~ServiceFactory() {}
36 37
37 void ConnectToClient(ScopedMessagePipeHandle handle) { 38 void ConnectToClient(ScopedMessagePipeHandle handle) {
38 if (handle.is_valid()) { 39 if (handle.is_valid()) {
39 AllocationScope scope; 40 AllocationScope scope;
40 shell_client_->AcceptConnection(url_.spec(), handle.Pass()); 41 shell_client_->AcceptConnection(url_.spec(), handle.Pass());
41 } 42 }
42 } 43 }
43 44
44 virtual void Connect(const String& url, 45 virtual void Connect(const String& url,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 82 }
82 83
83 // static 84 // static
84 ServiceManager* ServiceManager::GetInstance() { 85 ServiceManager* ServiceManager::GetInstance() {
85 static base::LazyInstance<ServiceManager> instance = 86 static base::LazyInstance<ServiceManager> instance =
86 LAZY_INSTANCE_INITIALIZER; 87 LAZY_INSTANCE_INITIALIZER;
87 has_created_instance = true; 88 has_created_instance = true;
88 return &instance.Get(); 89 return &instance.Get();
89 } 90 }
90 91
91 void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& gurl) { 92 void ServiceManager::SetLoaderForScheme(ServiceLoader* loader,
92 DCHECK(url_to_loader_.find(gurl) == url_to_loader_.end()); 93 const std::string& scheme) {
93 url_to_loader_[gurl] = loader; 94 DCHECK(scheme_to_loader_.find(scheme) == scheme_to_loader_.end());
95 scheme_to_loader_[scheme] = loader;
94 } 96 }
95 97
96 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& gurl) { 98 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& gurl) {
97 LoaderMap::const_iterator it = url_to_loader_.find(gurl); 99 LoaderMap::const_iterator it = scheme_to_loader_.find(gurl.scheme());
98 if (it != url_to_loader_.end()) 100 if (it != scheme_to_loader_.end())
99 return it->second; 101 return it->second;
100 DCHECK(default_loader_); 102 DCHECK(default_loader_);
101 return default_loader_; 103 return default_loader_;
102 } 104 }
103 105
104 void ServiceManager::Connect(const GURL& url, 106 void ServiceManager::Connect(const GURL& url,
105 ScopedMessagePipeHandle client_handle) { 107 ScopedMessagePipeHandle client_handle) {
106 ServiceFactoryMap::const_iterator service_it = 108 ServiceFactoryMap::const_iterator service_it =
107 url_to_service_factory_.find(url); 109 url_to_service_factory_.find(url);
108 ServiceFactory* service_factory; 110 ServiceFactory* service_factory;
109 if (service_it != url_to_service_factory_.end()) { 111 if (service_it != url_to_service_factory_.end()) {
110 service_factory = service_it->second; 112 service_factory = service_it->second;
111 } else { 113 } else {
112 service_factory = new ServiceFactory(this, url); 114 service_factory = new ServiceFactory(this, url);
113 url_to_service_factory_[url] = service_factory; 115 url_to_service_factory_[url] = service_factory;
114 } 116 }
115 service_factory->ConnectToClient(client_handle.Pass()); 117 service_factory->ConnectToClient(client_handle.Pass());
116 } 118 }
117 119
118 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) { 120 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
119 const GURL url = service_factory->url(); 121 const GURL url = service_factory->url();
120 ServiceFactoryMap::iterator it = url_to_service_factory_.find(url); 122 ServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
121 DCHECK(it != url_to_service_factory_.end()); 123 DCHECK(it != url_to_service_factory_.end());
122 delete it->second; 124 delete it->second;
123 url_to_service_factory_.erase(it); 125 url_to_service_factory_.erase(it);
124 GetLoaderForURL(url)->OnServiceError(this, url); 126 GetLoaderForURL(url)->OnServiceError(this, url);
125 } 127 }
126 128
127 } // namespace mojo 129 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698