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

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

Issue 663693002: [Easy Unlock] Port the BluetoothThrottler class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 8 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 2015 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_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H
6 #define COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/proximity_auth/connection_finder.h"
13 #include "components/proximity_auth/connection_observer.h"
14
15 namespace base {
16 class TaskRunner;
17 }
18
19 namespace proximity_auth {
20
21 class BluetoothConnectionFinder;
22 class BluetoothThrottler;
23 class Connection;
24
25 // A Bluetooth connection finder that delays Find() requests according to the
26 // throttler's cooldown period.
27 class ThrottledBluetoothConnectionFinder : public ConnectionFinder,
28 public ConnectionObserver {
29 public:
30 // Note: The |throttler| is not owned, and must outlive |this| instance.
31 ThrottledBluetoothConnectionFinder(
32 scoped_ptr<BluetoothConnectionFinder> connection_finder,
33 scoped_refptr<base::TaskRunner> task_runner,
34 BluetoothThrottler* throttler);
35 ~ThrottledBluetoothConnectionFinder() override;
36
37 // ConnectionFinder:
38 void Find(const ConnectionCallback& connection_callback) override;
39
40 private:
41 // Callback to be called when a connection is found.
42 void OnConnection(const ConnectionCallback& connection_callback,
43 scoped_ptr<Connection> connection);
44
45 // ConnectionObserver:
46 void OnConnectionStatusChanged(const Connection& connection,
47 Connection::Status old_status,
48 Connection::Status new_status) override;
49
50 // The underlying connection finder.
51 scoped_ptr<BluetoothConnectionFinder> connection_finder_;
52
53 // The task runner used for posting delayed messages.
54 scoped_refptr<base::TaskRunner> task_runner_;
55
56 // The throttler managing this connection finder. The throttler is not owned,
57 // and must outlive |this| instance.
58 BluetoothThrottler* throttler_;
59
60 // The found connection; null if no connection has yet been found.
61 // Stored as a weak reference, which is safe because |this| instance is
62 // registered as an observer, and will unregister when the connection
63 // disconnects, which is guaranteed to occur before the connection is
64 // destroyed.
65 Connection* connection_;
66
67 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_;
68
69 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder);
70 };
71
72 } // namespace proximity_auth
73
74 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698