Roll forward up to cl/355234568.

This commit is contained in:
hai007
2021-02-04 13:27:30 -08:00
parent 8a3b5f2f65
commit cd992ba413
3 changed files with 28 additions and 54 deletions
+1 -31
View File
@@ -40,36 +40,6 @@ namespace location {
namespace nearby {
namespace connections {
// Define a class that supports move operation for pointers using std::swap.
// It replicates std::unique_ptr<> behavior, but it does not own the pointer,
// so it does not attempt destroy it.
// This approach was recommended during code review, as a better alternative to
// reuse of std::unique_ptr<> with custom no-op deleter, for the sake of
// readability.
template <typename T>
class Swapper {
public:
Swapper(T* pointer) : pointer_(pointer) {} // NOLINT.
Swapper(Swapper&& other) { *this = std::move(other); }
Swapper& operator=(Swapper&& other) {
std::swap(pointer_, other.pointer_);
return *this;
}
T* operator->() const { return pointer_; }
T& operator*() { return *pointer_; }
operator T*() { return pointer_; } // NOLINT.
T* get() const { return pointer_; }
void reset() { pointer_ = nullptr; }
private:
T* pointer_ = nullptr;
};
template <typename T>
Swapper<T> MakeSwapper(T* value) {
return Swapper<T>(value);
}
// Represents the WebRtc state that mediums are connectable or not.
enum class WebRtcState {
kUndefined = 0,
@@ -341,7 +311,7 @@ class BasePcpHandler : public PcpHandler,
// Only set for outgoing connections. If set, we must call
// result->Set() when connection is established, or rejected.
Swapper<Future<Status>> result = nullptr;
std::weak_ptr<Future<Status>> result;
// Only (possibly) vector for incoming connections.
std::vector<proto::connections::Medium> supported_mediums;