Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 { | |
|
Wez
2016/10/08 01:02:29
Can we break this into a interface and a separate
Kevin M
2016/10/11 20:02:37
Done.
| |
| 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. | |
|
Wez
2016/10/08 01:02:29
nit: Could we arrange things to make this safe?
I
Kevin M
2016/10/11 20:02:37
I've been getting a lot of mixed signals from a lo
Garrett Casto
2016/10/11 20:27:03
To clarify my stance, I was originally for the del
| |
| 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); | |
| 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_ | |
| OLD | NEW |