OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_NQE_NETWORK_ID_H_ | 5 #ifndef NET_NQE_NETWORK_ID_H_ |
6 #define NET_NQE_NETWORK_ID_H_ | 6 #define NET_NQE_NETWORK_ID_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <tuple> | 9 #include <tuple> |
10 | 10 |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
13 | 13 |
14 namespace { | |
15 const char kValueSeparator[] = ","; | |
16 } | |
17 | |
14 namespace net { | 18 namespace net { |
15 namespace nqe { | 19 namespace nqe { |
16 namespace internal { | 20 namespace internal { |
17 | 21 |
18 // NetworkID is used to uniquely identify a network. | 22 // NetworkID is used to uniquely identify a network. |
19 // For the purpose of network quality estimation and caching, a network is | 23 // For the purpose of network quality estimation and caching, a network is |
20 // uniquely identified by a combination of |type| and | 24 // uniquely identified by a combination of |type| and |
21 // |id|. This approach is unable to distinguish networks with | 25 // |id|. This approach is unable to distinguish networks with |
22 // same name (e.g., different Wi-Fi networks with same SSID). | 26 // same name (e.g., different Wi-Fi networks with same SSID). |
23 // This is a protected member to expose it to tests. | 27 // This is a protected member to expose it to tests. |
24 struct NET_EXPORT_PRIVATE NetworkID { | 28 struct NET_EXPORT_PRIVATE NetworkID { |
25 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 29 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
26 : type(type), id(id) {} | 30 : type(type), id(id) {} |
27 NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} | 31 NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} |
28 ~NetworkID() {} | 32 ~NetworkID() {} |
29 | 33 |
30 NetworkID& operator=(const NetworkID& other) { | 34 NetworkID& operator=(const NetworkID& other) { |
31 type = other.type; | 35 type = other.type; |
32 id = other.id; | 36 id = other.id; |
33 return *this; | 37 return *this; |
34 } | 38 } |
35 | 39 |
36 // Overloaded to support ordered collections. | 40 // Overloaded to support ordered collections. |
37 bool operator<(const NetworkID& other) const { | 41 bool operator<(const NetworkID& other) const { |
38 return std::tie(type, id) < std::tie(other.type, other.id); | 42 return std::tie(type, id) < std::tie(other.type, other.id); |
39 } | 43 } |
40 | 44 |
45 std::string ToString() const { | |
46 return id + kValueSeparator + | |
bengr
2016/09/22 23:35:46
It seems like overill to define kValueSeparator. I
tbansal1
2016/09/23 17:10:32
The value separator is going to be used soon (in t
bengr
2016/09/23 20:31:06
Nah. If you're gonna use it, keep it.
tbansal1
2016/09/23 20:50:13
Acknowledged.
| |
47 NetworkChangeNotifier::ConnectionTypeToString(type); | |
48 } | |
49 | |
41 // Connection type of the network. | 50 // Connection type of the network. |
42 NetworkChangeNotifier::ConnectionType type; | 51 NetworkChangeNotifier::ConnectionType type; |
43 | 52 |
44 // Name of this network. This is set to: | 53 // Name of this network. This is set to: |
45 // - Wi-Fi SSID if the device is connected to a Wi-Fi access point and the | 54 // - Wi-Fi SSID if the device is connected to a Wi-Fi access point and the |
46 // SSID name is available, or | 55 // SSID name is available, or |
47 // - MCC/MNC code of the cellular carrier if the device is connected to a | 56 // - MCC/MNC code of the cellular carrier if the device is connected to a |
48 // cellular network, or | 57 // cellular network, or |
49 // - "Ethernet" in case the device is connected to ethernet. | 58 // - "Ethernet" in case the device is connected to ethernet. |
50 // - An empty string in all other cases or if the network name is not | 59 // - An empty string in all other cases or if the network name is not |
51 // exposed by platform APIs. | 60 // exposed by platform APIs. |
52 std::string id; | 61 std::string id; |
53 }; | 62 }; |
54 | 63 |
55 } // namespace internal | 64 } // namespace internal |
56 } // namespace nqe | 65 } // namespace nqe |
57 } // namespace net | 66 } // namespace net |
58 | 67 |
59 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 68 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |