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

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

Issue 256133002: Changes view manager test to connect via shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge to trunk Created 6 years, 7 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 virtual void OnError() OVERRIDE { 51 virtual void OnError() OVERRIDE {
52 manager_->OnServiceFactoryError(this); 52 manager_->OnServiceFactoryError(this);
53 } 53 }
54 54
55 const GURL& url() const { return url_; } 55 const GURL& url() const { return url_; }
56 56
57 private: 57 private:
58 ServiceManager* const manager_; 58 ServiceManager* const manager_;
59 const GURL url_; 59 const GURL url_;
60 RemotePtr<ShellClient> shell_client_; 60 RemotePtr<ShellClient> shell_client_;
61
61 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); 62 DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
62 }; 63 };
63 64
65 class ServiceManager::TestAPI::TestShellConnection
66 : public Shell,
67 public ErrorHandler {
68 public:
69 explicit TestShellConnection(ServiceManager* manager) : manager_(manager) {
70 InterfacePipe<Shell> pipe;
71 shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
72 shell_handle_ = pipe.handle_to_self.Pass();
73 }
74 virtual ~TestShellConnection() {}
75
76 ScopedShellHandle GetShellHandle() {
77 return shell_handle_.Pass();
78 }
79
80 // Shell:
81 virtual void Connect(const String& url,
82 ScopedMessagePipeHandle client_pipe) OVERRIDE {
83 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
84 }
85
86 virtual void OnError() OVERRIDE {
87 }
88
89 private:
90 ServiceManager* manager_;
91 RemotePtr<ShellClient> shell_client_;
92 ScopedShellHandle shell_handle_;
93
94 DISALLOW_COPY_AND_ASSIGN(TestShellConnection);
95 };
96
64 // static 97 // static
98 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) {
99 }
100
101 ServiceManager::TestAPI::~TestAPI() {
102 }
103
65 bool ServiceManager::TestAPI::HasCreatedInstance() { 104 bool ServiceManager::TestAPI::HasCreatedInstance() {
66 return has_created_instance; 105 return has_created_instance;
67 } 106 }
68 107
108 ScopedShellHandle ServiceManager::TestAPI::GetShellHandle() {
109 if (!shell_connection_.get())
110 shell_connection_.reset(new TestShellConnection(manager_));
111 return shell_connection_->GetShellHandle().Pass();
112 }
113
69 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { 114 bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
70 return manager_->url_to_service_factory_.find(url) != 115 return manager_->url_to_service_factory_.find(url) !=
71 manager_->url_to_service_factory_.end(); 116 manager_->url_to_service_factory_.end();
72 } 117 }
73 118
74 ServiceManager::ServiceManager() 119 ServiceManager::ServiceManager()
75 : interceptor_(NULL) { 120 : interceptor_(NULL) {
76 } 121 }
77 122
78 ServiceManager::~ServiceManager() { 123 ServiceManager::~ServiceManager() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) { 188 void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
144 const GURL url = service_factory->url(); 189 const GURL url = service_factory->url();
145 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); 190 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
146 DCHECK(it != url_to_service_factory_.end()); 191 DCHECK(it != url_to_service_factory_.end());
147 delete it->second; 192 delete it->second;
148 url_to_service_factory_.erase(it); 193 url_to_service_factory_.erase(it);
149 GetLoaderForURL(url)->OnServiceError(this, url); 194 GetLoaderForURL(url)->OnServiceError(this, url);
150 } 195 }
151 196
152 } // namespace mojo 197 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager.h ('k') | mojo/services/view_manager/view_manager_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698