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

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

Issue 13004024: Add ConnectToBestServices call when Certs are loaded (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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_state_handler.h ('k') | chromeos/network/shill_property_handler.h » ('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_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include "base/bind.h"
7 #include "base/format_macros.h" 8 #include "base/format_macros.h"
8 #include "base/stl_util.h" 9 #include "base/stl_util.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chromeos/network/device_state.h" 13 #include "chromeos/network/device_state.h"
13 #include "chromeos/network/managed_state.h" 14 #include "chromeos/network/managed_state.h"
14 #include "chromeos/network/network_event_log.h" 15 #include "chromeos/network/network_event_log.h"
15 #include "chromeos/network/network_state.h" 16 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_state_handler_observer.h" 17 #include "chromeos/network/network_state_handler_observer.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 list->clear(); 291 list->clear();
291 for (ManagedStateList::const_iterator iter = network_list_.begin(); 292 for (ManagedStateList::const_iterator iter = network_list_.begin();
292 iter != network_list_.end(); ++iter) { 293 iter != network_list_.end(); ++iter) {
293 const NetworkState* network = (*iter)->AsNetworkState(); 294 const NetworkState* network = (*iter)->AsNetworkState();
294 DCHECK(network); 295 DCHECK(network);
295 list->push_back(network); 296 list->push_back(network);
296 } 297 }
297 } 298 }
298 299
299 void NetworkStateHandler::RequestScan() const { 300 void NetworkStateHandler::RequestScan() const {
301 network_event_log::AddEntry(kLogModule, "RequestScan", "");
300 shill_property_handler_->RequestScan(); 302 shill_property_handler_->RequestScan();
301 } 303 }
302 304
305 void NetworkStateHandler::WaitForScan(const std::string& type,
306 const base::Closure& callback) {
307 scan_complete_callbacks_[type].push_back(callback);
308 if (!GetScanningByType(type))
309 RequestScan();
310 }
311
312 void NetworkStateHandler::ConnectToBestWifiNetwork() {
313 network_event_log::AddEntry(kLogModule, "ConnectToBestWifiNetwork", "");
314 WaitForScan(flimflam::kTypeWifi,
315 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices,
316 shill_property_handler_->AsWeakPtr()));
317 }
318
303 void NetworkStateHandler::SetConnectingNetwork( 319 void NetworkStateHandler::SetConnectingNetwork(
304 const std::string& service_path) { 320 const std::string& service_path) {
305 connecting_network_ = service_path; 321 connecting_network_ = service_path;
306 network_event_log::AddEntry( 322 network_event_log::AddEntry(
307 kLogModule, "SetConnectingNetwork", service_path); 323 kLogModule, "SetConnectingNetwork", service_path);
308 } 324 }
309 325
310 void NetworkStateHandler::GetNetworkStatePropertiesForTest( 326 void NetworkStateHandler::GetNetworkStatePropertiesForTest(
311 base::DictionaryValue* dictionary) const { 327 base::DictionaryValue* dictionary) const {
312 for (ManagedStateList::const_iterator iter = network_list_.begin(); 328 for (ManagedStateList::const_iterator iter = network_list_.begin();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 prev_connection_state = managed->AsNetworkState()->connection_state(); 395 prev_connection_state = managed->AsNetworkState()->connection_state();
380 for (base::DictionaryValue::Iterator iter(properties); 396 for (base::DictionaryValue::Iterator iter(properties);
381 iter.HasNext(); iter.Advance()) { 397 iter.HasNext(); iter.Advance()) {
382 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 398 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
383 if (managed->PropertyChanged(iter.key(), iter.value())) 399 if (managed->PropertyChanged(iter.key(), iter.value()))
384 network_property_updated = true; 400 network_property_updated = true;
385 } else { 401 } else {
386 managed->PropertyChanged(iter.key(), iter.value()); 402 managed->PropertyChanged(iter.key(), iter.value());
387 } 403 }
388 } 404 }
405 network_event_log::AddEntry(
406 kLogModule, "PropertiesReceived",
407 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str()));
389 // Notify observers. 408 // Notify observers.
390 if (network_property_updated) { 409 if (network_property_updated) {
391 NetworkState* network = managed->AsNetworkState(); 410 NetworkState* network = managed->AsNetworkState();
392 DCHECK(network); 411 DCHECK(network);
393 // Signal connection state changed after all properties have been updated. 412 // Signal connection state changed after all properties have been updated.
394 if (network->connection_state() != prev_connection_state) 413 if (network->connection_state() != prev_connection_state)
395 OnNetworkConnectionStateChanged(network); 414 OnNetworkConnectionStateChanged(network);
396 NetworkPropertiesUpdated(network); 415 NetworkPropertiesUpdated(network);
397 } 416 }
398 network_event_log::AddEntry(
399 kLogModule, "PropertiesReceived",
400 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str()));
401 } 417 }
402 418
403 void NetworkStateHandler::UpdateNetworkServiceProperty( 419 void NetworkStateHandler::UpdateNetworkServiceProperty(
404 const std::string& service_path, 420 const std::string& service_path,
405 const std::string& key, 421 const std::string& key,
406 const base::Value& value) { 422 const base::Value& value) {
407 NetworkState* network = GetModifiableNetworkState(service_path); 423 NetworkState* network = GetModifiableNetworkState(service_path);
408 if (!network) 424 if (!network)
409 return; 425 return;
410 std::string prev_connection_state = network->connection_state(); 426 std::string prev_connection_state = network->connection_state();
411 if (!network->PropertyChanged(key, value)) 427 if (!network->PropertyChanged(key, value))
412 return; 428 return;
413 if (network->connection_state() != prev_connection_state)
414 OnNetworkConnectionStateChanged(network);
415
416 NetworkPropertiesUpdated(network);
417 429
418 std::string detail = network->name() + "." + key; 430 std::string detail = network->name() + "." + key;
419 std::string vstr = ValueAsString(value); 431 std::string vstr = ValueAsString(value);
420 if (!vstr.empty()) 432 if (!vstr.empty())
421 detail += " = " + vstr; 433 detail += " = " + vstr;
422 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); 434 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail);
435
436 if (network->connection_state() != prev_connection_state)
437 OnNetworkConnectionStateChanged(network);
438 NetworkPropertiesUpdated(network);
423 } 439 }
424 440
425 void NetworkStateHandler::UpdateNetworkServiceIPAddress( 441 void NetworkStateHandler::UpdateNetworkServiceIPAddress(
426 const std::string& service_path, 442 const std::string& service_path,
427 const std::string& ip_address) { 443 const std::string& ip_address) {
428 NetworkState* network = GetModifiableNetworkState(service_path); 444 NetworkState* network = GetModifiableNetworkState(service_path);
429 if (!network) 445 if (!network)
430 return; 446 return;
431 std::string detail = network->name() + ".IPAddress = " + ip_address; 447 std::string detail = network->name() + ".IPAddress = " + ip_address;
432 network_event_log::AddEntry(kLogModule, "NetworkIPChanged", detail); 448 network_event_log::AddEntry(kLogModule, "NetworkIPChanged", detail);
433 network->set_ip_address(ip_address); 449 network->set_ip_address(ip_address);
434 NetworkPropertiesUpdated(network); 450 NetworkPropertiesUpdated(network);
435 } 451 }
436 452
437 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 453 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
438 const std::string& key, 454 const std::string& key,
439 const base::Value& value) { 455 const base::Value& value) {
440 DeviceState* device = GetModifiableDeviceState(device_path); 456 DeviceState* device = GetModifiableDeviceState(device_path);
441 if (!device) 457 if (!device)
442 return; 458 return;
443 if (!device->PropertyChanged(key, value)) 459 if (!device->PropertyChanged(key, value))
444 return; 460 return;
445 461
446 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
447 DeviceListChanged());
448
449 std::string detail = device->name() + "." + key; 462 std::string detail = device->name() + "." + key;
450 std::string vstr = ValueAsString(value); 463 std::string vstr = ValueAsString(value);
451 if (!vstr.empty()) 464 if (!vstr.empty())
452 detail += " = " + vstr; 465 detail += " = " + vstr;
453 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); 466 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail);
467
468 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
469 DeviceListChanged());
470
471 if (key == flimflam::kScanningProperty && device->scanning() == false)
472 ScanCompleted(device->type());
454 } 473 }
455 474
456 void NetworkStateHandler::ManagerPropertyChanged() { 475 void NetworkStateHandler::ManagerPropertyChanged() {
457 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 476 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
458 NetworkManagerChanged()); 477 NetworkManagerChanged());
459 } 478 }
460 479
461 void NetworkStateHandler::ManagedStateListChanged( 480 void NetworkStateHandler::ManagedStateListChanged(
462 ManagedState::ManagedType type) { 481 ManagedState::ManagedType type) {
463 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 482 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 !network->IsConnectingState() && 587 !network->IsConnectingState() &&
569 network->connection_state() != flimflam::kStateIdle) { 588 network->connection_state() != flimflam::kStateIdle) {
570 connecting_network_.clear(); 589 connecting_network_.clear();
571 network_event_log::AddEntry( 590 network_event_log::AddEntry(
572 kLogModule, "ClearConnectingNetwork", 591 kLogModule, "ClearConnectingNetwork",
573 base::StringPrintf("%s: %s", network->path().c_str(), 592 base::StringPrintf("%s: %s", network->path().c_str(),
574 network->connection_state().c_str())); 593 network->connection_state().c_str()));
575 } 594 }
576 } 595 }
577 596
597 void NetworkStateHandler::ScanCompleted(const std::string& type) {
598 size_t num_callbacks = scan_complete_callbacks_.count(type);
599 network_event_log::AddEntry(
600 kLogModule, "ScanCompleted",
601 base::StringPrintf("%s: %"PRIuS, type.c_str(), num_callbacks));
602 if (num_callbacks == 0)
603 return;
604 ScanCallbackList& callback_list = scan_complete_callbacks_[type];
605 for (ScanCallbackList::iterator iter = callback_list.begin();
606 iter != callback_list.end(); ++iter) {
607 (*iter).Run();
608 }
609 scan_complete_callbacks_.erase(type);
610 }
611
578 } // namespace chromeos 612 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/shill_property_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698