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

Side by Side Diff: net/base/network_activity_monitor.cc

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/base/network_activity_monitor.h ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « net/base/network_activity_monitor.h ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698