OLD | NEW |
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" | |
14 #include "mojo/service_manager/service_loader.h" | 13 #include "mojo/service_manager/service_loader.h" |
15 | 14 |
16 namespace mojo { | 15 namespace mojo { |
17 | 16 |
18 namespace { | 17 namespace { |
19 // Used by TestAPI. | 18 // Used by TestAPI. |
20 bool has_created_instance = false; | 19 bool has_created_instance = false; |
21 } | 20 } |
22 | 21 |
23 class ServiceManager::ServiceFactory : public InterfaceImpl<Shell> { | 22 class ServiceManager::ServiceFactory : public InterfaceImpl<Shell> { |
24 public: | 23 public: |
25 ServiceFactory(ServiceManager* manager, const GURL& url) | 24 ServiceFactory(ServiceManager* manager, const GURL& url) |
26 : manager_(manager), | 25 : manager_(manager), |
27 url_(url) { | 26 url_(url) { |
28 } | 27 } |
29 | 28 |
30 virtual ~ServiceFactory() { | 29 virtual ~ServiceFactory() { |
31 } | 30 } |
32 | 31 |
33 void ConnectToClient(ScopedMessagePipeHandle handle) { | 32 void ConnectToClient(ScopedMessagePipeHandle handle) { |
34 if (handle.is_valid()) { | 33 if (handle.is_valid()) |
35 AllocationScope scope; | 34 client()->AcceptConnection(String::From(url_.spec()), handle.Pass()); |
36 client()->AcceptConnection(url_.spec(), handle.Pass()); | |
37 } | |
38 } | 35 } |
39 | 36 |
40 // Shell implementation: | 37 // Shell implementation: |
41 virtual void Connect(const String& url, | 38 virtual void Connect(String url, |
42 ScopedMessagePipeHandle client_pipe) OVERRIDE { | 39 ScopedMessagePipeHandle client_pipe) OVERRIDE { |
43 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass()); | 40 manager_->Connect(GURL(url), client_pipe.Pass()); |
44 } | 41 } |
45 | 42 |
46 const GURL& url() const { return url_; } | 43 const GURL& url() const { return url_; } |
47 | 44 |
48 private: | 45 private: |
49 virtual void OnConnectionError() OVERRIDE { | 46 virtual void OnConnectionError() OVERRIDE { |
50 manager_->OnServiceFactoryError(this); | 47 manager_->OnServiceFactoryError(this); |
51 } | 48 } |
52 | 49 |
53 ServiceManager* const manager_; | 50 ServiceManager* const manager_; |
54 const GURL url_; | 51 const GURL url_; |
55 | 52 |
56 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); | 53 DISALLOW_COPY_AND_ASSIGN(ServiceFactory); |
57 }; | 54 }; |
58 | 55 |
59 class ServiceManager::TestAPI::TestShellConnection | 56 class ServiceManager::TestAPI::TestShellConnection |
60 : public InterfaceImpl<Shell> { | 57 : public InterfaceImpl<Shell> { |
61 public: | 58 public: |
62 explicit TestShellConnection(ServiceManager* manager) : manager_(manager) {} | 59 explicit TestShellConnection(ServiceManager* manager) : manager_(manager) {} |
63 virtual ~TestShellConnection() {} | 60 virtual ~TestShellConnection() {} |
64 | 61 |
65 virtual void OnConnectionError() OVERRIDE { | 62 virtual void OnConnectionError() OVERRIDE { |
66 // TODO(darin): How should we handle this error? | 63 // TODO(darin): How should we handle this error? |
67 } | 64 } |
68 | 65 |
69 // Shell: | 66 // Shell: |
70 virtual void Connect(const String& url, | 67 virtual void Connect(String url, |
71 ScopedMessagePipeHandle client_pipe) OVERRIDE { | 68 ScopedMessagePipeHandle client_pipe) OVERRIDE { |
72 manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass()); | 69 manager_->Connect(GURL(url), client_pipe.Pass()); |
73 } | 70 } |
74 | 71 |
75 private: | 72 private: |
76 ServiceManager* manager_; | 73 ServiceManager* manager_; |
77 | 74 |
78 DISALLOW_COPY_AND_ASSIGN(TestShellConnection); | 75 DISALLOW_COPY_AND_ASSIGN(TestShellConnection); |
79 }; | 76 }; |
80 | 77 |
81 // static | 78 // static |
82 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { | 79 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // Called from ~ServiceFactory, so we do not need to call Destroy here. | 176 // Called from ~ServiceFactory, so we do not need to call Destroy here. |
180 const GURL url = service_factory->url(); | 177 const GURL url = service_factory->url(); |
181 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); | 178 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); |
182 DCHECK(it != url_to_service_factory_.end()); | 179 DCHECK(it != url_to_service_factory_.end()); |
183 delete it->second; | 180 delete it->second; |
184 url_to_service_factory_.erase(it); | 181 url_to_service_factory_.erase(it); |
185 GetLoaderForURL(url)->OnServiceError(this, url); | 182 GetLoaderForURL(url)->OnServiceError(this, url); |
186 } | 183 } |
187 | 184 |
188 } // namespace mojo | 185 } // namespace mojo |
OLD | NEW |