Chromium Code Reviews| 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/shill_property_handler.h" | 5 #include "chromeos/network/shill_property_handler.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | |
|
stevenjb
2015/11/11 18:07:31
not needed?
fqj
2015/11/12 10:23:01
Needed.
// Send updated prohibited technology l
| |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" | 15 #include "chromeos/dbus/shill_device_client.h" |
| 15 #include "chromeos/dbus/shill_ipconfig_client.h" | 16 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 16 #include "chromeos/dbus/shill_manager_client.h" | 17 #include "chromeos/dbus/shill_manager_client.h" |
| 17 #include "chromeos/dbus/shill_profile_client.h" | 18 #include "chromeos/dbus/shill_profile_client.h" |
| 18 #include "chromeos/dbus/shill_service_client.h" | 19 #include "chromeos/dbus/shill_service_client.h" |
| 20 #include "chromeos/network/managed_network_configuration_handler.h" | |
| 21 #include "chromeos/network/network_handler.h" | |
| 22 #include "chromeos/network/network_handler_callbacks.h" | |
|
stevenjb
2015/11/11 18:07:31
Not needed
fqj
2015/11/12 10:23:01
Done.
| |
| 19 #include "chromeos/network/network_state.h" | 23 #include "chromeos/network/network_state.h" |
| 20 #include "components/device_event_log/device_event_log.h" | 24 #include "components/device_event_log/device_event_log.h" |
| 21 #include "dbus/object_path.h" | 25 #include "dbus/object_path.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 27 |
| 24 namespace { | 28 namespace { |
| 25 | 29 |
| 26 // Limit the number of services or devices we observe. Since they are listed in | 30 // Limit the number of services or devices we observe. Since they are listed in |
| 27 // priority order, it should be reasonable to ignore services past this. | 31 // priority order, it should be reasonable to ignore services past this. |
| 28 const size_t kMaxObserved = 100; | 32 const size_t kMaxObserved = 100; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 Handler handler_; | 101 Handler handler_; |
| 98 | 102 |
| 99 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); | 103 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 //------------------------------------------------------------------------------ | 106 //------------------------------------------------------------------------------ |
| 103 // ShillPropertyHandler | 107 // ShillPropertyHandler |
| 104 | 108 |
| 105 ShillPropertyHandler::ShillPropertyHandler(Listener* listener) | 109 ShillPropertyHandler::ShillPropertyHandler(Listener* listener) |
| 106 : listener_(listener), | 110 : listener_(listener), |
| 107 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) { | 111 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) {} |
| 108 } | |
| 109 | 112 |
| 110 ShillPropertyHandler::~ShillPropertyHandler() { | 113 ShillPropertyHandler::~ShillPropertyHandler() { |
| 111 // Delete network service observers. | 114 // Delete network service observers. |
| 112 STLDeleteContainerPairSecondPointers(observed_networks_.begin(), | 115 STLDeleteContainerPairSecondPointers(observed_networks_.begin(), |
| 113 observed_networks_.end()); | 116 observed_networks_.end()); |
| 114 STLDeleteContainerPairSecondPointers(observed_devices_.begin(), | 117 STLDeleteContainerPairSecondPointers(observed_devices_.begin(), |
| 115 observed_devices_.end()); | 118 observed_devices_.end()); |
| 116 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); | 119 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); |
| 117 shill_manager_->RemovePropertyChangedObserver(this); | 120 shill_manager_->RemovePropertyChangedObserver(this); |
| 118 } | 121 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 146 bool ShillPropertyHandler::IsTechnologyUninitialized( | 149 bool ShillPropertyHandler::IsTechnologyUninitialized( |
| 147 const std::string& technology) const { | 150 const std::string& technology) const { |
| 148 return uninitialized_technologies_.count(technology) != 0; | 151 return uninitialized_technologies_.count(technology) != 0; |
| 149 } | 152 } |
| 150 | 153 |
| 151 void ShillPropertyHandler::SetTechnologyEnabled( | 154 void ShillPropertyHandler::SetTechnologyEnabled( |
| 152 const std::string& technology, | 155 const std::string& technology, |
| 153 bool enabled, | 156 bool enabled, |
| 154 const network_handler::ErrorCallback& error_callback) { | 157 const network_handler::ErrorCallback& error_callback) { |
| 155 if (enabled) { | 158 if (enabled) { |
| 159 if (prohibited_technologies_.find(technology) != | |
| 160 prohibited_technologies_.end()) { | |
| 161 chromeos::network_handler::RunErrorCallback( | |
| 162 error_callback, "", "prohibited_technologies", | |
| 163 "Ignored: Attempt to enable prohibited network technology " + | |
| 164 technology); | |
|
stevenjb
2015/11/11 18:07:31
Align
fqj
2015/11/12 10:23:01
Not modified.
Actually, git cl format made it like
stevenjb
2015/11/12 18:20:38
Sorry, you're right, didn't notice there was a + o
| |
| 165 return; | |
| 166 } | |
| 156 enabling_technologies_.insert(technology); | 167 enabling_technologies_.insert(technology); |
| 157 shill_manager_->EnableTechnology( | 168 shill_manager_->EnableTechnology( |
| 158 technology, base::Bind(&base::DoNothing), | 169 technology, base::Bind(&base::DoNothing), |
| 159 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, AsWeakPtr(), | 170 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, AsWeakPtr(), |
| 160 technology, error_callback)); | 171 technology, error_callback)); |
| 161 } else { | 172 } else { |
| 162 // Immediately clear locally from enabled and enabling lists. | 173 // Immediately clear locally from enabled and enabling lists. |
| 163 enabled_technologies_.erase(technology); | 174 enabled_technologies_.erase(technology); |
| 164 enabling_technologies_.erase(technology); | 175 enabling_technologies_.erase(technology); |
| 165 shill_manager_->DisableTechnology( | 176 shill_manager_->DisableTechnology( |
| 166 technology, base::Bind(&base::DoNothing), | 177 technology, base::Bind(&base::DoNothing), |
| 167 base::Bind(&network_handler::ShillErrorCallbackFunction, | 178 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 168 "SetTechnologyEnabled Failed", technology, error_callback)); | 179 "SetTechnologyEnabled Failed", technology, error_callback)); |
| 169 } | 180 } |
| 170 } | 181 } |
| 171 | 182 |
| 183 void ShillPropertyHandler::SetProhibitedTechnologies( | |
| 184 const std::vector<std::string>& prohibited_technologies, | |
| 185 const network_handler::ErrorCallback& error_callback) { | |
| 186 // Remove technologies from the other lists. | |
|
stevenjb
2015/11/11 18:07:31
Update / move comment
fqj
2015/11/12 10:23:01
Done.
| |
| 187 for (const auto& technology : prohibited_technologies) | |
| 188 prohibited_technologies_.insert(technology); | |
| 189 for (auto iter_prohibited_technology = prohibited_technologies_.begin(); | |
| 190 iter_prohibited_technology != prohibited_technologies_.end();) { | |
| 191 if (std::find(prohibited_technologies.begin(), | |
| 192 prohibited_technologies.end(), | |
| 193 *iter_prohibited_technology) == prohibited_technologies.end()) | |
| 194 iter_prohibited_technology = | |
| 195 prohibited_technologies_.erase(iter_prohibited_technology); | |
| 196 else | |
| 197 iter_prohibited_technology++; | |
|
stevenjb
2015/11/11 18:07:31
{}
fqj
2015/11/12 10:23:01
189-197 no longer used.
| |
| 198 } | |
|
stevenjb
2015/11/11 18:07:31
Why not just clear prohibited_technologies_ and re
fqj
2015/11/12 10:23:01
Done.
But is it possible trying SetTechnologyEnabl
stevenjb
2015/11/12 18:20:38
No. DBus calls must all be made from the UI thread
| |
| 199 | |
| 200 for (const auto& technology : prohibited_technologies) { | |
| 201 enabling_technologies_.erase(technology); | |
| 202 enabled_technologies_.erase(technology); | |
| 203 shill_manager_->DisableTechnology( | |
| 204 technology, base::Bind(&base::DoNothing), | |
| 205 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
| 206 "DisableTechnology Failed", technology, error_callback)); | |
| 207 } | |
| 208 | |
| 209 // Send updated prohibited technology list to shill. | |
| 210 const std::string prohibited_list = | |
| 211 base::JoinString(prohibited_technologies, ","); | |
| 212 base::StringValue value(prohibited_list); | |
| 213 shill_manager_->SetProperty( | |
| 214 "ProhibitedTechnologies", value, base::Bind(&base::DoNothing), | |
| 215 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
| 216 "SetTechnologiesProhibited Failed", prohibited_list, | |
| 217 error_callback)); | |
| 218 } | |
| 219 | |
| 172 void ShillPropertyHandler::SetCheckPortalList( | 220 void ShillPropertyHandler::SetCheckPortalList( |
| 173 const std::string& check_portal_list) { | 221 const std::string& check_portal_list) { |
| 174 base::StringValue value(check_portal_list); | 222 base::StringValue value(check_portal_list); |
| 175 shill_manager_->SetProperty( | 223 shill_manager_->SetProperty( |
| 176 shill::kCheckPortalListProperty, value, base::Bind(&base::DoNothing), | 224 shill::kCheckPortalListProperty, value, base::Bind(&base::DoNothing), |
| 177 base::Bind(&network_handler::ShillErrorCallbackFunction, | 225 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 178 "SetCheckPortalList Failed", "Manager", | 226 "SetCheckPortalList Failed", "Manager", |
| 179 network_handler::ErrorCallback())); | 227 network_handler::ErrorCallback())); |
| 180 } | 228 } |
| 181 | 229 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 NET_LOG(EVENT) << "Failed to get IP Config properties: " << ip_config_path | 564 NET_LOG(EVENT) << "Failed to get IP Config properties: " << ip_config_path |
| 517 << ": " << call_status << ", For: " << path; | 565 << ": " << call_status << ", For: " << path; |
| 518 return; | 566 return; |
| 519 } | 567 } |
| 520 NET_LOG(EVENT) << "IP Config properties received: " << path; | 568 NET_LOG(EVENT) << "IP Config properties received: " << path; |
| 521 listener_->UpdateIPConfigProperties(type, path, ip_config_path, properties); | 569 listener_->UpdateIPConfigProperties(type, path, ip_config_path, properties); |
| 522 } | 570 } |
| 523 | 571 |
| 524 } // namespace internal | 572 } // namespace internal |
| 525 } // namespace chromeos | 573 } // namespace chromeos |
| OLD | NEW |