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