Chromium Code Reviews| Index: content/browser/navigator_connect/navigator_connect_context_impl.h |
| diff --git a/content/browser/navigator_connect/navigator_connect_context_impl.h b/content/browser/navigator_connect/navigator_connect_context_impl.h |
| index d5b2d047c31872c4395b2763bd4923bd22b5415b..f93eac427d018d4b7e039f9fd5a99f012aa0c7ff 100644 |
| --- a/content/browser/navigator_connect/navigator_connect_context_impl.h |
| +++ b/content/browser/navigator_connect/navigator_connect_context_impl.h |
| @@ -8,23 +8,21 @@ |
| #include <map> |
| #include "base/callback_forward.h" |
| #include "base/memory/scoped_vector.h" |
| -#include "content/public/browser/message_port_delegate.h" |
| +#include "base/strings/string16.h" |
| +#include "content/common/service_worker/service_worker_status_code.h" |
| #include "content/public/browser/navigator_connect_context.h" |
| -// Windows headers will redefine SendMessage. |
| -#ifdef SendMessage |
| -#undef SendMessage |
| -#endif |
|
Avi (use Gerrit)
2015/08/05 15:17:20
Is being able to do this a consequence of removing
Marijn Kruisselbrink
2015/08/05 17:00:16
I think in this case it is just the case that this
|
| - |
| class GURL; |
| namespace content { |
| -class MessagePortMessageFilter; |
| +struct MessagePortMessage; |
| class NavigatorConnectService; |
| class NavigatorConnectServiceFactory; |
| struct NavigatorConnectClient; |
| class ServicePortServiceImpl; |
| +class ServiceWorkerContextWrapper; |
| +class ServiceWorkerRegistration; |
| struct TransferredMessagePort; |
| // Tracks all active navigator.services connections, as well as available |
| @@ -32,17 +30,17 @@ struct TransferredMessagePort; |
| // passes messages on to the correct service. |
| // One instance of this class exists per StoragePartition. |
| // TODO(mek): Clean up connections, fire of closed events when connections die. |
| -// TODO(mek): Update service side API to be ServicePort based and get rid of |
| -// MessagePort dependency. |
| +// TODO(mek): Update service side API to be fully ServicePort based. |
| // TODO(mek): Make ServicePorts that live in a service worker be able to survive |
| // the worker being restarted. |
| -class NavigatorConnectContextImpl : public NavigatorConnectContext, |
| - public MessagePortDelegate { |
| +// TODO(mek): Add back ability for service ports to be backed by native code. |
| +class NavigatorConnectContextImpl : public NavigatorConnectContext { |
| public: |
| using ConnectCallback = |
| base::Callback<void(int message_port_id, bool success)>; |
| - explicit NavigatorConnectContextImpl(); |
| + explicit NavigatorConnectContextImpl( |
| + const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| // Called when a new connection request comes in from a client. Finds the |
| // correct service factory and passes the connection request off to there. |
| @@ -52,6 +50,14 @@ class NavigatorConnectContextImpl : public NavigatorConnectContext, |
| ServicePortServiceImpl* service_port_service, |
| const ConnectCallback& callback); |
| + // Called when a message is send to a ServicePort. The |sender_port_id| is the |
|
Avi (use Gerrit)
2015/08/05 15:17:20
s/send/sent/
Marijn Kruisselbrink
2015/08/05 17:00:16
Done
|
| + // id of the port the message is sent from, this will look up what other port |
| + // the port is entangled with and deliver the message to that port. |
| + void PostMessage( |
| + int sender_port_id, |
| + const MessagePortMessage& message, |
| + const std::vector<TransferredMessagePort>& sent_message_ports); |
| + |
| // Called by a ServicePortServiceImpl instance when it is about to be |
| // destroyed to inform this class that all its connections are no longer |
| // valid. |
| @@ -61,24 +67,41 @@ class NavigatorConnectContextImpl : public NavigatorConnectContext, |
| // NavigatorConnectContext implementation. |
| void AddFactory(scoped_ptr<NavigatorConnectServiceFactory> factory) override; |
| - // MessagePortDelegate implementation. |
| - void SendMessage( |
| - int route_id, |
| - const MessagePortMessage& message, |
| - const std::vector<TransferredMessagePort>& sent_message_ports) override; |
| - void SendMessagesAreQueued(int route_id) override; |
| - |
| private: |
| ~NavigatorConnectContextImpl() override; |
| void AddFactoryOnIOThread(scoped_ptr<NavigatorConnectServiceFactory> factory); |
| + // Callback called when a ServiceWorkerRegistration has been located (or |
| + // failed to locate) for a connection attempt. |
|
Avi (use Gerrit)
2015/08/05 15:17:20
... has been located (or has failed to be located)
Marijn Kruisselbrink
2015/08/05 17:00:16
Done
|
| + void GotServiceWorkerRegistration( |
| + const ConnectCallback& callback, |
| + int client_port_id, |
| + int service_port_id, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration); |
| + |
| // Callback called by service factories when a connection succeeded or failed. |
| - void OnConnectResult(const NavigatorConnectClient& client, |
| - int client_message_port_id, |
| - const ConnectCallback& callback, |
| - MessagePortDelegate* delegate, |
| - bool data_as_values); |
| + void OnConnectResult(const ConnectCallback& callback, |
| + int client_port_id, |
| + int service_port_id, |
| + const scoped_refptr<ServiceWorkerRegistration>& |
| + service_worker_registration, |
| + ServiceWorkerStatusCode status, |
| + bool accept_connection, |
| + const base::string16& name, |
| + const base::string16& data); |
| + |
| + // Callback called when a ServiceWorkerRegistration has been located to |
| + // deliver a message to. |
| + void DeliverMessage( |
| + int port_id, |
| + const base::string16& message, |
| + const std::vector<TransferredMessagePort>& sent_message_ports, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration); |
| + |
| + scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| // List of factories to try to handle URLs. |
| ScopedVector<NavigatorConnectServiceFactory> service_factories_; |
| @@ -86,6 +109,7 @@ class NavigatorConnectContextImpl : public NavigatorConnectContext, |
| // List of currently active ServicePorts. |
| struct Port; |
| std::map<int, Port> ports_; |
| + int next_port_id_; |
| }; |
| } // namespace content |