| 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_HELIUM_TRANSPORT_H_ | |
| 6 #define BLIMP_HELIUM_TRANSPORT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/cancelable_callback.h" | |
| 12 #include "blimp/helium/result.h" | |
| 13 | |
| 14 namespace blimp { | |
| 15 namespace helium { | |
| 16 | |
| 17 // Pure virtual interface for a helium::Stream factory. Subclasses can use this | |
| 18 // interface to encapsulate transport-specific stream connection semantics. | |
| 19 class Transport { | |
| 20 public: | |
| 21 // Callback invoked with the stream and result code of a Connect or Accept | |
| 22 // attempt. | |
| 23 // The helium::Stream is assumed to be authenticated and ready to use. | |
| 24 // If the connection attempt failed, the value of |stream| will be null and | |
| 25 // |result| will be set to the relevant error code. | |
| 26 using StreamCreatedCallback = | |
| 27 base::CancelableCallback<void(std::unique_ptr<Stream> stream, | |
| 28 Result result)>; | |
| 29 | |
| 30 // Callback to be invoked when the underlying transport transitions | |
| 31 // between an offline/unusable state and an online/usable state. | |
| 32 using AvailabilityChangedCallback = base::Callback<void(bool)>; | |
| 33 | |
| 34 virtual void SetAvailabilityChangedCallback( | |
| 35 const AvailabilityChangedCallback& callback); | |
| 36 | |
| 37 // Asynchronously attempts to connect a new helium::Stream. | |
| 38 // Multiple overlapping connection attempts are permitted. | |
| 39 // The caller can cancel |cb| if it no longer needs the stream. | |
| 40 virtual void Connect(const StreamCreatedCallback& cb) = 0; | |
| 41 | |
| 42 // Accepts an incoming connection from the peer. | |
| 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; | |
| 48 }; | |
| 49 | |
| 50 } // namespace helium | |
| 51 } // namespace blimp | |
| 52 | |
| 53 #endif // BLIMP_HELIUM_TRANSPORT_H_ | |
| OLD | NEW |