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

Unified 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698