| 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 #include "blimp/net/blimp_stats.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace blimp { | |
| 10 | |
| 11 // static | |
| 12 base::LazyInstance<BlimpStats> BlimpStats::instance_ = | |
| 13 LAZY_INSTANCE_INITIALIZER; | |
| 14 | |
| 15 // static | |
| 16 BlimpStats* BlimpStats::GetInstance() { | |
| 17 return &instance_.Get(); | |
| 18 } | |
| 19 | |
| 20 BlimpStats::BlimpStats() { | |
| 21 for (size_t i = 0; i <= EVENT_TYPE_MAX; ++i) { | |
| 22 base::subtle::NoBarrier_Store(&values_[i], 0); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 BlimpStats::~BlimpStats() {} | |
| 27 | |
| 28 void BlimpStats::Add(EventType type, base::subtle::Atomic32 amount) { | |
| 29 if (amount < 0) { | |
| 30 DLOG(FATAL) << "Illegal negative stat value: type=" << type | |
| 31 << ", amount=" << amount << "."; | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 base::subtle::NoBarrier_AtomicIncrement(&values_[type], amount); | |
| 36 } | |
| 37 | |
| 38 base::subtle::Atomic32 BlimpStats::Get(EventType type) const { | |
| 39 return base::subtle::NoBarrier_Load(&values_[type]); | |
| 40 } | |
| 41 | |
| 42 } // namespace blimp | |
| OLD | NEW |