| 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 "chromeos/network/network_util.h" | 5 #include "chromeos/network/network_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_tokenizer.h" | 7 #include "base/strings/string_tokenizer.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chromeos/login/login_state.h" |
| 11 #include "chromeos/network/managed_network_configuration_handler.h" |
| 10 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
| 11 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 14 #include "chromeos/network/network_ui_data.h" |
| 12 #include "chromeos/network/onc/onc_signature.h" | 15 #include "chromeos/network/onc/onc_signature.h" |
| 13 #include "chromeos/network/onc/onc_translation_tables.h" | 16 #include "chromeos/network/onc/onc_translation_tables.h" |
| 14 #include "chromeos/network/onc/onc_translator.h" | 17 #include "chromeos/network/onc/onc_translator.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 19 |
| 17 namespace chromeos { | 20 namespace chromeos { |
| 18 | 21 |
| 19 WifiAccessPoint::WifiAccessPoint() | 22 WifiAccessPoint::WifiAccessPoint() |
| 20 : signal_strength(0), | 23 : signal_strength(0), |
| 21 signal_to_noise(0), | 24 signal_to_noise(0), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 142 } |
| 140 return true; | 143 return true; |
| 141 } | 144 } |
| 142 | 145 |
| 143 scoped_ptr<base::DictionaryValue> TranslateNetworkStateToONC( | 146 scoped_ptr<base::DictionaryValue> TranslateNetworkStateToONC( |
| 144 const NetworkState* network) { | 147 const NetworkState* network) { |
| 145 // Get the properties from the NetworkState. | 148 // Get the properties from the NetworkState. |
| 146 base::DictionaryValue shill_dictionary; | 149 base::DictionaryValue shill_dictionary; |
| 147 network->GetStateProperties(&shill_dictionary); | 150 network->GetStateProperties(&shill_dictionary); |
| 148 | 151 |
| 152 // NetworkState is always associated with the primary user profile, regardless |
| 153 // of what profile is associated with the page that calls this method. We do |
| 154 // not expose any sensitive properties in the resulting dictionary, it is |
| 155 // only used to show connection state and icons. |
| 156 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); |
| 157 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE; |
| 158 NetworkHandler::Get() |
| 159 ->managed_network_configuration_handler() |
| 160 ->FindPolicyByGUID(user_id_hash, network->guid(), &onc_source); |
| 161 |
| 149 scoped_ptr<base::DictionaryValue> onc_dictionary = | 162 scoped_ptr<base::DictionaryValue> onc_dictionary = |
| 150 TranslateShillServiceToONCPart(shill_dictionary, | 163 TranslateShillServiceToONCPart(shill_dictionary, onc_source, |
| 151 ::onc::ONC_SOURCE_UNKNOWN, | |
| 152 &onc::kNetworkWithStateSignature); | 164 &onc::kNetworkWithStateSignature); |
| 153 return onc_dictionary.Pass(); | 165 return onc_dictionary.Pass(); |
| 154 } | 166 } |
| 155 | 167 |
| 156 scoped_ptr<base::ListValue> TranslateNetworkListToONC( | 168 scoped_ptr<base::ListValue> TranslateNetworkListToONC( |
| 157 NetworkTypePattern pattern, | 169 NetworkTypePattern pattern, |
| 158 bool configured_only, | 170 bool configured_only, |
| 159 bool visible_only, | 171 bool visible_only, |
| 160 int limit, | 172 int limit, |
| 161 bool debugging_properties) { | 173 bool debugging_properties) { |
| 162 NetworkStateHandler::NetworkStateList network_states; | 174 NetworkStateHandler::NetworkStateList network_states; |
| 163 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( | 175 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( |
| 164 pattern, configured_only, visible_only, limit, &network_states); | 176 pattern, configured_only, visible_only, limit, &network_states); |
| 165 | 177 |
| 166 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue); | 178 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue); |
| 167 for (NetworkStateHandler::NetworkStateList::iterator it = | 179 for (const NetworkState* state : network_states) { |
| 168 network_states.begin(); | |
| 169 it != network_states.end(); | |
| 170 ++it) { | |
| 171 scoped_ptr<base::DictionaryValue> onc_dictionary = | 180 scoped_ptr<base::DictionaryValue> onc_dictionary = |
| 172 TranslateNetworkStateToONC(*it); | 181 TranslateNetworkStateToONC(state); |
| 173 | 182 |
| 174 if (debugging_properties) { | 183 if (debugging_properties) { |
| 175 onc_dictionary->SetBoolean("connectable", (*it)->connectable()); | 184 onc_dictionary->SetBoolean("connectable", state->connectable()); |
| 176 onc_dictionary->SetBoolean("visible", (*it)->visible()); | 185 onc_dictionary->SetBoolean("visible", state->visible()); |
| 177 onc_dictionary->SetString("profile_path", (*it)->profile_path()); | 186 onc_dictionary->SetString("profile_path", state->profile_path()); |
| 178 onc_dictionary->SetString("service_path", (*it)->path()); | 187 onc_dictionary->SetString("service_path", state->path()); |
| 179 } | 188 } |
| 180 | 189 |
| 181 network_properties_list->Append(onc_dictionary.release()); | 190 network_properties_list->Append(onc_dictionary.release()); |
| 182 } | 191 } |
| 183 return network_properties_list.Pass(); | 192 return network_properties_list.Pass(); |
| 184 } | 193 } |
| 185 | 194 |
| 186 std::string TranslateONCTypeToShill(const std::string& onc_type) { | 195 std::string TranslateONCTypeToShill(const std::string& onc_type) { |
| 187 if (onc_type == ::onc::network_type::kEthernet) | 196 if (onc_type == ::onc::network_type::kEthernet) |
| 188 return shill::kTypeEthernet; | 197 return shill::kTypeEthernet; |
| 189 std::string shill_type; | 198 std::string shill_type; |
| 190 onc::TranslateStringToShill(onc::kNetworkTypeTable, onc_type, &shill_type); | 199 onc::TranslateStringToShill(onc::kNetworkTypeTable, onc_type, &shill_type); |
| 191 return shill_type; | 200 return shill_type; |
| 192 } | 201 } |
| 193 | 202 |
| 194 std::string TranslateShillTypeToONC(const std::string& shill_type) { | 203 std::string TranslateShillTypeToONC(const std::string& shill_type) { |
| 195 if (shill_type == shill::kTypeEthernet) | 204 if (shill_type == shill::kTypeEthernet) |
| 196 return ::onc::network_type::kEthernet; | 205 return ::onc::network_type::kEthernet; |
| 197 std::string onc_type; | 206 std::string onc_type; |
| 198 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type); | 207 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type); |
| 199 return onc_type; | 208 return onc_type; |
| 200 } | 209 } |
| 201 | 210 |
| 202 } // namespace network_util | 211 } // namespace network_util |
| 203 } // namespace chromeos | 212 } // namespace chromeos |
| OLD | NEW |