OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/net/onc_utils.h" | 5 #include "chrome/browser/chromeos/net/onc_utils.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 UserStringSubstitution substitution(user); | 71 UserStringSubstitution substitution(user); |
72 chromeos::onc::ExpandStringsInNetworks(substitution, network_configs); | 72 chromeos::onc::ExpandStringsInNetworks(substitution, network_configs); |
73 } | 73 } |
74 | 74 |
75 void ImportNetworksForUser(const user_manager::User* user, | 75 void ImportNetworksForUser(const user_manager::User* user, |
76 const base::ListValue& network_configs, | 76 const base::ListValue& network_configs, |
77 std::string* error) { | 77 std::string* error) { |
78 error->clear(); | 78 error->clear(); |
79 | 79 |
80 scoped_ptr<base::ListValue> expanded_networks(network_configs.DeepCopy()); | 80 std::unique_ptr<base::ListValue> expanded_networks( |
| 81 network_configs.DeepCopy()); |
81 ExpandStringPlaceholdersInNetworksForUser(user, expanded_networks.get()); | 82 ExpandStringPlaceholdersInNetworksForUser(user, expanded_networks.get()); |
82 | 83 |
83 const NetworkProfile* profile = | 84 const NetworkProfile* profile = |
84 NetworkHandler::Get()->network_profile_handler()->GetProfileForUserhash( | 85 NetworkHandler::Get()->network_profile_handler()->GetProfileForUserhash( |
85 user->username_hash()); | 86 user->username_hash()); |
86 if (!profile) { | 87 if (!profile) { |
87 *error = "User profile doesn't exist."; | 88 *error = "User profile doesn't exist."; |
88 return; | 89 return; |
89 } | 90 } |
90 | 91 |
91 bool ethernet_not_found = false; | 92 bool ethernet_not_found = false; |
92 for (base::ListValue::const_iterator it = expanded_networks->begin(); | 93 for (base::ListValue::const_iterator it = expanded_networks->begin(); |
93 it != expanded_networks->end(); | 94 it != expanded_networks->end(); |
94 ++it) { | 95 ++it) { |
95 const base::DictionaryValue* network = NULL; | 96 const base::DictionaryValue* network = NULL; |
96 (*it)->GetAsDictionary(&network); | 97 (*it)->GetAsDictionary(&network); |
97 DCHECK(network); | 98 DCHECK(network); |
98 | 99 |
99 // Remove irrelevant fields. | 100 // Remove irrelevant fields. |
100 onc::Normalizer normalizer(true /* remove recommended fields */); | 101 onc::Normalizer normalizer(true /* remove recommended fields */); |
101 scoped_ptr<base::DictionaryValue> normalized_network = | 102 std::unique_ptr<base::DictionaryValue> normalized_network = |
102 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, | 103 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, |
103 *network); | 104 *network); |
104 | 105 |
105 // TODO(pneubeck): Use ONC and ManagedNetworkConfigurationHandler instead. | 106 // TODO(pneubeck): Use ONC and ManagedNetworkConfigurationHandler instead. |
106 // crbug.com/457936 | 107 // crbug.com/457936 |
107 scoped_ptr<base::DictionaryValue> shill_dict = | 108 std::unique_ptr<base::DictionaryValue> shill_dict = |
108 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, | 109 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, |
109 *normalized_network); | 110 *normalized_network); |
110 | 111 |
111 scoped_ptr<NetworkUIData> ui_data( | 112 std::unique_ptr<NetworkUIData> ui_data( |
112 NetworkUIData::CreateFromONC(::onc::ONC_SOURCE_USER_IMPORT)); | 113 NetworkUIData::CreateFromONC(::onc::ONC_SOURCE_USER_IMPORT)); |
113 base::DictionaryValue ui_data_dict; | 114 base::DictionaryValue ui_data_dict; |
114 ui_data->FillDictionary(&ui_data_dict); | 115 ui_data->FillDictionary(&ui_data_dict); |
115 std::string ui_data_json; | 116 std::string ui_data_json; |
116 base::JSONWriter::Write(ui_data_dict, &ui_data_json); | 117 base::JSONWriter::Write(ui_data_dict, &ui_data_json); |
117 shill_dict->SetStringWithoutPathExpansion(shill::kUIDataProperty, | 118 shill_dict->SetStringWithoutPathExpansion(shill::kUIDataProperty, |
118 ui_data_json); | 119 ui_data_json); |
119 | 120 |
120 shill_dict->SetStringWithoutPathExpansion(shill::kProfileProperty, | 121 shill_dict->SetStringWithoutPathExpansion(shill::kProfileProperty, |
121 profile->path); | 122 profile->path); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 const PrefService* local_state_prefs, | 338 const PrefService* local_state_prefs, |
338 const NetworkState& network) { | 339 const NetworkState& network) { |
339 ::onc::ONCSource ignored_onc_source; | 340 ::onc::ONCSource ignored_onc_source; |
340 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( | 341 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( |
341 profile_prefs, local_state_prefs, network, &ignored_onc_source); | 342 profile_prefs, local_state_prefs, network, &ignored_onc_source); |
342 return policy != NULL; | 343 return policy != NULL; |
343 } | 344 } |
344 | 345 |
345 } // namespace onc | 346 } // namespace onc |
346 } // namespace chromeos | 347 } // namespace chromeos |
OLD | NEW |