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

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: 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 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/associated_binding.h"
10 #include "platform/heap/GarbageCollected.h"
11 #include "platform/heap/HeapAllocator.h"
12 #include "platform/weborigin/SecurityOriginHash.h"
13 #include "wtf/text/StringHash.h"
14
15 namespace blink {
16
17 // To ensure proper message ordering, all BroadcastChannel instances on the same
18 // thread share a single mojo connection. This class represents such a
19 // connection. BroadcastChannel instances register themselves with the correct
20 // connection, and use the connection to broadcast messages.
21 class BroadcastChannelConnection final
22 : public GarbageCollectedFinalized<BroadcastChannelConnection>
23 , 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
24 WTF_MAKE_NONCOPYABLE(BroadcastChannelConnection);
25 public:
26 class Client : public GarbageCollectedMixin {
27 public:
28 virtual String name() const = 0;
29 virtual SecurityOrigin* origin() const = 0;
30
31 // Called when a message is received for this channel. Not called for
32 // 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
33 virtual void onMessage(const String& message) = 0;
34
35 // Called when the connection this client is registered with closes.
36 // After onError is called a client should not try to do anything with
37 // the connection anymore.
38 virtual void onError() = 0;
39 };
40
41 // Returns the BroadcastChannelConnection instance to use for the channel
42 // identified by the particular origin and name. When called with the same
43 // parameters on the same thread this will always return the same instance,
44 // except if for some reason the mojo connection got severed.
45 //
46 // If all clients using this particular connection get closed, the
47 // connection itself might also be closed, in which case the next time the
48 // method is called a new connection is created.
49 static BroadcastChannelConnection* getForChannel(const RefPtr<SecurityOrigin >&, const String& name);
50 ~BroadcastChannelConnection();
51
52 // Register a new client that uses this connection.
53 void registerClient(Client*);
54 void unregisterClient(Client*);
55
56 // Broadcasts a message to the channel this connection is for. The message
57 // will be delivered to all clients except the client that send the message.
58 void broadcast(Client*, const String& message);
59
60 DECLARE_TRACE();
61
62 private:
63 BroadcastChannelConnection(const String& name, const RefPtr<SecurityOrigin>& , webmessaging::mojom::blink::BroadcastChannelClientAssociatedPtrInfo*, mojo::As sociatedGroup*);
64
65 // webmessaging::mojom::blink::BroadcastChannelClient:
66 void OnMessage(const String& message) override;
67
68 // Called when the mojo binding disconnects.
69 void onError();
70
71 String m_name;
72 RefPtr<SecurityOrigin> m_origin;
73 HeapLinkedHashSet<WeakMember<Client>> m_clients;
74 mojo::AssociatedBinding<webmessaging::mojom::blink::BroadcastChannelClient> m_binding;
75 };
76
77 } // namespace blink
78
79 #endif // BroadcastChannelConnection_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698