Chromium Code Reviews| 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..48d03d04f6c4d634190d65043f4ab81f046bf55b | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h | 
| @@ -0,0 +1,70 @@ | 
| +// 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/strong_associated_binding.h" | 
| +#include "platform/weborigin/SecurityOriginHash.h" | 
| +#include "wtf/ListHashSet.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 webmessaging::mojom::blink::BroadcastChannelClient { | 
| + WTF_MAKE_NONCOPYABLE(BroadcastChannelConnection); | 
| +public: | 
| + class Client { | 
| 
 
haraken
2016/06/02 04:23:41
We should make this a GarbageCollectedMixin. Curre
 
Marijn Kruisselbrink
2016/06/02 18:33:30
Unfortunately I couldn't figure out a way to do wh
 
haraken
2016/06/03 05:33:03
This Client must be GarbageCollectedMixin, because
 
 | 
| + 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. | 
| + 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. The client must call | 
| + // unregisterClient when the client object is destroyed. | 
| + 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); | 
| +private: | 
| + BroadcastChannelConnection(const String& name, const RefPtr<SecurityOrigin>&, webmessaging::mojom::blink::BroadcastChannelClientAssociatedPtrInfo*, mojo::AssociatedGroup*); | 
| + | 
| + // webmessaging::mojom::blink::BroadcastChannelClient: | 
| + void OnMessage(const String& message) override; | 
| + | 
| + String m_name; | 
| + RefPtr<SecurityOrigin> m_origin; | 
| + ListHashSet<Client*> m_clients; | 
| 
 
haraken
2016/06/02 04:23:41
Does it need to be a ListHashSet? I guess HashSet
 
Marijn Kruisselbrink
2016/06/02 18:33:29
The List parts of ListHashSet (specifically the or
 
haraken
2016/06/03 05:33:03
You can use HeapListHashSet<WeakMember<>>.
Also y
 
 | 
| + mojo::StrongAssociatedBinding<webmessaging::mojom::blink::BroadcastChannelClient> m_binding; | 
| +}; | 
| + | 
| +} // namespace blink | 
| + | 
| +#endif // BroadcastChannelConnection_h |