effective_connection_type.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef NET_NQE_EFFECTIVE_CONNECTION_TYPE_H_
  5. #define NET_NQE_EFFECTIVE_CONNECTION_TYPE_H_
  6. #include "base/strings/string_piece.h"
  7. #include "net/base/net_export.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. namespace net {
  10. NET_EXPORT extern const char kEffectiveConnectionTypeUnknown[];
  11. NET_EXPORT extern const char kEffectiveConnectionTypeOffline[];
  12. NET_EXPORT extern const char kEffectiveConnectionTypeSlow2G[];
  13. NET_EXPORT extern const char kEffectiveConnectionType2G[];
  14. NET_EXPORT extern const char kEffectiveConnectionType3G[];
  15. NET_EXPORT extern const char kEffectiveConnectionType4G[];
  16. // EffectiveConnectionType is the connection type whose typical performance is
  17. // most similar to the measured performance of the network in use. In many
  18. // cases, the "effective" connection type and the actual type of connection in
  19. // use are the same, but often a network connection performs significantly
  20. // differently, usually worse, from its expected capabilities.
  21. // EffectiveConnectionType of a network is independent of if the current
  22. // connection is metered or not. For example, an unmetered slow connection may
  23. // have EFFECTIVE_CONNECTION_TYPE_SLOW_2G as its effective connection type. The
  24. // effective connection type enums are be in increasing order of quality.
  25. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
  26. // GENERATED_JAVA_PREFIX_TO_STRIP: EFFECTIVE_CONNECTION_
  27. enum EffectiveConnectionType {
  28. // Effective connection type reported when the network quality is unknown.
  29. EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0,
  30. // Effective connection type reported when the Internet is unreachable
  31. // because the device does not have a connection (as reported by underlying
  32. // platform APIs). Note that due to rare but potential bugs in the platform
  33. // APIs, it is possible that effective connection type is reported as
  34. // EFFECTIVE_CONNECTION_TYPE_OFFLINE. Callers must use caution when using
  35. // acting on this.
  36. EFFECTIVE_CONNECTION_TYPE_OFFLINE,
  37. // Effective connection type reported when the network has the quality of a
  38. // poor 2G connection.
  39. EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
  40. // Effective connection type reported when the network has the quality of a
  41. // faster 2G connection.
  42. EFFECTIVE_CONNECTION_TYPE_2G,
  43. // Effective connection type reported when the network has the quality of a 3G
  44. // connection.
  45. EFFECTIVE_CONNECTION_TYPE_3G,
  46. // Effective connection type reported when the network has the quality of a 4G
  47. // connection.
  48. EFFECTIVE_CONNECTION_TYPE_4G,
  49. // Last value of the effective connection type. This value is unused.
  50. EFFECTIVE_CONNECTION_TYPE_LAST,
  51. };
  52. // Returns the string equivalent of |type|.
  53. NET_EXPORT const char* GetNameForEffectiveConnectionType(
  54. EffectiveConnectionType type);
  55. // Returns the EffectiveConnectionType that corresponds to
  56. // |connection_type_name|. If the effective connection type is unavailable or if
  57. // |connection_type_name| does not match to a known effective connection type,
  58. // an unset value is returned.
  59. NET_EXPORT absl::optional<EffectiveConnectionType>
  60. GetEffectiveConnectionTypeForName(base::StringPiece connection_type_name);
  61. // Returns the string equivalent of |type|. Deprecated, and replaced by
  62. // GetNameForEffectiveConnectionType.
  63. NET_EXPORT_PRIVATE const char* DeprecatedGetNameForEffectiveConnectionType(
  64. EffectiveConnectionType type);
  65. } // namespace net
  66. #endif // NET_NQE_EFFECTIVE_CONNECTION_TYPE_H_