cellular_logic_helper.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "components/metrics/net/cellular_logic_helper.h"
  5. #include "base/time/time.h"
  6. #include "build/build_config.h"
  7. #include "build/chromeos_buildflags.h"
  8. #include "net/base/network_change_notifier.h"
  9. namespace metrics {
  10. namespace {
  11. // Standard interval between log uploads, in seconds.
  12. #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
  13. const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes.
  14. const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes.
  15. #else
  16. const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes.
  17. #endif
  18. #if BUILDFLAG(IS_ANDROID)
  19. const bool kDefaultCellularLogicEnabled = true;
  20. #else
  21. const bool kDefaultCellularLogicEnabled = false;
  22. #endif
  23. } // namespace
  24. base::TimeDelta GetUploadInterval(bool use_cellular_upload_interval) {
  25. #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
  26. if (use_cellular_upload_interval)
  27. return base::Seconds(kStandardUploadIntervalCellularSeconds);
  28. #endif
  29. return base::Seconds(kStandardUploadIntervalSeconds);
  30. }
  31. bool ShouldUseCellularUploadInterval() {
  32. if (!kDefaultCellularLogicEnabled)
  33. return false;
  34. return net::NetworkChangeNotifier::IsConnectionCellular(
  35. net::NetworkChangeNotifier::GetConnectionType());
  36. }
  37. } // namespace metrics