Chromium Code Reviews| Index: blimp/net/blimp_connection_statistics.h |
| diff --git a/blimp/net/blimp_connection_statistics.h b/blimp/net/blimp_connection_statistics.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..252d21c933bc760ed4f490a3eb34b683a6270d1d |
| --- /dev/null |
| +++ b/blimp/net/blimp_connection_statistics.h |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2016 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 BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ |
| +#define BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ |
| + |
| +#include <map> |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "blimp/net/blimp_net_export.h" |
| + |
| +namespace blimp { |
| + |
| +// Collects network traffic statistics. Maintains a counter for number of |
| +// completed commits, bytes sent and received over network and notifies its |
| +// observers on the main thread. Presents the data on a per navigation basis. |
| +// This class is supposed to live an entire session, created and destroyed along |
| +// it. This class internally takes care of the fact that the stats can be |
| +// written from multiple threads while it is read only from the UI thread. |
| +class BLIMP_NET_EXPORT BlimpConnectionStatistics { |
| + public: |
| + enum EventType { |
| + BYTES_SENT = 0, |
| + BYTES_RECEIVED = 1, |
| + COMMIT = 2, |
| + }; |
| + typedef std::map<EventType, int> StatisticsMap; |
| + |
| + BlimpConnectionStatistics( |
| + const scoped_refptr<base::TaskRunner>& main_thread_task_runner); |
| + |
| + ~BlimpConnectionStatistics(); |
| + |
| + // Can be called from any thread. |
|
Kevin M
2016/05/20 01:02:04
Document the purpose and parameters of these funct
|
| + void Add(EventType type, int data); |
|
Kevin M
2016/05/20 01:02:03
We can use a better parameter name instead of "dat
shaktisahu
2016/05/22 22:36:57
I feel "data" is better than "x".
|
| + void Increment(EventType type); |
| + |
| + // Must be called only on UI thread. |
| + void GetDebugInfo(const base::Callback<void(StatisticsMap stats)>& callback); |
|
Kevin M
2016/05/20 01:02:04
If we require that this method be invoked on the c
Kevin M
2016/05/20 04:01:52
After a bit of thought, I think we need to have th
shaktisahu
2016/05/22 22:36:57
Thank you. This would be much better.
|
| + |
| + private: |
| + StatisticsMap statistics_; |
| + |
| + // Main thread counterparts of the stats collection functions. |
| + void AddOnMain(EventType type, int data); |
| + void IncrementOnMain(EventType type); |
| + |
| + scoped_refptr<base::TaskRunner> main_thread_task_runner_; |
| + |
| + base::WeakPtrFactory<BlimpConnectionStatistics> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlimpConnectionStatistics); |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ |