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

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

Issue 280023003: Implement networkingPrivate.getNetworks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nonchromeos Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/network/network_util.h ('k') | chromeos/network/onc/onc_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chromeos/network/favorite_state.h"
9 #include "chromeos/network/network_state.h" 10 #include "chromeos/network/network_state.h"
10 #include "chromeos/network/network_state_handler.h" 11 #include "chromeos/network/network_state_handler.h"
11 #include "chromeos/network/onc/onc_signature.h" 12 #include "chromeos/network/onc/onc_signature.h"
12 #include "chromeos/network/onc/onc_translator.h" 13 #include "chromeos/network/onc/onc_translator.h"
13 #include "chromeos/network/shill_property_util.h" 14 #include "chromeos/network/shill_property_util.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
15 16
16 namespace chromeos { 17 namespace chromeos {
17 18
18 WifiAccessPoint::WifiAccessPoint() 19 WifiAccessPoint::WifiAccessPoint()
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 &scan_result.long_name); 121 &scan_result.long_name);
121 dict->GetStringWithoutPathExpansion(shill::kShortNameProperty, 122 dict->GetStringWithoutPathExpansion(shill::kShortNameProperty,
122 &scan_result.short_name); 123 &scan_result.short_name);
123 dict->GetStringWithoutPathExpansion(shill::kTechnologyProperty, 124 dict->GetStringWithoutPathExpansion(shill::kTechnologyProperty,
124 &scan_result.technology); 125 &scan_result.technology);
125 scan_results->push_back(scan_result); 126 scan_results->push_back(scan_result);
126 } 127 }
127 return true; 128 return true;
128 } 129 }
129 130
131 scoped_ptr<base::DictionaryValue> TranslateFavoriteStateToONC(
132 const FavoriteState* favorite) {
133 // Get the properties from the FavoriteState.
134 base::DictionaryValue shill_dictionary;
135 favorite->GetStateProperties(&shill_dictionary);
136
137 // If a corresponding NetworkState exists, merge its State properties.
138 const NetworkState* network_state =
139 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
140 favorite->path());
141 if (network_state) {
142 base::DictionaryValue shill_network_dictionary;
143 network_state->GetStateProperties(&shill_network_dictionary);
144 shill_dictionary.MergeDictionary(&shill_network_dictionary);
145 }
146
147 scoped_ptr<base::DictionaryValue> onc_dictionary =
148 TranslateShillServiceToONCPart(
149 shill_dictionary, &onc::kNetworkWithStateSignature);
150 return onc_dictionary.Pass();
151 }
152
130 scoped_ptr<base::ListValue> TranslateNetworkListToONC( 153 scoped_ptr<base::ListValue> TranslateNetworkListToONC(
131 NetworkTypePattern pattern) { 154 NetworkTypePattern pattern,
132 NetworkStateHandler::NetworkStateList network_states; 155 bool configured_only,
133 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 156 bool visible_only,
134 pattern, &network_states); 157 int limit) {
158 NetworkStateHandler::FavoriteStateList favorite_states;
159 NetworkHandler::Get()->network_state_handler()->GetFavoriteListByType(
160 pattern, configured_only, visible_only, limit, &favorite_states);
135 161
136 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue); 162 scoped_ptr<base::ListValue> network_properties_list(new base::ListValue);
137 for (NetworkStateHandler::NetworkStateList::iterator it = 163 for (NetworkStateHandler::FavoriteStateList::iterator it =
138 network_states.begin(); 164 favorite_states.begin();
139 it != network_states.end(); 165 it != favorite_states.end();
140 ++it) { 166 ++it) {
141 base::DictionaryValue shill_dictionary; 167 scoped_ptr<base::DictionaryValue> onc_dictionary =
142 (*it)->GetStateProperties(&shill_dictionary); 168 TranslateFavoriteStateToONC(*it);
143 169 network_properties_list->Append(onc_dictionary.release());
144 scoped_ptr<base::DictionaryValue> onc_network_part =
145 TranslateShillServiceToONCPart(
146 shill_dictionary, &onc::kNetworkWithStateSignature);
147 network_properties_list->Append(onc_network_part.release());
148 } 170 }
149 return network_properties_list.Pass(); 171 return network_properties_list.Pass();
150 } 172 }
151 173
152 } // namespace network_util 174 } // namespace network_util
153 } // namespace chromeos 175 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_util.h ('k') | chromeos/network/onc/onc_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698