1 // Copyright 2019 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 5 #ifndef CHROMEOS_COMPONENTS_SYNC_WIFI_NETWORK_IDENTIFIER_H_ 6 #define CHROMEOS_COMPONENTS_SYNC_WIFI_NETWORK_IDENTIFIER_H_ 7 8 #include <string> 9 10 #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h" 11 12 namespace sync_pb { 13 class WifiConfigurationSpecifics; 14 } 15 16 namespace chromeos { 17 18 class NetworkState; 19 20 namespace sync_wifi { 21 22 // A unique identifier for synced networks which contains the properties 23 // necessary to differentiate a synced network from another with the same name. 24 class NetworkIdentifier { 25 public: 26 static NetworkIdentifier FromProto( 27 const sync_pb::WifiConfigurationSpecifics& specifics); 28 static NetworkIdentifier FromMojoNetwork( 29 const network_config::mojom::NetworkStatePropertiesPtr& network); 30 static NetworkIdentifier FromNetworkState(const NetworkState* network); 31 // |serialized_string| is in the format of hex_ssid and security_type 32 // concatenated with an underscore. security_type is the shill constant 33 // returned from NetworkState::security_class(). For example, it would be 34 // "2F_psk" if the hex_ssid is 2F and the security_type is psk. 35 static NetworkIdentifier DeserializeFromString( 36 const std::string& serialized_string); 37 38 // |hex_ssid| hex encoded representation of an ssid. For example, ssid 39 // "network" could be provided as "6E6574776F726B" or "0x6e6574776f726b". 40 // |security_type| is the shill constant that would be returned from 41 // NetworkState::security_class(). 42 NetworkIdentifier(const std::string& hex_ssid, 43 const std::string& security_type); 44 virtual ~NetworkIdentifier(); 45 46 // Note that invalid identifiers are never considered equal to each other. 47 bool operator==(const NetworkIdentifier& o) const; 48 bool operator!=(const NetworkIdentifier& o) const; 49 bool operator<(const NetworkIdentifier& o) const; 50 bool operator>(const NetworkIdentifier& o) const; 51 52 std::string SerializeToString() const; 53 54 // This will always be returned in a format with upper case letters and no 55 // 0x prefix. hex_ssid()56 const std::string& hex_ssid() const { return hex_ssid_; } security_type()57 const std::string& security_type() const { return security_type_; } 58 59 // True if there is a valid ssid and security type. 60 bool IsValid() const; 61 62 private: 63 std::string hex_ssid_; 64 std::string security_type_; 65 }; 66 67 } // namespace sync_wifi 68 69 } // namespace chromeos 70 71 #endif // CHROMEOS_COMPONENTS_SYNC_WIFI_NETWORK_IDENTIFIER_H_ 72