1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/network/shill_property_handler.h"
#include <stddef.h>
#include <memory>
#include <sstream>
#include "base/containers/contains.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "chromeos/ash/components/dbus/shill/shill_device_client.h"
#include "chromeos/ash/components/dbus/shill/shill_ipconfig_client.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "chromeos/ash/components/dbus/shill/shill_profile_client.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
#include "chromeos/ash/components/network/metrics/network_metrics_helper.h"
#include "chromeos/ash/components/network/network_event_log.h"
#include "chromeos/ash/components/network/network_state.h"
#include "dbus/object_path.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace {
// Limit the number of services or devices we observe. Since they are listed in
// priority order, it should be reasonable to ignore services past this.
const size_t kMaxObserved = 100;
bool CheckListValue(const std::string& key, const base::Value& value) {
if (!value.is_list()) {
NET_LOG(ERROR) << "Error parsing key as list: " << key;
return false;
}
return true;
}
} // namespace
namespace ash::internal {
// Class to manage Shill service property changed observers. Observers are
// added on construction and removed on destruction. Runs the handler when
// OnPropertyChanged is called.
class ShillPropertyObserver : public ShillPropertyChangedObserver {
public:
using Handler = base::RepeatingCallback<void(ManagedState::ManagedType type,
const std::string& service,
const std::string& name,
const base::Value& value)>;
ShillPropertyObserver(ManagedState::ManagedType type,
const std::string& path,
const Handler& handler)
: type_(type), path_(path), handler_(handler) {
switch (type_) {
case ManagedState::MANAGED_TYPE_NETWORK:
DVLOG(2) << "ShillPropertyObserver: Network: " << path;
ShillServiceClient::Get()->AddPropertyChangedObserver(
dbus::ObjectPath(path_), this);
break;
case ManagedState::MANAGED_TYPE_DEVICE:
DVLOG(2) << "ShillPropertyObserver: Device: " << path;
ShillDeviceClient::Get()->AddPropertyChangedObserver(
dbus::ObjectPath(path_), this);
break;
}
}
ShillPropertyObserver(const ShillPropertyObserver&) = delete;
ShillPropertyObserver& operator=(const ShillPropertyObserver&) = delete;
~ShillPropertyObserver() override {
switch (type_) {
case ManagedState::MANAGED_TYPE_NETWORK:
ShillServiceClient::Get()->RemovePropertyChangedObserver(
dbus::ObjectPath(path_), this);
break;
case ManagedState::MANAGED_TYPE_DEVICE:
ShillDeviceClient::Get()->RemovePropertyChangedObserver(
dbus::ObjectPath(path_), this);
break;
}
}
// ShillPropertyChangedObserver overrides.
void OnPropertyChanged(const std::string& key,
const base::Value& value) override {
handler_.Run(type_, path_, key, value);
}
private:
ManagedState::ManagedType type_;
std::string path_;
Handler handler_;
};
//------------------------------------------------------------------------------
// ShillPropertyHandler
ShillPropertyHandler::ShillPropertyHandler(Listener* listener)
: listener_(listener), shill_manager_(ShillManagerClient::Get()) {}
ShillPropertyHandler::~ShillPropertyHandler() {
// Delete network service observers.
CHECK(shill_manager_ == ShillManagerClient::Get());
shill_manager_->RemovePropertyChangedObserver(this);
}
void ShillPropertyHandler::Init() {
UpdateManagerProperties();
shill_manager_->AddPropertyChangedObserver(this);
}
void ShillPropertyHandler::UpdateManagerProperties() {
NET_LOG(EVENT) << "UpdateManagerProperties";
shill_manager_->GetProperties(
base::BindOnce(&ShillPropertyHandler::ManagerPropertiesCallback,
weak_ptr_factory_.GetWeakPtr()));
}
bool ShillPropertyHandler::IsTechnologyAvailable(
const std::string& technology) const {
return available_technologies_.count(technology) != 0;
}
bool ShillPropertyHandler::IsTechnologyEnabled(
const std::string& technology) const {
return enabled_technologies_.count(technology) != 0;
}
bool ShillPropertyHandler::IsTechnologyEnabling(
const std::string& technology) const {
return enabling_technologies_.count(technology) != 0;
}
bool ShillPropertyHandler::IsTechnologyDisabling(
const std::string& technology) const {
return disabling_technologies_.count(technology) != 0;
}
bool ShillPropertyHandler::IsTechnologyProhibited(
const std::string& technology) const {
return prohibited_technologies_.count(technology) != 0;
}
bool ShillPropertyHandler::IsTechnologyUninitialized(
const std::string& technology) const {
return uninitialized_technologies_.count(technology) != 0;
}
void ShillPropertyHandler::SetTechnologyEnabled(
const std::string& technology,
bool enabled,
network_handler::ErrorCallback error_callback,
base::OnceClosure success_callback) {
if (enabled) {
if (base::Contains(prohibited_technologies_, technology)) {
NET_LOG(ERROR) << "Attempt to enable prohibited network technology: "
<< technology;
network_handler::RunErrorCallback(std::move(error_callback),
"prohibited_technologies");
NetworkMetricsHelper::LogEnableTechnologyResult(technology,
/*success=*/false);
return;
}
enabling_technologies_.insert(technology);
disabling_technologies_.erase(technology);
shill_manager_->EnableTechnology(
technology,
base::BindOnce(&ShillPropertyHandler::EnableTechnologySuccess,
weak_ptr_factory_.GetWeakPtr(), technology,
std::move(success_callback)),
base::BindOnce(&ShillPropertyHandler::EnableTechnologyFailed,
weak_ptr_factory_.GetWeakPtr(), technology,
std::move(error_callback)));
} else {
// Clear locally from enabling lists and add to the disabling list.
enabling_technologies_.erase(technology);
disabling_technologies_.insert(technology);
shill_manager_->DisableTechnology(
technology,
base::BindOnce(&ShillPropertyHandler::DisableTechnologySuccess,
weak_ptr_factory_.GetWeakPtr(), technology,
std::move(success_callback)),
base::BindOnce(&ShillPropertyHandler::DisableTechnologyFailed,
weak_ptr_factory_.GetWeakPtr(), technology,
std::move(error_callback)));
}
}
void ShillPropertyHandler::SetProhibitedTechnologies(
const std::vector<std::string>& prohibited_technologies) {
prohibited_technologies_.clear();
prohibited_technologies_.insert(prohibited_technologies.begin(),
prohibited_technologies.end());
// Remove technologies from the other lists.
// And manually disable them.
for (const auto& technology : prohibited_technologies) {
enabling_technologies_.erase(technology);
enabled_technologies_.erase(technology);
shill_manager_->DisableTechnology(
technology, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"DisableTechnology Failed", technology,
network_handler::ErrorCallback()));
}
// Send updated prohibited technology list to shill.
const std::string prohibited_list =
base::JoinString(prohibited_technologies, ",");
base::Value value(prohibited_list);
shill_manager_->SetProperty(
"ProhibitedTechnologies", value, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"SetTechnologiesProhibited Failed", prohibited_list,
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::SetWakeOnLanEnabled(bool enabled) {
base::Value value(enabled);
shill_manager_->SetProperty(
shill::kWakeOnLanEnabledProperty, value, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"SetWakeOnLanEnabled Failed", "Manager",
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::SetHostname(const std::string& hostname) {
base::Value value(hostname);
shill_manager_->SetProperty(
shill::kDhcpPropertyHostnameProperty, value, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"SetHostname Failed", "Manager",
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::SetNetworkThrottlingStatus(
bool throttling_enabled,
uint32_t upload_rate_kbits,
uint32_t download_rate_kbits) {
shill_manager_->SetNetworkThrottlingStatus(
ShillManagerClient::NetworkThrottlingStatus{
throttling_enabled,
upload_rate_kbits,
download_rate_kbits,
},
base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"SetNetworkThrottlingStatus failed", "Manager",
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::SetFastTransitionStatus(bool enabled) {
base::Value value(enabled);
shill_manager_->SetProperty(
shill::kWifiGlobalFTEnabledProperty, value, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"SetFastTransitionStatus failed", "Manager",
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::RequestScanByType(const std::string& type) const {
shill_manager_->RequestScan(
type, base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"RequestScan Failed", type,
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type,
const std::string& path) {
if (base::Contains(pending_updates_[type], path)) {
return; // Update already requested.
}
NET_LOG(DEBUG) << "Request Properties for: " << NetworkPathId(path);
pending_updates_[type].insert(path);
switch (type) {
case ManagedState::MANAGED_TYPE_NETWORK:
ShillServiceClient::Get()->GetProperties(
dbus::ObjectPath(path),
base::BindOnce(&ShillPropertyHandler::GetPropertiesCallback,
weak_ptr_factory_.GetWeakPtr(), type, path));
return;
case ManagedState::MANAGED_TYPE_DEVICE:
ShillDeviceClient::Get()->GetProperties(
dbus::ObjectPath(path),
base::BindOnce(&ShillPropertyHandler::GetPropertiesCallback,
weak_ptr_factory_.GetWeakPtr(), type, path));
return;
}
NOTREACHED();
}
void ShillPropertyHandler::RequestPortalDetection(
const std::string& service_path) {
ShillServiceClient::Get()->RequestPortalDetection(
dbus::ObjectPath(service_path),
base::BindOnce(
[](const std::string& service_path, bool success) {
if (!success) {
NET_LOG(ERROR) << "Shill RecheckPortal call failed for: "
<< NetworkPathId(service_path);
}
},
service_path));
}
void ShillPropertyHandler::RequestTrafficCounters(
const std::string& service_path,
chromeos::DBusMethodCallback<base::Value> callback) {
ShillServiceClient::Get()->RequestTrafficCounters(
dbus::ObjectPath(service_path),
base::BindOnce(
[](const std::string& service_path,
chromeos::DBusMethodCallback<base::Value> callback,
std::optional<base::Value> traffic_counters) {
if (!traffic_counters) {
NET_LOG(ERROR) << "Error requesting traffic counters for: "
<< NetworkPathId(service_path);
} else {
NET_LOG(EVENT) << "Received traffic counters for "
<< NetworkPathId(service_path);
}
std::move(callback).Run(std::move(traffic_counters));
},
service_path, std::move(callback)));
}
void ShillPropertyHandler::ResetTrafficCounters(
const std::string& service_path) {
NET_LOG(EVENT) << "ResetTrafficCounters: Success";
ShillServiceClient::Get()->ResetTrafficCounters(
dbus::ObjectPath(service_path), base::DoNothing(),
base::BindOnce(&network_handler::ShillErrorCallbackFunction,
"ResetTrafficCounters Failed", service_path,
network_handler::ErrorCallback()));
}
void ShillPropertyHandler::OnPropertyChanged(const std::string& key,
const base::Value& value) {
ManagerPropertyChanged(key, value);
CheckPendingStateListUpdates(key);
}
//------------------------------------------------------------------------------
// Private methods
void ShillPropertyHandler::ManagerPropertiesCallback(
std::optional<base::Value::Dict> properties) {
if (!properties) {
NET_LOG(ERROR) << "ManagerPropertiesCallback Failed";
return;
}
NET_LOG(EVENT) << "ManagerPropertiesCallback: Success";
for (const auto item : *properties) {
ManagerPropertyChanged(item.first, item.second);
}
CheckPendingStateListUpdates("");
}
void ShillPropertyHandler::CheckPendingStateListUpdates(
const std::string& key) {
// Once there are no pending updates, signal the state list changed
// callbacks.
if ((key.empty() || key == shill::kServiceCompleteListProperty) &&
pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) {
listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK);
}
if ((key.empty() || key == shill::kDevicesProperty) &&
pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) {
listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE);
}
}
void ShillPropertyHandler::ManagerPropertyChanged(const std::string& key,
const base::Value& value) {
if (key == shill::kDefaultServiceProperty) {
std::string service_path;
if (value.is_string()) {
service_path = value.GetString();
}
NET_LOG(EVENT) << "Manager.DefaultService = "
<< NetworkPathId(service_path);
listener_->DefaultNetworkServiceChanged(service_path);
return;
}
NET_LOG(DEBUG) << "ManagerPropertyChanged: " << key << " = " << value;
if (key == shill::kServiceCompleteListProperty) {
if (CheckListValue(key, value)) {
listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK,
value.GetList());
UpdateProperties(ManagedState::MANAGED_TYPE_NETWORK, value);
UpdateObserved(ManagedState::MANAGED_TYPE_NETWORK, value);
}
} else if (key == shill::kDevicesProperty) {
if (CheckListValue(key, value)) {
listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE,
value.GetList());
UpdateProperties(ManagedState::MANAGED_TYPE_DEVICE, value);
UpdateObserved(ManagedState::MANAGED_TYPE_DEVICE, value);
}
} else if (key == shill::kAvailableTechnologiesProperty) {
if (CheckListValue(key, value)) {
UpdateAvailableTechnologies(value);
}
} else if (key == shill::kEnabledTechnologiesProperty) {
if (CheckListValue(key, value)) {
UpdateEnabledTechnologies(value);
}
} else if (key == shill::kUninitializedTechnologiesProperty) {
if (CheckListValue(key, value)) {
UpdateUninitializedTechnologies(value);
}
} else if (key == shill::kProhibitedTechnologiesProperty) {
if (value.is_string()) {
UpdateProhibitedTechnologies(value.GetString());
}
} else if (key == shill::kProfilesProperty) {
if (value.is_list()) {
listener_->ProfileListChanged(value.GetList());
}
} else if (key == shill::kCheckPortalListProperty) {
if (value.is_string()) {
listener_->CheckPortalListChanged(value.GetString());
}
} else if (key == shill::kDhcpPropertyHostnameProperty) {
if (value.is_string()) {
listener_->HostnameChanged(value.GetString());
}
} else {
VLOG(2) << "Ignored Manager Property: " << key;
}
}
void ShillPropertyHandler::UpdateProperties(ManagedState::ManagedType type,
const base::Value& entries) {
std::set<std::string>& requested_updates = requested_updates_[type];
std::set<std::string> new_requested_updates;
NET_LOG(DEBUG) << "UpdateProperties: " << ManagedState::TypeToString(type)
<< ": " << entries.GetList().size();
for (const auto& entry : entries.GetList()) {
const std::string* path = entry.GetIfString();
if (!path || (*path).empty())
continue;
// We add a special case for devices here to work around an issue in shill
// that prevents it from sending property changed signals for cellular
// devices (see crbug.com/321854).
if (type == ManagedState::MANAGED_TYPE_DEVICE ||
!base::Contains(requested_updates, *path)) {
RequestProperties(type, *path);
}
new_requested_updates.insert(*path);
}
requested_updates.swap(new_requested_updates);
}
void ShillPropertyHandler::UpdateObserved(ManagedState::ManagedType type,
const base::Value& entries) {
ShillPropertyObserverMap& observer_map =
(type == ManagedState::MANAGED_TYPE_NETWORK) ? observed_networks_
: observed_devices_;
ShillPropertyObserverMap new_observed;
for (const auto& entry : entries.GetList()) {
const std::string* path = entry.GetIfString();
if (!path || (*path).empty())
continue;
auto iter = observer_map.find(*path);
std::unique_ptr<ShillPropertyObserver> observer;
if (iter != observer_map.end()) {
observer = std::move(iter->second);
} else {
// Create an observer for future updates.
observer = std::make_unique<ShillPropertyObserver>(
type, *path,
base::BindRepeating(&ShillPropertyHandler::PropertyChangedCallback,
weak_ptr_factory_.GetWeakPtr()));
}
auto result =
new_observed.insert(std::make_pair(*path, std::move(observer)));
if (!result.second) {
NET_LOG(ERROR) << *path << " is duplicated in the list.";
}
observer_map.erase(*path);
// Limit the number of observed services.
if (new_observed.size() >= kMaxObserved)
break;
}
observer_map.swap(new_observed);
}
void ShillPropertyHandler::UpdateAvailableTechnologies(
const base::Value& technologies) {
NET_LOG(EVENT) << "AvailableTechnologies:" << technologies;
std::set<std::string> new_available_technologies;
for (const base::Value& technology : technologies.GetList())
new_available_technologies.insert(technology.GetString());
if (new_available_technologies == available_technologies_)
return;
available_technologies_.swap(new_available_technologies);
// If any entries in |enabling_technologies_| are no longer available,
// remove them from the enabling list.
for (auto iter = enabling_technologies_.begin();
iter != enabling_technologies_.end();) {
if (!available_technologies_.count(*iter))
iter = enabling_technologies_.erase(iter);
else
++iter;
}
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::UpdateEnabledTechnologies(
const base::Value& technologies) {
NET_LOG(EVENT) << "EnabledTechnologies:" << technologies;
std::set<std::string> new_enabled_technologies;
for (const base::Value& technology : technologies.GetList())
new_enabled_technologies.insert(technology.GetString());
if (new_enabled_technologies == enabled_technologies_)
return;
enabled_technologies_.swap(new_enabled_technologies);
// If any entries in |disabling_technologies_| are disabled, remove them
// from the disabling list.
for (auto it = disabling_technologies_.begin();
it != disabling_technologies_.end();) {
base::Value technology_value(*it);
if (!base::Contains(technologies.GetList(), technology_value))
it = disabling_technologies_.erase(it);
else
++it;
}
// If any entries in |enabling_technologies_| are enabled, remove them from
// the enabling list.
for (auto iter = enabling_technologies_.begin();
iter != enabling_technologies_.end();) {
if (enabled_technologies_.count(*iter))
iter = enabling_technologies_.erase(iter);
else
++iter;
}
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::UpdateUninitializedTechnologies(
const base::Value& technologies) {
NET_LOG(EVENT) << "UninitializedTechnologies:" << technologies;
std::set<std::string> new_uninitialized_technologies;
for (const base::Value& technology : technologies.GetList())
new_uninitialized_technologies.insert(technology.GetString());
if (new_uninitialized_technologies == uninitialized_technologies_)
return;
uninitialized_technologies_.swap(new_uninitialized_technologies);
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::UpdateProhibitedTechnologies(
const std::string& technologies) {
std::vector<std::string> prohibited_list = base::SplitString(
technologies, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::set<std::string> new_prohibited_technologies(prohibited_list.begin(),
prohibited_list.end());
if (new_prohibited_technologies == prohibited_technologies_)
return;
prohibited_technologies_.swap(new_prohibited_technologies);
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::EnableTechnologySuccess(
const std::string& technology,
base::OnceClosure success_callback) {
NetworkMetricsHelper::LogEnableTechnologyResult(technology, /*success=*/true);
std::move(success_callback).Run();
}
void ShillPropertyHandler::EnableTechnologyFailed(
const std::string& technology,
network_handler::ErrorCallback error_callback,
const std::string& dbus_error_name,
const std::string& dbus_error_message) {
NetworkMetricsHelper::LogEnableTechnologyResult(technology,
/*success=*/false,
dbus_error_name);
enabling_technologies_.erase(technology);
network_handler::ShillErrorCallbackFunction(
"EnableTechnology Failed", technology, std::move(error_callback),
dbus_error_name, dbus_error_message);
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::DisableTechnologySuccess(
const std::string& technology,
base::OnceClosure success_callback) {
NetworkMetricsHelper::LogDisableTechnologyResult(technology,
/*success=*/true);
std::move(success_callback).Run();
}
void ShillPropertyHandler::DisableTechnologyFailed(
const std::string& technology,
network_handler::ErrorCallback error_callback,
const std::string& dbus_error_name,
const std::string& dbus_error_message) {
NetworkMetricsHelper::LogDisableTechnologyResult(technology,
/*success=*/false,
dbus_error_name);
disabling_technologies_.erase(technology);
network_handler::ShillErrorCallbackFunction(
"DisableTechnology Failed", technology, std::move(error_callback),
dbus_error_name, dbus_error_message);
listener_->TechnologyListChanged();
}
void ShillPropertyHandler::GetPropertiesCallback(
ManagedState::ManagedType type,
const std::string& path,
std::optional<base::Value::Dict> properties) {
pending_updates_[type].erase(path);
if (!properties) {
// The shill service no longer exists. This can happen when a network
// has been removed.
return;
}
NET_LOG(DEBUG) << "GetProperties received for " << NetworkPathId(path);
listener_->UpdateManagedStateProperties(type, path, *properties);
if (type == ManagedState::MANAGED_TYPE_NETWORK) {
// Request IPConfig properties.
const base::Value* value = properties->Find(shill::kIPConfigProperty);
if (value)
RequestIPConfig(type, path, *value);
} else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
// Clear and request IPConfig properties for each entry in IPConfigs.
const base::Value* value = properties->Find(shill::kIPConfigsProperty);
if (value)
RequestIPConfigsList(type, path, *value);
}
// Notify the listener only when all updates for that type have completed.
if (pending_updates_[type].size() == 0)
listener_->ManagedStateListChanged(type);
}
void ShillPropertyHandler::PropertyChangedCallback(
ManagedState::ManagedType type,
const std::string& path,
const std::string& key,
const base::Value& value) {
if (type == ManagedState::MANAGED_TYPE_NETWORK &&
key == shill::kIPConfigProperty) {
RequestIPConfig(type, path, value);
} else if (type == ManagedState::MANAGED_TYPE_DEVICE &&
key == shill::kIPConfigsProperty) {
RequestIPConfigsList(type, path, value);
}
switch (type) {
case ManagedState::MANAGED_TYPE_NETWORK:
listener_->UpdateNetworkServiceProperty(path, key, value);
return;
case ManagedState::MANAGED_TYPE_DEVICE:
listener_->UpdateDeviceProperty(path, key, value);
return;
}
NOTREACHED();
}
void ShillPropertyHandler::RequestIPConfig(
ManagedState::ManagedType type,
const std::string& path,
const base::Value& ip_config_path_value) {
const std::string* ip_config_path = ip_config_path_value.GetIfString();
if (!ip_config_path || (*ip_config_path).empty()) {
NET_LOG(ERROR) << "Invalid IPConfig: " << path;
return;
}
ShillIPConfigClient::Get()->GetProperties(
dbus::ObjectPath(*ip_config_path),
base::BindOnce(&ShillPropertyHandler::GetIPConfigCallback,
weak_ptr_factory_.GetWeakPtr(), type, path,
*ip_config_path));
}
void ShillPropertyHandler::RequestIPConfigsList(
ManagedState::ManagedType type,
const std::string& path,
const base::Value& ip_config_list_value) {
if (!ip_config_list_value.is_list())
return;
for (const auto& entry : ip_config_list_value.GetList()) {
RequestIPConfig(type, path, entry);
}
}
void ShillPropertyHandler::GetIPConfigCallback(
ManagedState::ManagedType type,
const std::string& path,
const std::string& ip_config_path,
std::optional<base::Value::Dict> properties) {
if (!properties) {
// IP Config properties not available. Shill will emit a property change
// when they are.
NET_LOG(EVENT) << "Failed to get IP Config properties: " << ip_config_path
<< ", For: " << NetworkPathId(path);
return;
}
NET_LOG(EVENT) << "IP Config properties received: " << NetworkPathId(path);
listener_->UpdateIPConfigProperties(type, path, ip_config_path,
std::move(*properties));
}
} // namespace ash::internal
|