| OLD | NEW |
| 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( |
| 25 std::move(connection), 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> |
| 34 SecureChannel::Factory::BuildInstance(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]"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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( |
| 43 std::unique_ptr<Connection> connection, | 69 std::unique_ptr<Connection> connection, |
| 44 std::unique_ptr<Delegate> delegate) | 70 std::unique_ptr<Delegate> delegate) |
| 45 : connection_(std::move(connection)), | 71 : status_(Status::DISCONNECTED), |
| 72 connection_(std::move(connection)), |
| 46 delegate_(std::move(delegate)), | 73 delegate_(std::move(delegate)), |
| 47 status_(Status::DISCONNECTED), | |
| 48 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { |
| 49 DCHECK(connection_); | 75 DCHECK(connection_); |
| 50 DCHECK(!connection_->IsConnected()); | 76 DCHECK(!connection_->IsConnected()); |
| 51 DCHECK(!connection_->remote_device().user_id.empty()); | 77 DCHECK(!connection_->remote_device().user_id.empty()); |
| 52 DCHECK(delegate_); | 78 DCHECK(delegate_); |
| 53 | 79 |
| 54 connection_->AddObserver(this); | 80 connection_->AddObserver(this); |
| 55 } | 81 } |
| 56 | 82 |
| 57 SecureChannel::~SecureChannel() { | 83 SecureChannel::~SecureChannel() { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 << connection_->remote_device().GetTruncatedDeviceIdForLogs(); | 264 << connection_->remote_device().GetTruncatedDeviceIdForLogs(); |
| 239 Disconnect(); | 265 Disconnect(); |
| 240 return; | 266 return; |
| 241 } | 267 } |
| 242 | 268 |
| 243 secure_context_ = std::move(secure_context); | 269 secure_context_ = std::move(secure_context); |
| 244 TransitionToStatus(Status::AUTHENTICATED); | 270 TransitionToStatus(Status::AUTHENTICATED); |
| 245 } | 271 } |
| 246 | 272 |
| 247 } // namespace cryptauth | 273 } // namespace cryptauth |
| OLD | NEW |