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

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

Issue 2383533003: Blimp: define HeliumTransport/HeliumStream interfaces. (Closed)
Patch Set: Back to ReceiveMessage 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
« no previous file with comments | « blimp/net/BUILD.gn ('k') | blimp/net/helium/helium_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/callback.h"
11 #include "blimp/net/helium/helium_result.h"
12
13 namespace blimp {
14
15 class HeliumMessage;
16
17 // Pure virtual interface 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 Delegate {
23 public:
24 // Invoked when the HeliumStream is disconnected.
25 //
26 // An observer which owns |this| may delete the HeliumStream in response to
27 // receiving an OnStreamDisconnected() notification. The deletion method
28 // must be asynchronously posted to occur *after* the OnStreamDisconnected()
29 // handler, not during.
30 virtual void OnStreamDisconnected(HeliumStream* stream,
31 HeliumResult reason) = 0;
Garrett Casto 2016/10/11 22:33:22 We shouldn't need this and ReceiveMessage(). If we
Kevin M 2016/10/11 23:25:16 Done.
32 };
33
34 virtual ~HeliumStream() = default;
35
36 virtual void SetDelegate(std::unique_ptr<Delegate> delegate) = 0;
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(
45 std::unique_ptr<HeliumMessage> helium_message,
46 const base::Callback<void(HeliumResult)>& callback) = 0;
perumaal 2016/10/11 23:09:39 Ah I now see this problem: The caller of SendMessa
Kevin M 2016/10/11 23:25:16 That's by design, actually. The construction of He
47
48 // Asynchronously reads a HeliumMessage from the stream.
49 // The caller is responsible for ensuring that only one outstanding
50 // ReceiveMessage() call is made at a time.
51 // The implementation classes should refrain from preemptively buffering
52 // incoming messages to ensure proper pushback w/transport-level flow control.
Garrett Casto 2016/10/11 22:33:22 Nit: Sounds like we explicitly are okay with pre-e
Kevin M 2016/10/11 23:25:16 Done.
53 virtual void ReceiveMessage(
54 base::Callback<void(std::unique_ptr<HeliumMessage>, HeliumResult)>
perumaal 2016/10/11 22:36:36 Could we alias this as HeliumMsgReceivedCallback?
Kevin M 2016/10/11 23:25:16 Done.
55 on_receive_cb) = 0;
56 };
57
58 // Abstract base class, to be used by non-test implementers of HeliumStream.
59 class HeliumStreamBase : public HeliumStream {
60 public:
61 HeliumStreamBase();
62 ~HeliumStreamBase() override;
63
64 // HeliumStream implementation.
65 void SetDelegate(std::unique_ptr<Delegate> delegate) override;
66
67 protected:
68 Delegate* delegate() { return delegate_.get(); }
69
70 private:
71 std::unique_ptr<Delegate> delegate_;
72
73 DISALLOW_COPY_AND_ASSIGN(HeliumStreamBase);
74 };
75
76 } // namespace blimp
77
78 #endif // BLIMP_NET_HELIUM_HELIUM_STREAM_H_
OLDNEW
« no previous file with comments | « blimp/net/BUILD.gn ('k') | blimp/net/helium/helium_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698