OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014 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 "net/base/network_activity_monitor.h" | |
6 | |
7 namespace net { | |
8 | |
9 namespace { | |
10 | |
11 base::LazyInstance<NetworkActivityMonitor>::Leaky g_network_activity_monitor = | |
12 LAZY_INSTANCE_INITIALIZER; | |
13 | |
14 } // namespace | |
15 | |
16 NetworkActivityMonitor::NetworkActivityMonitor() | |
17 : bytes_received_(0), bytes_sent_(0) { | |
18 } | |
19 | |
20 NetworkActivityMonitor::~NetworkActivityMonitor() { | |
21 } | |
22 | |
23 // static | |
24 NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() { | |
25 return g_network_activity_monitor.Pointer(); | |
26 } | |
27 | |
28 void NetworkActivityMonitor::IncrementBytesReceived(uint64_t bytes_received) { | |
29 base::TimeTicks now = base::TimeTicks::Now(); | |
30 base::AutoLock lock(lock_); | |
31 bytes_received_ += bytes_received; | |
32 last_received_ticks_ = now; | |
33 } | |
34 | |
35 void NetworkActivityMonitor::IncrementBytesSent(uint64_t bytes_sent) { | |
36 base::TimeTicks now = base::TimeTicks::Now(); | |
37 base::AutoLock lock(lock_); | |
38 bytes_sent_ += bytes_sent; | |
39 last_sent_ticks_ = now; | |
40 } | |
41 | |
42 uint64_t NetworkActivityMonitor::GetBytesReceived() const { | |
43 base::AutoLock lock(lock_); | |
44 return bytes_received_; | |
45 } | |
46 | |
47 uint64_t NetworkActivityMonitor::GetBytesSent() const { | |
48 base::AutoLock lock(lock_); | |
49 return bytes_sent_; | |
50 } | |
51 | |
52 base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastReceived() const { | |
53 base::TimeTicks now = base::TimeTicks::Now(); | |
54 base::AutoLock lock(lock_); | |
55 return now - last_received_ticks_; | |
56 } | |
57 | |
58 base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastSent() const { | |
59 base::TimeTicks now = base::TimeTicks::Now(); | |
60 base::AutoLock lock(lock_); | |
61 return now - last_sent_ticks_; | |
62 } | |
63 | |
64 } // namespace net | |
OLD | NEW |