| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H | 6 #define COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/cryptauth/bluetooth_throttler.h" |
| 15 #include "components/cryptauth/connection.h" |
| 14 #include "components/cryptauth/remote_device.h" | 16 #include "components/cryptauth/remote_device.h" |
| 15 #include "components/proximity_auth/authenticator.h" | 17 #include "components/proximity_auth/authenticator.h" |
| 16 #include "components/proximity_auth/messenger_observer.h" | 18 #include "components/proximity_auth/messenger_observer.h" |
| 17 #include "components/proximity_auth/remote_device_life_cycle.h" | 19 #include "components/proximity_auth/remote_device_life_cycle.h" |
| 18 | 20 |
| 19 namespace proximity_auth { | 21 namespace proximity_auth { |
| 20 | 22 |
| 21 class BluetoothThrottler; | |
| 22 class Messenger; | 23 class Messenger; |
| 23 class Connection; | |
| 24 class ConnectionFinder; | 24 class ConnectionFinder; |
| 25 class ProximityAuthClient; | 25 class ProximityAuthClient; |
| 26 class SecureContext; | 26 class SecureContext; |
| 27 | 27 |
| 28 // Implementation of RemoteDeviceLifeCycle. | 28 // Implementation of RemoteDeviceLifeCycle. |
| 29 class RemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycle, | 29 class RemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycle, |
| 30 public MessengerObserver { | 30 public MessengerObserver { |
| 31 public: | 31 public: |
| 32 // Creates the life cycle for controlling the given |remote_device|. | 32 // Creates the life cycle for controlling the given |remote_device|. |
| 33 // |proximity_auth_client| is not owned. | 33 // |proximity_auth_client| is not owned. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // Transitions to |new_state|, and notifies observers. | 56 // Transitions to |new_state|, and notifies observers. |
| 57 void TransitionToState(RemoteDeviceLifeCycle::State new_state); | 57 void TransitionToState(RemoteDeviceLifeCycle::State new_state); |
| 58 | 58 |
| 59 // Transtitions to FINDING_CONNECTION state. Creates and starts | 59 // Transtitions to FINDING_CONNECTION state. Creates and starts |
| 60 // |connection_finder_|. | 60 // |connection_finder_|. |
| 61 void FindConnection(); | 61 void FindConnection(); |
| 62 | 62 |
| 63 // Called when |connection_finder_| finds a connection. | 63 // Called when |connection_finder_| finds a connection. |
| 64 void OnConnectionFound(std::unique_ptr<Connection> connection); | 64 void OnConnectionFound(std::unique_ptr<cryptauth::Connection> connection); |
| 65 | 65 |
| 66 // Callback when |authenticator_| completes authentication. | 66 // Callback when |authenticator_| completes authentication. |
| 67 void OnAuthenticationResult(Authenticator::Result result, | 67 void OnAuthenticationResult(Authenticator::Result result, |
| 68 std::unique_ptr<SecureContext> secure_context); | 68 std::unique_ptr<SecureContext> secure_context); |
| 69 | 69 |
| 70 // Creates the messenger which parses status updates. | 70 // Creates the messenger which parses status updates. |
| 71 void CreateMessenger(); | 71 void CreateMessenger(); |
| 72 | 72 |
| 73 // MessengerObserver: | 73 // MessengerObserver: |
| 74 void OnDisconnected() override; | 74 void OnDisconnected() override; |
| 75 | 75 |
| 76 // The remote device being controlled. | 76 // The remote device being controlled. |
| 77 const cryptauth::RemoteDevice remote_device_; | 77 const cryptauth::RemoteDevice remote_device_; |
| 78 | 78 |
| 79 // Used to grab dependencies in chrome. Not owned. | 79 // Used to grab dependencies in chrome. Not owned. |
| 80 ProximityAuthClient* proximity_auth_client_; | 80 ProximityAuthClient* proximity_auth_client_; |
| 81 | 81 |
| 82 // The current state in the life cycle. | 82 // The current state in the life cycle. |
| 83 RemoteDeviceLifeCycle::State state_; | 83 RemoteDeviceLifeCycle::State state_; |
| 84 | 84 |
| 85 // Observers added to the life cycle. Configured as NOTIFY_EXISTING_ONLY. | 85 // Observers added to the life cycle. Configured as NOTIFY_EXISTING_ONLY. |
| 86 base::ObserverList<Observer> observers_; | 86 base::ObserverList<Observer> observers_; |
| 87 | 87 |
| 88 // The connection that is established by |connection_finder_|. | 88 // The connection that is established by |connection_finder_|. |
| 89 std::unique_ptr<Connection> connection_; | 89 std::unique_ptr<cryptauth::Connection> connection_; |
| 90 | 90 |
| 91 // Context for encrypting and decrypting messages. Created after | 91 // Context for encrypting and decrypting messages. Created after |
| 92 // authentication succeeds. Ownership is eventually passed to |messenger_|. | 92 // authentication succeeds. Ownership is eventually passed to |messenger_|. |
| 93 std::unique_ptr<SecureContext> secure_context_; | 93 std::unique_ptr<SecureContext> secure_context_; |
| 94 | 94 |
| 95 // The messenger for sending and receiving messages in the | 95 // The messenger for sending and receiving messages in the |
| 96 // SECURE_CHANNEL_ESTABLISHED state. | 96 // SECURE_CHANNEL_ESTABLISHED state. |
| 97 std::unique_ptr<Messenger> messenger_; | 97 std::unique_ptr<Messenger> messenger_; |
| 98 | 98 |
| 99 // Authenticates the remote device after it is connected. Used in the | 99 // Authenticates the remote device after it is connected. Used in the |
| 100 // AUTHENTICATING state. | 100 // AUTHENTICATING state. |
| 101 std::unique_ptr<Authenticator> authenticator_; | 101 std::unique_ptr<Authenticator> authenticator_; |
| 102 | 102 |
| 103 // Used in the FINDING_CONNECTION state to establish a connection to the | 103 // Used in the FINDING_CONNECTION state to establish a connection to the |
| 104 // remote device. | 104 // remote device. |
| 105 std::unique_ptr<ConnectionFinder> connection_finder_; | 105 std::unique_ptr<ConnectionFinder> connection_finder_; |
| 106 | 106 |
| 107 // Rate limits Bluetooth connections to the same device. Used to in the | 107 // Rate limits Bluetooth connections to the same device. Used to in the |
| 108 // created ConnectionFinder. | 108 // created ConnectionFinder. |
| 109 std::unique_ptr<BluetoothThrottler> bluetooth_throttler_; | 109 std::unique_ptr<cryptauth::BluetoothThrottler> bluetooth_throttler_; |
| 110 | 110 |
| 111 // After authentication fails, this timer waits for a period of time before | 111 // After authentication fails, this timer waits for a period of time before |
| 112 // retrying the connection. | 112 // retrying the connection. |
| 113 base::OneShotTimer authentication_recovery_timer_; | 113 base::OneShotTimer authentication_recovery_timer_; |
| 114 | 114 |
| 115 base::WeakPtrFactory<RemoteDeviceLifeCycleImpl> weak_ptr_factory_; | 115 base::WeakPtrFactory<RemoteDeviceLifeCycleImpl> weak_ptr_factory_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLifeCycleImpl); | 117 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLifeCycleImpl); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace proximity_auth | 120 } // namespace proximity_auth |
| 121 | 121 |
| 122 #endif // COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H | 122 #endif // COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H |
| OLD | NEW |