| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/proximity_auth/messenger_impl.h" | 5 #include "components/proximity_auth/messenger_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 MessengerImpl::MessengerImpl(std::unique_ptr<Connection> connection, | 71 MessengerImpl::MessengerImpl(std::unique_ptr<Connection> connection, |
| 72 std::unique_ptr<SecureContext> secure_context) | 72 std::unique_ptr<SecureContext> secure_context) |
| 73 : connection_(std::move(connection)), | 73 : connection_(std::move(connection)), |
| 74 secure_context_(std::move(secure_context)), | 74 secure_context_(std::move(secure_context)), |
| 75 weak_ptr_factory_(this) { | 75 weak_ptr_factory_(this) { |
| 76 DCHECK(connection_->IsConnected()); | 76 DCHECK(connection_->IsConnected()); |
| 77 connection_->AddObserver(this); | 77 connection_->AddObserver(this); |
| 78 | 78 |
| 79 // TODO(tengs): We need CryptAuth to report if the phone runs iOS or Android, | 79 // TODO(tengs): We need CryptAuth to report if the phone runs iOS or Android, |
| 80 // rather than relying on this heuristic. | 80 // rather than relying on this heuristic. |
| 81 if (connection_->remote_device().bluetooth_type == RemoteDevice::BLUETOOTH_LE) | 81 if (connection_->remote_device().bluetooth_type == |
| 82 cryptauth::RemoteDevice::BLUETOOTH_LE) |
| 82 PollScreenStateForIOS(); | 83 PollScreenStateForIOS(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 MessengerImpl::~MessengerImpl() { | 86 MessengerImpl::~MessengerImpl() { |
| 86 if (connection_) | 87 if (connection_) |
| 87 connection_->RemoveObserver(this); | 88 connection_->RemoveObserver(this); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void MessengerImpl::AddObserver(MessengerObserver* observer) { | 91 void MessengerImpl::AddObserver(MessengerObserver* observer) { |
| 91 observers_.AddObserver(observer); | 92 observers_.AddObserver(observer); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void MessengerImpl::RemoveObserver(MessengerObserver* observer) { | 95 void MessengerImpl::RemoveObserver(MessengerObserver* observer) { |
| 95 observers_.RemoveObserver(observer); | 96 observers_.RemoveObserver(observer); |
| 96 } | 97 } |
| 97 | 98 |
| 98 bool MessengerImpl::SupportsSignIn() const { | 99 bool MessengerImpl::SupportsSignIn() const { |
| 99 // TODO(tengs): Support sign-in for Bluetooth LE protocol. | 100 // TODO(tengs): Support sign-in for Bluetooth LE protocol. |
| 100 return (secure_context_->GetProtocolVersion() == | 101 return (secure_context_->GetProtocolVersion() == |
| 101 SecureContext::PROTOCOL_VERSION_THREE_ONE) && | 102 SecureContext::PROTOCOL_VERSION_THREE_ONE) && |
| 102 connection_->remote_device().bluetooth_type != | 103 connection_->remote_device().bluetooth_type != |
| 103 RemoteDevice::BLUETOOTH_LE; | 104 cryptauth::RemoteDevice::BLUETOOTH_LE; |
| 104 } | 105 } |
| 105 | 106 |
| 106 void MessengerImpl::DispatchUnlockEvent() { | 107 void MessengerImpl::DispatchUnlockEvent() { |
| 107 base::DictionaryValue message; | 108 base::DictionaryValue message; |
| 108 message.SetString(kTypeKey, kMessageTypeLocalEvent); | 109 message.SetString(kTypeKey, kMessageTypeLocalEvent); |
| 109 message.SetString(kNameKey, kUnlockEventName); | 110 message.SetString(kNameKey, kUnlockEventName); |
| 110 queued_messages_.push_back(PendingMessage(message)); | 111 queued_messages_.push_back(PendingMessage(message)); |
| 111 ProcessMessageQueue(); | 112 ProcessMessageQueue(); |
| 112 } | 113 } |
| 113 | 114 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } else { | 357 } else { |
| 357 PA_LOG(ERROR) << "Message of unknown type '" << pending_message_->type | 358 PA_LOG(ERROR) << "Message of unknown type '" << pending_message_->type |
| 358 << "' sent."; | 359 << "' sent."; |
| 359 } | 360 } |
| 360 | 361 |
| 361 pending_message_.reset(); | 362 pending_message_.reset(); |
| 362 ProcessMessageQueue(); | 363 ProcessMessageQueue(); |
| 363 } | 364 } |
| 364 | 365 |
| 365 } // namespace proximity_auth | 366 } // namespace proximity_auth |
| OLD | NEW |