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 ffb4647041f445d342383a458f59eea8e3df778f..d5b2d047c31872c4395b2763bd4923bd22b5415b 100644 |
--- a/content/browser/navigator_connect/navigator_connect_context_impl.h |
+++ b/content/browser/navigator_connect/navigator_connect_context_impl.h |
@@ -11,38 +11,63 @@ |
#include "content/public/browser/message_port_delegate.h" |
#include "content/public/browser/navigator_connect_context.h" |
+// Windows headers will redefine SendMessage. |
+#ifdef SendMessage |
+#undef SendMessage |
+#endif |
+ |
+class GURL; |
+ |
namespace content { |
class MessagePortMessageFilter; |
class NavigatorConnectService; |
class NavigatorConnectServiceFactory; |
struct NavigatorConnectClient; |
+class ServicePortServiceImpl; |
struct TransferredMessagePort; |
-// Tracks all active navigator.connect connections, as well as available service |
-// factories. Delegates connection requests to the correct factory and passes |
-// messages on to the correct service. |
+// Tracks all active navigator.services connections, as well as available |
+// service factories. Delegates connection requests to the correct factory and |
+// passes messages on to the correct service. |
// One instance of this class exists per StoragePartition. |
-// TODO(mek): Somehow clean up connections when the client side goes away. |
-class NavigatorConnectContextImpl : public NavigatorConnectContext { |
+// 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): Make ServicePorts that live in a service worker be able to survive |
+// the worker being restarted. |
+class NavigatorConnectContextImpl : public NavigatorConnectContext, |
+ public MessagePortDelegate { |
public: |
using ConnectCallback = |
- base::Callback<void(const TransferredMessagePort& message_port, |
- int message_port_route_id, |
- bool success)>; |
+ base::Callback<void(int message_port_id, bool success)>; |
explicit NavigatorConnectContextImpl(); |
// Called when a new connection request comes in from a client. Finds the |
// correct service factory and passes the connection request off to there. |
// Can call the callback before this method call returns. |
- void Connect(NavigatorConnectClient client, |
- MessagePortMessageFilter* message_port_message_filter, |
+ void Connect(const GURL& target_url, |
+ const GURL& origin, |
+ ServicePortServiceImpl* service_port_service, |
const ConnectCallback& callback); |
+ // Called by a ServicePortServiceImpl instance when it is about to be |
+ // destroyed to inform this class that all its connections are no longer |
+ // valid. |
+ void ServicePortServiceDestroyed( |
+ ServicePortServiceImpl* service_port_service); |
+ |
// 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; |
@@ -51,13 +76,16 @@ class NavigatorConnectContextImpl : public NavigatorConnectContext { |
// Callback called by service factories when a connection succeeded or failed. |
void OnConnectResult(const NavigatorConnectClient& client, |
int client_message_port_id, |
- int client_port_route_id, |
const ConnectCallback& callback, |
MessagePortDelegate* delegate, |
bool data_as_values); |
// List of factories to try to handle URLs. |
ScopedVector<NavigatorConnectServiceFactory> service_factories_; |
+ |
+ // List of currently active ServicePorts. |
+ struct Port; |
+ std::map<int, Port> ports_; |
}; |
} // namespace content |