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

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

Issue 1912433002: Convert //components/proximity_auth from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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_THROTTLER_IMPL_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H
7 7
8 #include <memory>
8 #include <set> 9 #include <set>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/proximity_auth/bluetooth_throttler.h" 13 #include "components/proximity_auth/bluetooth_throttler.h"
14 #include "components/proximity_auth/connection_observer.h" 14 #include "components/proximity_auth/connection_observer.h"
15 15
16 namespace base { 16 namespace base {
17 class TickClock; 17 class TickClock;
18 } 18 }
19 19
20 namespace proximity_auth { 20 namespace proximity_auth {
21 21
22 class Connection; 22 class Connection;
23 23
24 // This class throttles repeated connection attempts to the same device. This 24 // This class throttles repeated connection attempts to the same device. This
25 // throttling is necessary to prevent a kernel race condition when connecting 25 // throttling is necessary to prevent a kernel race condition when connecting
26 // before the previous connection fully closes, putting the connection in a 26 // before the previous connection fully closes, putting the connection in a
27 // corrupted, and unrecoverable state. http://crbug.com/345232 27 // corrupted, and unrecoverable state. http://crbug.com/345232
28 class BluetoothThrottlerImpl : public BluetoothThrottler, 28 class BluetoothThrottlerImpl : public BluetoothThrottler,
29 public ConnectionObserver { 29 public ConnectionObserver {
30 public: 30 public:
31 // Creates a throttler for connections to a remote device, using the |clock| 31 // Creates a throttler for connections to a remote device, using the |clock|
32 // as a time source. 32 // as a time source.
33 explicit BluetoothThrottlerImpl(scoped_ptr<base::TickClock> clock); 33 explicit BluetoothThrottlerImpl(std::unique_ptr<base::TickClock> clock);
34 ~BluetoothThrottlerImpl() override; 34 ~BluetoothThrottlerImpl() override;
35 35
36 // BluetoothThrottler: 36 // BluetoothThrottler:
37 base::TimeDelta GetDelay() const override; 37 base::TimeDelta GetDelay() const override;
38 void OnConnection(Connection* connection) override; 38 void OnConnection(Connection* connection) override;
39 39
40 protected: 40 protected:
41 // Returns the duration to wait, after disconnecting, before reattempting a 41 // Returns the duration to wait, after disconnecting, before reattempting a
42 // connection to the remote device. Exposed for testing. 42 // connection to the remote device. Exposed for testing.
43 base::TimeDelta GetCooldownTimeDelta() const; 43 base::TimeDelta GetCooldownTimeDelta() const;
44 44
45 private: 45 private:
46 // ConnectionObserver: 46 // ConnectionObserver:
47 void OnConnectionStatusChanged(Connection* connection, 47 void OnConnectionStatusChanged(Connection* connection,
48 Connection::Status old_status, 48 Connection::Status old_status,
49 Connection::Status new_status) override; 49 Connection::Status new_status) override;
50 50
51 // Tracks the last seen disconnect time for the |remote_device_|. 51 // Tracks the last seen disconnect time for the |remote_device_|.
52 base::TimeTicks last_disconnect_time_; 52 base::TimeTicks last_disconnect_time_;
53 53
54 // The time source. 54 // The time source.
55 scoped_ptr<base::TickClock> clock_; 55 std::unique_ptr<base::TickClock> clock_;
56 56
57 // The currently connected connections. 57 // The currently connected connections.
58 // Each connection is stored as a weak reference, which is safe because |this| 58 // Each connection is stored as a weak reference, which is safe because |this|
59 // instance is registered as an observer, and will unregister when the 59 // instance is registered as an observer, and will unregister when the
60 // connection disconnects, which is guaranteed to occur before the connection 60 // connection disconnects, which is guaranteed to occur before the connection
61 // is destroyed. 61 // is destroyed.
62 std::set<Connection*> connections_; 62 std::set<Connection*> connections_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(BluetoothThrottlerImpl); 64 DISALLOW_COPY_AND_ASSIGN(BluetoothThrottlerImpl);
65 }; 65 };
66 66
67 } // namespace proximity_auth 67 } // namespace proximity_auth
68 68
69 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H 69 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H
OLDNEW
« no previous file with comments | « components/proximity_auth/bluetooth_connection_unittest.cc ('k') | components/proximity_auth/bluetooth_throttler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698