Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ | |
| 6 #define BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include "base/callback.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "blimp/net/blimp_net_export.h" | |
| 13 | |
| 14 namespace blimp { | |
| 15 | |
| 16 // Collects network traffic statistics. Maintains a counter for number of | |
| 17 // completed commits, bytes sent and received over network and notifies its | |
| 18 // observers on the main thread. Presents the data on a per navigation basis. | |
| 19 // This class is supposed to live an entire session, created and destroyed along | |
| 20 // it. This class internally takes care of the fact that the stats can be | |
| 21 // written from multiple threads while it is read only from the UI thread. | |
| 22 class BLIMP_NET_EXPORT BlimpConnectionStatistics { | |
| 23 public: | |
| 24 enum EventType { | |
| 25 BYTES_SENT = 0, | |
| 26 BYTES_RECEIVED = 1, | |
| 27 COMMIT = 2, | |
| 28 }; | |
| 29 typedef std::map<EventType, int> StatisticsMap; | |
| 30 | |
| 31 BlimpConnectionStatistics( | |
| 32 const scoped_refptr<base::TaskRunner>& main_thread_task_runner); | |
| 33 | |
| 34 ~BlimpConnectionStatistics(); | |
| 35 | |
| 36 // Can be called from any thread. | |
|
Kevin M
2016/05/20 01:02:04
Document the purpose and parameters of these funct
| |
| 37 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".
| |
| 38 void Increment(EventType type); | |
| 39 | |
| 40 // Must be called only on UI thread. | |
| 41 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.
| |
| 42 | |
| 43 private: | |
| 44 StatisticsMap statistics_; | |
| 45 | |
| 46 // Main thread counterparts of the stats collection functions. | |
| 47 void AddOnMain(EventType type, int data); | |
| 48 void IncrementOnMain(EventType type); | |
| 49 | |
| 50 scoped_refptr<base::TaskRunner> main_thread_task_runner_; | |
| 51 | |
| 52 base::WeakPtrFactory<BlimpConnectionStatistics> weak_factory_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(BlimpConnectionStatistics); | |
| 55 }; | |
| 56 | |
| 57 } // namespace blimp | |
| 58 | |
| 59 #endif // BLIMP_NET_BLIMP_CONNECTION_STATISTICS_H_ | |
| OLD | NEW |