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

Unified Diff: net/base/network_activity_monitor.cc

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 | « net/base/network_activity_monitor.h ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..78da8c8d4f387be182af3d09b7a0c25b798b3c87
--- /dev/null
+++ b/net/base/network_activity_monitor.cc
@@ -0,0 +1,64 @@
+// 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 {
+
+base::LazyInstance<NetworkActivityMonitor>::Leaky g_network_activity_monitor =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+NetworkActivityMonitor::NetworkActivityMonitor()
+ : bytes_received_(0), bytes_sent_(0) {
+}
+
+NetworkActivityMonitor::~NetworkActivityMonitor() {
+}
+
+// static
+NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() {
+ return g_network_activity_monitor.Pointer();
+}
+
+void NetworkActivityMonitor::IncrementBytesReceived(uint64_t bytes_received) {
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::AutoLock lock(lock_);
+ bytes_received_ += bytes_received;
+ last_received_ticks_ = now;
+}
+
+void NetworkActivityMonitor::IncrementBytesSent(uint64_t bytes_sent) {
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::AutoLock lock(lock_);
+ bytes_sent_ += bytes_sent;
+ last_sent_ticks_ = now;
+}
+
+uint64_t NetworkActivityMonitor::GetBytesReceived() const {
+ base::AutoLock lock(lock_);
+ return bytes_received_;
+}
+
+uint64_t NetworkActivityMonitor::GetBytesSent() const {
+ base::AutoLock lock(lock_);
+ return bytes_sent_;
+}
+
+base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastReceived() const {
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::AutoLock lock(lock_);
+ return now - last_received_ticks_;
+}
+
+base::TimeDelta NetworkActivityMonitor::GetTimeSinceLastSent() const {
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::AutoLock lock(lock_);
+ return now - last_sent_ticks_;
+}
+
+} // namespace net
« no previous file with comments | « net/base/network_activity_monitor.h ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698