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