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 "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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 shill_manager_->RemovePropertyChangedObserver(this); | 114 shill_manager_->RemovePropertyChangedObserver(this); |
115 } | 115 } |
116 | 116 |
117 void ShillPropertyHandler::Init() { | 117 void ShillPropertyHandler::Init() { |
118 shill_manager_->GetProperties( | 118 shill_manager_->GetProperties( |
119 base::Bind(&ShillPropertyHandler::ManagerPropertiesCallback, | 119 base::Bind(&ShillPropertyHandler::ManagerPropertiesCallback, |
120 AsWeakPtr())); | 120 AsWeakPtr())); |
121 shill_manager_->AddPropertyChangedObserver(this); | 121 shill_manager_->AddPropertyChangedObserver(this); |
122 } | 122 } |
123 | 123 |
124 bool ShillPropertyHandler::TechnologyAvailable( | 124 bool ShillPropertyHandler::IsTechnologyAvailable( |
125 const std::string& technology) const { | 125 const std::string& technology) const { |
126 return available_technologies_.count(technology) != 0; | 126 return available_technologies_.count(technology) != 0; |
127 } | 127 } |
128 | 128 |
129 bool ShillPropertyHandler::TechnologyEnabled( | 129 bool ShillPropertyHandler::IsTechnologyEnabled( |
130 const std::string& technology) const { | 130 const std::string& technology) const { |
131 return enabled_technologies_.count(technology) != 0; | 131 return enabled_technologies_.count(technology) != 0; |
132 } | 132 } |
133 | 133 |
134 bool ShillPropertyHandler::TechnologyUninitialized( | 134 bool ShillPropertyHandler::IsTechnologyEnabling( |
| 135 const std::string& technology) const { |
| 136 return enabling_technologies_.count(technology) != 0; |
| 137 } |
| 138 |
| 139 bool ShillPropertyHandler::IsTechnologyUninitialized( |
135 const std::string& technology) const { | 140 const std::string& technology) const { |
136 return uninitialized_technologies_.count(technology) != 0; | 141 return uninitialized_technologies_.count(technology) != 0; |
137 } | 142 } |
138 | 143 |
139 void ShillPropertyHandler::SetTechnologyEnabled( | 144 void ShillPropertyHandler::SetTechnologyEnabled( |
140 const std::string& technology, | 145 const std::string& technology, |
141 bool enabled, | 146 bool enabled, |
142 const network_handler::ErrorCallback& error_callback) { | 147 const network_handler::ErrorCallback& error_callback) { |
143 if (enabled) { | 148 if (enabled) { |
| 149 enabling_technologies_.insert(technology); |
144 shill_manager_->EnableTechnology( | 150 shill_manager_->EnableTechnology( |
145 technology, | 151 technology, |
146 base::Bind(&base::DoNothing), | 152 base::Bind(&base::DoNothing), |
147 base::Bind(&network_handler::ShillErrorCallbackFunction, | 153 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, |
148 kLogModule, technology, error_callback)); | 154 AsWeakPtr(), technology, error_callback)); |
149 } else { | 155 } else { |
| 156 // Imediately clear locally from enabled and enabling lists. |
| 157 enabled_technologies_.erase(technology); |
| 158 enabling_technologies_.erase(technology); |
150 shill_manager_->DisableTechnology( | 159 shill_manager_->DisableTechnology( |
151 technology, | 160 technology, |
152 base::Bind(&base::DoNothing), | 161 base::Bind(&base::DoNothing), |
153 base::Bind(&network_handler::ShillErrorCallbackFunction, | 162 base::Bind(&network_handler::ShillErrorCallbackFunction, |
154 kLogModule, technology, error_callback)); | 163 kLogModule, technology, error_callback)); |
155 } | 164 } |
156 } | 165 } |
157 | 166 |
158 void ShillPropertyHandler::RequestScan() const { | 167 void ShillPropertyHandler::RequestScan() const { |
159 shill_manager_->RequestScan( | 168 shill_manager_->RequestScan( |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 enabled_technologies_.clear(); | 353 enabled_technologies_.clear(); |
345 network_event_log::AddEntry( | 354 network_event_log::AddEntry( |
346 kLogModule, "EnabledTechnologiesChanged", | 355 kLogModule, "EnabledTechnologiesChanged", |
347 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); | 356 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); |
348 for (base::ListValue::const_iterator iter = technologies.begin(); | 357 for (base::ListValue::const_iterator iter = technologies.begin(); |
349 iter != technologies.end(); ++iter) { | 358 iter != technologies.end(); ++iter) { |
350 std::string technology; | 359 std::string technology; |
351 (*iter)->GetAsString(&technology); | 360 (*iter)->GetAsString(&technology); |
352 DCHECK(!technology.empty()); | 361 DCHECK(!technology.empty()); |
353 enabled_technologies_.insert(technology); | 362 enabled_technologies_.insert(technology); |
| 363 enabling_technologies_.erase(technology); |
354 } | 364 } |
355 } | 365 } |
356 | 366 |
357 void ShillPropertyHandler::UpdateUninitializedTechnologies( | 367 void ShillPropertyHandler::UpdateUninitializedTechnologies( |
358 const base::ListValue& technologies) { | 368 const base::ListValue& technologies) { |
359 uninitialized_technologies_.clear(); | 369 uninitialized_technologies_.clear(); |
360 network_event_log::AddEntry( | 370 network_event_log::AddEntry( |
361 kLogModule, "UninitializedTechnologiesChanged", | 371 kLogModule, "UninitializedTechnologiesChanged", |
362 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); | 372 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); |
363 for (base::ListValue::const_iterator iter = technologies.begin(); | 373 for (base::ListValue::const_iterator iter = technologies.begin(); |
364 iter != technologies.end(); ++iter) { | 374 iter != technologies.end(); ++iter) { |
365 std::string technology; | 375 std::string technology; |
366 (*iter)->GetAsString(&technology); | 376 (*iter)->GetAsString(&technology); |
367 DCHECK(!technology.empty()); | 377 DCHECK(!technology.empty()); |
368 uninitialized_technologies_.insert(technology); | 378 uninitialized_technologies_.insert(technology); |
369 } | 379 } |
370 } | 380 } |
371 | 381 |
| 382 void ShillPropertyHandler::EnableTechnologyFailed( |
| 383 const std::string& technology, |
| 384 const network_handler::ErrorCallback& error_callback, |
| 385 const std::string& error_name, |
| 386 const std::string& error_message) { |
| 387 enabling_technologies_.erase(technology); |
| 388 network_handler::ShillErrorCallbackFunction( |
| 389 kLogModule, technology, error_callback, error_name, error_message); |
| 390 } |
| 391 |
372 void ShillPropertyHandler::GetPropertiesCallback( | 392 void ShillPropertyHandler::GetPropertiesCallback( |
373 ManagedState::ManagedType type, | 393 ManagedState::ManagedType type, |
374 const std::string& path, | 394 const std::string& path, |
375 DBusMethodCallStatus call_status, | 395 DBusMethodCallStatus call_status, |
376 const base::DictionaryValue& properties) { | 396 const base::DictionaryValue& properties) { |
377 VLOG(2) << "GetPropertiesCallback: " << type << " : " << path; | 397 VLOG(2) << "GetPropertiesCallback: " << type << " : " << path; |
378 pending_updates_[type].erase(path); | 398 pending_updates_[type].erase(path); |
379 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 399 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
380 LOG(ERROR) << "Failed to get properties for: " << path | 400 LOG(ERROR) << "Failed to get properties for: " << path |
381 << ": " << call_status; | 401 << ": " << call_status; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 485 |
466 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( | 486 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( |
467 const std::string& path, | 487 const std::string& path, |
468 const std::string& key, | 488 const std::string& key, |
469 const base::Value& value) { | 489 const base::Value& value) { |
470 listener_->UpdateDeviceProperty(path, key, value); | 490 listener_->UpdateDeviceProperty(path, key, value); |
471 } | 491 } |
472 | 492 |
473 } // namespace internal | 493 } // namespace internal |
474 } // namespace chromeos | 494 } // namespace chromeos |
OLD | NEW |