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

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

Issue 726673002: Add a new NetworkActivityMonitor to track network activity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments 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
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 // The actual singleton notifier. The class contract forbids usage of the API
eroman 2014/11/14 00:06:16 I am not sure what this comment means. I suggest d
Ryan Hamilton 2014/11/14 00:32:28 Done.
12 // in ways that would require us to place locks around access to this object.
13 // (The prohibition on global non-POD objects makes it tricky to do such a thing
14 // anyway.)
15
16 base::LazyInstance<NetworkActivityMonitor>::Leaky g_network_activity_monitor =
17 LAZY_INSTANCE_INITIALIZER;
18
19 } // namespace
20
21 NetworkActivityMonitor::NetworkActivityMonitor()
22 : bytes_received_(0),
23 bytes_written_(0) {
24 }
25
26 NetworkActivityMonitor::~NetworkActivityMonitor() {
27 }
28
29 // static
30 NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() {
31 return g_network_activity_monitor.Pointer();
32 }
33
34 void NetworkActivityMonitor::IncrementBytesReceived(uint64 bytes_received) {
35 if (bytes_received != 0) {
eroman 2014/11/14 00:06:16 meh, suggest removing.
Ryan Hamilton 2014/11/14 00:32:28 Done.
36 base::AutoLock lock(lock_);
37 bytes_received_ += bytes_received;
38 last_received_ticks_ = base::TimeTicks::Now();
eroman 2014/11/14 00:06:15 Can you move the call to TimeTicks::Now() outside
Ryan Hamilton 2014/11/14 00:32:28 Done, I think. But I'm not sure if I need to use {
39 }
40 }
41
42 void NetworkActivityMonitor::IncrementBytesWritten(uint64 bytes_written) {
43 if (bytes_written != 0) {
eroman 2014/11/14 00:06:16 meh, suggest removing (just one more branch and li
Ryan Hamilton 2014/11/14 00:32:28 Done.
44 base::AutoLock lock(lock_);
45 bytes_written_ += bytes_written;
46 last_write_ticks_ = base::TimeTicks::Now();
eroman 2014/11/14 00:06:15 Same thing here
Ryan Hamilton 2014/11/14 00:32:28 Done.
47 }
48 }
49
50
51 uint64 NetworkActivityMonitor::GetBytesReceived() const {
52 base::AutoLock lock(lock_);
53 return bytes_received_;
54 }
55
56 uint64 NetworkActivityMonitor::GetBytesWritten() const {
57 base::AutoLock lock(lock_);
58 return bytes_written_;
59 }
60
61 base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastReceived() const {
62 base::AutoLock lock(lock_);
63 return base::TimeTicks::Now() - last_received_ticks_;
eroman 2014/11/14 00:06:16 Suggest moving Now() outside of lock
Ryan Hamilton 2014/11/14 00:32:28 Done.
64 }
65
66 base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastWrite() const {
67 base::AutoLock lock(lock_);
68 return base::TimeTicks::Now() - last_write_ticks_;
eroman 2014/11/14 00:06:15 Same here.
Ryan Hamilton 2014/11/14 00:32:28 Done.
69 }
70
71
72 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698