| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 #include "components/proximity_auth/fake_connection.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "components/proximity_auth/wire_message.h" | |
| 11 | |
| 12 namespace proximity_auth { | |
| 13 | |
| 14 FakeConnection::FakeConnection(const cryptauth::RemoteDevice& remote_device) | |
| 15 : Connection(remote_device) { | |
| 16 Connect(); | |
| 17 } | |
| 18 | |
| 19 FakeConnection::~FakeConnection() { | |
| 20 Disconnect(); | |
| 21 } | |
| 22 | |
| 23 void FakeConnection::Connect() { | |
| 24 SetStatus(CONNECTED); | |
| 25 } | |
| 26 | |
| 27 void FakeConnection::Disconnect() { | |
| 28 SetStatus(DISCONNECTED); | |
| 29 } | |
| 30 | |
| 31 void FakeConnection::FinishSendingMessageWithSuccess(bool success) { | |
| 32 CHECK(current_message_); | |
| 33 // Capture a copy of the message, as OnDidSendMessage() might reentrantly | |
| 34 // call SendMessage(). | |
| 35 std::unique_ptr<WireMessage> sent_message = std::move(current_message_); | |
| 36 OnDidSendMessage(*sent_message, success); | |
| 37 } | |
| 38 | |
| 39 void FakeConnection::ReceiveMessageWithPayload(const std::string& payload) { | |
| 40 pending_payload_ = payload; | |
| 41 OnBytesReceived(std::string()); | |
| 42 pending_payload_.clear(); | |
| 43 } | |
| 44 | |
| 45 void FakeConnection::SendMessageImpl(std::unique_ptr<WireMessage> message) { | |
| 46 CHECK(!current_message_); | |
| 47 current_message_ = std::move(message); | |
| 48 } | |
| 49 | |
| 50 std::unique_ptr<WireMessage> FakeConnection::DeserializeWireMessage( | |
| 51 bool* is_incomplete_message) { | |
| 52 *is_incomplete_message = false; | |
| 53 return base::MakeUnique<WireMessage>(pending_payload_); | |
| 54 } | |
| 55 | |
| 56 } // namespace proximity_auth | |
| OLD | NEW |