Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: components/wifi_sync/wifi_credential.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/wifi_sync/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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "components/onc/onc_constants.h" 13 #include "components/onc/onc_constants.h"
13 14
14 namespace wifi_sync { 15 namespace wifi_sync {
15 16
16 WifiCredential::WifiCredential(const WifiCredential& other) = default; 17 WifiCredential::WifiCredential(const WifiCredential& other) = default;
17 18
18 WifiCredential::~WifiCredential() { 19 WifiCredential::~WifiCredential() {
19 } 20 }
20 21
21 // static 22 // static
22 scoped_ptr<WifiCredential> WifiCredential::Create( 23 std::unique_ptr<WifiCredential> WifiCredential::Create(
23 const SsidBytes& ssid, 24 const SsidBytes& ssid,
24 WifiSecurityClass security_class, 25 WifiSecurityClass security_class,
25 const std::string& passphrase) { 26 const std::string& passphrase) {
26 if (security_class == SECURITY_CLASS_INVALID) { 27 if (security_class == SECURITY_CLASS_INVALID) {
27 LOG(ERROR) << "SecurityClass is invalid."; 28 LOG(ERROR) << "SecurityClass is invalid.";
28 return nullptr; 29 return nullptr;
29 } 30 }
30 31
31 if (!base::StreamingUtf8Validator::Validate(passphrase)) { 32 if (!base::StreamingUtf8Validator::Validate(passphrase)) {
32 LOG(ERROR) << "Passphrase is not valid UTF-8"; 33 LOG(ERROR) << "Passphrase is not valid UTF-8";
33 return nullptr; 34 return nullptr;
34 } 35 }
35 36
36 return make_scoped_ptr(new WifiCredential(ssid, security_class, passphrase)); 37 return base::WrapUnique(new WifiCredential(ssid, security_class, passphrase));
37 } 38 }
38 39
39 scoped_ptr<base::DictionaryValue> WifiCredential::ToOncProperties() const { 40 std::unique_ptr<base::DictionaryValue> WifiCredential::ToOncProperties() const {
40 const std::string ssid_utf8(ssid().begin(), ssid().end()); 41 const std::string ssid_utf8(ssid().begin(), ssid().end());
41 // TODO(quiche): Remove this test, once ONC suports non-UTF-8 SSIDs. 42 // TODO(quiche): Remove this test, once ONC suports non-UTF-8 SSIDs.
42 // crbug.com/432546. 43 // crbug.com/432546.
43 if (!base::StreamingUtf8Validator::Validate(ssid_utf8)) { 44 if (!base::StreamingUtf8Validator::Validate(ssid_utf8)) {
44 LOG(ERROR) << "SSID is not valid UTF-8"; 45 LOG(ERROR) << "SSID is not valid UTF-8";
45 return nullptr; 46 return nullptr;
46 } 47 }
47 48
48 std::string onc_security; 49 std::string onc_security;
49 if (!WifiSecurityClassToOncSecurityString(security_class(), &onc_security)) { 50 if (!WifiSecurityClassToOncSecurityString(security_class(), &onc_security)) {
50 NOTREACHED() << "Failed to convert SecurityClass with value " 51 NOTREACHED() << "Failed to convert SecurityClass with value "
51 << security_class(); 52 << security_class();
52 return make_scoped_ptr(new base::DictionaryValue()); 53 return base::WrapUnique(new base::DictionaryValue());
53 } 54 }
54 55
55 scoped_ptr<base::DictionaryValue> onc_properties( 56 std::unique_ptr<base::DictionaryValue> onc_properties(
56 new base::DictionaryValue()); 57 new base::DictionaryValue());
57 onc_properties->Set(onc::toplevel_config::kType, 58 onc_properties->Set(onc::toplevel_config::kType,
58 new base::StringValue(onc::network_type::kWiFi)); 59 new base::StringValue(onc::network_type::kWiFi));
59 // TODO(quiche): Switch to the HexSSID property, once ONC fully supports it. 60 // TODO(quiche): Switch to the HexSSID property, once ONC fully supports it.
60 // crbug.com/432546. 61 // crbug.com/432546.
61 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSSID), 62 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSSID),
62 new base::StringValue(ssid_utf8)); 63 new base::StringValue(ssid_utf8));
63 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity), 64 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity),
64 new base::StringValue(onc_security)); 65 new base::StringValue(onc_security));
65 if (WifiSecurityClassSupportsPassphrases(security_class())) { 66 if (WifiSecurityClassSupportsPassphrases(security_class())) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 WifiCredential::WifiCredential( 102 WifiCredential::WifiCredential(
102 const std::vector<unsigned char>& ssid, 103 const std::vector<unsigned char>& ssid,
103 WifiSecurityClass security_class, 104 WifiSecurityClass security_class,
104 const std::string& passphrase) 105 const std::string& passphrase)
105 : ssid_(ssid), 106 : ssid_(ssid),
106 security_class_(security_class), 107 security_class_(security_class),
107 passphrase_(passphrase) { 108 passphrase_(passphrase) {
108 } 109 }
109 110
110 } // namespace wifi_sync 111 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/wifi_credential.h ('k') | components/wifi_sync/wifi_credential_syncable_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698