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

Unified Diff: net/base/network_activity_monitor.h

Issue 726673002: Add a new NetworkActivityMonitor to track network activity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Reset method 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/network_activity_monitor.cc » ('j') | net/base/network_activity_monitor_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..98ad189146c0f221c6cdea994cdd6c1af29fa158
--- /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 sent to and received from
+// the network. It uses locks to ensure thread-safety.
eroman 2014/11/14 20:57:04 nit: locks --> "a lock" or alternately "locking"
Ryan Hamilton 2014/11/14 22:18:17 Done.
+//
+// There are a few caveats:
+// * Bytes "sent" includes all bytes all send attempts and may include
eroman 2014/11/14 20:57:04 "all bytes all send attempts" --> reword
Ryan Hamilton 2014/11/14 22:18:17 Done.
+// some bytes which were actually never sent over the network.
+// * Bytes received includes only bytes actually received from the network,
+// and does not include any bytes read from the the cache.
+// * Network activity not initiated directly using chromium sockets won't
+// be reflected here (for instance DNS queries issued by getaddrinfo()).
+class NET_EXPORT_PRIVATE NetworkActivityMonitor {
+ public:
+ // Returns the singleton instance of the monitor.
+ static NetworkActivityMonitor* GetInstance();
+
+ void IncrementBytesReceived(uint64_t bytes_received);
+ void IncrementBytesSent(uint64_t bytes_sent);
+
+ uint64_t GetBytesReceived() const;
+ uint64_t GetBytesSent() const;
+
+ base::TimeDelta GetTimeSinceLastReceived() const;
+ base::TimeDelta GetTimeSinceLastSent() const;
+
+ private:
+ friend class test::NetworkActivityMonitorPeer;
+
+ NetworkActivityMonitor();
+ ~NetworkActivityMonitor();
+ friend struct base::DefaultLazyInstanceTraits<NetworkActivityMonitor>;
+
+ // Protects all the following members.
+ mutable base::Lock lock_;
+
+ uint64_t bytes_received_;
+ uint64_t bytes_sent_;
+
+ base::TimeTicks last_received_ticks_;
+ base::TimeTicks last_write_ticks_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkActivityMonitor);
+};
+
+} // namespace net
+
+#endif // NET_BASE_NETWORK_ACTIVITY_MONITOR_H_
« no previous file with comments | « no previous file | net/base/network_activity_monitor.cc » ('j') | net/base/network_activity_monitor_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698