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

Side by Side Diff: chromeos/network/network_util.cc

Issue 917053002: Add Source property to networkingPrivate.getState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 scan_results->push_back(scan_result); 141 scan_results->push_back(scan_result);
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);
151 // Set the Profile property so that Source gets translated.
152 shill_dictionary.SetStringWithoutPathExpansion(shill::kProfileProperty,
pneubeck (no reviews) 2015/02/17 18:00:49 why not adding this in NetworkState::GetStatePrope
stevenjb 2015/02/17 18:23:30 Done.
153 network->profile_path());
154
155 // NetworkState is always associated with the primary user profile, regardless
156 // of what profile is associated with the page that calls this method. We do
157 // not expose any sensitive properties in the resulting dictionary, it is
158 // only used to show connection state and icons.
159 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
160 ::onc::ONCSource onc_source;
pneubeck (no reviews) 2015/02/17 18:00:49 pls initialize explicitly to ONC_SOURCE_NONE to pr
stevenjb 2015/02/17 18:23:31 Done.
161 NetworkHandler::Get()
162 ->managed_network_configuration_handler()
163 ->FindPolicyByGUID(user_id_hash, network->guid(), &onc_source);
148 164
149 scoped_ptr<base::DictionaryValue> onc_dictionary = 165 scoped_ptr<base::DictionaryValue> onc_dictionary =
150 TranslateShillServiceToONCPart(shill_dictionary, 166 TranslateShillServiceToONCPart(shill_dictionary, onc_source,
151 ::onc::ONC_SOURCE_UNKNOWN,
152 &onc::kNetworkWithStateSignature); 167 &onc::kNetworkWithStateSignature);
153 return onc_dictionary.Pass(); 168 return onc_dictionary.Pass();
154 } 169 }
155 170
156 scoped_ptr<base::ListValue> TranslateNetworkListToONC( 171 scoped_ptr<base::ListValue> TranslateNetworkListToONC(
157 NetworkTypePattern pattern, 172 NetworkTypePattern pattern,
158 bool configured_only, 173 bool configured_only,
159 bool visible_only, 174 bool visible_only,
160 int limit, 175 int limit,
161 bool debugging_properties) { 176 bool debugging_properties) {
162 NetworkStateHandler::NetworkStateList network_states; 177 NetworkStateHandler::NetworkStateList network_states;
163 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 178 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
164 pattern, configured_only, visible_only, limit, &network_states); 179 pattern, configured_only, visible_only, limit, &network_states);
165 180
166 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue); 181 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue);
167 for (NetworkStateHandler::NetworkStateList::iterator it = 182 for (auto state : network_states) {
pneubeck (no reviews) 2015/02/17 18:00:49 optional nit: I usually prefer keeping the element
stevenjb 2015/02/17 18:23:30 Done.
168 network_states.begin();
169 it != network_states.end();
170 ++it) {
171 scoped_ptr<base::DictionaryValue> onc_dictionary = 183 scoped_ptr<base::DictionaryValue> onc_dictionary =
172 TranslateNetworkStateToONC(*it); 184 TranslateNetworkStateToONC(state);
173 185
174 if (debugging_properties) { 186 if (debugging_properties) {
175 onc_dictionary->SetBoolean("connectable", (*it)->connectable()); 187 onc_dictionary->SetBoolean("connectable", state->connectable());
176 onc_dictionary->SetBoolean("visible", (*it)->visible()); 188 onc_dictionary->SetBoolean("visible", state->visible());
177 onc_dictionary->SetString("profile_path", (*it)->profile_path()); 189 onc_dictionary->SetString("profile_path", state->profile_path());
178 onc_dictionary->SetString("service_path", (*it)->path()); 190 onc_dictionary->SetString("service_path", state->path());
179 } 191 }
180 192
181 network_properties_list->Append(onc_dictionary.release()); 193 network_properties_list->Append(onc_dictionary.release());
182 } 194 }
183 return network_properties_list.Pass(); 195 return network_properties_list.Pass();
184 } 196 }
185 197
186 std::string TranslateONCTypeToShill(const std::string& onc_type) { 198 std::string TranslateONCTypeToShill(const std::string& onc_type) {
187 if (onc_type == ::onc::network_type::kEthernet) 199 if (onc_type == ::onc::network_type::kEthernet)
188 return shill::kTypeEthernet; 200 return shill::kTypeEthernet;
189 std::string shill_type; 201 std::string shill_type;
190 onc::TranslateStringToShill(onc::kNetworkTypeTable, onc_type, &shill_type); 202 onc::TranslateStringToShill(onc::kNetworkTypeTable, onc_type, &shill_type);
191 return shill_type; 203 return shill_type;
192 } 204 }
193 205
194 std::string TranslateShillTypeToONC(const std::string& shill_type) { 206 std::string TranslateShillTypeToONC(const std::string& shill_type) {
195 if (shill_type == shill::kTypeEthernet) 207 if (shill_type == shill::kTypeEthernet)
196 return ::onc::network_type::kEthernet; 208 return ::onc::network_type::kEthernet;
197 std::string onc_type; 209 std::string onc_type;
198 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type); 210 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type);
199 return onc_type; 211 return onc_type;
200 } 212 }
201 213
202 } // namespace network_util 214 } // namespace network_util
203 } // namespace chromeos 215 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698