| 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> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "components/proximity_auth/authenticator.h" | 14 #include "components/proximity_auth/authenticator.h" |
| 14 #include "components/proximity_auth/messenger_observer.h" | 15 #include "components/proximity_auth/messenger_observer.h" |
| 15 #include "components/proximity_auth/remote_device.h" | 16 #include "components/proximity_auth/remote_device.h" |
| 16 #include "components/proximity_auth/remote_device_life_cycle.h" | 17 #include "components/proximity_auth/remote_device_life_cycle.h" |
| 17 | 18 |
| 18 namespace proximity_auth { | 19 namespace proximity_auth { |
| 19 | 20 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 void Start() override; | 40 void Start() override; |
| 40 RemoteDevice GetRemoteDevice() const override; | 41 RemoteDevice GetRemoteDevice() const override; |
| 41 RemoteDeviceLifeCycle::State GetState() const override; | 42 RemoteDeviceLifeCycle::State GetState() const override; |
| 42 Messenger* GetMessenger() override; | 43 Messenger* GetMessenger() override; |
| 43 void AddObserver(Observer* observer) override; | 44 void AddObserver(Observer* observer) override; |
| 44 void RemoveObserver(Observer* observer) override; | 45 void RemoveObserver(Observer* observer) override; |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 // Creates and returns a ConnectionFinder instance for |remote_device_|. | 48 // Creates and returns a ConnectionFinder instance for |remote_device_|. |
| 48 // Exposed for testing. | 49 // Exposed for testing. |
| 49 virtual scoped_ptr<ConnectionFinder> CreateConnectionFinder(); | 50 virtual std::unique_ptr<ConnectionFinder> CreateConnectionFinder(); |
| 50 | 51 |
| 51 // Creates and returns an Authenticator instance for |connection_|. | 52 // Creates and returns an Authenticator instance for |connection_|. |
| 52 // Exposed for testing. | 53 // Exposed for testing. |
| 53 virtual scoped_ptr<Authenticator> CreateAuthenticator(); | 54 virtual std::unique_ptr<Authenticator> CreateAuthenticator(); |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 // Transitions to |new_state|, and notifies observers. | 57 // Transitions to |new_state|, and notifies observers. |
| 57 void TransitionToState(RemoteDeviceLifeCycle::State new_state); | 58 void TransitionToState(RemoteDeviceLifeCycle::State new_state); |
| 58 | 59 |
| 59 // Transtitions to FINDING_CONNECTION state. Creates and starts | 60 // Transtitions to FINDING_CONNECTION state. Creates and starts |
| 60 // |connection_finder_|. | 61 // |connection_finder_|. |
| 61 void FindConnection(); | 62 void FindConnection(); |
| 62 | 63 |
| 63 // Called when |connection_finder_| finds a connection. | 64 // Called when |connection_finder_| finds a connection. |
| 64 void OnConnectionFound(scoped_ptr<Connection> connection); | 65 void OnConnectionFound(std::unique_ptr<Connection> connection); |
| 65 | 66 |
| 66 // Callback when |authenticator_| completes authentication. | 67 // Callback when |authenticator_| completes authentication. |
| 67 void OnAuthenticationResult(Authenticator::Result result, | 68 void OnAuthenticationResult(Authenticator::Result result, |
| 68 scoped_ptr<SecureContext> secure_context); | 69 std::unique_ptr<SecureContext> secure_context); |
| 69 | 70 |
| 70 // Creates the messenger which parses status updates. | 71 // Creates the messenger which parses status updates. |
| 71 void CreateMessenger(); | 72 void CreateMessenger(); |
| 72 | 73 |
| 73 // MessengerObserver: | 74 // MessengerObserver: |
| 74 void OnDisconnected() override; | 75 void OnDisconnected() override; |
| 75 | 76 |
| 76 // The remote device being controlled. | 77 // The remote device being controlled. |
| 77 const RemoteDevice remote_device_; | 78 const RemoteDevice remote_device_; |
| 78 | 79 |
| 79 // Used to grab dependencies in chrome. Not owned. | 80 // Used to grab dependencies in chrome. Not owned. |
| 80 ProximityAuthClient* proximity_auth_client_; | 81 ProximityAuthClient* proximity_auth_client_; |
| 81 | 82 |
| 82 // The current state in the life cycle. | 83 // The current state in the life cycle. |
| 83 RemoteDeviceLifeCycle::State state_; | 84 RemoteDeviceLifeCycle::State state_; |
| 84 | 85 |
| 85 // Observers added to the life cycle. Configured as NOTIFY_EXISTING_ONLY. | 86 // Observers added to the life cycle. Configured as NOTIFY_EXISTING_ONLY. |
| 86 base::ObserverList<Observer> observers_; | 87 base::ObserverList<Observer> observers_; |
| 87 | 88 |
| 88 // The connection that is established by |connection_finder_|. | 89 // The connection that is established by |connection_finder_|. |
| 89 scoped_ptr<Connection> connection_; | 90 std::unique_ptr<Connection> connection_; |
| 90 | 91 |
| 91 // Context for encrypting and decrypting messages. Created after | 92 // Context for encrypting and decrypting messages. Created after |
| 92 // authentication succeeds. Ownership is eventually passed to |messenger_|. | 93 // authentication succeeds. Ownership is eventually passed to |messenger_|. |
| 93 scoped_ptr<SecureContext> secure_context_; | 94 std::unique_ptr<SecureContext> secure_context_; |
| 94 | 95 |
| 95 // The messenger for sending and receiving messages in the | 96 // The messenger for sending and receiving messages in the |
| 96 // SECURE_CHANNEL_ESTABLISHED state. | 97 // SECURE_CHANNEL_ESTABLISHED state. |
| 97 scoped_ptr<Messenger> messenger_; | 98 std::unique_ptr<Messenger> messenger_; |
| 98 | 99 |
| 99 // Authenticates the remote device after it is connected. Used in the | 100 // Authenticates the remote device after it is connected. Used in the |
| 100 // AUTHENTICATING state. | 101 // AUTHENTICATING state. |
| 101 scoped_ptr<Authenticator> authenticator_; | 102 std::unique_ptr<Authenticator> authenticator_; |
| 102 | 103 |
| 103 // Used in the FINDING_CONNECTION state to establish a connection to the | 104 // Used in the FINDING_CONNECTION state to establish a connection to the |
| 104 // remote device. | 105 // remote device. |
| 105 scoped_ptr<ConnectionFinder> connection_finder_; | 106 std::unique_ptr<ConnectionFinder> connection_finder_; |
| 106 | 107 |
| 107 // Rate limits Bluetooth connections to the same device. Used to in the | 108 // Rate limits Bluetooth connections to the same device. Used to in the |
| 108 // created ConnectionFinder. | 109 // created ConnectionFinder. |
| 109 scoped_ptr<BluetoothThrottler> bluetooth_throttler_; | 110 std::unique_ptr<BluetoothThrottler> bluetooth_throttler_; |
| 110 | 111 |
| 111 // After authentication fails, this timer waits for a period of time before | 112 // After authentication fails, this timer waits for a period of time before |
| 112 // retrying the connection. | 113 // retrying the connection. |
| 113 base::OneShotTimer authentication_recovery_timer_; | 114 base::OneShotTimer authentication_recovery_timer_; |
| 114 | 115 |
| 115 base::WeakPtrFactory<RemoteDeviceLifeCycleImpl> weak_ptr_factory_; | 116 base::WeakPtrFactory<RemoteDeviceLifeCycleImpl> weak_ptr_factory_; |
| 116 | 117 |
| 117 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLifeCycleImpl); | 118 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLifeCycleImpl); |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 } // namespace proximity_auth | 121 } // namespace proximity_auth |
| 121 | 122 |
| 122 #endif // COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H | 123 #endif // COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_IMPL_H |
| OLD | NEW |