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

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

Issue 280003003: Add SetClient method implementation to InterfaceImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "mojo/public/cpp/bindings/allocation_scope.h" 13 #include "mojo/public/cpp/bindings/allocation_scope.h"
14 #include "mojo/service_manager/service_loader.h" 14 #include "mojo/service_manager/service_loader.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 namespace { 18 namespace {
19 // Used by TestAPI. 19 // Used by TestAPI.
20 bool has_created_instance = false; 20 bool has_created_instance = false;
21 } 21 }
22 22
23 class ServiceManager::ServiceFactory : public InterfaceImpl<Shell> { 23 class ServiceManager::ServiceFactory : public InterfaceImpl<Shell> {
24 public: 24 public:
25 ServiceFactory(ServiceManager* manager, const GURL& url) 25 ServiceFactory(ServiceManager* manager, const GURL& url)
26 : manager_(manager), 26 : manager_(manager),
27 url_(url), 27 url_(url) {
28 client_(NULL) {
29 } 28 }
30 29
31 virtual ~ServiceFactory() { 30 virtual ~ServiceFactory() {
32 } 31 }
33 32
34 void ConnectToClient(ScopedMessagePipeHandle handle) { 33 void ConnectToClient(ScopedMessagePipeHandle handle) {
35 if (!handle.is_valid()) { 34 if (!handle.is_valid()) {
36 assert(false); 35 assert(false);
37 return; 36 return;
38 } 37 }
39 AllocationScope scope; 38 AllocationScope scope;
40 client_->AcceptConnection(url_.spec(), handle.Pass()); 39 client()->AcceptConnection(url_.spec(), handle.Pass());
41 } 40 }
42 41
43 // Shell implementation: 42 // Shell implementation:
44 virtual void SetClient(ShellClient* client) OVERRIDE {
45 client_ = client;
46 }
47 virtual void Connect(const String& url, 43 virtual void Connect(const String& url,
48 ScopedMessagePipeHandle client_pipe) OVERRIDE { 44 ScopedMessagePipeHandle client_pipe) OVERRIDE {
49 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass()); 45 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
50 } 46 }
51 47
52 const GURL& url() const { return url_; } 48 const GURL& url() const { return url_; }
53 49
54 private: 50 private:
55 virtual void OnConnectionError() OVERRIDE { 51 virtual void OnConnectionError() OVERRIDE {
56 manager_->OnServiceFactoryError(this); 52 manager_->OnServiceFactoryError(this);
57 } 53 }
58 54
59 ServiceManager* const manager_; 55 ServiceManager* const manager_;
60 const GURL url_; 56 const GURL url_;
61 ShellClient* client_;
62 57
63 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); 58 DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
64 }; 59 };
65 60
66 class ServiceManager::TestAPI::TestShellConnection 61 class ServiceManager::TestAPI::TestShellConnection
67 : public InterfaceImpl<Shell> { 62 : public InterfaceImpl<Shell> {
68 public: 63 public:
69 explicit TestShellConnection(ServiceManager* manager) 64 explicit TestShellConnection(ServiceManager* manager) : manager_(manager) {}
70 : manager_(manager),
71 client_(NULL) {
72 }
73 virtual ~TestShellConnection() {} 65 virtual ~TestShellConnection() {}
74 66
75 virtual void OnConnectionError() OVERRIDE { 67 virtual void OnConnectionError() OVERRIDE {
76 // TODO(darin): How should we handle this error? 68 // TODO(darin): How should we handle this error?
77 } 69 }
78 70
79 // Shell: 71 // Shell:
80 virtual void SetClient(ShellClient* client) OVERRIDE {
81 client_ = client;
82 }
83 virtual void Connect(const String& url, 72 virtual void Connect(const String& url,
84 ScopedMessagePipeHandle client_pipe) OVERRIDE { 73 ScopedMessagePipeHandle client_pipe) OVERRIDE {
85 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass()); 74 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
86 } 75 }
87 76
88 private: 77 private:
89 ServiceManager* manager_; 78 ServiceManager* manager_;
90 ShellClient* client_;
91 79
92 DISALLOW_COPY_AND_ASSIGN(TestShellConnection); 80 DISALLOW_COPY_AND_ASSIGN(TestShellConnection);
93 }; 81 };
94 82
95 // static 83 // static
96 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { 84 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) {
97 } 85 }
98 86
99 ServiceManager::TestAPI::~TestAPI() { 87 ServiceManager::TestAPI::~TestAPI() {
100 } 88 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Called from ~ServiceFactory, so we do not need to call Destroy here. 181 // Called from ~ServiceFactory, so we do not need to call Destroy here.
194 const GURL url = service_factory->url(); 182 const GURL url = service_factory->url();
195 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); 183 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
196 DCHECK(it != url_to_service_factory_.end()); 184 DCHECK(it != url_to_service_factory_.end());
197 delete it->second; 185 delete it->second;
198 url_to_service_factory_.erase(it); 186 url_to_service_factory_.erase(it);
199 GetLoaderForURL(url)->OnServiceError(this, url); 187 GetLoaderForURL(url)->OnServiceError(this, url);
200 } 188 }
201 189
202 } // namespace mojo 190 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698