| 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 #ifndef CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |
| 6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "content/common/service_port_service.mojom.h" |
| 12 #include "content/common/service_worker/service_worker_status_code.h" | 13 #include "content/common/service_worker/service_worker_status_code.h" |
| 13 #include "content/public/browser/navigator_connect_context.h" | 14 #include "content/public/browser/navigator_connect_context.h" |
| 14 | 15 |
| 15 class GURL; | 16 class GURL; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 struct MessagePortMessage; | 20 struct MessagePortMessage; |
| 20 class NavigatorConnectService; | 21 class NavigatorConnectService; |
| 21 class NavigatorConnectServiceFactory; | 22 class NavigatorConnectServiceFactory; |
| 22 struct NavigatorConnectClient; | 23 struct NavigatorConnectClient; |
| 23 class ServicePortServiceImpl; | 24 class ServicePortServiceImpl; |
| 24 class ServiceWorkerContextWrapper; | 25 class ServiceWorkerContextWrapper; |
| 25 class ServiceWorkerRegistration; | 26 class ServiceWorkerRegistration; |
| 27 class ServiceWorkerVersion; |
| 26 struct TransferredMessagePort; | 28 struct TransferredMessagePort; |
| 27 | 29 |
| 28 // Tracks all active navigator.services connections, as well as available | 30 // Tracks all active navigator.services connections, as well as available |
| 29 // service factories. Delegates connection requests to the correct factory and | 31 // service factories. Delegates connection requests to the correct factory and |
| 30 // passes messages on to the correct service. | 32 // passes messages on to the correct service. |
| 31 // One instance of this class exists per StoragePartition. | 33 // One instance of this class exists per StoragePartition. |
| 32 // TODO(mek): Clean up connections, fire of closed events when connections die. | 34 // TODO(mek): Clean up connections, fire of closed events when connections die. |
| 33 // TODO(mek): Update service side API to be fully ServicePort based. | 35 // TODO(mek): Update service side API to be fully ServicePort based. |
| 34 // TODO(mek): Make ServicePorts that live in a service worker be able to survive | 36 // TODO(mek): Make ServicePorts that live in a service worker be able to survive |
| 35 // the worker being restarted. | 37 // the worker being restarted. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 76 |
| 75 // Callback called when a ServiceWorkerRegistration has been located (or | 77 // Callback called when a ServiceWorkerRegistration has been located (or |
| 76 // has failed to be located) for a connection attempt. | 78 // has failed to be located) for a connection attempt. |
| 77 void GotServiceWorkerRegistration( | 79 void GotServiceWorkerRegistration( |
| 78 const ConnectCallback& callback, | 80 const ConnectCallback& callback, |
| 79 int client_port_id, | 81 int client_port_id, |
| 80 int service_port_id, | 82 int service_port_id, |
| 81 ServiceWorkerStatusCode status, | 83 ServiceWorkerStatusCode status, |
| 82 const scoped_refptr<ServiceWorkerRegistration>& registration); | 84 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 83 | 85 |
| 84 // Callback called by service factories when a connection succeeded or failed. | 86 void DispatchConnectEvent(const ConnectCallback& callback, |
| 87 int client_port_id, |
| 88 int service_port_id, |
| 89 const scoped_refptr<ServiceWorkerRegistration>& |
| 90 service_worker_registration, |
| 91 const scoped_refptr<ServiceWorkerVersion>& worker); |
| 92 |
| 93 // Callback called when dispatching a connect event failed. |
| 94 void OnConnectError(const ConnectCallback& calback, |
| 95 int client_port_id, |
| 96 int service_port_id, |
| 97 ServiceWorkerStatusCode status); |
| 98 |
| 99 // Callback called with the response to a connect event. |
| 85 void OnConnectResult(const ConnectCallback& callback, | 100 void OnConnectResult(const ConnectCallback& callback, |
| 86 int client_port_id, | 101 int client_port_id, |
| 87 int service_port_id, | 102 int service_port_id, |
| 88 const scoped_refptr<ServiceWorkerRegistration>& | 103 const scoped_refptr<ServiceWorkerRegistration>& |
| 89 service_worker_registration, | 104 service_worker_registration, |
| 90 ServiceWorkerStatusCode status, | 105 const scoped_refptr<ServiceWorkerVersion>& worker, |
| 91 bool accept_connection, | 106 int request_id, |
| 92 const base::string16& name, | 107 ServicePortConnectResult result, |
| 93 const base::string16& data); | 108 const mojo::String& name, |
| 109 const mojo::String& data); |
| 94 | 110 |
| 95 // Callback called when a ServiceWorkerRegistration has been located to | 111 // Callback called when a ServiceWorkerRegistration has been located to |
| 96 // deliver a message to. | 112 // deliver a message to. |
| 97 void DeliverMessage( | 113 void DeliverMessage( |
| 98 int port_id, | 114 int port_id, |
| 99 const base::string16& message, | 115 const base::string16& message, |
| 100 const std::vector<TransferredMessagePort>& sent_message_ports, | 116 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 101 ServiceWorkerStatusCode status, | 117 ServiceWorkerStatusCode status, |
| 102 const scoped_refptr<ServiceWorkerRegistration>& registration); | 118 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 103 | 119 |
| 104 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 120 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 105 | 121 |
| 106 // List of factories to try to handle URLs. | 122 // List of factories to try to handle URLs. |
| 107 ScopedVector<NavigatorConnectServiceFactory> service_factories_; | 123 ScopedVector<NavigatorConnectServiceFactory> service_factories_; |
| 108 | 124 |
| 109 // List of currently active ServicePorts. | 125 // List of currently active ServicePorts. |
| 110 struct Port; | 126 struct Port; |
| 111 std::map<int, Port> ports_; | 127 std::map<int, Port> ports_; |
| 112 int next_port_id_; | 128 int next_port_id_; |
| 113 }; | 129 }; |
| 114 | 130 |
| 115 } // namespace content | 131 } // namespace content |
| 116 | 132 |
| 117 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ | 133 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |
| OLD | NEW |