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