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

Side by Side 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: NET_EXPORT_PRIVATE 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/network_activity_monitor.h"
6
7 namespace net {
8
9 namespace {
10
11 // The actual singleton notifier. The class contract forbids usage of the API
12 // in ways that would require us to place locks around access to this object.
13 // (The prohibition on global non-POD objects makes it tricky to do such a thing
14 // anyway.)
15 NetworkActivityMonitor* g_network_activity_monitor = NULL;
16
17 } // namespace
18
19 NetworkActivityMonitor::NetworkActivityMonitor()
20 : bytes_read_(0),
21 bytes_written_(0) {
22 }
23
24 NetworkActivityMonitor::~NetworkActivityMonitor() {
25 }
26
27 // static
28 NetworkActivityMonitor* NetworkActivityMonitor::GetInstance() {
29 if (!g_network_activity_monitor) {
30 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.
31 }
32 return g_network_activity_monitor;
33 }
34
35 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
36 base::AutoLock lock(bytes_read_lock_);
37 bytes_read_ += bytes_read;
38 }
39
40 void NetworkActivityMonitor::AddBytesWritten(uint64 bytes_written) {
41 base::AutoLock lock(bytes_written_lock_);
42 bytes_written_ += bytes_written;
43 }
44
45
46 uint64 NetworkActivityMonitor::GetBytesRead() {
47 base::AutoLock lock(bytes_read_lock_);
48 return bytes_read_;
49 }
50
51 uint64 NetworkActivityMonitor::GetBytesWritten() {
52 base::AutoLock lock(bytes_written_lock_);
53 return bytes_written_;
54 }
55
56 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698