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

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

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 #include "components/proximity_auth/bluetooth_throttler_impl.h"
6
7 #include "base/time/tick_clock.h"
8
9 namespace proximity_auth {
10 namespace {
11
12 // Time to wait after disconnect before reconnecting.
13 const int kCooldownTimeSecs = 7;
14
15 } // namespace
16
17 BluetoothThrottlerImpl::BluetoothThrottlerImpl(
18 scoped_ptr<base::TickClock> clock)
19 : clock_(clock.Pass()) {
20 }
21
22 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() {
23 }
24
25 base::TimeDelta BluetoothThrottlerImpl::GetDelay() const {
26 if (last_disconnect_time_.is_null())
27 return base::TimeDelta();
28
29 base::TimeTicks now = clock_->NowTicks();
30 base::TimeTicks throttled_start_time =
31 last_disconnect_time_ + GetCooldownTimeDelta();
32 if (now >= throttled_start_time)
33 return base::TimeDelta();
34
35 return throttled_start_time - now;
36 }
37
38 void BluetoothThrottlerImpl::OnConnectionClosed() {
39 last_disconnect_time_ = clock_->NowTicks();
40 }
41
42 base::TimeDelta BluetoothThrottlerImpl::GetCooldownTimeDelta() const {
43 return base::TimeDelta::FromSeconds(kCooldownTimeSecs);
44 }
45
46 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698