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

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

Issue 23681010: Prevent that uninitialized ManagedState objects are returned from NetworkStateHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 3 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 | « no previous file | no next file » | 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_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 NET_LOG_USER("SetTechnologyEnabled", 161 NET_LOG_USER("SetTechnologyEnabled",
162 base::StringPrintf("%s:%d", technology.c_str(), enabled)); 162 base::StringPrintf("%s:%d", technology.c_str(), enabled));
163 shill_property_handler_->SetTechnologyEnabled( 163 shill_property_handler_->SetTechnologyEnabled(
164 technology, enabled, error_callback); 164 technology, enabled, error_callback);
165 // Signal Technology state changed -> ENABLING 165 // Signal Technology state changed -> ENABLING
166 NotifyManagerPropertyChanged(); 166 NotifyManagerPropertyChanged();
167 } 167 }
168 168
169 const DeviceState* NetworkStateHandler::GetDeviceState( 169 const DeviceState* NetworkStateHandler::GetDeviceState(
170 const std::string& device_path) const { 170 const std::string& device_path) const {
171 return GetModifiableDeviceState(device_path); 171 const DeviceState* device = GetModifiableDeviceState(device_path);
172 DCHECK(!device || device->update_received());
173 return device;
172 } 174 }
173 175
174 const DeviceState* NetworkStateHandler::GetDeviceStateByType( 176 const DeviceState* NetworkStateHandler::GetDeviceStateByType(
175 const std::string& type) const { 177 const std::string& type) const {
176 for (ManagedStateList::const_iterator iter = device_list_.begin(); 178 for (ManagedStateList::const_iterator iter = device_list_.begin();
177 iter != device_list_.end(); ++iter) { 179 iter != device_list_.end(); ++iter) {
178 ManagedState* device = *iter; 180 ManagedState* device = *iter;
181 if (!device->update_received())
182 continue;
179 if (ManagedStateMatchesType(device, type)) 183 if (ManagedStateMatchesType(device, type))
180 return device->AsDeviceState(); 184 return device->AsDeviceState();
181 } 185 }
182 return NULL; 186 return NULL;
183 } 187 }
184 188
185 bool NetworkStateHandler::GetScanningByType(const std::string& type) const { 189 bool NetworkStateHandler::GetScanningByType(const std::string& type) const {
186 for (ManagedStateList::const_iterator iter = device_list_.begin(); 190 for (ManagedStateList::const_iterator iter = device_list_.begin();
187 iter != device_list_.end(); ++iter) { 191 iter != device_list_.end(); ++iter) {
188 const DeviceState* device = (*iter)->AsDeviceState(); 192 const DeviceState* device = (*iter)->AsDeviceState();
189 DCHECK(device); 193 DCHECK(device);
194 if (!device->update_received())
195 continue;
190 if (ManagedStateMatchesType(device, type) && device->scanning()) 196 if (ManagedStateMatchesType(device, type) && device->scanning())
191 return true; 197 return true;
192 } 198 }
193 return false; 199 return false;
194 } 200 }
195 201
196 const NetworkState* NetworkStateHandler::GetNetworkState( 202 const NetworkState* NetworkStateHandler::GetNetworkState(
197 const std::string& service_path) const { 203 const std::string& service_path) const {
198 return GetModifiableNetworkState(service_path); 204 const NetworkState* network = GetModifiableNetworkState(service_path);
205 DCHECK(!network || network->update_received());
206 return network;
199 } 207 }
200 208
201 const NetworkState* NetworkStateHandler::DefaultNetwork() const { 209 const NetworkState* NetworkStateHandler::DefaultNetwork() const {
202 if (network_list_.empty()) 210 if (network_list_.empty())
203 return NULL; 211 return NULL;
204 const NetworkState* network = network_list_.front()->AsNetworkState(); 212 const NetworkState* network = network_list_.front()->AsNetworkState();
205 DCHECK(network); 213 DCHECK(network);
206 if (!network->IsConnectedState()) 214 if (!network->update_received() || !network->IsConnectedState())
207 return NULL; 215 return NULL;
208 return network; 216 return network;
209 } 217 }
210 218
211 const NetworkState* NetworkStateHandler::ConnectedNetworkByType( 219 const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
212 const std::string& type) const { 220 const std::string& type) const {
213 for (ManagedStateList::const_iterator iter = network_list_.begin(); 221 for (ManagedStateList::const_iterator iter = network_list_.begin();
214 iter != network_list_.end(); ++iter) { 222 iter != network_list_.end(); ++iter) {
215 const NetworkState* network = (*iter)->AsNetworkState(); 223 const NetworkState* network = (*iter)->AsNetworkState();
216 DCHECK(network); 224 DCHECK(network);
225 if (!network->update_received())
226 continue;
217 if (!network->IsConnectedState()) 227 if (!network->IsConnectedState())
218 break; // Connected networks are listed first. 228 break; // Connected networks are listed first.
219 if (ManagedStateMatchesType(network, type)) 229 if (ManagedStateMatchesType(network, type))
220 return network; 230 return network;
221 } 231 }
222 return NULL; 232 return NULL;
223 } 233 }
224 234
225 const NetworkState* NetworkStateHandler::ConnectingNetworkByType( 235 const NetworkState* NetworkStateHandler::ConnectingNetworkByType(
226 const std::string& type) const { 236 const std::string& type) const {
227 for (ManagedStateList::const_iterator iter = network_list_.begin(); 237 for (ManagedStateList::const_iterator iter = network_list_.begin();
228 iter != network_list_.end(); ++iter) { 238 iter != network_list_.end(); ++iter) {
229 const NetworkState* network = (*iter)->AsNetworkState(); 239 const NetworkState* network = (*iter)->AsNetworkState();
230 DCHECK(network); 240 DCHECK(network);
231 if (network->IsConnectedState()) 241 if (!network->update_received() || network->IsConnectedState())
232 continue; 242 continue;
233 if (!network->IsConnectingState()) 243 if (!network->IsConnectingState())
234 break; // Connected and connecting networks are listed first. 244 break; // Connected and connecting networks are listed first.
235 if (ManagedStateMatchesType(network, type)) 245 if (ManagedStateMatchesType(network, type))
236 return network; 246 return network;
237 } 247 }
238 return NULL; 248 return NULL;
239 } 249 }
240 250
241 const NetworkState* NetworkStateHandler::FirstNetworkByType( 251 const NetworkState* NetworkStateHandler::FirstNetworkByType(
242 const std::string& type) const { 252 const std::string& type) const {
243 for (ManagedStateList::const_iterator iter = network_list_.begin(); 253 for (ManagedStateList::const_iterator iter = network_list_.begin();
244 iter != network_list_.end(); ++iter) { 254 iter != network_list_.end(); ++iter) {
245 const NetworkState* network = (*iter)->AsNetworkState(); 255 const NetworkState* network = (*iter)->AsNetworkState();
246 DCHECK(network); 256 DCHECK(network);
257 if (!network->update_received())
258 continue;
247 if (ManagedStateMatchesType(network, type)) 259 if (ManagedStateMatchesType(network, type))
248 return network; 260 return network;
249 } 261 }
250 return NULL; 262 return NULL;
251 } 263 }
252 264
253 std::string NetworkStateHandler::HardwareAddressForType( 265 std::string NetworkStateHandler::HardwareAddressForType(
254 const std::string& type) const { 266 const std::string& type) const {
255 std::string result;
256 const NetworkState* network = ConnectedNetworkByType(type); 267 const NetworkState* network = ConnectedNetworkByType(type);
257 if (network) { 268 if (!network)
258 const DeviceState* device = GetDeviceState(network->device_path()); 269 return std::string();
259 if (device) 270 const DeviceState* device = GetDeviceState(network->device_path());
260 result = device->mac_address(); 271 if (!device)
261 } 272 return std::string();
273 std::string result = device->mac_address();
262 StringToUpperASCII(&result); 274 StringToUpperASCII(&result);
263 return result; 275 return result;
264 } 276 }
265 277
266 std::string NetworkStateHandler::FormattedHardwareAddressForType( 278 std::string NetworkStateHandler::FormattedHardwareAddressForType(
267 const std::string& type) const { 279 const std::string& type) const {
268 std::string address = HardwareAddressForType(type); 280 std::string address = HardwareAddressForType(type);
269 if (address.size() % 2 != 0) 281 if (address.size() % 2 != 0)
270 return address; 282 return address;
271 std::string result; 283 std::string result;
272 for (size_t i = 0; i < address.size(); ++i) { 284 for (size_t i = 0; i < address.size(); ++i) {
273 if ((i != 0) && (i % 2 == 0)) 285 if ((i != 0) && (i % 2 == 0))
274 result.push_back(':'); 286 result.push_back(':');
275 result.push_back(address[i]); 287 result.push_back(address[i]);
276 } 288 }
277 return result; 289 return result;
278 } 290 }
279 291
280 void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { 292 void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const {
281 GetNetworkListByType(kMatchTypeDefault, list); 293 GetNetworkListByType(kMatchTypeDefault, list);
282 } 294 }
283 295
284 void NetworkStateHandler::GetNetworkListByType(const std::string& type, 296 void NetworkStateHandler::GetNetworkListByType(const std::string& type,
285 NetworkStateList* list) const { 297 NetworkStateList* list) const {
286 DCHECK(list); 298 DCHECK(list);
287 list->clear(); 299 list->clear();
288 for (ManagedStateList::const_iterator iter = network_list_.begin(); 300 for (ManagedStateList::const_iterator iter = network_list_.begin();
289 iter != network_list_.end(); ++iter) { 301 iter != network_list_.end(); ++iter) {
290 if (!(*iter)->update_received())
291 continue;
292 const NetworkState* network = (*iter)->AsNetworkState(); 302 const NetworkState* network = (*iter)->AsNetworkState();
293 DCHECK(network); 303 DCHECK(network);
304 if (!network->update_received())
305 continue;
294 if (ManagedStateMatchesType(network, type)) 306 if (ManagedStateMatchesType(network, type))
295 list->push_back(network); 307 list->push_back(network);
296 } 308 }
297 } 309 }
298 310
299 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { 311 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
300 DCHECK(list); 312 DCHECK(list);
301 list->clear(); 313 list->clear();
302 for (ManagedStateList::const_iterator iter = device_list_.begin(); 314 for (ManagedStateList::const_iterator iter = device_list_.begin();
303 iter != device_list_.end(); ++iter) { 315 iter != device_list_.end(); ++iter) {
304 if (!(*iter)->update_received())
305 continue;
306 const DeviceState* device = (*iter)->AsDeviceState(); 316 const DeviceState* device = (*iter)->AsDeviceState();
307 DCHECK(device); 317 DCHECK(device);
318 if (!device->update_received())
319 continue;
308 list->push_back(device); 320 list->push_back(device);
309 } 321 }
310 } 322 }
311 323
312 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { 324 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const {
313 DCHECK(list); 325 DCHECK(list);
314 FavoriteStateList result; 326 FavoriteStateList result;
315 list->clear(); 327 list->clear();
316 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); 328 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
317 iter != favorite_list_.end(); ++iter) { 329 iter != favorite_list_.end(); ++iter) {
318 if (!(*iter)->update_received())
319 continue;
320 const FavoriteState* favorite = (*iter)->AsFavoriteState(); 330 const FavoriteState* favorite = (*iter)->AsFavoriteState();
321 DCHECK(favorite); 331 DCHECK(favorite);
332 if (!favorite->update_received())
333 continue;
322 if (favorite->is_favorite()) 334 if (favorite->is_favorite())
323 list->push_back(favorite); 335 list->push_back(favorite);
324 } 336 }
325 } 337 }
326 338
327 const FavoriteState* NetworkStateHandler::GetFavoriteState( 339 const FavoriteState* NetworkStateHandler::GetFavoriteState(
328 const std::string& service_path) const { 340 const std::string& service_path) const {
329 ManagedState* managed = 341 ManagedState* managed =
330 GetModifiableManagedState(&favorite_list_, service_path); 342 GetModifiableManagedState(&favorite_list_, service_path);
331 if (!managed) 343 if (!managed)
332 return NULL; 344 return NULL;
345 DCHECK(managed->update_received());
333 return managed->AsFavoriteState(); 346 return managed->AsFavoriteState();
334 } 347 }
335 348
336 void NetworkStateHandler::RequestScan() const { 349 void NetworkStateHandler::RequestScan() const {
337 NET_LOG_USER("RequestScan", ""); 350 NET_LOG_USER("RequestScan", "");
338 shill_property_handler_->RequestScan(); 351 shill_property_handler_->RequestScan();
339 } 352 }
340 353
341 void NetworkStateHandler::WaitForScan(const std::string& type, 354 void NetworkStateHandler::WaitForScan(const std::string& type,
342 const base::Closure& callback) { 355 const base::Closure& callback) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 754 }
742 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || 755 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual ||
743 type == kMatchTypeWireless) { 756 type == kMatchTypeWireless) {
744 NOTREACHED(); 757 NOTREACHED();
745 return flimflam::kTypeWifi; 758 return flimflam::kTypeWifi;
746 } 759 }
747 return type; 760 return type;
748 } 761 }
749 762
750 } // namespace chromeos 763 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698