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

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

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 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 #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 written to and received from
24 // the network. It uses locks to ensure threceived-safety.
eroman 2014/11/14 00:06:16 typeo in the last word. unless this is german and
Ryan Hamilton 2014/11/14 00:32:29 *facepalm* s/read/received/ fail!
25 //
26 // There are a few caveats:
27 // * This does not include cache activity.
28 // * Bytes "written" is attempted bytes written (no guarantee they were
29 // actually sent over the network).
30 // * Whereas bytes received is the actual bytes received from the network.
31 // * Network activity not initiated directly using client sockets won't
32 // be reflected here (for instance DNS queries issued by getaddrinfo()).
eroman 2014/11/14 00:06:16 I see you took my examples verbatim. while I am fl
Ryan Hamilton 2014/11/14 00:32:29 Sounded great to me :> How's this look now?
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 bytes_received);
eroman 2014/11/14 00:06:16 Prefer uint64_t for new code. See: https://code.go
Ryan Hamilton 2014/11/14 00:32:29 Done.
39 void IncrementBytesWritten(uint64 bytes_written);
40
41 uint64 GetBytesReceived() const;
42 uint64 GetBytesWritten() const;
43
44 base::TimeDelta GetTimeSinceLastReceived() const;
eroman 2014/11/14 00:06:16 as a side rant: Both base::Time::Now() and base::
Ryan Hamilton 2014/11/14 00:32:29 Awesome! :|
45 base::TimeDelta GetTimeSinceLastWrite() 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 bytes_received_;
58 uint64 bytes_written_;
59
60 base::TimeTicks last_received_ticks_;
61 base::TimeTicks last_write_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 | « no previous file | net/base/network_activity_monitor.cc » ('j') | net/base/network_activity_monitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698