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

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

Issue 2383533003: Blimp: define HeliumTransport/HeliumStream interfaces. (Closed)
Patch Set: ReadMessage delegate 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/callback.h"
11 #include "blimp/net/helium/helium_result.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 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) = 0;
31
32 // Called when a message is read from the HeliumStream.
33 virtual void OnMessageReceived(std::unique_ptr<HeliumMessage> message) = 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 void SetDelegate(std::unique_ptr<Delegate> delegate);
perumaal 2016/10/06 00:02:11 nit: Delegates in general (IMO) are better off bei
Kevin M 2016/10/06 00:44:32 Not sure if I agree. WeakPtrs are definitely good
50
51 protected:
52 Delegate* delegate() { return delegate_.get(); }
53
54 private:
55 std::unique_ptr<Delegate> delegate_;
56
57 DISALLOW_COPY_AND_ASSIGN(HeliumStream);
58 };
59
60 } // namespace blimp
61
62 #endif // BLIMP_NET_HELIUM_HELIUM_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698