| 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 21%
|
| rename from content/browser/navigator_connect/navigator_connect_context.h
|
| rename to content/browser/navigator_connect/navigator_connect_context_impl.h
|
| index 37948674de4062a04df3300566b55823a602208c..8a983d584a978e3fc93f1296497113278bbf870d 100644
|
| --- a/content/browser/navigator_connect/navigator_connect_context.h
|
| +++ b/content/browser/navigator_connect/navigator_connect_context_impl.h
|
| @@ -2,65 +2,53 @@
|
| // 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 "content/common/service_worker/service_worker_status_code.h"
|
| +#include "base/callback_forward.h"
|
| +#include "base/memory/scoped_vector.h"
|
| #include "content/public/browser/message_port_delegate.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:
|
| - 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();
|
|
|
| - // 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 SendMessagesAreQueued(int route_id) override;
|
| + // 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(const NavigatorConnectClient& client,
|
| + const ConnectCallback& callback);
|
| +
|
| + // NavigatorConnectContext implementation.
|
| + void AddFactory(scoped_ptr<NavigatorConnectServiceFactory> factory) override;
|
|
|
| private:
|
| - friend class base::RefCountedThreadSafe<NavigatorConnectContext>;
|
| - ~NavigatorConnectContext() override;
|
| + ~NavigatorConnectContextImpl() override;
|
|
|
| - // 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);
|
| + // Callback called by service factories when a connection succeeded or failed.
|
| + void OnConnectResult(const NavigatorConnectClient& client,
|
| + const ConnectCallback& callback,
|
| + MessagePortDelegate* delegate);
|
|
|
| - 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_;
|
| + // List of factories to try to handle URLs.
|
| + ScopedVector<NavigatorConnectServiceFactory> service_factories_;
|
| };
|
|
|
| } // namespace content
|
|
|
| -#endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_
|
| +#endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_IMPL_H_
|
|
|