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

Side by Side Diff: blimp/net/helium/helium_stream.h

Issue 2383533003: Blimp: define HeliumTransport/HeliumStream interfaces. (Closed)
Patch Set: Asymmetric connect/listen API Created 4 years, 2 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 BLIMP_NET_HELIUM_HELIUM_STREAM_H_
6 #define BLIMP_NET_HELIUM_HELIUM_STREAM_H_
7
8 #include <memory>
9
10 #include "base/observer_list.h"
11 #include "blimp/net/helium/helium_result.h"
12 #include "net/base/completion_callback.h"
13
14 namespace blimp {
15
16 class HeliumMessage;
17
18 // Abstract base class for HeliumMessage-oriented transport streams.
19 // Details about how the HeliumStream is bound to the network layer are handled
20 // by subclasses of HeliumStream.
21 class HeliumStream {
22 public:
23 class Observer {
24 public:
25 // Informs observers that the HeliumStream is disconnected.
26 // Any outstanding read or write callbacks will be dropped and never
27 // invoked.
28 //
29 // An observer which owns |this| may delete the HeliumStream in response to
30 // receiving an OnStreamDisconnected() notification. The deletion method
31 // must be asynchronously posted to occur *after* the OnStreamDisconnected()
32 // handler, not during.
33 virtual void OnStreamDisconnected(HeliumStream* stream) = 0;
34 };
35
36 HeliumStream();
37 virtual ~HeliumStream();
38
39 // Sends |helium_message| over the Stream. |callback| is invoked when the
40 // message is sent (or otherwise moved to the low-level write buffers),
41 // which signals the caller that it is clear to send another message.
42 //
43 // The caller is responsible for ensuring that only one outstanding
44 // SendMessage() call is made at a time.
45 virtual void SendMessage(
46 std::unique_ptr<HeliumMessage> helium_message,
47 const base::Callback<void(HeliumResult)>& callback) = 0;
48
49 // Asynchronously reads a HeliumMessage from the stream.
50 // The caller is responsible for ensuring that only one outstanding
51 // ReceiveMessage() call is made at a time.
52 // The implementation classes should refrain from preemptively buffering
53 // incoming messages to ensure proper pushback w/transport-level flow control.
54 virtual void ReceiveMessage(
perumaal 2016/10/05 20:40:44 I think this would be better suited as SetMessageR
Garrett Casto 2016/10/05 20:53:07 Note that we originally had this as a callback tha
55 base::Callback<void(std::unique_ptr<HeliumMessage>, HeliumResult)>
56 on_receive_cb) = 0;
57
58 // Lets other objects observe the Stream for major state changes (e.g.
59 // connectivity).
60 void AddObserver(Observer* observer);
61
62 protected:
63 // Notifies observers that the underlying transport for this Stream is no
64 // longer connected. Must be called by a subclass before the HeliumStream
65 // can be torn down.
66 void NotifyStreamDisconnected();
67
68 private:
69 base::ObserverList<HeliumStream::Observer> observers_;
70
71 DISALLOW_COPY_AND_ASSIGN(HeliumStream);
72 };
73
74 } // namespace blimp
75
76 #endif // BLIMP_NET_HELIUM_HELIUM_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698