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..82cc96137a0f9a095080ca6aeeb073efa0951a5f |
--- /dev/null |
+++ b/net/base/network_activity_monitor.cc |
@@ -0,0 +1,56 @@ |
+// 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 |
+// 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.) |
+NetworkActivityMonitor* g_network_activity_monitor = NULL; |
+ |
+} // namespace |
+ |
+NetworkActivityMonitor::NetworkActivityMonitor() |
+ : bytes_read_(0), |
+ bytes_written_(0) { |
+} |
+ |
+NetworkActivityMonitor::~NetworkActivityMonitor() { |
+} |
+ |
+// static |
+NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() { |
+ if (!g_network_activity_monitor) { |
+ g_network_activity_monitor = new NetworkActivityMonitor(); |
eroman
2014/11/13 22:18:39
This not a good pattern as it leads to a race when
Ryan Hamilton
2014/11/13 23:38:17
Done! I should have discovered this on my own.
|
+ } |
+ return g_network_activity_monitor; |
+} |
+ |
+void NetworkActivityMonitor::AddBytesRead(uint64 bytes_read) { |
eroman
2014/11/13 22:18:39
Not sure if it will be useful, but you may conside
Ryan Hamilton
2014/11/13 23:38:17
I thought about this, and am happy to do so if we
eroman
2014/11/14 00:06:15
sgtm
|
+ base::AutoLock lock(bytes_read_lock_); |
+ bytes_read_ += bytes_read; |
+} |
+ |
+void NetworkActivityMonitor::AddBytesWritten(uint64 bytes_written) { |
+ base::AutoLock lock(bytes_written_lock_); |
+ bytes_written_ += bytes_written; |
+} |
+ |
+ |
+uint64 NetworkActivityMonitor::GetBytesRead() { |
+ base::AutoLock lock(bytes_read_lock_); |
+ return bytes_read_; |
+} |
+ |
+uint64 NetworkActivityMonitor::GetBytesWritten() { |
+ base::AutoLock lock(bytes_written_lock_); |
+ return bytes_written_; |
+} |
+ |
+} // namespace net |