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

Unified Diff: third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h

Issue 2004643002: Implement BroadcastChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on hashtraits change Created 4 years, 6 months 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: third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
diff --git a/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h b/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
new file mode 100644
index 0000000000000000000000000000000000000000..a8027a33654de1e88e220da79b4207087e899129
--- /dev/null
+++ b/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
@@ -0,0 +1,79 @@
+// Copyright 2016 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 BroadcastChannelConnection_h
+#define BroadcastChannelConnection_h
+
+#include "components/webmessaging/public/interfaces/broadcast_channel.mojom-blink.h"
+#include "mojo/public/cpp/bindings/associated_binding.h"
+#include "platform/heap/GarbageCollected.h"
+#include "platform/heap/HeapAllocator.h"
+#include "platform/weborigin/SecurityOriginHash.h"
+#include "wtf/text/StringHash.h"
+
+namespace blink {
+
+// To ensure proper message ordering, all BroadcastChannel instances on the same
+// thread share a single mojo connection. This class represents such a
+// connection. BroadcastChannel instances register themselves with the correct
+// connection, and use the connection to broadcast messages.
+class BroadcastChannelConnection final
+ : public GarbageCollectedFinalized<BroadcastChannelConnection>
+ , public webmessaging::mojom::blink::BroadcastChannelClient {
haraken 2016/06/06 02:05:48 Just to confirm: No one is keeping a reference to
Marijn Kruisselbrink 2016/06/06 20:05:30 m_binding obviously is, to be able to call methods
Marijn Kruisselbrink 2016/06/07 01:18:39 I'm still curious about this though. It sounds lik
haraken 2016/06/07 01:29:55 Can we use the same pattern as m_paymentProvider?
Marijn Kruisselbrink 2016/06/07 17:41:39 m_clientBinding in PaymentRequest has the same iss
+ WTF_MAKE_NONCOPYABLE(BroadcastChannelConnection);
+public:
+ class Client : public GarbageCollectedMixin {
+ public:
+ virtual String name() const = 0;
+ virtual SecurityOrigin* origin() const = 0;
+
+ // Called when a message is received for this channel. Not called for
+ // messages send by this client to the channel.
haraken 2016/06/06 02:05:47 sent by
Marijn Kruisselbrink 2016/06/06 20:05:30 fixed
+ virtual void onMessage(const String& message) = 0;
+
+ // Called when the connection this client is registered with closes.
+ // After onError is called a client should not try to do anything with
+ // the connection anymore.
+ virtual void onError() = 0;
+ };
+
+ // Returns the BroadcastChannelConnection instance to use for the channel
+ // identified by the particular origin and name. When called with the same
+ // parameters on the same thread this will always return the same instance,
+ // except if for some reason the mojo connection got severed.
+ //
+ // If all clients using this particular connection get closed, the
+ // connection itself might also be closed, in which case the next time the
+ // method is called a new connection is created.
+ static BroadcastChannelConnection* getForChannel(const RefPtr<SecurityOrigin>&, const String& name);
+ ~BroadcastChannelConnection();
+
+ // Register a new client that uses this connection.
+ void registerClient(Client*);
+ void unregisterClient(Client*);
+
+ // Broadcasts a message to the channel this connection is for. The message
+ // will be delivered to all clients except the client that send the message.
+ void broadcast(Client*, const String& message);
+
+ DECLARE_TRACE();
+
+private:
+ BroadcastChannelConnection(const String& name, const RefPtr<SecurityOrigin>&, webmessaging::mojom::blink::BroadcastChannelClientAssociatedPtrInfo*, mojo::AssociatedGroup*);
+
+ // webmessaging::mojom::blink::BroadcastChannelClient:
+ void OnMessage(const String& message) override;
+
+ // Called when the mojo binding disconnects.
+ void onError();
+
+ String m_name;
+ RefPtr<SecurityOrigin> m_origin;
+ HeapLinkedHashSet<WeakMember<Client>> m_clients;
+ mojo::AssociatedBinding<webmessaging::mojom::blink::BroadcastChannelClient> m_binding;
+};
+
+} // namespace blink
+
+#endif // BroadcastChannelConnection_h

Powered by Google App Engine
This is Rietveld 408576698