Chromium Code Reviews| 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 { | 14 namespace { |
| 15 const char kValueSeparator[] = ","; | 15 const char kValueSeparator[] = ","; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 namespace nqe { | 19 namespace nqe { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 // NetworkID is used to uniquely identify a network. | 22 // NetworkID is used to uniquely identify a network. |
| 23 // 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 |
| 24 // uniquely identified by a combination of |type| and | 24 // uniquely identified by a combination of |type| and |
| 25 // |id|. This approach is unable to distinguish networks with | 25 // |id|. This approach is unable to distinguish networks with |
| 26 // same name (e.g., different Wi-Fi networks with same SSID). | 26 // same name (e.g., different Wi-Fi networks with same SSID). |
| 27 // This is a protected member to expose it to tests. | 27 // This is a protected member to expose it to tests. |
| 28 struct NET_EXPORT_PRIVATE NetworkID { | 28 struct NET_EXPORT_PRIVATE NetworkID { |
| 29 static NetworkID FromString(const std::string& network_id) { | |
| 30 size_t separator_index = network_id.find(kValueSeparator); | |
| 31 DCHECK_NE(std::string::npos, separator_index); | |
| 32 if (separator_index == std::string::npos) { | |
| 33 return NetworkID(NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
| 34 std::string()); | |
| 35 } | |
| 36 return NetworkID(NetworkChangeNotifier::StringToConnectionType( | |
| 37 network_id.substr(separator_index + 1)), | |
| 38 network_id.substr(0, separator_index)); | |
| 39 } | |
| 29 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 40 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
| 30 : type(type), id(id) {} | 41 : type(type), id(id) {} |
| 31 NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} | 42 NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} |
| 32 ~NetworkID() {} | 43 ~NetworkID() {} |
| 33 | 44 |
| 45 bool operator==(const NetworkID& other) const { | |
| 46 return type == other.type && id == other.id; | |
| 47 } | |
| 48 | |
| 49 bool operator!=(const NetworkID& other) const { | |
| 50 return type != other.type || id != other.id; | |
|
RyanSturm
2016/10/12 21:33:34
maybe something like this:
return !operator==(oth
tbansal1
2016/10/12 22:04:01
Done.
| |
| 51 } | |
| 52 | |
| 34 NetworkID& operator=(const NetworkID& other) { | 53 NetworkID& operator=(const NetworkID& other) { |
| 35 type = other.type; | 54 type = other.type; |
| 36 id = other.id; | 55 id = other.id; |
| 37 return *this; | 56 return *this; |
| 38 } | 57 } |
| 39 | 58 |
| 40 // Overloaded to support ordered collections. | 59 // Overloaded to support ordered collections. |
| 41 bool operator<(const NetworkID& other) const { | 60 bool operator<(const NetworkID& other) const { |
| 42 return std::tie(type, id) < std::tie(other.type, other.id); | 61 return std::tie(type, id) < std::tie(other.type, other.id); |
| 43 } | 62 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 59 // - An empty string in all other cases or if the network name is not | 78 // - An empty string in all other cases or if the network name is not |
| 60 // exposed by platform APIs. | 79 // exposed by platform APIs. |
| 61 std::string id; | 80 std::string id; |
| 62 }; | 81 }; |
| 63 | 82 |
| 64 } // namespace internal | 83 } // namespace internal |
| 65 } // namespace nqe | 84 } // namespace nqe |
| 66 } // namespace net | 85 } // namespace net |
| 67 | 86 |
| 68 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 87 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |