summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth/fake_connection.cc
blob: d7219665ac6ed2f8ef16dddb386d9c68e33be560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/proximity_auth/fake_connection.h"

#include <utility>

#include "components/proximity_auth/wire_message.h"

namespace proximity_auth {

FakeConnection::FakeConnection(const RemoteDevice& remote_device)
    : Connection(remote_device) {
  Connect();
}

FakeConnection::~FakeConnection() {
  Disconnect();
}

void FakeConnection::Connect() {
  SetStatus(CONNECTED);
}

void FakeConnection::Disconnect() {
  SetStatus(DISCONNECTED);
}

void FakeConnection::FinishSendingMessageWithSuccess(bool success) {
  CHECK(current_message_);
  // Capture a copy of the message, as OnDidSendMessage() might reentrantly
  // call SendMessage().
  scoped_ptr<WireMessage> sent_message = std::move(current_message_);
  OnDidSendMessage(*sent_message, success);
}

void FakeConnection::ReceiveMessageWithPayload(const std::string& payload) {
  pending_payload_ = payload;
  OnBytesReceived(std::string());
  pending_payload_.clear();
}

void FakeConnection::SendMessageImpl(scoped_ptr<WireMessage> message) {
  CHECK(!current_message_);
  current_message_ = std::move(message);
}

scoped_ptr<WireMessage> FakeConnection::DeserializeWireMessage(
    bool* is_incomplete_message) {
  *is_incomplete_message = false;
  return make_scoped_ptr(new WireMessage(pending_payload_));
}

}  // namespace proximity_auth