Index: components/proximity_auth/bluetooth_throttler_impl.h |
diff --git a/components/proximity_auth/bluetooth_throttler_impl.h b/components/proximity_auth/bluetooth_throttler_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..00c91614e3692ed37bc00f8d3bb093c08f5e1cd0 |
--- /dev/null |
+++ b/components/proximity_auth/bluetooth_throttler_impl.h |
@@ -0,0 +1,51 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H |
+#define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H |
+ |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/time/time.h" |
+#include "components/proximity_auth/bluetooth_throttler.h" |
+ |
+namespace base { |
+class TickClock; |
+} |
+ |
+namespace proximity_auth { |
+ |
+// This class throttles repeated connection attempts to the same device. This |
+// throttling is necessary to prevent a kernel race condition when connecting |
+// before the previous connection fully closes, putting the connection in a |
+// corrupted, and unrecoverable state. http://crbug.com/345232 |
+class BluetoothThrottlerImpl : public BluetoothThrottler { |
+ public: |
+ // Creates a throttler for connections to a remote device, using the |clock| |
+ // as a time source. |
+ explicit BluetoothThrottlerImpl(scoped_ptr<base::TickClock> clock); |
+ ~BluetoothThrottlerImpl() override; |
+ |
+ // BluetoothThrottler: |
+ base::TimeDelta GetDelay() const override; |
+ void OnConnectionClosed() override; |
+ |
+ protected: |
+ // Returns the duration to wait, after disconnecting, before reattempting a |
+ // connection to the remote device. Exposed for testing. |
+ base::TimeDelta GetCooldownTimeDelta() const; |
+ |
+ private: |
+ // Tracks the last seen disconnect time for the |remote_device_|. |
+ base::TimeTicks last_disconnect_time_; |
+ |
+ // The time source. |
+ scoped_ptr<base::TickClock> clock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothThrottlerImpl); |
+}; |
+ |
+} // namespace proximity_auth |
+ |
+#endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_THROTTLER_IMPL_H |