Index: net/base/network_activity_monitor.h |
diff --git a/net/base/network_activity_monitor.h b/net/base/network_activity_monitor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be8fd5b97fc019b7ddfc2293f12cd09677be1089 |
--- /dev/null |
+++ b/net/base/network_activity_monitor.h |
@@ -0,0 +1,68 @@ |
+// 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. |
+ |
+#ifndef NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |
+#define NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/lazy_instance.h" |
+#include "base/synchronization/lock.h" |
+#include "base/time/time.h" |
+#include "net/base/net_export.h" |
+ |
+namespace net { |
+ |
+namespace test { |
+ |
+class NetworkActivityMonitorPeer; |
+ |
+} // namespace test |
+ |
+// NetworkActivityMonitor tracks network activity across all sockets and |
+// provides cumulative statistics about bytes written to and received from |
+// the network. It uses locks to ensure threceived-safety. |
eroman
2014/11/14 00:06:16
typeo in the last word.
unless this is german and
Ryan Hamilton
2014/11/14 00:32:29
*facepalm* s/read/received/ fail!
|
+// |
+// There are a few caveats: |
+// * This does not include cache activity. |
+// * Bytes "written" is attempted bytes written (no guarantee they were |
+// actually sent over the network). |
+// * Whereas bytes received is the actual bytes received from the network. |
+// * Network activity not initiated directly using client sockets won't |
+// be reflected here (for instance DNS queries issued by getaddrinfo()). |
eroman
2014/11/14 00:06:16
I see you took my examples verbatim. while I am fl
Ryan Hamilton
2014/11/14 00:32:29
Sounded great to me :> How's this look now?
|
+class NET_EXPORT_PRIVATE NetworkActivityMonitor { |
+ public: |
+ // Returns the singleton instance of the monitor. |
+ static NetworkActivityMonitor* GetInstance(); |
+ |
+ void IncrementBytesReceived(uint64 bytes_received); |
eroman
2014/11/14 00:06:16
Prefer uint64_t for new code. See: https://code.go
Ryan Hamilton
2014/11/14 00:32:29
Done.
|
+ void IncrementBytesWritten(uint64 bytes_written); |
+ |
+ uint64 GetBytesReceived() const; |
+ uint64 GetBytesWritten() const; |
+ |
+ base::TimeDelta GetTimeSinceLastReceived() const; |
eroman
2014/11/14 00:06:16
as a side rant:
Both base::Time::Now() and base::
Ryan Hamilton
2014/11/14 00:32:29
Awesome! :|
|
+ base::TimeDelta GetTimeSinceLastWrite() const; |
+ |
+ private: |
+ friend class test::NetworkActivityMonitorPeer; |
+ |
+ NetworkActivityMonitor(); |
+ ~NetworkActivityMonitor(); |
+ friend struct base::DefaultLazyInstanceTraits<NetworkActivityMonitor>; |
+ |
+ // Protects all the following members. |
+ mutable base::Lock lock_; |
+ |
+ uint64 bytes_received_; |
+ uint64 bytes_written_; |
+ |
+ base::TimeTicks last_received_ticks_; |
+ base::TimeTicks last_write_ticks_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkActivityMonitor); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |