OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/cryptauth/fake_secure_channel.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace cryptauth { |
| 10 |
| 11 FakeSecureChannel::SentMessage::SentMessage(const std::string& feature, |
| 12 const std::string& payload) |
| 13 : feature(feature), payload(payload) {} |
| 14 |
| 15 FakeSecureChannel::FakeSecureChannel(std::unique_ptr<Connection> connection, |
| 16 std::unique_ptr<Delegate> delegate) |
| 17 : SecureChannel(std::move(connection), std::move(delegate)) {} |
| 18 |
| 19 FakeSecureChannel::~FakeSecureChannel() {} |
| 20 |
| 21 void FakeSecureChannel::ChangeStatus(const Status& new_status) { |
| 22 Status old_status = status_; |
| 23 status_ = new_status; |
| 24 |
| 25 // Copy to prevent channel from being removed during handler. |
| 26 std::vector<Observer*> observers_copy = observers_; |
| 27 for (auto observer : observers_copy) { |
| 28 observer->OnSecureChannelStatusChanged(this, old_status, status_); |
| 29 } |
| 30 } |
| 31 |
| 32 void FakeSecureChannel::ReceiveMessage(const std::string& feature, |
| 33 const std::string& payload) { |
| 34 // Copy to prevent channel from being removed during handler. |
| 35 std::vector<Observer*> observers_copy = observers_; |
| 36 for (auto observer : observers_copy) { |
| 37 observer->OnMessageReceived(this, feature, payload); |
| 38 } |
| 39 } |
| 40 |
| 41 void FakeSecureChannel::Initialize() {} |
| 42 |
| 43 void FakeSecureChannel::SendMessage(const std::string& feature, |
| 44 const std::string& payload) { |
| 45 sent_messages_.push_back(SentMessage(feature, payload)); |
| 46 } |
| 47 |
| 48 void FakeSecureChannel::Disconnect() { |
| 49 ChangeStatus(Status::DISCONNECTED); |
| 50 } |
| 51 |
| 52 void FakeSecureChannel::AddObserver(Observer* observer) { |
| 53 observers_.push_back(observer); |
| 54 } |
| 55 |
| 56 void FakeSecureChannel::RemoveObserver(Observer* observer) { |
| 57 observers_.erase(std::find(observers_.begin(), observers_.end(), observer), |
| 58 observers_.end()); |
| 59 } |
| 60 |
| 61 } // namespace cryptauth |
OLD | NEW |