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

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

Issue 633253002: [Easy Unlock] Port the BluetoothConnectionFinder class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "components/proximity_auth/connection_finder.h"
15 #include "components/proximity_auth/connection_observer.h"
16 #include "components/proximity_auth/remote_device.h"
17 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_uuid.h"
19
20 namespace proximity_auth {
21
22 class BluetoothConnection;
23
24 // This ConnectionFinder implementation tries to find a Bluetooth connection to
25 // the remote device by polling at a fixed interval.
26 class BluetoothConnectionFinder : public ConnectionFinder,
27 public ConnectionObserver,
28 public device::BluetoothAdapter::Observer {
29 public:
30 BluetoothConnectionFinder(const RemoteDevice& remote_device,
31 const device::BluetoothUUID& uuid,
32 const base::TimeDelta& polling_interval);
33 virtual ~BluetoothConnectionFinder();
34
35 // ConnectionFinder:
36 virtual void Find(const ConnectionCallback& connection_callback) override;
37
38 protected:
39 // Exposed for mocking out the connection in tests.
40 virtual scoped_ptr<Connection> CreateConnection();
41
42 // BluetoothAdapter::Observer:
43 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
44 bool present) override;
45 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
46 bool powered) override;
47
48 // TODO(isherman): Wire up and document:
49 virtual void OnScreenLockStateChanged();
50
51 private:
52 // Returns true iff the system is in a state where Easy Unlock connections
53 // should be made: the Bluetooth adapter is ready to make connections and the
54 // screen is locked.
55 bool IsReadyToPoll();
56
57 // Attempts to connect to the |remote_device_| if the system is ready for
58 // another iteration of polling.
59 void PollIfReady();
60
61 // Wrapper around |PollIfReady()| that can be posted as a delayed task.
62 void DelayedPollIfReady();
63
64 // Unregisters |this| instance as an observer from all objects that it might
65 // have registered with.
66 void UnregisterAsObserver();
67
68 // Callback to be called when the Bluetooth adapter is initialized.
69 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter);
70
71 // ConnectionObserver:
72 virtual void OnConnectionStatusChanged(
73 const Connection& connection,
74 Connection::Status old_status,
75 Connection::Status new_status) override;
76
77 // The remote device to connect to.
78 const RemoteDevice remote_device_;
79
80 // The UUID of the service on the remote device.
81 const device::BluetoothUUID uuid_;
82
83 // The time to wait between polling attempts.
84 const base::TimeDelta polling_interval_;
85
86 // Records the time at which the finder began searching for connections.
87 base::TimeTicks start_time_;
88
89 // The callback that should be called upon a successful connection.
90 ConnectionCallback connection_callback_;
91
92 // The Bluetooth adapter over which the Bluetooth connection will be made.
93 scoped_refptr<device::BluetoothAdapter> adapter_;
94
95 // The Bluetooth connection that will be opened.
96 scoped_ptr<Connection> connection_;
97
98 // Whether there is currently a polling task scheduled.
99 bool has_delayed_poll_scheduled_;
100
101 // Used to schedule everything else.
102 base::WeakPtrFactory<BluetoothConnectionFinder> weak_ptr_factory_;
103
104 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder);
105 };
106
107 } // namespace proximity_auth
108
109 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698