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

Side by Side Diff: net/base/network_activity_monitor.h

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 unified diff | Download patch
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/base/network_activity_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NET_BASE_NETWORK_ACTIVITY_MONITOR_H_
6 #define NET_BASE_NETWORK_ACTIVITY_MONITOR_H_
7
8 #include "base/basictypes.h"
9 #include "base/lazy_instance.h"
10 #include "base/synchronization/lock.h"
11 #include "base/time/time.h"
12 #include "net/base/net_export.h"
13
14 namespace net {
15
16 namespace test {
17
18 class NetworkActivityMonitorPeer;
19
20 } // namespace test
21
22 // NetworkActivityMonitor tracks network activity across all sockets and
23 // provides cumulative statistics about bytes sent to and received from
24 // the network. It uses a lock to ensure thread-safety.
25 //
26 // There are a few caveats:
27 // * Bytes "sent" includes all send attempts and may include
28 // some bytes which were actually never sent over the network.
29 // * Bytes received includes only bytes actually received from the network,
30 // and does not include any bytes read from the the cache.
31 // * Network activity not initiated directly using chromium sockets won't
32 // be reflected here (for instance DNS queries issued by getaddrinfo()).
33 class NET_EXPORT_PRIVATE NetworkActivityMonitor {
34 public:
35 // Returns the singleton instance of the monitor.
36 static NetworkActivityMonitor* GetInstance();
37
38 void IncrementBytesReceived(uint64_t bytes_received);
39 void IncrementBytesSent(uint64_t bytes_sent);
40
41 uint64_t GetBytesReceived() const;
42 uint64_t GetBytesSent() const;
43
44 base::TimeDelta GetTimeSinceLastReceived() const;
45 base::TimeDelta GetTimeSinceLastSent() const;
46
47 private:
48 friend class test::NetworkActivityMonitorPeer;
49
50 NetworkActivityMonitor();
51 ~NetworkActivityMonitor();
52 friend struct base::DefaultLazyInstanceTraits<NetworkActivityMonitor>;
53
54 // Protects all the following members.
55 mutable base::Lock lock_;
56
57 uint64_t bytes_received_;
58 uint64_t bytes_sent_;
59
60 base::TimeTicks last_received_ticks_;
61 base::TimeTicks last_sent_ticks_;
62
63 DISALLOW_COPY_AND_ASSIGN(NetworkActivityMonitor);
64 };
65
66 } // namespace net
67
68 #endif // NET_BASE_NETWORK_ACTIVITY_MONITOR_H_
OLDNEW
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/base/network_activity_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698