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

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

Issue 831693005: wifi_sync: add function to create a network in Shill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.0-wifi-security-class
Patch Set: rename managed_net_config_handler Created 5 years, 11 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
« no previous file with comments | « components/wifi_sync/network_state_helper_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/network_state_helper_chromeos.h" 5 #include "components/wifi_sync/network_state_helper_chromeos.h"
6 6
7 #include "base/i18n/streaming_utf8_validator.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "chromeos/network/managed_network_configuration_handler.h"
8 #include "chromeos/network/network_state.h" 11 #include "chromeos/network/network_state.h"
9 #include "chromeos/network/network_state_handler.h" 12 #include "chromeos/network/network_state_handler.h"
10 #include "chromeos/network/network_type_pattern.h" 13 #include "chromeos/network/network_type_pattern.h"
14 #include "components/onc/onc_constants.h"
11 #include "components/wifi_sync/wifi_security_class.h" 15 #include "components/wifi_sync/wifi_security_class.h"
12 16
13 namespace wifi_sync { 17 namespace wifi_sync {
14 18
19 void CreateWifiNetworkInShillUserProfile(
20 chromeos::ManagedNetworkConfigurationHandler* network_config_handler,
21 const std::string& user_hash,
22 const WifiCredential& wifi_credential,
23 const chromeos::network_handler::StringResultCallback& success_callback,
24 const chromeos::network_handler::ErrorCallback& error_callback) {
25 const std::string ssid_utf8(wifi_credential.ssid().begin(),
26 wifi_credential.ssid().end());
27 if (!base::StreamingUtf8Validator::Validate(ssid_utf8)) {
28 LOG(ERROR) << "SSID is not valid UTF-8";
29 return;
30 }
31
32 std::string onc_security;
33 if (!WifiSecurityClassToOncSecurityString(
34 wifi_credential.security_class(), &onc_security)) {
35 LOG(ERROR) << "Error converting SecurityClass with value "
36 << wifi_credential.security_class();
37 return;
38 }
39
40 base::DictionaryValue onc_properties;
41 onc_properties.Set(onc::toplevel_config::kType,
42 new base::StringValue(onc::network_type::kWiFi));
43 // TODO(quiche): Switch to the HexSSID property, once ONC fully supports it.
44 onc_properties.Set(onc::network_config::WifiProperty(onc::wifi::kSSID),
45 new base::StringValue(ssid_utf8));
46 onc_properties.Set(onc::network_config::WifiProperty(onc::wifi::kSecurity),
47 new base::StringValue(onc_security));
48 if (WifiSecurityClassSupportsPassphrases(
49 wifi_credential.security_class())) {
50 onc_properties.Set(
51 onc::network_config::WifiProperty(onc::wifi::kPassphrase),
52 new base::StringValue(wifi_credential.passphrase()));
53 }
54 network_config_handler->CreateConfiguration(
55 user_hash, onc_properties, success_callback, error_callback);
56 }
57
15 WifiCredential::CredentialSet GetWifiCredentialsForShillProfile( 58 WifiCredential::CredentialSet GetWifiCredentialsForShillProfile(
16 chromeos::NetworkStateHandler* network_state_handler, 59 chromeos::NetworkStateHandler* network_state_handler,
17 const std::string& shill_profile_path) { 60 const std::string& shill_profile_path) {
18 DCHECK(network_state_handler); 61 DCHECK(network_state_handler);
19 62
20 chromeos::NetworkStateHandler::NetworkStateList networks; 63 chromeos::NetworkStateHandler::NetworkStateList networks;
21 network_state_handler->GetNetworkListByType( 64 network_state_handler->GetNetworkListByType(
22 chromeos::NetworkTypePattern::WiFi(), 65 chromeos::NetworkTypePattern::WiFi(),
23 true /* configured_only */, 66 true /* configured_only */,
24 false /* visible_only */, 67 false /* visible_only */,
(...skipping 13 matching lines...) Expand all
38 // GetProperties method. 81 // GetProperties method.
39 credentials.insert( 82 credentials.insert(
40 WifiCredential(network->raw_ssid(), 83 WifiCredential(network->raw_ssid(),
41 WifiSecurityClassFromShillSecurity(network->security()), 84 WifiSecurityClassFromShillSecurity(network->security()),
42 "" /* empty passphrase */)); 85 "" /* empty passphrase */));
43 } 86 }
44 return credentials; 87 return credentials;
45 } 88 }
46 89
47 } // namespace wifi_sync 90 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/network_state_helper_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698