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<ServiceProvider> { | 22 class ServiceManager::ServiceFactory : public InterfaceImpl<ServiceProvider> { |
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; | |
36 client()->ConnectToService(url_.spec(), handle.Pass()); | 34 client()->ConnectToService(url_.spec(), handle.Pass()); |
37 } | |
38 } | 35 } |
39 | 36 |
40 // ServiceProvider implementation: | 37 // ServiceProvider implementation: |
41 virtual void ConnectToService(const String& url, | 38 virtual void ConnectToService(const String& url, |
42 ScopedMessagePipeHandle client_pipe) OVERRIDE { | 39 ScopedMessagePipeHandle client_pipe) OVERRIDE { |
43 manager_->ConnectToService(GURL(url.To<std::string>()), client_pipe.Pass()); | 40 manager_->ConnectToService(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::TestServiceProviderConnection | 56 class ServiceManager::TestAPI::TestServiceProviderConnection |
60 : public InterfaceImpl<ServiceProvider> { | 57 : public InterfaceImpl<ServiceProvider> { |
61 public: | 58 public: |
62 explicit TestServiceProviderConnection(ServiceManager* manager) | 59 explicit TestServiceProviderConnection(ServiceManager* manager) |
63 : manager_(manager) {} | 60 : manager_(manager) {} |
64 virtual ~TestServiceProviderConnection() {} | 61 virtual ~TestServiceProviderConnection() {} |
65 | 62 |
66 virtual void OnConnectionError() OVERRIDE { | 63 virtual void OnConnectionError() OVERRIDE { |
67 // TODO(darin): How should we handle this error? | 64 // TODO(darin): How should we handle this error? |
68 } | 65 } |
69 | 66 |
70 // ServiceProvider: | 67 // ServiceProvider: |
71 virtual void ConnectToService(const String& url, | 68 virtual void ConnectToService(const String& url, |
72 ScopedMessagePipeHandle client_pipe) OVERRIDE { | 69 ScopedMessagePipeHandle client_pipe) OVERRIDE { |
73 manager_->ConnectToService(GURL(url.To<std::string>()), client_pipe.Pass()); | 70 manager_->ConnectToService(GURL(url), client_pipe.Pass()); |
74 } | 71 } |
75 | 72 |
76 private: | 73 private: |
77 ServiceManager* manager_; | 74 ServiceManager* manager_; |
78 | 75 |
79 DISALLOW_COPY_AND_ASSIGN(TestServiceProviderConnection); | 76 DISALLOW_COPY_AND_ASSIGN(TestServiceProviderConnection); |
80 }; | 77 }; |
81 | 78 |
82 // static | 79 // static |
83 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { | 80 ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // Called from ~ServiceFactory, so we do not need to call Destroy here. | 178 // Called from ~ServiceFactory, so we do not need to call Destroy here. |
182 const GURL url = service_factory->url(); | 179 const GURL url = service_factory->url(); |
183 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); | 180 URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url); |
184 DCHECK(it != url_to_service_factory_.end()); | 181 DCHECK(it != url_to_service_factory_.end()); |
185 delete it->second; | 182 delete it->second; |
186 url_to_service_factory_.erase(it); | 183 url_to_service_factory_.erase(it); |
187 GetLoaderForURL(url)->OnServiceError(this, url); | 184 GetLoaderForURL(url)->OnServiceError(this, url); |
188 } | 185 } |
189 | 186 |
190 } // namespace mojo | 187 } // namespace mojo |
OLD | NEW |