Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: components/cryptauth/fake_secure_channel.cc

Issue 2697763002: [CrOS Tether]: Create BleConnectionManager, which manages secure connections between the current de… (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(
12 const std::string& feature, 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(
33 const std::string& feature, 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(
44 const std::string& feature, 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(
58 std::find(observers_.begin(), observers_.end(), observer),
59 observers_.end());
60 }
61
62 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698