Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / proximity_auth / throttled_bluetooth_connection_finder.h
blobc107bb33b544380db9a447ed3bd2f8b83d5e07b4
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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H
6 #define COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H
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"
14 namespace base {
15 class TaskRunner;
18 namespace proximity_auth {
20 class BluetoothConnectionFinder;
21 class BluetoothThrottler;
22 class Connection;
24 // A Bluetooth connection finder that delays Find() requests according to the
25 // throttler's cooldown period.
26 class ThrottledBluetoothConnectionFinder : public ConnectionFinder {
27 public:
28 // Note: The |throttler| is not owned, and must outlive |this| instance.
29 ThrottledBluetoothConnectionFinder(
30 scoped_ptr<BluetoothConnectionFinder> connection_finder,
31 scoped_refptr<base::TaskRunner> task_runner,
32 BluetoothThrottler* throttler);
33 ~ThrottledBluetoothConnectionFinder() override;
35 // ConnectionFinder:
36 void Find(const ConnectionCallback& connection_callback) override;
38 private:
39 // Callback to be called when a connection is found.
40 void OnConnection(const ConnectionCallback& connection_callback,
41 scoped_ptr<Connection> connection);
43 // The underlying connection finder.
44 scoped_ptr<BluetoothConnectionFinder> connection_finder_;
46 // The task runner used for posting delayed messages.
47 scoped_refptr<base::TaskRunner> task_runner_;
49 // The throttler managing this connection finder. The throttler is not owned,
50 // and must outlive |this| instance.
51 BluetoothThrottler* throttler_;
53 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_;
55 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder);
58 } // namespace proximity_auth
60 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H