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

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

Issue 1277483007: Implement finding BLE connections in chrome://proximity-auth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months 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 "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/proximity_auth/bluetooth_util.h"
14 #include "components/proximity_auth/connection_finder.h" 15 #include "components/proximity_auth/connection_finder.h"
15 #include "components/proximity_auth/connection_observer.h" 16 #include "components/proximity_auth/connection_observer.h"
16 #include "components/proximity_auth/remote_device.h" 17 #include "components/proximity_auth/remote_device.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 18 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_uuid.h" 19 #include "device/bluetooth/bluetooth_uuid.h"
19 20
20 namespace proximity_auth { 21 namespace proximity_auth {
21 22
22 class BluetoothConnection; 23 class BluetoothConnection;
23 24
24 // This ConnectionFinder implementation tries to find a Bluetooth connection to 25 // This ConnectionFinder implementation tries to find a Bluetooth connection to
25 // the remote device by polling at a fixed interval. 26 // the remote device by polling at a fixed interval.
26 class BluetoothConnectionFinder : public ConnectionFinder, 27 class BluetoothConnectionFinder : public ConnectionFinder,
27 public ConnectionObserver, 28 public ConnectionObserver,
28 public device::BluetoothAdapter::Observer { 29 public device::BluetoothAdapter::Observer {
29 public: 30 public:
30 BluetoothConnectionFinder(const RemoteDevice& remote_device, 31 BluetoothConnectionFinder(const RemoteDevice& remote_device,
31 const device::BluetoothUUID& uuid, 32 const device::BluetoothUUID& uuid,
32 const base::TimeDelta& polling_interval); 33 const base::TimeDelta& polling_interval);
33 ~BluetoothConnectionFinder() override; 34 ~BluetoothConnectionFinder() override;
34 35
35 // ConnectionFinder: 36 // ConnectionFinder:
36 void Find(const ConnectionCallback& connection_callback) override; 37 void Find(const ConnectionCallback& connection_callback) override;
37 38
38 protected: 39 protected:
39 // Exposed for mocking out the connection in tests. 40 // Exposed for mocking out the connection in tests.
40 virtual scoped_ptr<Connection> CreateConnection(); 41 virtual scoped_ptr<Connection> CreateConnection();
41 42
43 // Calls bluetooth_util::SeekDeviceByAddress. Exposed for testing, as this
44 // utility function is platform dependent.
45 virtual void SeekDeviceByAddress(
46 const std::string& bluetooth_address,
47 const base::Closure& callback,
48 const bluetooth_util::ErrorCallback& error_callback);
49
42 // BluetoothAdapter::Observer: 50 // BluetoothAdapter::Observer:
43 void AdapterPresentChanged(device::BluetoothAdapter* adapter, 51 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
44 bool present) override; 52 bool present) override;
45 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 53 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
46 bool powered) override; 54 bool powered) override;
47 55
48 private: 56 private:
49 // Returns true iff the Bluetooth adapter is ready to make connections. 57 // Returns true iff the Bluetooth adapter is ready to make connections.
50 bool IsReadyToPoll(); 58 bool IsReadyToPoll();
51 59
52 // Attempts to connect to the |remote_device_| if the system is ready for 60 // Attempts to connect to the |remote_device_| if the system is ready for
53 // another iteration of polling. 61 // another iteration of polling.
54 void PollIfReady(); 62 void PollIfReady();
55 63
56 // Wrapper around |PollIfReady()| that can be posted as a delayed task. 64 // Posts a delayed task to call |PollIfReady|. |OnDelayedPoll()| will be
57 void DelayedPollIfReady(); 65 // called when the task fires.
66 void PostDelayedPoll();
67 void OnDelayedPoll();
68
69 // Callbacks for bluetooth_util::SeekDeviceByAddress().
70 void OnSeekedDeviceByAddress();
71 void OnSeekedDeviceByAddressError(const std::string& error_message);
58 72
59 // Unregisters |this| instance as an observer from all objects that it might 73 // Unregisters |this| instance as an observer from all objects that it might
60 // have registered with. 74 // have registered with.
61 void UnregisterAsObserver(); 75 void UnregisterAsObserver();
62 76
63 // Callback to be called when the Bluetooth adapter is initialized. 77 // Callback to be called when the Bluetooth adapter is initialized.
64 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); 78 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter);
65 79
66 // ConnectionObserver: 80 // ConnectionObserver:
67 void OnConnectionStatusChanged(Connection* connection, 81 void OnConnectionStatusChanged(Connection* connection,
68 Connection::Status old_status, 82 Connection::Status old_status,
69 Connection::Status new_status) override; 83 Connection::Status new_status) override;
70 84
85 // Used to invokes |connection_callback_| asynchronously, decoupling the
sacomoto 2015/08/10 19:40:28 nit: s/invokes/invoke/
Tim Song 2015/08/10 22:17:55 Done.
86 // callback invocation from the ConnectionObserver callstack.
87 void InvokeCallbackAsync();
88
71 // The remote device to connect to. 89 // The remote device to connect to.
72 const RemoteDevice remote_device_; 90 const RemoteDevice remote_device_;
73 91
74 // The UUID of the service on the remote device. 92 // The UUID of the service on the remote device.
75 const device::BluetoothUUID uuid_; 93 const device::BluetoothUUID uuid_;
76 94
77 // The time to wait between polling attempts. 95 // The time to wait between polling attempts.
78 const base::TimeDelta polling_interval_; 96 const base::TimeDelta polling_interval_;
79 97
80 // Records the time at which the finder began searching for connections. 98 // Records the time at which the finder began searching for connections.
(...skipping 17 matching lines...) Expand all
98 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder); 116 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder);
99 }; 117 };
100 118
101 // TODO(isherman): Make sure to wire up the controller to listen for screen lock 119 // TODO(isherman): Make sure to wire up the controller to listen for screen lock
102 // state change events, and create or destroy the connection finder as 120 // state change events, and create or destroy the connection finder as
103 // appropriate. 121 // appropriate.
104 122
105 } // namespace proximity_auth 123 } // namespace proximity_auth
106 124
107 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H 125 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698