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

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

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

Powered by Google App Engine
This is Rietveld 408576698