| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_BASE_BANDWIDTH_METRICS_H_ | 5 #ifndef NET_BASE_BANDWIDTH_METRICS_H_ |
| 6 #define NET_BASE_BANDWIDTH_METRICS_H_ | 6 #define NET_BASE_BANDWIDTH_METRICS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 int64 bytes_since_last_start_; // Bytes tracked during this "session". | 115 int64 bytes_since_last_start_; // Bytes tracked during this "session". |
| 116 base::TimeTicks last_start_; // Timestamp of the begin of this "session". | 116 base::TimeTicks last_start_; // Timestamp of the begin of this "session". |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 // A utility class for managing the lifecycle of a measured stream. | 119 // A utility class for managing the lifecycle of a measured stream. |
| 120 // It is important that we not leave unclosed streams, and this class helps | 120 // It is important that we not leave unclosed streams, and this class helps |
| 121 // ensure we always stop them. | 121 // ensure we always stop them. |
| 122 class ScopedBandwidthMetrics { | 122 class ScopedBandwidthMetrics { |
| 123 public: | 123 public: |
| 124 ScopedBandwidthMetrics(); | 124 ScopedBandwidthMetrics(); |
| 125 ~ScopedBandwidthMetrics(); |
| 125 | 126 |
| 126 ~ScopedBandwidthMetrics() { | 127 void StartStream(); |
| 127 if (started_) | 128 void StopStream(); |
| 128 metrics_->StopStream(); | 129 void RecordBytes(int bytes); |
| 129 } | |
| 130 | |
| 131 void StartStream() { | |
| 132 started_ = true; | |
| 133 metrics_->StartStream(); | |
| 134 } | |
| 135 | |
| 136 void StopStream() { | |
| 137 started_ = false; | |
| 138 metrics_->StopStream(); | |
| 139 } | |
| 140 | |
| 141 void RecordBytes(int bytes) { metrics_->RecordBytes(bytes); } | |
| 142 | 130 |
| 143 private: | 131 private: |
| 144 BandwidthMetrics* metrics_; | |
| 145 bool started_; | 132 bool started_; |
| 146 }; | 133 }; |
| 147 | 134 |
| 148 } // namespace net | 135 } // namespace net |
| 149 | 136 |
| 150 #endif // NET_BASE_BANDWIDTH_METRICS_H_ | 137 #endif // NET_BASE_BANDWIDTH_METRICS_H_ |
| 151 | |
| OLD | NEW |