network_activity_monitor.cc 933 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2014 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. #include "net/base/network_activity_monitor.h"
  5. #include <atomic>
  6. #include <type_traits>
  7. #include "third_party/abseil-cpp/absl/base/attributes.h"
  8. namespace net::activity_monitor {
  9. namespace {
  10. ABSL_CONST_INIT std::atomic<uint64_t> g_bytes_received = 0;
  11. } // namespace
  12. void IncrementBytesReceived(uint64_t bytes_received) {
  13. // std::memory_order_relaxed is used because no other operation on
  14. // |bytes_received_| depends on memory operations that happened before this
  15. // increment.
  16. g_bytes_received.fetch_add(bytes_received, std::memory_order_relaxed);
  17. }
  18. uint64_t GetBytesReceived() {
  19. return g_bytes_received.load(std::memory_order_relaxed);
  20. }
  21. void ResetBytesReceivedForTesting() {
  22. g_bytes_received = 0;
  23. }
  24. } // namespace net::activity_monitor