| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 double data_sum_; // The sum of all samples collected. | 114 double data_sum_; // The sum of all samples collected. |
| 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 explicit ScopedBandwidthMetrics(BandwidthMetrics* metrics) | 124 ScopedBandwidthMetrics(); |
| 125 : metrics_(metrics), started_(false) { | |
| 126 } | |
| 127 | 125 |
| 128 ~ScopedBandwidthMetrics() { | 126 ~ScopedBandwidthMetrics() { |
| 129 if (started_) | 127 if (started_) |
| 130 metrics_->StopStream(); | 128 metrics_->StopStream(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 void StartStream() { | 131 void StartStream() { |
| 134 started_ = true; | 132 started_ = true; |
| 135 metrics_->StartStream(); | 133 metrics_->StartStream(); |
| 136 } | 134 } |
| 137 | 135 |
| 138 void StopStream() { | 136 void StopStream() { |
| 139 started_ = false; | 137 started_ = false; |
| 140 metrics_->StopStream(); | 138 metrics_->StopStream(); |
| 141 } | 139 } |
| 142 | 140 |
| 143 void RecordBytes(int bytes) { metrics_->RecordBytes(bytes); } | 141 void RecordBytes(int bytes) { metrics_->RecordBytes(bytes); } |
| 144 | 142 |
| 145 private: | 143 private: |
| 146 BandwidthMetrics* metrics_; | 144 BandwidthMetrics* metrics_; |
| 147 bool started_; | 145 bool started_; |
| 148 }; | 146 }; |
| 149 | 147 |
| 150 } // namespace net | 148 } // namespace net |
| 151 | 149 |
| 152 #endif // NET_BASE_BANDWIDTH_METRICS_H_ | 150 #endif // NET_BASE_BANDWIDTH_METRICS_H_ |
| 153 | 151 |
| OLD | NEW |