| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/proximity_auth/fake_connection.h" | 5 #include "components/proximity_auth/fake_connection.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "components/proximity_auth/wire_message.h" | 9 #include "components/proximity_auth/wire_message.h" |
| 8 | 10 |
| 9 namespace proximity_auth { | 11 namespace proximity_auth { |
| 10 | 12 |
| 11 FakeConnection::FakeConnection(const RemoteDevice& remote_device) | 13 FakeConnection::FakeConnection(const RemoteDevice& remote_device) |
| 12 : Connection(remote_device) { | 14 : Connection(remote_device) { |
| 13 Connect(); | 15 Connect(); |
| 14 } | 16 } |
| 15 | 17 |
| 16 FakeConnection::~FakeConnection() { | 18 FakeConnection::~FakeConnection() { |
| 17 Disconnect(); | 19 Disconnect(); |
| 18 } | 20 } |
| 19 | 21 |
| 20 void FakeConnection::Connect() { | 22 void FakeConnection::Connect() { |
| 21 SetStatus(CONNECTED); | 23 SetStatus(CONNECTED); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void FakeConnection::Disconnect() { | 26 void FakeConnection::Disconnect() { |
| 25 SetStatus(DISCONNECTED); | 27 SetStatus(DISCONNECTED); |
| 26 } | 28 } |
| 27 | 29 |
| 28 void FakeConnection::FinishSendingMessageWithSuccess(bool success) { | 30 void FakeConnection::FinishSendingMessageWithSuccess(bool success) { |
| 29 CHECK(current_message_); | 31 CHECK(current_message_); |
| 30 // Capture a copy of the message, as OnDidSendMessage() might reentrantly | 32 // Capture a copy of the message, as OnDidSendMessage() might reentrantly |
| 31 // call SendMessage(). | 33 // call SendMessage(). |
| 32 scoped_ptr<WireMessage> sent_message = current_message_.Pass(); | 34 scoped_ptr<WireMessage> sent_message = std::move(current_message_); |
| 33 OnDidSendMessage(*sent_message, success); | 35 OnDidSendMessage(*sent_message, success); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void FakeConnection::ReceiveMessageWithPayload(const std::string& payload) { | 38 void FakeConnection::ReceiveMessageWithPayload(const std::string& payload) { |
| 37 pending_payload_ = payload; | 39 pending_payload_ = payload; |
| 38 OnBytesReceived(std::string()); | 40 OnBytesReceived(std::string()); |
| 39 pending_payload_.clear(); | 41 pending_payload_.clear(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void FakeConnection::SendMessageImpl(scoped_ptr<WireMessage> message) { | 44 void FakeConnection::SendMessageImpl(scoped_ptr<WireMessage> message) { |
| 43 CHECK(!current_message_); | 45 CHECK(!current_message_); |
| 44 current_message_ = message.Pass(); | 46 current_message_ = std::move(message); |
| 45 } | 47 } |
| 46 | 48 |
| 47 scoped_ptr<WireMessage> FakeConnection::DeserializeWireMessage( | 49 scoped_ptr<WireMessage> FakeConnection::DeserializeWireMessage( |
| 48 bool* is_incomplete_message) { | 50 bool* is_incomplete_message) { |
| 49 *is_incomplete_message = false; | 51 *is_incomplete_message = false; |
| 50 return make_scoped_ptr(new WireMessage(pending_payload_)); | 52 return make_scoped_ptr(new WireMessage(pending_payload_)); |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // namespace proximity_auth | 55 } // namespace proximity_auth |
| OLD | NEW |