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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: blimp/net/helium/helium_stream.h
diff --git a/blimp/net/helium/helium_stream.h b/blimp/net/helium/helium_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c63131c08b7432227cdb4e92e96717415ade637
--- /dev/null
+++ b/blimp/net/helium/helium_stream.h
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BLIMP_NET_HELIUM_HELIUM_STREAM_H_
+#define BLIMP_NET_HELIUM_HELIUM_STREAM_H_
+
+#include <memory>
+
+#include "base/callback.h"
+#include "blimp/net/helium/helium_result.h"
+
+namespace blimp {
+
+class HeliumMessage;
+
+// Abstract base class for HeliumMessage-oriented transport streams.
+// Details about how the HeliumStream is bound to the network layer are handled
+// by subclasses of HeliumStream.
+class HeliumStream {
+ public:
+ class Delegate {
+ public:
+ // Invoked when the HeliumStream is disconnected.
+ //
+ // An observer which owns |this| may delete the HeliumStream in response to
+ // receiving an OnStreamDisconnected() notification. The deletion method
+ // must be asynchronously posted to occur *after* the OnStreamDisconnected()
+ // handler, not during.
+ virtual void OnStreamDisconnected(HeliumStream* stream) = 0;
+
+ // Called when a message is read from the HeliumStream.
+ virtual void OnMessageReceived(std::unique_ptr<HeliumMessage> message) = 0;
+ };
+
+ HeliumStream();
+ virtual ~HeliumStream();
+
+ // Sends |helium_message| over the Stream. |callback| is invoked when the
+ // message is sent (or otherwise moved to the low-level write buffers),
+ // which signals the caller that it is clear to send another message.
+ //
+ // The caller is responsible for ensuring that only one outstanding
+ // SendMessage() call is made at a time.
+ virtual void SendMessage(
+ std::unique_ptr<HeliumMessage> helium_message,
+ const base::Callback<void(HeliumResult)>& callback) = 0;
+
+ 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
+
+ protected:
+ Delegate* delegate() { return delegate_.get(); }
+
+ private:
+ std::unique_ptr<Delegate> delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(HeliumStream);
+};
+
+} // namespace blimp
+
+#endif // BLIMP_NET_HELIUM_HELIUM_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698