OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/application_manager/application_manager.h" | 5 #include "mojo/application_manager/application_manager.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 namespace { | 23 namespace { |
24 // Used by TestAPI. | 24 // Used by TestAPI. |
25 bool has_created_instance = false; | 25 bool has_created_instance = false; |
26 | 26 |
27 class StubServiceProvider : public InterfaceImpl<ServiceProvider> { | 27 class StubServiceProvider : public InterfaceImpl<ServiceProvider> { |
28 public: | 28 public: |
29 ServiceProvider* GetRemoteServiceProvider() { return client(); } | 29 ServiceProvider* GetRemoteServiceProvider() { return client(); } |
30 | 30 |
31 private: | 31 private: |
32 virtual void ConnectToService( | 32 void ConnectToService(const String& service_name, |
33 const String& service_name, | 33 ScopedMessagePipeHandle client_handle) override {} |
34 ScopedMessagePipeHandle client_handle) override {} | |
35 }; | 34 }; |
36 | 35 |
37 } // namespace | 36 } // namespace |
38 | 37 |
39 ApplicationManager::Delegate::~Delegate() {} | 38 ApplicationManager::Delegate::~Delegate() {} |
40 | 39 |
41 class ApplicationManager::LoadCallbacksImpl | 40 class ApplicationManager::LoadCallbacksImpl |
42 : public ApplicationLoader::LoadCallbacks { | 41 : public ApplicationLoader::LoadCallbacks { |
43 public: | 42 public: |
44 LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager, | 43 LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager, |
45 const GURL& requested_url, | 44 const GURL& requested_url, |
46 const GURL& requestor_url, | 45 const GURL& requestor_url, |
47 ServiceProviderPtr service_provider) | 46 ServiceProviderPtr service_provider) |
48 : manager_(manager), | 47 : manager_(manager), |
49 requested_url_(requested_url), | 48 requested_url_(requested_url), |
50 requestor_url_(requestor_url), | 49 requestor_url_(requestor_url), |
51 service_provider_(service_provider.Pass()) {} | 50 service_provider_(service_provider.Pass()) {} |
52 | 51 |
53 private: | 52 private: |
54 virtual ~LoadCallbacksImpl() {} | 53 ~LoadCallbacksImpl() override {} |
55 | 54 |
56 // LoadCallbacks implementation | 55 // LoadCallbacks implementation |
57 virtual ScopedMessagePipeHandle RegisterApplication() override { | 56 ScopedMessagePipeHandle RegisterApplication() override { |
58 ScopedMessagePipeHandle shell_handle; | 57 ScopedMessagePipeHandle shell_handle; |
59 if (manager_) { | 58 if (manager_) { |
60 manager_->RegisterLoadedApplication(requested_url_, | 59 manager_->RegisterLoadedApplication(requested_url_, |
61 requestor_url_, | 60 requestor_url_, |
62 service_provider_.Pass(), | 61 service_provider_.Pass(), |
63 &shell_handle); | 62 &shell_handle); |
64 } | 63 } |
65 return shell_handle.Pass(); | 64 return shell_handle.Pass(); |
66 } | 65 } |
67 | 66 |
68 virtual void LoadWithContentHandler(const GURL& content_handler_url, | 67 void LoadWithContentHandler(const GURL& content_handler_url, |
69 URLResponsePtr url_response) override { | 68 URLResponsePtr url_response) override { |
70 if (manager_) { | 69 if (manager_) { |
71 manager_->LoadWithContentHandler(requested_url_, | 70 manager_->LoadWithContentHandler(requested_url_, |
72 requestor_url_, | 71 requestor_url_, |
73 content_handler_url, | 72 content_handler_url, |
74 url_response.Pass(), | 73 url_response.Pass(), |
75 service_provider_.Pass()); | 74 service_provider_.Pass()); |
76 } | 75 } |
77 } | 76 } |
78 | 77 |
79 base::WeakPtr<ApplicationManager> manager_; | 78 base::WeakPtr<ApplicationManager> manager_; |
80 GURL requested_url_; | 79 GURL requested_url_; |
81 GURL requestor_url_; | 80 GURL requestor_url_; |
82 ServiceProviderPtr service_provider_; | 81 ServiceProviderPtr service_provider_; |
83 }; | 82 }; |
84 | 83 |
85 class ApplicationManager::ShellImpl : public InterfaceImpl<Shell> { | 84 class ApplicationManager::ShellImpl : public InterfaceImpl<Shell> { |
86 public: | 85 public: |
87 ShellImpl(ApplicationManager* manager, const GURL& url) | 86 ShellImpl(ApplicationManager* manager, const GURL& url) |
88 : manager_(manager), url_(url) {} | 87 : manager_(manager), url_(url) {} |
89 | 88 |
90 virtual ~ShellImpl() {} | 89 ~ShellImpl() override {} |
91 | 90 |
92 void ConnectToClient(const GURL& requestor_url, | 91 void ConnectToClient(const GURL& requestor_url, |
93 ServiceProviderPtr service_provider) { | 92 ServiceProviderPtr service_provider) { |
94 client()->AcceptConnection(String::From(requestor_url), | 93 client()->AcceptConnection(String::From(requestor_url), |
95 service_provider.Pass()); | 94 service_provider.Pass()); |
96 } | 95 } |
97 | 96 |
98 // ServiceProvider implementation: | 97 // ServiceProvider implementation: |
99 virtual void ConnectToApplication( | 98 void ConnectToApplication( |
100 const String& app_url, | 99 const String& app_url, |
101 InterfaceRequest<ServiceProvider> in_service_provider) override { | 100 InterfaceRequest<ServiceProvider> in_service_provider) override { |
102 ServiceProviderPtr out_service_provider; | 101 ServiceProviderPtr out_service_provider; |
103 out_service_provider.Bind(in_service_provider.PassMessagePipe()); | 102 out_service_provider.Bind(in_service_provider.PassMessagePipe()); |
104 manager_->ConnectToApplication( | 103 manager_->ConnectToApplication( |
105 app_url.To<GURL>(), url_, out_service_provider.Pass()); | 104 app_url.To<GURL>(), url_, out_service_provider.Pass()); |
106 } | 105 } |
107 | 106 |
108 const GURL& url() const { return url_; } | 107 const GURL& url() const { return url_; } |
109 | 108 |
110 private: | 109 private: |
111 virtual void OnConnectionError() override { | 110 void OnConnectionError() override { manager_->OnShellImplError(this); } |
112 manager_->OnShellImplError(this); | |
113 } | |
114 | 111 |
115 ApplicationManager* const manager_; | 112 ApplicationManager* const manager_; |
116 const GURL url_; | 113 const GURL url_; |
117 | 114 |
118 DISALLOW_COPY_AND_ASSIGN(ShellImpl); | 115 DISALLOW_COPY_AND_ASSIGN(ShellImpl); |
119 }; | 116 }; |
120 | 117 |
121 struct ApplicationManager::ContentHandlerConnection { | 118 struct ApplicationManager::ContentHandlerConnection { |
122 ContentHandlerConnection(ApplicationManager* manager, | 119 ContentHandlerConnection(ApplicationManager* manager, |
123 const GURL& content_handler_url) { | 120 const GURL& content_handler_url) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 StubServiceProvider* stub_sp = new StubServiceProvider; | 316 StubServiceProvider* stub_sp = new StubServiceProvider; |
320 ServiceProviderPtr spp; | 317 ServiceProviderPtr spp; |
321 BindToProxy(stub_sp, &spp); | 318 BindToProxy(stub_sp, &spp); |
322 ConnectToApplication(application_url, GURL(), spp.Pass()); | 319 ConnectToApplication(application_url, GURL(), spp.Pass()); |
323 MessagePipe pipe; | 320 MessagePipe pipe; |
324 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, | 321 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, |
325 pipe.handle1.Pass()); | 322 pipe.handle1.Pass()); |
326 return pipe.handle0.Pass(); | 323 return pipe.handle0.Pass(); |
327 } | 324 } |
328 } // namespace mojo | 325 } // namespace mojo |
OLD | NEW |