OLD | NEW |
---|---|
(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 | |
OLD | NEW |