Chromium Code Reviews| Index: net/base/network_activity_monitor.cc |
| diff --git a/net/base/network_activity_monitor.cc b/net/base/network_activity_monitor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6432c627fb894ffdbe4f4683a9b1239f93a0809 |
| --- /dev/null |
| +++ b/net/base/network_activity_monitor.cc |
| @@ -0,0 +1,72 @@ |
| +// 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 { |
| + |
| +// 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.
|
| +// in ways that would require us to place locks around access to this object. |
| +// (The prohibition on global non-POD objects makes it tricky to do such a thing |
| +// anyway.) |
| + |
| +base::LazyInstance<NetworkActivityMonitor>::Leaky g_network_activity_monitor = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +NetworkActivityMonitor::NetworkActivityMonitor() |
| + : bytes_received_(0), |
| + bytes_written_(0) { |
| +} |
| + |
| +NetworkActivityMonitor::~NetworkActivityMonitor() { |
| +} |
| + |
| +// static |
| +NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() { |
| + return g_network_activity_monitor.Pointer(); |
| +} |
| + |
| +void NetworkActivityMonitor::IncrementBytesReceived(uint64 bytes_received) { |
| + if (bytes_received != 0) { |
|
eroman
2014/11/14 00:06:16
meh, suggest removing.
Ryan Hamilton
2014/11/14 00:32:28
Done.
|
| + base::AutoLock lock(lock_); |
| + bytes_received_ += bytes_received; |
| + 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 {
|
| + } |
| +} |
| + |
| +void NetworkActivityMonitor::IncrementBytesWritten(uint64 bytes_written) { |
| + 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.
|
| + base::AutoLock lock(lock_); |
| + bytes_written_ += bytes_written; |
| + 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.
|
| + } |
| +} |
| + |
| + |
| +uint64 NetworkActivityMonitor::GetBytesReceived() const { |
| + base::AutoLock lock(lock_); |
| + return bytes_received_; |
| +} |
| + |
| +uint64 NetworkActivityMonitor::GetBytesWritten() const { |
| + base::AutoLock lock(lock_); |
| + return bytes_written_; |
| +} |
| + |
| +base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastReceived() const { |
| + base::AutoLock lock(lock_); |
| + 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.
|
| +} |
| + |
| +base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastWrite() const { |
| + base::AutoLock lock(lock_); |
| + 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.
|
| +} |
| + |
| + |
| +} // namespace net |