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

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

Issue 2383533003: Blimp: define HeliumTransport/HeliumStream interfaces. (Closed)
Patch Set: 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;
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.
Brian Goldman 2016/09/29 18:20:21 Maybe I'm just not familiar with the pattern, but
scf 2016/09/29 19:12:22 I agree. Or what we could do is make the impl of H
50 virtual void ReceiveMessage(
51 base::Callback<void(std::unique_ptr<HeliumMessage>)> on_receive_cb) = 0;
52
53 // Lets other objects observe the Stream for major state changes (e.g.
54 // connectivity).
55 void AddObserver(Observer* observer);
scf 2016/09/29 19:12:22 dumb q: What is the rationale for allowing multipl
56
57 protected:
58 // Notifies observers that the underlying transport for this Stream is no
59 // longer connected. Must be called by a subclass before the HeliumStream
60 // can be torn down.
61 void NotifyStreamDisconnected();
62
63 private:
64 base::ObserverList<HeliumStream::Observer> observers_;
65
66 DISALLOW_COPY_AND_ASSIGN(HeliumStream);
67 };
68
69 } // namespace blimp
70
71 #endif // BLIMP_NET_HELIUM_HELIUM_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698