Chromium Code Reviews| Index: net/base/network_activity_monitor.h |
| diff --git a/net/base/network_activity_monitor.h b/net/base/network_activity_monitor.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..71ef323174182afb1b75798ead613106cb9d68bd |
| --- /dev/null |
| +++ b/net/base/network_activity_monitor.h |
| @@ -0,0 +1,53 @@ |
| +// 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. |
| + |
| +#ifndef NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |
| +#define NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/synchronization/lock.h" |
| +#include "net/base/net_export.h" |
| + |
| +namespace net { |
| + |
| +namespace test { |
| + |
| +class NetworkActivityMonitorPeer; |
| + |
| +} // namespace test |
| + |
| +// NetworkActivityMonitor tracks network activity across all sockets and |
| +// provides cumulative statistics about bytes written to and read from |
| +// the network. It uses locks to ensure thread-safety. |
|
eroman
2014/11/13 22:18:39
I would also emphasize the caveats of what this is
Ryan Hamilton
2014/11/13 23:38:17
Done.
|
| +class NET_EXPORT_PRIVATE NetworkActivityMonitor { |
| + public: |
| + // Returns the singleton instance of the monitor. |
| + static NetworkActivityMonitor* GetInstance(); |
| + |
| + void AddBytesRead(uint64 bytes_read); |
|
eroman
2014/11/13 22:18:39
[optional] Consider "Increment" instead of Add
Ryan Hamilton
2014/11/13 23:38:17
Done.
|
| + void AddBytesWritten(uint64 bytes_written); |
| + |
| + uint64 GetBytesRead(); |
| + uint64 GetBytesWritten(); |
| + |
| + private: |
| + friend class test::NetworkActivityMonitorPeer; |
|
eroman
2014/11/13 22:18:39
What about using a friend_test macro? Or at a mini
Ryan Hamilton
2014/11/13 23:38:18
Doesn't the test:: prefix do that? Personally, I'm
eroman
2014/11/14 00:06:15
Ah, I hadn't noticed the test:: prefix!
|
| + |
| + NetworkActivityMonitor(); |
|
eroman
2014/11/13 22:18:39
Another interesting API for future consideration w
Ryan Hamilton
2014/11/13 23:38:17
Oo! Interesting. That's a good idea. Done. (Though
|
| + ~NetworkActivityMonitor(); |
| + |
| + // Protects bytes_read_. |
| + mutable base::Lock bytes_read_lock_; |
|
eroman
2014/11/13 22:18:39
Why is this mutable? Presumably you meant to make
Ryan Hamilton
2014/11/13 23:38:18
Whoops, yes. Done.
|
| + uint64 bytes_read_; |
| + |
| + // Protects bytes_written_. |
| + mutable base::Lock bytes_written_lock_; |
|
eroman
2014/11/13 22:18:39
A single lock to protect all members should suffic
Ryan Hamilton
2014/11/13 23:38:17
Done.
|
| + uint64 bytes_written_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkActivityMonitor); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_BASE_NETWORK_ACTIVITY_MONITOR_H_ |