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

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

Issue 2697763002: [CrOS Tether]: Create BleConnectionManager, which manages secure connections between the current de… (Closed)
Patch Set: Add missing DEP. 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
« no previous file with comments | « components/cryptauth/secure_channel.h ('k') | components/cryptauth/secure_channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/cryptauth/secure_channel.h" 5 #include "components/cryptauth/secure_channel.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "components/cryptauth/wire_message.h" 9 #include "components/cryptauth/wire_message.h"
10 #include "components/proximity_auth/logging/logging.h" 10 #include "components/proximity_auth/logging/logging.h"
11 11
12 namespace cryptauth { 12 namespace cryptauth {
13 13
14 // static 14 // static
15 SecureChannel::Factory* SecureChannel::Factory::factory_instance_ = nullptr;
16
17 // static
18 std::unique_ptr<SecureChannel> SecureChannel::Factory::NewInstance(
19 std::unique_ptr<Connection> connection,
20 std::unique_ptr<Delegate> delegate) {
21 if (!factory_instance_) {
22 factory_instance_ = new Factory();
23 }
24 return factory_instance_->BuildInstance(std::move(connection),
25 std::move(delegate));
26 }
27
28 // static
29 void SecureChannel::Factory::SetInstanceForTesting(Factory* factory) {
30 factory_instance_ = factory;
31 }
32
33 std::unique_ptr<SecureChannel> SecureChannel::Factory::BuildInstance(
34 std::unique_ptr<Connection> connection,
35 std::unique_ptr<Delegate> delegate) {
36 return base::WrapUnique(
37 new SecureChannel(std::move(connection), std::move(delegate)));
38 }
39
40 // static
15 std::string SecureChannel::StatusToString(const Status& status) { 41 std::string SecureChannel::StatusToString(const Status& status) {
16 switch (status) { 42 switch (status) {
17 case Status::DISCONNECTED: 43 case Status::DISCONNECTED:
18 return "[disconnected]"; 44 return "[disconnected]";
19 case Status::CONNECTING: 45 case Status::CONNECTING:
20 return "[connecting]"; 46 return "[connecting]";
21 case Status::CONNECTED: 47 case Status::CONNECTED:
22 return "[connected]"; 48 return "[connected]";
23 case Status::AUTHENTICATING: 49 case Status::AUTHENTICATING:
24 return "[authenticating]"; 50 return "[authenticating]";
25 case Status::AUTHENTICATED: 51 case Status::AUTHENTICATED:
26 return "[authenticated]"; 52 return "[authenticated]";
27 default: 53 default:
28 return "[unknown status]"; 54 return "[unknown status]";
29 } 55 }
30 } 56 }
31 57
32 SecureChannel::Delegate::~Delegate() {} 58 SecureChannel::Delegate::~Delegate() {}
33 59
34 SecureChannel::PendingMessage::PendingMessage() {} 60 SecureChannel::PendingMessage::PendingMessage() {}
35 61
36 SecureChannel::PendingMessage::PendingMessage( 62 SecureChannel::PendingMessage::PendingMessage(
37 const std::string& feature, const std::string& payload) 63 const std::string& feature, const std::string& payload)
38 : feature(feature), payload(payload) {} 64 : feature(feature), payload(payload) {}
39 65
40 SecureChannel::PendingMessage::~PendingMessage() {} 66 SecureChannel::PendingMessage::~PendingMessage() {}
41 67
42 SecureChannel::SecureChannel( 68 SecureChannel::SecureChannel(std::unique_ptr<Connection> connection,
43 std::unique_ptr<Connection> connection, 69 std::unique_ptr<Delegate> delegate)
44 std::unique_ptr<Delegate> delegate) 70 : status_(Status::DISCONNECTED),
45 : connection_(std::move(connection)), 71 connection_(std::move(connection)),
46 delegate_(std::move(delegate)), 72 delegate_(std::move(delegate)),
47 status_(Status::DISCONNECTED),
48 weak_ptr_factory_(this) { 73 weak_ptr_factory_(this) {
49 DCHECK(connection_); 74 DCHECK(connection_);
50 DCHECK(!connection_->IsConnected()); 75 DCHECK(!connection_->IsConnected());
51 DCHECK(!connection_->remote_device().user_id.empty()); 76 DCHECK(!connection_->remote_device().user_id.empty());
52 DCHECK(delegate_); 77 DCHECK(delegate_);
53 78
54 connection_->AddObserver(this); 79 connection_->AddObserver(this);
55 } 80 }
56 81
57 SecureChannel::~SecureChannel() { 82 SecureChannel::~SecureChannel() {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 << connection_->remote_device().GetTruncatedDeviceIdForLogs(); 263 << connection_->remote_device().GetTruncatedDeviceIdForLogs();
239 Disconnect(); 264 Disconnect();
240 return; 265 return;
241 } 266 }
242 267
243 secure_context_ = std::move(secure_context); 268 secure_context_ = std::move(secure_context);
244 TransitionToStatus(Status::AUTHENTICATED); 269 TransitionToStatus(Status::AUTHENTICATED);
245 } 270 }
246 271
247 } // namespace cryptauth 272 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/secure_channel.h ('k') | components/cryptauth/secure_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698