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

Side by Side 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: better tests 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BroadcastChannelConnection_h
6 #define BroadcastChannelConnection_h
7
8 #include "components/webmessaging/public/interfaces/broadcast_channel.mojom-blin k.h"
9 #include "mojo/public/cpp/bindings/strong_associated_binding.h"
10 #include "platform/weborigin/SecurityOriginHash.h"
11 #include "wtf/ListHashSet.h"
12 #include "wtf/text/StringHash.h"
13
14 namespace blink {
15
16 // To ensure proper message ordering, all BroadcastChannel instances on the same
17 // thread share a single mojo connection. This class represents such a
18 // connection. BroadcastChannel instances register themselves with the correct
19 // connection, and use the connection to broadcast messages.
20 class BroadcastChannelConnection final : public webmessaging::mojom::blink::Broa dcastChannelClient {
21 WTF_MAKE_NONCOPYABLE(BroadcastChannelConnection);
22 public:
23 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
24 public:
25 virtual String name() const = 0;
26 virtual SecurityOrigin* origin() const = 0;
27
28 // Called when a message is received for this channel. Not called for
29 // messages send by this client to the channel.
30 virtual void onMessage(const String& message) = 0;
31
32 // Called when the connection this client is registered with closes.
33 // After onError is called a client should not try to do anything with
34 // the connection anymore.
35 virtual void onError() = 0;
36 };
37
38 // Returns the BroadcastChannelConnection instance to use for the channel
39 // identified by the particular origin and name. When called with the same
40 // parameters on the same thread this will always return the same instance,
41 // except if for some reason the mojo connection got severed.
42 // If all clients using this particular connection get closed, the
43 // connection itself might also be closed, in which case the next time the
44 // method is called a new connection is created.
45 static BroadcastChannelConnection* getForChannel(const RefPtr<SecurityOrigin >&, const String& name);
46 ~BroadcastChannelConnection();
47
48 // Register a new client that uses this connection. The client must call
49 // unregisterClient when the client object is destroyed.
50 void registerClient(Client*);
51 void unregisterClient(Client*);
52
53 // Broadcasts a message to the channel this connection is for. The message
54 // will be delivered to all clients except the client that send the message.
55 void broadcast(Client*, const String& message);
56 private:
57 BroadcastChannelConnection(const String& name, const RefPtr<SecurityOrigin>& , webmessaging::mojom::blink::BroadcastChannelClientAssociatedPtrInfo*, mojo::As sociatedGroup*);
58
59 // webmessaging::mojom::blink::BroadcastChannelClient:
60 void OnMessage(const String& message) override;
61
62 String m_name;
63 RefPtr<SecurityOrigin> m_origin;
64 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
65 mojo::StrongAssociatedBinding<webmessaging::mojom::blink::BroadcastChannelCl ient> m_binding;
66 };
67
68 } // namespace blink
69
70 #endif // BroadcastChannelConnection_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698