quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 1 | // Copyright 2015 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 | |
maxbogue | 53381b6 | 2016-11-01 17:17:47 | [diff] [blame] | 5 | #include "components/sync_wifi/wifi_config_delegate_chromeos.h" |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 6 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 9 | #include "base/bind.h" |
| 10 | #include "base/logging.h" |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 11 | #include "base/values.h" |
| 12 | #include "chromeos/network/managed_network_configuration_handler.h" |
maxbogue | 53381b6 | 2016-11-01 17:17:47 | [diff] [blame] | 13 | #include "components/sync_wifi/wifi_credential.h" |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 14 | |
maxbogue | 53381b6 | 2016-11-01 17:17:47 | [diff] [blame] | 15 | namespace sync_wifi { |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 16 | |
| 17 | namespace { |
| 18 | |
| 19 | void OnCreateConfigurationFailed( |
| 20 | const WifiCredential& wifi_credential, |
| 21 | const std::string& config_handler_error_message, |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 22 | std::unique_ptr<base::DictionaryValue> error_data) { |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 23 | LOG(ERROR) << "Create configuration failed"; |
| 24 | // TODO(quiche): check if there is a matching network already. If |
| 25 | // so, try to configure it with |wifi_credential|. |
| 26 | } |
| 27 | |
| 28 | } // namespace |
| 29 | |
| 30 | WifiConfigDelegateChromeOs::WifiConfigDelegateChromeOs( |
| 31 | const std::string& user_hash, |
| 32 | chromeos::ManagedNetworkConfigurationHandler* managed_net_config_handler) |
| 33 | : user_hash_(user_hash), |
| 34 | managed_network_configuration_handler_(managed_net_config_handler) { |
| 35 | DCHECK(!user_hash_.empty()); |
| 36 | DCHECK(managed_network_configuration_handler_); |
| 37 | } |
| 38 | |
maxbogue | 53381b6 | 2016-11-01 17:17:47 | [diff] [blame] | 39 | WifiConfigDelegateChromeOs::~WifiConfigDelegateChromeOs() {} |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 40 | |
| 41 | void WifiConfigDelegateChromeOs::AddToLocalNetworks( |
| 42 | const WifiCredential& network_credential) { |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 43 | std::unique_ptr<base::DictionaryValue> onc_properties( |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 44 | network_credential.ToOncProperties()); |
| 45 | // TODO(quiche): Replace with DCHECK, once ONC supports non-UTF-8 SSIDs. |
| 46 | // crbug.com/432546 |
| 47 | if (!onc_properties) { |
| 48 | LOG(ERROR) << "Failed to generate ONC properties for " |
| 49 | << network_credential.ToString(); |
| 50 | return; |
| 51 | } |
| 52 | |
cernekee | f1da84b | 2016-03-15 23:33:03 | [diff] [blame] | 53 | managed_network_configuration_handler_->CreateConfiguration( |
| 54 | user_hash_, *onc_properties, |
| 55 | chromeos::network_handler::ServiceResultCallback(), |
| 56 | base::Bind(OnCreateConfigurationFailed, network_credential)); |
quiche | 9d40dcf | 2015-01-17 00:35:22 | [diff] [blame] | 57 | } |
| 58 | |
maxbogue | 53381b6 | 2016-11-01 17:17:47 | [diff] [blame] | 59 | } // namespace sync_wifi |