blob: e1323dbcdc8267069446ccb2aecd065c875d2b76 [file] [log] [blame]
quiche9d40dcf2015-01-17 00:35:221// 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
maxbogue53381b62016-11-01 17:17:475#include "components/sync_wifi/wifi_config_delegate_chromeos.h"
quiche9d40dcf2015-01-17 00:35:226
dcheng3f767dc32016-04-25 22:54:227#include <memory>
8
quiche9d40dcf2015-01-17 00:35:229#include "base/bind.h"
10#include "base/logging.h"
quiche9d40dcf2015-01-17 00:35:2211#include "base/values.h"
12#include "chromeos/network/managed_network_configuration_handler.h"
maxbogue53381b62016-11-01 17:17:4713#include "components/sync_wifi/wifi_credential.h"
quiche9d40dcf2015-01-17 00:35:2214
maxbogue53381b62016-11-01 17:17:4715namespace sync_wifi {
quiche9d40dcf2015-01-17 00:35:2216
17namespace {
18
19void OnCreateConfigurationFailed(
20 const WifiCredential& wifi_credential,
21 const std::string& config_handler_error_message,
dcheng3f767dc32016-04-25 22:54:2222 std::unique_ptr<base::DictionaryValue> error_data) {
quiche9d40dcf2015-01-17 00:35:2223 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
30WifiConfigDelegateChromeOs::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
maxbogue53381b62016-11-01 17:17:4739WifiConfigDelegateChromeOs::~WifiConfigDelegateChromeOs() {}
quiche9d40dcf2015-01-17 00:35:2240
41void WifiConfigDelegateChromeOs::AddToLocalNetworks(
42 const WifiCredential& network_credential) {
dcheng3f767dc32016-04-25 22:54:2243 std::unique_ptr<base::DictionaryValue> onc_properties(
quiche9d40dcf2015-01-17 00:35:2244 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
cernekeef1da84b2016-03-15 23:33:0353 managed_network_configuration_handler_->CreateConfiguration(
54 user_hash_, *onc_properties,
55 chromeos::network_handler::ServiceResultCallback(),
56 base::Bind(OnCreateConfigurationFailed, network_credential));
quiche9d40dcf2015-01-17 00:35:2257}
58
maxbogue53381b62016-11-01 17:17:4759} // namespace sync_wifi