| OLD | NEW |
| 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_configuration_handler.h" | 5 #include "chromeos/network/network_configuration_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const base::Closure& callback, | 88 const base::Closure& callback, |
| 89 const network_handler::ErrorCallback& error_callback) | 89 const network_handler::ErrorCallback& error_callback) |
| 90 : owner_(handler), | 90 : owner_(handler), |
| 91 service_path_(service_path), | 91 service_path_(service_path), |
| 92 guid_(guid), | 92 guid_(guid), |
| 93 source_(source), | 93 source_(source), |
| 94 callback_(callback), | 94 callback_(callback), |
| 95 error_callback_(error_callback), | 95 error_callback_(error_callback), |
| 96 weak_ptr_factory_(this) {} | 96 weak_ptr_factory_(this) {} |
| 97 | 97 |
| 98 void RestrictToProfilePath(const std::string& profile_path) { |
| 99 restrict_to_profile_path_ = profile_path; |
| 100 } |
| 101 |
| 98 void Run() { | 102 void Run() { |
| 99 DBusThreadManager::Get() | 103 DBusThreadManager::Get() |
| 100 ->GetShillServiceClient() | 104 ->GetShillServiceClient() |
| 101 ->GetLoadableProfileEntries( | 105 ->GetLoadableProfileEntries( |
| 102 dbus::ObjectPath(service_path_), | 106 dbus::ObjectPath(service_path_), |
| 103 base::Bind(&ProfileEntryDeleter::GetProfileEntriesToDeleteCallback, | 107 base::Bind(&ProfileEntryDeleter::GetProfileEntriesToDeleteCallback, |
| 104 weak_ptr_factory_.GetWeakPtr())); | 108 weak_ptr_factory_.GetWeakPtr())); |
| 105 } | 109 } |
| 106 | 110 |
| 107 private: | 111 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 125 if (profile_path.empty() || entry_path.empty()) { | 129 if (profile_path.empty() || entry_path.empty()) { |
| 126 NET_LOG(ERROR) << "Failed to parse Profile Entry: " << profile_path | 130 NET_LOG(ERROR) << "Failed to parse Profile Entry: " << profile_path |
| 127 << ": " << entry_path; | 131 << ": " << entry_path; |
| 128 continue; | 132 continue; |
| 129 } | 133 } |
| 130 if (profile_delete_entries_.count(profile_path) != 0) { | 134 if (profile_delete_entries_.count(profile_path) != 0) { |
| 131 NET_LOG(ERROR) << "Multiple Profile Entries: " << profile_path << ": " | 135 NET_LOG(ERROR) << "Multiple Profile Entries: " << profile_path << ": " |
| 132 << entry_path; | 136 << entry_path; |
| 133 continue; | 137 continue; |
| 134 } | 138 } |
| 139 |
| 140 if (!restrict_to_profile_path_.empty() && |
| 141 profile_path != restrict_to_profile_path_) { |
| 142 NET_LOG(DEBUG) << "Skip deleting Profile Entry: " << profile_path |
| 143 << ": " << entry_path << " - removal is restricted to " |
| 144 << restrict_to_profile_path_ << " profile"; |
| 145 continue; |
| 146 } |
| 147 |
| 135 NET_LOG(DEBUG) << "Delete Profile Entry: " << profile_path << ": " | 148 NET_LOG(DEBUG) << "Delete Profile Entry: " << profile_path << ": " |
| 136 << entry_path; | 149 << entry_path; |
| 137 profile_delete_entries_[profile_path] = entry_path; | 150 profile_delete_entries_[profile_path] = entry_path; |
| 138 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( | 151 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( |
| 139 dbus::ObjectPath(profile_path), entry_path, | 152 dbus::ObjectPath(profile_path), entry_path, |
| 140 base::Bind(&ProfileEntryDeleter::ProfileEntryDeletedCallback, | 153 base::Bind(&ProfileEntryDeleter::ProfileEntryDeletedCallback, |
| 141 weak_ptr_factory_.GetWeakPtr(), profile_path, entry_path), | 154 weak_ptr_factory_.GetWeakPtr(), profile_path, entry_path), |
| 142 base::Bind(&ProfileEntryDeleter::ShillErrorCallback, | 155 base::Bind(&ProfileEntryDeleter::ShillErrorCallback, |
| 143 weak_ptr_factory_.GetWeakPtr(), profile_path, entry_path)); | 156 weak_ptr_factory_.GetWeakPtr(), profile_path, entry_path)); |
| 144 } | 157 } |
| 158 |
| 159 RunCallbackIfDone(); |
| 145 } | 160 } |
| 146 | 161 |
| 147 void ProfileEntryDeletedCallback(const std::string& profile_path, | 162 void ProfileEntryDeletedCallback(const std::string& profile_path, |
| 148 const std::string& entry) { | 163 const std::string& entry) { |
| 149 NET_LOG(DEBUG) << "Profile Entry Deleted: " << profile_path << ": " | 164 NET_LOG(DEBUG) << "Profile Entry Deleted: " << profile_path << ": " |
| 150 << entry; | 165 << entry; |
| 151 profile_delete_entries_.erase(profile_path); | 166 profile_delete_entries_.erase(profile_path); |
| 167 |
| 168 RunCallbackIfDone(); |
| 169 } |
| 170 |
| 171 void RunCallbackIfDone() { |
| 152 if (!profile_delete_entries_.empty()) | 172 if (!profile_delete_entries_.empty()) |
| 153 return; | 173 return; |
| 154 // Run the callback if this is the last pending deletion. | 174 // Run the callback if this is the last pending deletion. |
| 155 if (!callback_.is_null()) | 175 if (!callback_.is_null()) |
| 156 callback_.Run(); | 176 callback_.Run(); |
| 157 // ProfileEntryDeleterCompleted will delete this. | 177 // ProfileEntryDeleterCompleted will delete this. |
| 158 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, | 178 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, |
| 159 true /* success */); | 179 true /* success */); |
| 160 } | 180 } |
| 161 | 181 |
| 162 void ShillErrorCallback(const std::string& profile_path, | 182 void ShillErrorCallback(const std::string& profile_path, |
| 163 const std::string& entry, | 183 const std::string& entry, |
| 164 const std::string& dbus_error_name, | 184 const std::string& dbus_error_name, |
| 165 const std::string& dbus_error_message) { | 185 const std::string& dbus_error_message) { |
| 166 // Any Shill Error triggers a failure / error. | 186 // Any Shill Error triggers a failure / error. |
| 167 network_handler::ShillErrorCallbackFunction( | 187 network_handler::ShillErrorCallbackFunction( |
| 168 "GetLoadableProfileEntries Failed", profile_path, error_callback_, | 188 "GetLoadableProfileEntries Failed", profile_path, error_callback_, |
| 169 dbus_error_name, dbus_error_message); | 189 dbus_error_name, dbus_error_message); |
| 170 // Delete this even if there are pending deletions; any callbacks will | 190 // Delete this even if there are pending deletions; any callbacks will |
| 171 // safely become no-ops (by invalidating the WeakPtrs). | 191 // safely become no-ops (by invalidating the WeakPtrs). |
| 172 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, | 192 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, |
| 173 false /* failed */); | 193 false /* failed */); |
| 174 } | 194 } |
| 175 | 195 |
| 176 NetworkConfigurationHandler* owner_; // Unowned | 196 NetworkConfigurationHandler* owner_; // Unowned |
| 177 std::string service_path_; | 197 std::string service_path_; |
| 198 // Non empty if the service has to be removed only from a single profile. This |
| 199 // value is the profile path of the profile in question. |
| 200 std::string restrict_to_profile_path_; |
| 178 std::string guid_; | 201 std::string guid_; |
| 179 NetworkConfigurationObserver::Source source_; | 202 NetworkConfigurationObserver::Source source_; |
| 180 base::Closure callback_; | 203 base::Closure callback_; |
| 181 network_handler::ErrorCallback error_callback_; | 204 network_handler::ErrorCallback error_callback_; |
| 182 | 205 |
| 183 // Map of pending profile entry deletions, indexed by profile path. | 206 // Map of pending profile entry deletions, indexed by profile path. |
| 184 std::map<std::string, std::string> profile_delete_entries_; | 207 std::map<std::string, std::string> profile_delete_entries_; |
| 185 | 208 |
| 186 base::WeakPtrFactory<ProfileEntryDeleter> weak_ptr_factory_; | 209 base::WeakPtrFactory<ProfileEntryDeleter> weak_ptr_factory_; |
| 187 | 210 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 base::Passed(&properties_copy), callback), | 353 base::Passed(&properties_copy), callback), |
| 331 base::Bind(&network_handler::ShillErrorCallbackFunction, | 354 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 332 "Config.CreateConfiguration Failed", "", error_callback)); | 355 "Config.CreateConfiguration Failed", "", error_callback)); |
| 333 } | 356 } |
| 334 | 357 |
| 335 void NetworkConfigurationHandler::RemoveConfiguration( | 358 void NetworkConfigurationHandler::RemoveConfiguration( |
| 336 const std::string& service_path, | 359 const std::string& service_path, |
| 337 NetworkConfigurationObserver::Source source, | 360 NetworkConfigurationObserver::Source source, |
| 338 const base::Closure& callback, | 361 const base::Closure& callback, |
| 339 const network_handler::ErrorCallback& error_callback) { | 362 const network_handler::ErrorCallback& error_callback) { |
| 363 RemoveConfigurationFromProfile(service_path, "", source, callback, |
| 364 error_callback); |
| 365 } |
| 366 |
| 367 void NetworkConfigurationHandler::RemoveConfigurationFromCurrentProfile( |
| 368 const std::string& service_path, |
| 369 NetworkConfigurationObserver::Source source, |
| 370 const base::Closure& callback, |
| 371 const network_handler::ErrorCallback& error_callback) { |
| 372 const NetworkState* network_state = |
| 373 network_state_handler_->GetNetworkState(service_path); |
| 374 |
| 375 if (!network_state || network_state->profile_path().empty()) { |
| 376 InvokeErrorCallback(service_path, error_callback, "NetworkNotConfigured"); |
| 377 return; |
| 378 } |
| 379 RemoveConfigurationFromProfile(service_path, network_state->profile_path(), |
| 380 source, callback, error_callback); |
| 381 } |
| 382 |
| 383 void NetworkConfigurationHandler::RemoveConfigurationFromProfile( |
| 384 const std::string& service_path, |
| 385 const std::string& profile_path, |
| 386 NetworkConfigurationObserver::Source source, |
| 387 const base::Closure& callback, |
| 388 const network_handler::ErrorCallback& error_callback) { |
| 340 // Service.Remove is not reliable. Instead, request the profile entries | 389 // Service.Remove is not reliable. Instead, request the profile entries |
| 341 // for the service and remove each entry. | 390 // for the service and remove each entry. |
| 342 if (base::ContainsKey(profile_entry_deleters_, service_path)) { | 391 if (base::ContainsKey(profile_entry_deleters_, service_path)) { |
| 343 InvokeErrorCallback(service_path, error_callback, | 392 InvokeErrorCallback(service_path, error_callback, |
| 344 "RemoveConfigurationInProgress"); | 393 "RemoveConfigurationInProgress"); |
| 345 return; | 394 return; |
| 346 } | 395 } |
| 347 | 396 |
| 348 std::string guid; | 397 std::string guid; |
| 349 const NetworkState* network_state = | 398 const NetworkState* network_state = |
| 350 network_state_handler_->GetNetworkState(service_path); | 399 network_state_handler_->GetNetworkState(service_path); |
| 351 if (network_state) | 400 if (network_state) |
| 352 guid = network_state->guid(); | 401 guid = network_state->guid(); |
| 353 NET_LOG(USER) << "Remove Configuration: " << service_path; | 402 NET_LOG(USER) << "Remove Configuration: " << service_path |
| 403 << " from profiles: " |
| 404 << (!profile_path.empty() ? profile_path : "all"); |
| 354 ProfileEntryDeleter* deleter = new ProfileEntryDeleter( | 405 ProfileEntryDeleter* deleter = new ProfileEntryDeleter( |
| 355 this, service_path, guid, source, callback, error_callback); | 406 this, service_path, guid, source, callback, error_callback); |
| 407 if (!profile_path.empty()) |
| 408 deleter->RestrictToProfilePath(profile_path); |
| 356 profile_entry_deleters_[service_path] = base::WrapUnique(deleter); | 409 profile_entry_deleters_[service_path] = base::WrapUnique(deleter); |
| 357 deleter->Run(); | 410 deleter->Run(); |
| 358 } | 411 } |
| 359 | 412 |
| 360 void NetworkConfigurationHandler::SetNetworkProfile( | 413 void NetworkConfigurationHandler::SetNetworkProfile( |
| 361 const std::string& service_path, | 414 const std::string& service_path, |
| 362 const std::string& profile_path, | 415 const std::string& profile_path, |
| 363 NetworkConfigurationObserver::Source source, | 416 NetworkConfigurationObserver::Source source, |
| 364 const base::Closure& callback, | 417 const base::Closure& callback, |
| 365 const network_handler::ErrorCallback& error_callback) { | 418 const network_handler::ErrorCallback& error_callback) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 // static | 646 // static |
| 594 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( | 647 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( |
| 595 NetworkStateHandler* network_state_handler, | 648 NetworkStateHandler* network_state_handler, |
| 596 NetworkDeviceHandler* network_device_handler) { | 649 NetworkDeviceHandler* network_device_handler) { |
| 597 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); | 650 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); |
| 598 handler->Init(network_state_handler, network_device_handler); | 651 handler->Init(network_state_handler, network_device_handler); |
| 599 return handler; | 652 return handler; |
| 600 } | 653 } |
| 601 | 654 |
| 602 } // namespace chromeos | 655 } // namespace chromeos |
| OLD | NEW |