Chromium Code Reviews| Index: content/browser/navigator_connect/navigator_connect_context_impl.h |
| diff --git a/content/browser/navigator_connect/navigator_connect_context.h b/content/browser/navigator_connect/navigator_connect_context_impl.h |
| similarity index 33% |
| rename from content/browser/navigator_connect/navigator_connect_context.h |
| rename to content/browser/navigator_connect/navigator_connect_context_impl.h |
| index db4edbcc8a02d5d9eee80f036667ed58f41344ec..e75e2ad098dc898182fff3927edd24f24ce433cb 100644 |
| --- a/content/browser/navigator_connect/navigator_connect_context.h |
| +++ b/content/browser/navigator_connect/navigator_connect_context_impl.h |
| @@ -2,65 +2,66 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ |
| -#define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ |
| +#ifndef CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |
| +#define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |
| #include <map> |
| -#include "base/memory/ref_counted.h" |
| +#include "base/callback_forward.h" |
| +#include "base/memory/scoped_vector.h" |
| #include "content/browser/message_port_delegate.h" |
| -#include "content/common/service_worker/service_worker_status_code.h" |
| +#include "content/public/browser/navigator_connect_context.h" |
| namespace content { |
| -struct CrossOriginServiceWorkerClient; |
| -class ServiceWorkerContextWrapper; |
| -class ServiceWorkerRegistration; |
| +struct NavigatorConnectClient; |
| +class NavigatorConnectService; |
| +class NavigatorConnectServiceFactory; |
| -// Tracks all active navigator.connect connections, wakes up service workers |
| -// when a message arrives, and routes the messages. |
| +// 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. |
| // One instance of this class exists per StoragePartition. |
| -// TODO(mek): Clean up message ports when a service worker is unregistered. |
| // TODO(mek): Somehow clean up connections when the client side goes away. |
| -class NavigatorConnectContext |
| - : public MessagePortDelegate, |
| - public base::RefCountedThreadSafe<NavigatorConnectContext> { |
| +class NavigatorConnectContextImpl : public NavigatorConnectContext, |
| + public MessagePortDelegate { |
| public: |
| - explicit NavigatorConnectContext( |
| - const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| + using ConnectCallback = base::Callback<void(bool success)>; |
| - // Registers an accepted connection and updates MessagePortService with the |
| - // new route/delegate for the message port associated with this connection. |
| - void RegisterConnection(const CrossOriginServiceWorkerClient& client, |
| - const scoped_refptr<ServiceWorkerRegistration>& |
| - service_worker_registration); |
| + explicit NavigatorConnectContextImpl(); |
| + |
| + // Called when a new connection request comes in from a client. Finds the |
| + // correct service factory and passes the connection request of to there. |
|
scheib
2015/01/23 22:03:58
of->off
Marijn Kruisselbrink
2015/01/26 21:34:26
Done.
|
| + // Can call the callback before this method call returns. |
| + void Connect(const NavigatorConnectClient& client, |
| + const ConnectCallback& callback); |
| + |
| + // NavigatorConnectContext implementation. |
| + void AddFactory(scoped_ptr<NavigatorConnectServiceFactory> factory) override; |
| // MessagePortDelegate implementation. For the implementation of this class, |
| // the route_id of a message port is always equal to the message_port_id. |
| - void SendMessage(int route_id, |
| - const base::string16& message, |
| - const std::vector<int>& sent_message_port_ids) override; |
| + void SendMessageToPort( |
| + int route_id, |
| + const base::string16& message, |
| + const std::vector<int>& sent_message_port_ids) override; |
| void SendMessagesAreQueued(int route_id) override; |
| private: |
| - friend class base::RefCountedThreadSafe<NavigatorConnectContext>; |
| - ~NavigatorConnectContext() override; |
| + ~NavigatorConnectContextImpl() override; |
| + |
| + // Callback called by service factories when a connection succeeded or failed. |
| + void OnConnectResult(const NavigatorConnectClient& client, |
| + const ConnectCallback& callback, |
| + scoped_ptr<NavigatorConnectService> service); |
| - // Callback called by SendMessage when a ServiceWorkerRegistration for the |
| - // given message port has been located. |
| - void DoSendMessage(const CrossOriginServiceWorkerClient& client, |
| - const base::string16& message, |
| - const std::vector<int>& sent_message_port_ids, |
| - ServiceWorkerStatusCode service_worker_status, |
| - const scoped_refptr<ServiceWorkerRegistration>& |
| - service_worker_registration); |
| + // List of factories to try to handle URLs. |
| + ScopedVector<NavigatorConnectServiceFactory> service_factories_; |
| - scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| - struct Connection; |
| // Maps route ids to connections. For the purpose of this class, the route id |
| // of a connection is the same as its message_port_id. |
| - std::map<int, Connection> connections_; |
| + std::map<int, NavigatorConnectService*> connected_services_; |
| }; |
| } // namespace content |
| -#endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ |
| +#endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_ |