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

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

Issue 267433005: Provide IPConfigs in networkingPrivate.GetProperties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
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/shill_property_handler.h" 5 #include "chromeos/network/shill_property_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/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // Only networks with a ProfilePath set are Favorites. 482 // Only networks with a ProfilePath set are Favorites.
483 std::string profile_path; 483 std::string profile_path;
484 properties.GetStringWithoutPathExpansion( 484 properties.GetStringWithoutPathExpansion(
485 shill::kProfileProperty, &profile_path); 485 shill::kProfileProperty, &profile_path);
486 if (!profile_path.empty()) { 486 if (!profile_path.empty()) {
487 listener_->UpdateManagedStateProperties( 487 listener_->UpdateManagedStateProperties(
488 ManagedState::MANAGED_TYPE_FAVORITE, path, properties); 488 ManagedState::MANAGED_TYPE_FAVORITE, path, properties);
489 } 489 }
490 } 490 }
491 listener_->UpdateManagedStateProperties(type, path, properties); 491 listener_->UpdateManagedStateProperties(type, path, properties);
492 // Request IPConfig parameters for networks. 492
493 if (type == ManagedState::MANAGED_TYPE_NETWORK && 493 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
494 properties.HasKey(shill::kIPConfigProperty)) { 494 // Request IPConfig properties.
495 std::string ip_config_path; 495 const base::Value* value;
496 if (properties.GetString(shill::kIPConfigProperty, &ip_config_path)) { 496 if (properties.GetWithoutPathExpansion(shill::kIPConfigProperty, &value))
497 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( 497 RequestIPConfig(type, path, *value);
498 dbus::ObjectPath(ip_config_path), 498 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
499 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, 499 // Clear and request IPConfig properties for each entry in IPConfigs.
500 AsWeakPtr(), path)); 500 const base::Value* value;
501 } 501 if (properties.GetWithoutPathExpansion(shill::kIPConfigsProperty, &value))
502 RequestIPConfigsList(type, path, *value);
502 } 503 }
503 504
504 // Notify the listener only when all updates for that type have completed. 505 // Notify the listener only when all updates for that type have completed.
505 if (pending_updates_[type].size() == 0) { 506 if (pending_updates_[type].size() == 0) {
506 listener_->ManagedStateListChanged(type); 507 listener_->ManagedStateListChanged(type);
507 // Notify that Favorites have changed when notifying for Networks if there 508 // Notify that Favorites have changed when notifying for Networks if there
508 // are no additional Favorite updates pending. 509 // are no additional Favorite updates pending.
509 if (type == ManagedState::MANAGED_TYPE_NETWORK && 510 if (type == ManagedState::MANAGED_TYPE_NETWORK &&
510 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) { 511 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) {
511 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE); 512 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE);
512 } 513 }
513 } 514 }
514 } 515 }
515 516
516 void ShillPropertyHandler::PropertyChangedCallback( 517 void ShillPropertyHandler::PropertyChangedCallback(
517 ManagedState::ManagedType type, 518 ManagedState::ManagedType type,
518 const std::string& path, 519 const std::string& path,
519 const std::string& key, 520 const std::string& key,
520 const base::Value& value) { 521 const base::Value& value) {
522 if (type == ManagedState::MANAGED_TYPE_NETWORK &&
523 key == shill::kIPConfigProperty) {
524 RequestIPConfig(type, path, value);
525 } else if (type == ManagedState::MANAGED_TYPE_DEVICE &&
526 key == shill::kIPConfigsProperty) {
527 RequestIPConfigsList(type, path, value);
528 }
529
521 if (type == ManagedState::MANAGED_TYPE_NETWORK) 530 if (type == ManagedState::MANAGED_TYPE_NETWORK)
522 NetworkServicePropertyChangedCallback(path, key, value); 531 listener_->UpdateNetworkServiceProperty(path, key, value);
523 else if (type == ManagedState::MANAGED_TYPE_DEVICE) 532 else if (type == ManagedState::MANAGED_TYPE_DEVICE)
524 NetworkDevicePropertyChangedCallback(path, key, value); 533 listener_->UpdateDeviceProperty(path, key, value);
525 else 534 else
526 NOTREACHED(); 535 NOTREACHED();
527 } 536 }
528 537
529 void ShillPropertyHandler::NetworkServicePropertyChangedCallback( 538 void ShillPropertyHandler::RequestIPConfig(
539 ManagedState::ManagedType type,
530 const std::string& path, 540 const std::string& path,
531 const std::string& key, 541 const base::Value& ip_config_path_value) {
532 const base::Value& value) { 542 std::string ip_config_path;
533 if (key == shill::kIPConfigProperty) { 543 if (!ip_config_path_value.GetAsString(&ip_config_path) ||
534 // Request the IPConfig for the network and update network properties 544 ip_config_path.empty()) {
535 // when the request completes. 545 NET_LOG_ERROR("Invalid IPConfig", path);
536 std::string ip_config_path; 546 return;
537 value.GetAsString(&ip_config_path); 547 }
538 DCHECK(!ip_config_path.empty()); 548 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties(
539 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( 549 dbus::ObjectPath(ip_config_path),
540 dbus::ObjectPath(ip_config_path), 550 base::Bind(&ShillPropertyHandler::GetIPConfigCallback,
541 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, 551 AsWeakPtr(), type, path, ip_config_path));
542 AsWeakPtr(), path)); 552 }
543 } else { 553
544 listener_->UpdateNetworkServiceProperty(path, key, value); 554 void ShillPropertyHandler::RequestIPConfigsList(
555 ManagedState::ManagedType type,
556 const std::string& path,
557 const base::Value& ip_config_list_value) {
558 const base::ListValue* ip_configs;
559 if (!ip_config_list_value.GetAsList(&ip_configs))
560 return;
561 for (base::ListValue::const_iterator iter = ip_configs->begin();
562 iter != ip_configs->end(); ++iter) {
563 RequestIPConfig(type, path, **iter);
545 } 564 }
546 } 565 }
547 566
548 void ShillPropertyHandler::GetIPConfigCallback( 567 void ShillPropertyHandler::GetIPConfigCallback(
549 const std::string& service_path, 568 ManagedState::ManagedType type,
569 const std::string& path,
570 const std::string& ip_config_path,
550 DBusMethodCallStatus call_status, 571 DBusMethodCallStatus call_status,
551 const base::DictionaryValue& properties) { 572 const base::DictionaryValue& properties) {
552 if (call_status != DBUS_METHOD_CALL_SUCCESS) { 573 if (call_status != DBUS_METHOD_CALL_SUCCESS) {
553 NET_LOG_ERROR("Failed to get IP Config properties", 574 NET_LOG_ERROR("Failed to get IP Config properties",
554 base::StringPrintf("%s: %d", 575 base::StringPrintf("%s: %d", path.c_str(), call_status));
555 service_path.c_str(), call_status));
556 return; 576 return;
557 } 577 }
558 UpdateIPConfigProperty(service_path, properties, shill::kAddressProperty); 578 NET_LOG_EVENT("IP Config properties received", path);
559 UpdateIPConfigProperty(service_path, properties, shill::kNameServersProperty); 579 listener_->UpdateIPConfigProperties(type, path, ip_config_path, properties);
560 UpdateIPConfigProperty(service_path, properties, shill::kPrefixlenProperty);
561 UpdateIPConfigProperty(service_path, properties, shill::kGatewayProperty);
562 UpdateIPConfigProperty(service_path, properties,
563 shill::kWebProxyAutoDiscoveryUrlProperty);
564 }
565
566 void ShillPropertyHandler::UpdateIPConfigProperty(
567 const std::string& service_path,
568 const base::DictionaryValue& properties,
569 const char* property) {
570 const base::Value* value;
571 if (!properties.GetWithoutPathExpansion(property, &value)) {
572 LOG(ERROR) << "Failed to get IPConfig property: " << property
573 << ", for: " << service_path;
574 return;
575 }
576 listener_->UpdateNetworkServiceProperty(
577 service_path, NetworkState::IPConfigProperty(property), *value);
578 }
579
580 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback(
581 const std::string& path,
582 const std::string& key,
583 const base::Value& value) {
584 listener_->UpdateDeviceProperty(path, key, value);
585 } 580 }
586 581
587 } // namespace internal 582 } // namespace internal
588 } // namespace chromeos 583 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/shill_property_handler.h ('k') | chromeos/network/shill_property_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698