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

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

Issue 187183002: Add creation of ServiceManager to Content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge problem 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
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/service_manager/service_manager_export.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>
6
5 #include "mojo/service_manager/service_manager.h" 7 #include "mojo/service_manager/service_manager.h"
6 8
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "mojo/public/bindings/allocation_scope.h" 12 #include "mojo/public/bindings/allocation_scope.h"
11 #include "mojo/public/bindings/error_handler.h" 13 #include "mojo/public/bindings/error_handler.h"
12 #include "mojo/public/bindings/remote_ptr.h" 14 #include "mojo/public/bindings/remote_ptr.h"
13 #include "mojo/service_manager/service_loader.h" 15 #include "mojo/service_manager/service_loader.h"
14 16
15 namespace mojo { 17 namespace mojo {
16 18
19 namespace {
20 // Used by TestAPI.
21 bool has_created_instance = false;
22 }
23
17 class ServiceManager::ServiceFactory : public Shell, public ErrorHandler { 24 class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
18 public: 25 public:
19 ServiceFactory(ServiceManager* manager, const GURL& url) 26 ServiceFactory(ServiceManager* manager, const GURL& url)
20 : manager_(manager), 27 : manager_(manager),
21 url_(url) { 28 url_(url) {
22 InterfacePipe<Shell> pipe; 29 InterfacePipe<Shell> pipe;
23 shell_client_.reset(pipe.handle_to_peer.Pass(), this, this); 30 shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
24 manager_->GetLoaderForURL(url)->LoadService(manager_, 31 manager_->GetLoaderForURL(url)->LoadService(manager_,
25 url, 32 url,
26 pipe.handle_to_self.Pass()); 33 pipe.handle_to_self.Pass());
(...skipping 18 matching lines...) Expand all
45 52
46 const GURL& url() const { return url_; } 53 const GURL& url() const { return url_; }
47 54
48 private: 55 private:
49 ServiceManager* const manager_; 56 ServiceManager* const manager_;
50 const GURL url_; 57 const GURL url_;
51 RemotePtr<ShellClient> shell_client_; 58 RemotePtr<ShellClient> shell_client_;
52 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); 59 DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
53 }; 60 };
54 61
62 // static
63 bool ServiceManager::TestAPI::HasCreatedInstance() {
64 return has_created_instance;
65 }
66
55 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { 67 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
56 return manager_->url_to_service_factory_.find(url) != 68 return manager_->url_to_service_factory_.find(url) !=
57 manager_->url_to_service_factory_.end(); 69 manager_->url_to_service_factory_.end();
58 } 70 }
59 71
60 ServiceManager::ServiceManager() : default_loader_(NULL) { 72 ServiceManager::ServiceManager() : default_loader_(NULL) {
61 } 73 }
62 74
63 ServiceManager::~ServiceManager() { 75 ServiceManager::~ServiceManager() {
64 for (ServiceFactoryMap::iterator it = url_to_service_factory_.begin(); 76 for (ServiceFactoryMap::iterator it = url_to_service_factory_.begin();
65 it != url_to_service_factory_.end(); ++it) { 77 it != url_to_service_factory_.end(); ++it) {
66 delete it->second; 78 delete it->second;
67 } 79 }
68 url_to_service_factory_.clear(); 80 url_to_service_factory_.clear();
69 } 81 }
70 82
71 // static 83 // static
72 ServiceManager* GetInstance() { 84 ServiceManager* ServiceManager::GetInstance() {
73 static base::LazyInstance<ServiceManager> instance = 85 static base::LazyInstance<ServiceManager> instance =
74 LAZY_INSTANCE_INITIALIZER; 86 LAZY_INSTANCE_INITIALIZER;
87 has_created_instance = true;
75 return &instance.Get(); 88 return &instance.Get();
76 } 89 }
77 90
78 void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& gurl) { 91 void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& gurl) {
79 DCHECK(url_to_loader_.find(gurl) == url_to_loader_.end()); 92 DCHECK(url_to_loader_.find(gurl) == url_to_loader_.end());
80 url_to_loader_[gurl] = loader; 93 url_to_loader_[gurl] = loader;
81 } 94 }
82 95
83 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& gurl) { 96 ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& gurl) {
84 LoaderMap::const_iterator it = url_to_loader_.find(gurl); 97 LoaderMap::const_iterator it = url_to_loader_.find(gurl);
(...skipping 19 matching lines...) Expand all
104 117
105 void ServiceManager::RemoveServiceFactory(ServiceFactory* service_factory) { 118 void ServiceManager::RemoveServiceFactory(ServiceFactory* service_factory) {
106 ServiceFactoryMap::iterator it = 119 ServiceFactoryMap::iterator it =
107 url_to_service_factory_.find(service_factory->url()); 120 url_to_service_factory_.find(service_factory->url());
108 DCHECK(it != url_to_service_factory_.end()); 121 DCHECK(it != url_to_service_factory_.end());
109 delete it->second; 122 delete it->second;
110 url_to_service_factory_.erase(it); 123 url_to_service_factory_.erase(it);
111 } 124 }
112 125
113 } // namespace mojo 126 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/service_manager/service_manager_export.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698