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_TRANSPORT_H_ | |
| 6 #define BLIMP_NET_HELIUM_HELIUM_TRANSPORT_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 // Abstract interface for a HeliumStream factory. Subclasses can use this | |
| 16 // interface to encapsulate transport-specific stream connection semantics. | |
| 17 class HeliumTransport { | |
| 18 public: | |
| 19 // Callback invoked with the stream and result code of a Connect or Accept | |
| 20 // attempt. | |
| 21 // The HeliumStream is assumed to be authenticated and ready to use. | |
| 22 // If the connection attempt failed, the value of |stream| will be null and | |
| 23 // |result| will be set to the relevant error code. | |
| 24 using StreamCreatedCallback = | |
| 25 base::Callback<void(std::unique_ptr<HeliumStream> stream, | |
| 26 HeliumResult result)>; | |
| 27 | |
| 28 class Delegate { | |
| 29 public: | |
| 30 // Called when the transport transitions between an offline/unusable state | |
| 31 // and an online/usable state. | |
| 32 virtual void OnAvailabilityChanged(bool available) = 0; | |
|
Wez
2016/10/08 01:02:29
nit: Since this has only a single method right now
Kevin M
2016/10/11 20:02:37
Done.
| |
| 33 }; | |
| 34 | |
| 35 virtual void SetDelegate(std::unique_ptr<Delegate> delegate); | |
| 36 | |
| 37 // Asynchronously attempts to connect a new HeliumStream. | |
| 38 // Multiple overlapping connection attempts are permitted. | |
| 39 virtual void Connect(const StreamCreatedCallback& cb) = 0; | |
|
Wez
2016/10/08 01:02:29
As discussed previously, I think we need a way to
Kevin M
2016/10/11 20:02:37
I switched to CancelableCallback. The Stream that
| |
| 40 | |
| 41 // Accepts an incoming connection from the peer. | |
| 42 // Only one Accept() call may be issued at a time. | |
|
Wez
2016/10/08 01:02:30
Do we need that restriction, really? We could make
Kevin M
2016/10/11 20:02:37
Done.
| |
| 43 virtual void Accept(const StreamCreatedCallback& cb) = 0; | |
| 44 | |
| 45 // Returns true if the underlying transport has the necessary resources | |
| 46 // and connectivity for Connect and Accept operations. | |
| 47 virtual bool IsAvailable() = 0; | |
|
Wez
2016/10/08 01:02:29
nit: Do we need both a notification *and* this?
Kevin M
2016/10/11 20:02:37
I think it's useful for querying the initial conne
| |
| 48 }; | |
| 49 | |
| 50 } // namespace blimp | |
| 51 | |
| 52 #endif // BLIMP_NET_HELIUM_HELIUM_TRANSPORT_H_ | |
| OLD | NEW |