| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/wifi_sync/wifi_credential.h" | 5 #include "components/sync_wifi/wifi_credential.h" |
| 6 | 6 |
| 7 #include "base/i18n/streaming_utf8_validator.h" | 7 #include "base/i18n/streaming_utf8_validator.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/onc/onc_constants.h" | 13 #include "components/onc/onc_constants.h" |
| 14 | 14 |
| 15 namespace wifi_sync { | 15 namespace sync_wifi { |
| 16 | 16 |
| 17 WifiCredential::WifiCredential(const WifiCredential& other) = default; | 17 WifiCredential::WifiCredential(const WifiCredential& other) = default; |
| 18 | 18 |
| 19 WifiCredential::~WifiCredential() { | 19 WifiCredential::~WifiCredential() {} |
| 20 } | |
| 21 | 20 |
| 22 // static | 21 // static |
| 23 std::unique_ptr<WifiCredential> WifiCredential::Create( | 22 std::unique_ptr<WifiCredential> WifiCredential::Create( |
| 24 const SsidBytes& ssid, | 23 const SsidBytes& ssid, |
| 25 WifiSecurityClass security_class, | 24 WifiSecurityClass security_class, |
| 26 const std::string& passphrase) { | 25 const std::string& passphrase) { |
| 27 if (security_class == SECURITY_CLASS_INVALID) { | 26 if (security_class == SECURITY_CLASS_INVALID) { |
| 28 LOG(ERROR) << "SecurityClass is invalid."; | 27 LOG(ERROR) << "SecurityClass is invalid."; |
| 29 return nullptr; | 28 return nullptr; |
| 30 } | 29 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 71 } |
| 73 | 72 |
| 74 std::string WifiCredential::ToString() const { | 73 std::string WifiCredential::ToString() const { |
| 75 return base::StringPrintf( | 74 return base::StringPrintf( |
| 76 "[SSID (hex): %s, SecurityClass: %d]", | 75 "[SSID (hex): %s, SecurityClass: %d]", |
| 77 base::HexEncode(&ssid_.front(), ssid_.size()).c_str(), | 76 base::HexEncode(&ssid_.front(), ssid_.size()).c_str(), |
| 78 security_class_); // Passphrase deliberately omitted. | 77 security_class_); // Passphrase deliberately omitted. |
| 79 } | 78 } |
| 80 | 79 |
| 81 // static | 80 // static |
| 82 bool WifiCredential::IsLessThan( | 81 bool WifiCredential::IsLessThan(const WifiCredential& a, |
| 83 const WifiCredential& a, const WifiCredential& b) { | 82 const WifiCredential& b) { |
| 84 return a.ssid_ < b.ssid_ || | 83 return a.ssid_ < b.ssid_ || a.security_class_ < b.security_class_ || |
| 85 a.security_class_< b.security_class_ || | 84 a.passphrase_ < b.passphrase_; |
| 86 a.passphrase_ < b.passphrase_; | |
| 87 } | 85 } |
| 88 | 86 |
| 89 // static | 87 // static |
| 90 WifiCredential::CredentialSet WifiCredential::MakeSet() { | 88 WifiCredential::CredentialSet WifiCredential::MakeSet() { |
| 91 return CredentialSet(WifiCredential::IsLessThan); | 89 return CredentialSet(WifiCredential::IsLessThan); |
| 92 } | 90 } |
| 93 | 91 |
| 94 // static | 92 // static |
| 95 WifiCredential::SsidBytes WifiCredential::MakeSsidBytesForTest( | 93 WifiCredential::SsidBytes WifiCredential::MakeSsidBytesForTest( |
| 96 const std::string& ssid) { | 94 const std::string& ssid) { |
| 97 return SsidBytes(ssid.begin(), ssid.end()); | 95 return SsidBytes(ssid.begin(), ssid.end()); |
| 98 } | 96 } |
| 99 | 97 |
| 100 // Private methods. | 98 // Private methods. |
| 101 | 99 |
| 102 WifiCredential::WifiCredential( | 100 WifiCredential::WifiCredential(const std::vector<unsigned char>& ssid, |
| 103 const std::vector<unsigned char>& ssid, | 101 WifiSecurityClass security_class, |
| 104 WifiSecurityClass security_class, | 102 const std::string& passphrase) |
| 105 const std::string& passphrase) | 103 : ssid_(ssid), security_class_(security_class), passphrase_(passphrase) {} |
| 106 : ssid_(ssid), | |
| 107 security_class_(security_class), | |
| 108 passphrase_(passphrase) { | |
| 109 } | |
| 110 | 104 |
| 111 } // namespace wifi_sync | 105 } // namespace sync_wifi |
| OLD | NEW |