Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1354)

Unified Diff: content/browser/navigator_connect/navigator_connect_context.h

Issue 785133006: Enable messaging over a navigator.connect initiated channel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigator-connect_serviceside
Patch Set: comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/navigator_connect/navigator_connect_context.h
diff --git a/content/browser/navigator_connect/navigator_connect_context.h b/content/browser/navigator_connect/navigator_connect_context.h
new file mode 100644
index 0000000000000000000000000000000000000000..2162d626c601dd27d551f01540ff775ae617dadd
--- /dev/null
+++ b/content/browser/navigator_connect/navigator_connect_context.h
@@ -0,0 +1,68 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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_
+
+#include <map>
+#include "base/memory/ref_counted.h"
+#include "content/browser/message_port_delegate.h"
+#include "content/common/service_worker/service_worker_status_code.h"
+
+namespace content {
+
+struct CrossOriginServiceWorkerClient;
+class ServiceWorkerContextWrapper;
+class ServiceWorkerRegistration;
+
+// Class that keeps track of all active navigator.connect connections. This
scheib 2014/12/18 00:24:10 Tracks all active navigator.connect connections, w
Marijn Kruisselbrink 2014/12/19 00:09:21 Done.
+// class is also responsible for waking up a service worker when a message
+// arrives, and properly routing the messages.
+// 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> {
+ public:
+ explicit NavigatorConnectContext(
+ const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context);
+
+ // Registers an accepted connection with this class. This method takes care
scheib 2014/12/18 00:24:10 Registers an accepted connection and updates Messa
Marijn Kruisselbrink 2014/12/19 00:09:21 Done.
+ // of updating MessagePortService with the new route/delegate for the message
+ // port associated with this connection, as well as adding the connection to
+ // this class' internal bookkeeping.
+ void RegisterConnection(const CrossOriginServiceWorkerClient& client,
+ const scoped_refptr<ServiceWorkerRegistration>&
+ service_worker_registration);
+
+ // 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;
+
+ private:
+ friend class base::RefCountedThreadSafe<NavigatorConnectContext>;
+ ~NavigatorConnectContext() 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);
+
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
+ struct Connection;
+ // Maps route ids to connections.
+ std::map<int, Connection> connections_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_

Powered by Google App Engine
This is Rietveld 408576698