OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dbus/shill_manager_client_stub.h" | 5 #include "chromeos/dbus/shill_manager_client_stub.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (GetListProperty(flimflam::kDevicesProperty)->Remove( | 235 if (GetListProperty(flimflam::kDevicesProperty)->Remove( |
236 device_path_value, NULL)) { | 236 device_path_value, NULL)) { |
237 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 237 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void ShillManagerClientStub::ClearDevices() { | 241 void ShillManagerClientStub::ClearDevices() { |
242 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); | 242 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); |
243 } | 243 } |
244 | 244 |
| 245 void ShillManagerClientStub::ClearServices() { |
| 246 stub_properties_.Remove(flimflam::kServicesProperty, NULL); |
| 247 stub_properties_.Remove(flimflam::kServiceWatchListProperty, NULL); |
| 248 } |
| 249 |
245 void ShillManagerClientStub::AddService(const std::string& service_path, | 250 void ShillManagerClientStub::AddService(const std::string& service_path, |
246 bool add_to_watch_list) { | 251 bool add_to_watch_list) { |
247 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( | 252 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( |
248 base::Value::CreateStringValue(service_path))) { | 253 base::Value::CreateStringValue(service_path))) { |
249 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 254 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
250 } | 255 } |
251 if (add_to_watch_list) | 256 if (add_to_watch_list) |
252 AddServiceToWatchList(service_path); | 257 AddServiceToWatchList(service_path); |
253 } | 258 } |
254 | 259 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 base::ListValue* list_property = NULL; | 412 base::ListValue* list_property = NULL; |
408 if (!stub_properties_.GetListWithoutPathExpansion( | 413 if (!stub_properties_.GetListWithoutPathExpansion( |
409 property, &list_property)) { | 414 property, &list_property)) { |
410 list_property = new base::ListValue; | 415 list_property = new base::ListValue; |
411 stub_properties_.SetWithoutPathExpansion(property, list_property); | 416 stub_properties_.SetWithoutPathExpansion(property, list_property); |
412 } | 417 } |
413 return list_property; | 418 return list_property; |
414 } | 419 } |
415 | 420 |
416 bool ShillManagerClientStub::TechnologyEnabled(const std::string& type) const { | 421 bool ShillManagerClientStub::TechnologyEnabled(const std::string& type) const { |
| 422 if (type == flimflam::kTypeVPN) |
| 423 return true; // VPN is always "enabled" since there is no associated device |
417 bool enabled = false; | 424 bool enabled = false; |
418 const base::ListValue* technologies; | 425 const base::ListValue* technologies; |
419 if (stub_properties_.GetListWithoutPathExpansion( | 426 if (stub_properties_.GetListWithoutPathExpansion( |
420 flimflam::kEnabledTechnologiesProperty, &technologies)) { | 427 flimflam::kEnabledTechnologiesProperty, &technologies)) { |
421 base::StringValue type_value(type); | 428 base::StringValue type_value(type); |
422 if (technologies->Find(type_value) != technologies->end()) | 429 if (technologies->Find(type_value) != technologies->end()) |
423 enabled = true; | 430 enabled = true; |
424 } | 431 } |
425 return enabled; | 432 return enabled; |
426 } | 433 } |
427 | 434 |
428 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( | 435 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( |
429 const std::string& property) const { | 436 const std::string& property) const { |
430 base::ListValue* new_service_list = new base::ListValue; | 437 base::ListValue* new_service_list = new base::ListValue; |
431 const base::ListValue* service_list; | 438 const base::ListValue* service_list; |
432 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 439 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
433 ShillServiceClient::TestInterface* service_client = | 440 ShillServiceClient::TestInterface* service_client = |
434 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 441 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
435 for (base::ListValue::const_iterator iter = service_list->begin(); | 442 for (base::ListValue::const_iterator iter = service_list->begin(); |
436 iter != service_list->end(); ++iter) { | 443 iter != service_list->end(); ++iter) { |
437 std::string service_path; | 444 std::string service_path; |
438 if (!(*iter)->GetAsString(&service_path)) | 445 if (!(*iter)->GetAsString(&service_path)) |
439 continue; | 446 continue; |
440 const base::DictionaryValue* properties = | 447 const base::DictionaryValue* properties = |
441 service_client->GetServiceProperties(service_path); | 448 service_client->GetServiceProperties(service_path); |
| 449 if (!properties) { |
| 450 LOG(ERROR) << "Properties not found for service: " << service_path; |
| 451 continue; |
| 452 } |
442 std::string name; | 453 std::string name; |
443 properties->GetString(flimflam::kNameProperty, &name); | 454 properties->GetString(flimflam::kNameProperty, &name); |
444 std::string type; | 455 std::string type; |
445 properties->GetString(flimflam::kTypeProperty, &type); | 456 properties->GetString(flimflam::kTypeProperty, &type); |
446 if (TechnologyEnabled(type)) | 457 if (TechnologyEnabled(type)) |
447 new_service_list->Append((*iter)->DeepCopy()); | 458 new_service_list->Append((*iter)->DeepCopy()); |
448 } | 459 } |
449 } | 460 } |
450 return new_service_list; | 461 return new_service_list; |
451 } | 462 } |
452 | 463 |
453 } // namespace chromeos | 464 } // namespace chromeos |
OLD | NEW |