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

Side by Side Diff: components/proximity_auth/bluetooth_connection_finder.h

Issue 2561203002: Migrate weave-related classes from proximity_auth/ble to cryptauth/ble. (Closed)
Patch Set: Rebase. Created 4 years 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
OLDNEW
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 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/cryptauth/connection.h"
16 #include "components/cryptauth/connection_finder.h"
17 #include "components/cryptauth/connection_observer.h"
15 #include "components/cryptauth/remote_device.h" 18 #include "components/cryptauth/remote_device.h"
16 #include "components/proximity_auth/bluetooth_util.h" 19 #include "components/proximity_auth/bluetooth_util.h"
17 #include "components/proximity_auth/connection_finder.h"
18 #include "components/proximity_auth/connection_observer.h"
19 #include "device/bluetooth/bluetooth_adapter.h" 20 #include "device/bluetooth/bluetooth_adapter.h"
20 #include "device/bluetooth/bluetooth_uuid.h" 21 #include "device/bluetooth/bluetooth_uuid.h"
21 22
22 namespace proximity_auth { 23 namespace proximity_auth {
23 24
24 // This ConnectionFinder implementation tries to find a Bluetooth connection to 25 // This cryptauth::ConnectionFinder implementation tries to find a Bluetooth
26 // connection to
25 // the remote device by polling at a fixed interval. 27 // the remote device by polling at a fixed interval.
26 class BluetoothConnectionFinder : public ConnectionFinder, 28 class BluetoothConnectionFinder : public cryptauth::ConnectionFinder,
27 public ConnectionObserver, 29 public cryptauth::ConnectionObserver,
28 public device::BluetoothAdapter::Observer { 30 public device::BluetoothAdapter::Observer {
29 public: 31 public:
30 BluetoothConnectionFinder(const cryptauth::RemoteDevice& remote_device, 32 BluetoothConnectionFinder(const cryptauth::RemoteDevice& remote_device,
31 const device::BluetoothUUID& uuid, 33 const device::BluetoothUUID& uuid,
32 const base::TimeDelta& polling_interval); 34 const base::TimeDelta& polling_interval);
33 ~BluetoothConnectionFinder() override; 35 ~BluetoothConnectionFinder() override;
34 36
35 // ConnectionFinder: 37 // cryptauth::ConnectionFinder:
36 void Find(const ConnectionCallback& connection_callback) override; 38 void Find(const cryptauth::ConnectionFinder::ConnectionCallback&
39 connection_callback) override;
37 40
38 protected: 41 protected:
39 // Exposed for mocking out the connection in tests. 42 // Exposed for mocking out the connection in tests.
40 virtual std::unique_ptr<Connection> CreateConnection(); 43 virtual std::unique_ptr<cryptauth::Connection> CreateConnection();
41 44
42 // Calls bluetooth_util::SeekDeviceByAddress. Exposed for testing, as this 45 // Calls bluetooth_util::SeekDeviceByAddress. Exposed for testing, as this
43 // utility function is platform dependent. 46 // utility function is platform dependent.
44 virtual void SeekDeviceByAddress( 47 virtual void SeekDeviceByAddress(
45 const std::string& bluetooth_address, 48 const std::string& bluetooth_address,
46 const base::Closure& callback, 49 const base::Closure& callback,
47 const bluetooth_util::ErrorCallback& error_callback); 50 const bluetooth_util::ErrorCallback& error_callback);
48 51
49 // BluetoothAdapter::Observer: 52 // BluetoothAdapter::Observer:
50 void AdapterPresentChanged(device::BluetoothAdapter* adapter, 53 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
(...skipping 19 matching lines...) Expand all
70 void OnSeekedDeviceByAddressError(const std::string& error_message); 73 void OnSeekedDeviceByAddressError(const std::string& error_message);
71 74
72 // Unregisters |this| instance as an observer from all objects that it might 75 // Unregisters |this| instance as an observer from all objects that it might
73 // have registered with. 76 // have registered with.
74 void UnregisterAsObserver(); 77 void UnregisterAsObserver();
75 78
76 // Callback to be called when the Bluetooth adapter is initialized. 79 // Callback to be called when the Bluetooth adapter is initialized.
77 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); 80 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter);
78 81
79 // ConnectionObserver: 82 // ConnectionObserver:
80 void OnConnectionStatusChanged(Connection* connection, 83 void OnConnectionStatusChanged(
81 Connection::Status old_status, 84 cryptauth::Connection* connection,
82 Connection::Status new_status) override; 85 cryptauth::Connection::Status old_status,
86 cryptauth::Connection::Status new_status) override;
83 87
84 // Used to invoke |connection_callback_| asynchronously, decoupling the 88 // Used to invoke |connection_callback_| asynchronously, decoupling the
85 // callback invocation from the ConnectionObserver callstack. 89 // callback invocation from the ConnectionObserver callstack.
86 void InvokeCallbackAsync(); 90 void InvokeCallbackAsync();
87 91
88 // The remote device to connect to. 92 // The remote device to connect to.
89 const cryptauth::RemoteDevice remote_device_; 93 const cryptauth::RemoteDevice remote_device_;
90 94
91 // The UUID of the service on the remote device. 95 // The UUID of the service on the remote device.
92 const device::BluetoothUUID uuid_; 96 const device::BluetoothUUID uuid_;
93 97
94 // The time to wait between polling attempts. 98 // The time to wait between polling attempts.
95 const base::TimeDelta polling_interval_; 99 const base::TimeDelta polling_interval_;
96 100
97 // Records the time at which the finder began searching for connections. 101 // Records the time at which the finder began searching for connections.
98 base::TimeTicks start_time_; 102 base::TimeTicks start_time_;
99 103
100 // The callback that should be called upon a successful connection. 104 // The callback that should be called upon a successful connection.
101 ConnectionCallback connection_callback_; 105 cryptauth::ConnectionFinder::ConnectionCallback connection_callback_;
102 106
103 // The Bluetooth adapter over which the Bluetooth connection will be made. 107 // The Bluetooth adapter over which the Bluetooth connection will be made.
104 scoped_refptr<device::BluetoothAdapter> adapter_; 108 scoped_refptr<device::BluetoothAdapter> adapter_;
105 109
106 // The Bluetooth connection that will be opened. 110 // The Bluetooth connection that will be opened.
107 std::unique_ptr<Connection> connection_; 111 std::unique_ptr<cryptauth::Connection> connection_;
108 112
109 // Whether there is currently a polling task scheduled. 113 // Whether there is currently a polling task scheduled.
110 bool has_delayed_poll_scheduled_; 114 bool has_delayed_poll_scheduled_;
111 115
112 // Used to schedule everything else. 116 // Used to schedule everything else.
113 base::WeakPtrFactory<BluetoothConnectionFinder> weak_ptr_factory_; 117 base::WeakPtrFactory<BluetoothConnectionFinder> weak_ptr_factory_;
114 118
115 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder); 119 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder);
116 }; 120 };
117 121
118 // TODO(isherman): Make sure to wire up the controller to listen for screen lock 122 // TODO(isherman): Make sure to wire up the controller to listen for screen lock
119 // state change events, and create or destroy the connection finder as 123 // state change events, and create or destroy the connection finder as
120 // appropriate. 124 // appropriate.
121 125
122 } // namespace proximity_auth 126 } // namespace proximity_auth
123 127
124 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H 128 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698