| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/lazy_instance.h" | 5 #include "base/lazy_instance.h" |
| 6 #include "net/base/bandwidth_metrics.h" | 6 #include "net/base/bandwidth_metrics.h" |
| 7 | 7 |
| 8 static base::LazyInstance<net::BandwidthMetrics> g_bandwidth_metrics = | 8 static base::LazyInstance<net::BandwidthMetrics> g_bandwidth_metrics = |
| 9 LAZY_INSTANCE_INITIALIZER; | 9 LAZY_INSTANCE_INITIALIZER; |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 ScopedBandwidthMetrics::ScopedBandwidthMetrics() | 13 ScopedBandwidthMetrics::ScopedBandwidthMetrics() : started_(false) { |
| 14 : started_(false) { | |
| 15 } | 14 } |
| 16 | 15 |
| 17 ScopedBandwidthMetrics::~ScopedBandwidthMetrics() { | 16 ScopedBandwidthMetrics::~ScopedBandwidthMetrics() { |
| 18 if (started_) | 17 if (started_) |
| 19 g_bandwidth_metrics.Get().StopStream(); | 18 g_bandwidth_metrics.Get().StopStream(); |
| 20 } | 19 } |
| 21 | 20 |
| 22 void ScopedBandwidthMetrics::StartStream() { | 21 void ScopedBandwidthMetrics::StartStream() { |
| 23 started_ = true; | 22 started_ = true; |
| 24 g_bandwidth_metrics.Get().StartStream(); | 23 g_bandwidth_metrics.Get().StartStream(); |
| 25 } | 24 } |
| 26 | 25 |
| 27 void ScopedBandwidthMetrics::StopStream() { | 26 void ScopedBandwidthMetrics::StopStream() { |
| 28 started_ = false; | 27 started_ = false; |
| 29 g_bandwidth_metrics.Get().StopStream(); | 28 g_bandwidth_metrics.Get().StopStream(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 void ScopedBandwidthMetrics::RecordBytes(int bytes) { | 31 void ScopedBandwidthMetrics::RecordBytes(int bytes) { |
| 33 g_bandwidth_metrics.Get().RecordBytes(bytes); | 32 g_bandwidth_metrics.Get().RecordBytes(bytes); |
| 34 } | 33 } |
| 35 | 34 |
| 36 } // namespace net | 35 } // namespace net |
| OLD | NEW |